Skip to content

Commit

Permalink
Rough implementaion of escaping for TGs (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Nov 14, 2015
1 parent da727a8 commit 97973dd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pacmacs-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ side-effects."
(cdr (assoc direction-vector
direction-table))))

(defun pacmacs--opposite-direction-name (direction-name)
(cl-case direction-name
('left 'right)
('right 'left)
('up 'down)
('down 'up)))

(defun pacmacs--levelname-from-filename (filename)
(when (string-match "\\(map[0-9]+\\)\\.txt" filename)
(match-string 1 filename)))
Expand Down
14 changes: 14 additions & 0 deletions pacmacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,13 @@
(let ((direction (pacmacs--cell-wrapped-get pacmacs--track-board row column)))
(pacmacs--switch-direction game-object direction))))

(defun pacmacs--back-track-object (game-object)
(plist-bind ((row :row)
(column :column))
game-object
(let ((direction (pacmacs--cell-wrapped-get pacmacs--track-board row column)))
(pacmacs--switch-direction game-object (pacmacs--opposite-direction-name direction)))))

(defun pacmacs-tick ()
(interactive)

Expand All @@ -358,6 +365,11 @@
(pacmacs--track-object ghost)
(pacmacs--step-object ghost)))

(defun pacmacs--step-terrified-ghosts ()
(dolist (terrified-ghost pacmacs--terrified-ghosts)
(pacmacs--back-track-object terrified-ghost)
(pacmacs--step-object terrified-ghost)))

(defun pacmacs--detect-pill-collision ()
(plist-bind ((row :row)
(column :column))
Expand All @@ -378,6 +390,7 @@
(pacmacs--anim-object-next-frame pacmacs--player-state pacmacs-tick-duration-ms)
(pacmacs--anim-object-list-next-frame pacmacs--ghosts pacmacs-tick-duration-ms)
(pacmacs--anim-object-list-next-frame pacmacs--pills pacmacs-tick-duration-ms)
(pacmacs--anim-object-list-next-frame pacmacs--terrified-ghosts pacmacs-tick-duration-ms)

(pacmacs--recalc-track-board)
(if pacmacs--pills
Expand All @@ -388,6 +401,7 @@
(pacmacs--switch-to-death-state))
(pacmacs--detect-pill-collision)
(pacmacs--step-ghosts)
(pacmacs--step-terrified-ghosts)
(when (pacmacs--ghost-collision-p)
(dolist (ghost pacmacs--ghosts)
(pacmacs--step-back-object ghost))
Expand Down

0 comments on commit 97973dd

Please sign in to comment.