~octaspire/crates2

fa55e9988f115fe5f330dabca4b25a082884a180 — octaspire 10 months ago 7254013
Purge lamented crates, add 'on-which-side-i-am'
M doc/TODO.org => doc/TODO.org +1 -1
@@ 1,1 1,1 @@
- Add delay into vacuum to leave time for animations.
Empty.

M src/classes.lisp => src/classes.lisp +5 -5
@@ 36,7 36,10 @@
             :accessor velocity)
   (active :initarg :active
           :initform t
           :accessor active)))
           :accessor active)
   (lamented :initarg lamented
             :initform nil
             :accessor lamented)))

(defclass wall (crate)
  ())


@@ 53,10 56,7 @@
          :initform 0)))

(defclass player (moving)
  ((lamented :initarg lamented
             :initform nil
             :accessor lamented)
   (delay :initform 0
  ((delay :initform 0
          :accessor player-delay)))

(defclass vacuum (crate)

M src/crate.lisp => src/crate.lisp +0 -3
@@ 34,9 34,6 @@
(defgeneric visual (self)
  (:documentation "Get visual representation for a crate"))

(defgeneric collide (moving target)
  (:documentation "Handle MOVING crate colliding into TARGET"))

(defgeneric handle-input (self input)
  (:documentation "React to input"))


M src/exit.lisp => src/exit.lisp +1 -1
@@ 32,4 32,4 @@

(defmethod collide ((self exit) (target player))
  (setf (exit-activated self) t)
  (setf (crate-state self) :activated))
\ No newline at end of file
  (setf (crate-state self) :activated))

M src/level.lisp => src/level.lisp +13 -2
@@ 18,11 18,22 @@

(defmethod update ((self list))
  (let ((level (get-current-level)))
    (when (runningp) (loop for crate in level
                           do (update crate)))))
    (when (runningp)
      (loop for crate in level
            do (update crate))
      (purge-lamented))))

(defmethod render ((self list))
  (when (runningp)
    (let ((level (get-current-level)))
      (loop for crate in level
            do (render crate)))))

;; Functions

(defun purge-lamented ()
  (setf *level* (remove-if #'(lambda (crate)
                               (let ((type (type-of crate)))
                                 (and (subtypep type 'moving)
                                      (not (eq type 'player))
                                      (lamented crate)))) *level*)))

M src/levels.lisp => src/levels.lisp +2 -1
@@ 23,7 23,8 @@

(defun load-level-0 ()
  (list (make-instance 'exit     :x 1 :y 3 :z 0)
        (make-instance 'player   :x 5 :y 3 :z 0)))
        (make-instance 'player   :x 3 :y 3 :z 0)
        (make-instance 'pushed   :x 5 :y 3 :z 0)))

(defun load-level-1 ()
  (list (make-instance 'exit     :x 1 :y 2 :z 0)

M src/main.lisp => src/main.lisp +2 -0
@@ 19,6 19,7 @@
(defparameter *version-minor* 1)
(defparameter *version-patch* 0)
(defparameter *errors* nil)
(defparameter *update-counter* 0)
(defparameter *input* nil)
(defparameter *level-number* -1)
(defparameter *running* t)


@@ 74,6 75,7 @@
             (update *level*)
             (when *next-level*
               (load-next-level))
             (incf *update-counter*)
             (sleep 2))))

(defun usage ()

M src/moving.lisp => src/moving.lisp +4 -1
@@ 16,6 16,9 @@

;; Generic functions

(defgeneric collide (self other)
  (:documentation "Collide SELF with OTHER"))

(defgeneric movingp (self)
  (:documentation "Predicate telling whether moving SELF is in motion"))



@@ 82,8 85,8 @@

(defmethod escape ((self moving))
  (setf (active self) nil)
  (setf (lamented self) t)
  (when (typep self 'player)
    (setf (lamented self) t)
    (request-restart-level)))

(defmethod collide ((self moving) (target crate))

M src/player.lisp => src/player.lisp +1 -1
@@ 65,4 65,4 @@
(defun player-update-lamented (self)
  (incf (player-delay self))
  (when (> (player-delay self) 3)
    (request-restart-level)))
\ No newline at end of file
    (request-restart-level)))

M src/simple-crates.lisp => src/simple-crates.lisp +3 -0
@@ 24,6 24,9 @@
(defmethod visual ((self wall))
  #\x)

(defmethod collide ((self pushed) (target moving))
  (setf (velocity self) (on-which-side-i-am self target)))

(defmethod visual ((self pushed))
  #\p)


M src/textual.lisp => src/textual.lisp +7 -2
@@ 29,7 29,10 @@
          do (setf (aref a i) (empty-line)))
    a))

(defparameter *fake-input* (list :west nil nil nil nil nil nil nil :west))
(defparameter *fake-input*
  (list nil :east nil nil nil nil nil nil nil nil nil nil nil nil nil nil
        :west nil nil nil nil nil nil nil ; 1
        :west))
(defparameter *last-fake-input* nil)

(defun ui-input ()


@@ 65,6 68,8 @@
          do (format t "~A|~A|" (mod y 10) line)
             (if (= y 0)
                 (format t " Input: ~@[~A~]~%" *last-fake-input*)
                 (format t "~%")))
                 (if (= y 1)
                     (format t " #updates: ~A~%" *update-counter*)
                     (format t "~%"))))
    (format t " +~A+~%" bar))
  (setf *last-fake-input* nil))
\ No newline at end of file

M src/utils.lisp => src/utils.lisp +20 -1
@@ 44,4 44,23 @@ directions."
    (:west  (if (eq v2 :east)  t nil))
    (:north (if (eq v2 :south) t nil))
    (:south (if (eq v2 :north) t nil))
    (:zero  nil)))
\ No newline at end of file
    (:zero  nil)))

(defun on-which-side-i-am (i other)
  (let ((ix (crate-x i))
        (iy (crate-y i))
        (ox (crate-x other))
        (oy (crate-y other)))
    (if (= iy oy)
        (if (= ix (- ox 1))
            :west
            (if (= ix (+ ox 1))
                :east
                :zero))
        (if (= ix ox)
            (if (= iy (- oy 1))
                :north
                (if (= iy (+ oy 1))
                    :south
                    :zero))
            :zero))))

M src/vacuum.lisp => src/vacuum.lisp +1 -1
@@ 30,4 30,4 @@

(defmethod collide ((self vacuum) (target player))
  (setf (crate-state self) :activated)
  (setf (full self) t))
\ No newline at end of file
  (setf (full self) t))