;; This file is part of Menace of the Mines.
;; Menace of the Mines is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; Menace of the Mines is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with Menace of the Mines in the file COPYING. If not, see <http://www.gnu.org/licenses/>.
(in-package :motm)
(defun mov-handler (char xadj yadj)
(defmethod _handle-key ((int (eql (char-code char))) (window (eql :game)) (mode (eql :command)))
(when (movep (+ xadj (player-x)) (+ yadj (player-y)))
(mov (player-x) (player-y) (+ xadj (player-x)) (+ yadj (player-y)) 'terrain)
(setf (player-x) (+ xadj (player-x)) (player-y) (+ yadj (player-y))))
(when (option :debug) (attrs :message (COLOR_PAIR 2)) (message "The player's at ~a ~a"(player-x) (player-y)) (attrs :message A_NORMAL))))
(mov-handler #\h -1 0)
(mov-handler #\l 1 0)
(mov-handler #\k 0 -1)
(mov-handler #\j 0 1)
(mov-handler #\y -1 -1)
(mov-handler #\u 1 -1)
(mov-handler #\b -1 1)
(mov-handler #\n 1 1)
(defmethod _handle-key (int window mode)
(if (option :debug) (message "ERROR: Pressed invalid key ~a ~s ~s" (code-char int) window mode)))
(defmethod _handle-key ((int (eql (char-code #\Q))) (window (eql :game)) (mode (eql :command)))
(motm-quit))
(defmethod _handle-key ((int (eql (char-code #\S))) (window (eql :game)) (mode (eql :command)))
(save))
(defmethod _handle-key ((int (eql (char-code #\i))) (window (eql :game)) (mode (eql :command)))
(setf (active-window) :status)
(printf :status "Press any key")
(draw *display*)
(message "You pressed ~a" (handle-key (getch)))
(werase (window :status))
(setf (active-window) :game))
(defmethod _handle-key (int (window (eql :status)) (mode (eql :press-one)))
(code-char int))
(defmethod _handle-key ((int (eql 27)) (window (eql :game)) (mode (eql :command)))
(setf (mode) :escape))
(defmethod _handle-key ((int (eql (char-code #\d))) (window (eql :game)) (mode (eql :escape)))
(setf (option :debug) (if (eql (option :debug) nil) t nil))
(setf (mode) :command))
;;Synomyms
(defun synonym-key (new-int old-int window mode)
(defmethod _handle-key ((int (eql new-int)) (window (eql window)) (mode (eql mode)))
(_handle-key old-int window mode)))
(synonym-key 258 (char-code #\j) :game :command)
(synonym-key 259 (char-code #\k) :game :command)
(synonym-key 260 (char-code #\h) :game :command)
(synonym-key 261 (char-code #\l) :game :command)
(synonym-key (char-code #\4) (char-code #\h) :game :command)
(synonym-key (char-code #\6) (char-code #\l) :game :command)
(synonym-key (char-code #\8) (char-code #\k) :game :command)
(synonym-key (char-code #\2) (char-code #\j) :game :command)
(synonym-key (char-code #\7) (char-code #\y) :game :command)
(synonym-key (char-code #\9) (char-code #\u) :game :command)
(synonym-key (char-code #\1) (char-code #\b) :game :command)
(synonym-key (char-code #\3) (char-code #\n) :game :command)