~octaspire/crates2

e8da88fc5f3821b47e1e0a4aa65a48716ac3cf61 — octaspire 9 months ago 54868df
Add 'Key'
8 files changed, 50 insertions(+), 5 deletions(-)

M crates2.asd
M src/classes.lisp
M src/exit.lisp
A src/key.lisp
M src/level.lisp
M src/levels.lisp
M src/main.lisp
M src/textual.lisp
M crates2.asd => crates2.asd +1 -0
@@ 24,6 24,7 @@
                 (:file "moving")
                 (:file "simple-crates")
                 (:file "exit")
                 (:file "key")
                 (:file "player")
                 (:file "slopes")
                 (:file "turnstiles")

M src/classes.lisp => src/classes.lisp +3 -0
@@ 125,6 125,9 @@
          :accessor exit-delay
          :initform 0)))

(defclass key (crate)
  ())

(defclass player (moving)
  ((delay :initform 0
          :accessor player-delay)))

M src/exit.lisp => src/exit.lisp +3 -1
@@ 22,7 22,9 @@
    (:activated
     (if (< (exit-delay self) 3)
         (incf (exit-delay self))
         (request-next-level))))
         (if (contains-keys-p)
             (request-restart-level)
             (request-next-level)))))
  (call-next-method))

(defmethod visual ((self exit))

A src/key.lisp => src/key.lisp +27 -0
@@ 0,0 1,27 @@
;; Octaspire Crates 2 - Puzzle Game
;; Copyright 2020 octaspire.com
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
(in-package :crates2)

;; Methods

(defmethod visual ((self key))
  "key-idle")

(defmethod collide ((self key) (target player))
  (ecase (crate-state self)
    (:idle
     (setf (velocity target) (on-which-side-i-am self target))
     (lament self))
    (:lamented nil)))

M src/level.lisp => src/level.lisp +4 -0
@@ 32,6 32,10 @@

;; Functions

(defun contains-keys-p ()
  (find-if #'(lambda (crate)
               (eq (type-of crate) 'key)) *level*))

(defun purge-lamented ()
  (setf *level* (remove-if #'(lambda (crate)
                               (let ((type (type-of crate)))

M src/levels.lisp => src/levels.lisp +8 -2
@@ 14,7 14,7 @@
;; limitations under the License.
(in-package :crates2)

(defparameter *num-levels* 14)
(defparameter *num-levels* 15)

(defun load-level (index)
  (ecase index


@@ 81,5 81,11 @@
                    (make-instance 'exit         :x 5 :y 5 :z 0)
                    (make-instance 'pass-timer   :x 4 :y 3 :z 1 :time 10)
                    (make-instance 'player       :x 6 :y 3 :z 0)
                    (make-instance 'wall         :x 8 :y 3 :z 0))))))
                    (make-instance 'wall         :x 8 :y 3 :z 0))))
    (14 (list (list nil nil nil nil :west nil nil nil nil nil nil nil nil :south)
              (list (make-instance 'wall         :x 1 :y 3 :z 0)
                    (make-instance 'exit         :x 6 :y 5 :z 0)
                    (make-instance 'exit         :x 2 :y 5 :z 0)
                    (make-instance 'key          :x 4 :y 3 :z 0)
                    (make-instance 'player       :x 6 :y 3 :z 0))))))


M src/main.lisp => src/main.lisp +2 -2
@@ 21,11 21,11 @@
(defparameter *errors* nil)
(defparameter *update-counter* 0)
(defparameter *input* nil)
(defparameter *level-number* 12)
(defparameter *level-number* 13)
(defparameter *running* t)
(defparameter *level* nil)
(defparameter *created* nil)
(defparameter *next-level* 13)
(defparameter *next-level* 14)
(defparameter *level-width* 18)
(defparameter *level-height* 12)


M src/textual.lisp => src/textual.lisp +2 -0
@@ 54,6 54,8 @@
  ;; EXIT
  (setf (gethash "exit-idle"              *visual-hash*) #("+----+" "|exit|" "+----+"))
  (setf (gethash "exit-active"            *visual-hash*) #("+----+" "|EXIT|" "+----+"))
  ;; KEY
  (setf (gethash "key-idle"               *visual-hash*) #("+----+" " KEY  " "+----+"))
  ;; PLAYER
  (setf (gethash "player-active"          *visual-hash*) #("+----+" "|oooo|" "+----+"))
  (setf (gethash "player-hidden"          *visual-hash*) #("      " "      " "      "))