branch: elpa/pacmacs
commit 86f76c4bef56663eaae2af5be1c0f972db9b23fa
Author: rexim <[email protected]>
Commit: rexim <[email protected]>
Implement switching level mechanics. Close #79
---
maps/map01.txt | 2 +-
maps/map02.txt | 2 +-
maps/map03.txt | 2 +-
maps/map04.txt | 2 +-
maps/map06.txt | 2 +-
pacmacs.el | 27 +++++++++++++++++++++++----
6 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/maps/map01.txt b/maps/map01.txt
index 9cf8388efe..674169eee4 100644
--- a/maps/map01.txt
+++ b/maps/map01.txt
@@ -2,6 +2,6 @@
#.......#####
#. . #
#.g## . ##
-#. ##g . o#
+#. ## . o#
#.......####
#########
diff --git a/maps/map02.txt b/maps/map02.txt
index dd7db15c48..fe3db346f1 100644
--- a/maps/map02.txt
+++ b/maps/map02.txt
@@ -1,5 +1,5 @@
#### ####
-# #
+#. .#
# ## ## #
# #
# ## ## #
diff --git a/maps/map03.txt b/maps/map03.txt
index fc3e294953..8935913fad 100644
--- a/maps/map03.txt
+++ b/maps/map03.txt
@@ -1,5 +1,5 @@
######
-# #
+# .#
# ## #
# ## #
# ## #
diff --git a/maps/map04.txt b/maps/map04.txt
index e748cabdc7..70d8183d9d 100644
--- a/maps/map04.txt
+++ b/maps/map04.txt
@@ -1,3 +1,3 @@
#######
- o
+. o .
#######
diff --git a/maps/map06.txt b/maps/map06.txt
index 7febcfcead..4b60914044 100644
--- a/maps/map06.txt
+++ b/maps/map06.txt
@@ -1,3 +1,3 @@
############
-#o g#
+#o . g#
############
diff --git a/pacmacs.el b/pacmacs.el
index 93ddfb68af..1bdd4bb92a 100644
--- a/pacmacs.el
+++ b/pacmacs.el
@@ -76,6 +76,10 @@
(defvar pacmacs-lives 3)
(defvar pacmacs-life-icon nil)
+(defvar pacmacs-levels ["map01" "map02" "map03"
+ "map04" "map05" "map06"])
+(defvar pacmacs-current-level 0)
+
(define-derived-mode pacmacs-mode special-mode "pacmacs-mode"
(define-key pacmacs-mode-map (kbd "<up>") 'pacmacs-up)
(define-key pacmacs-mode-map (kbd "<down>") 'pacmacs-down)
@@ -89,8 +93,11 @@
(interactive)
(switch-to-buffer-other-window pacmacs-buffer-name)
(pacmacs-mode)
- (pacmacs-load-map "map05")
+
(setq pacmacs-lives 3)
+ (setq pacmacs-current-level 0)
+ (pacmacs--load-current-level)
+
(unless pacmacs-timer
(setq pacmacs-timer (run-at-time nil (* pacmacs-tick-duration-ms 0.001)
'pacmacs-tick))))
@@ -99,6 +106,14 @@
(cancel-timer pacmacs-timer)
(setq pacmacs-timer nil)))
+(defun pacmacs--load-current-level ()
+ (pacmacs-load-map (aref pacmacs-levels
+ pacmacs-current-level)))
+(defun pacmacs--switch-to-next-level ()
+ (setq pacmacs-current-level
+ (mod (1+ pacmacs-current-level)
+ (length pacmacs-levels))))
+
(defun pacmacs--make-wall-cell (row column)
(list :current-animation (pacmacs-make-anim (list (pacmacs-make-frame '(0 0
40 40) 100))
(pacmacs-create-color-block 40
40 "red"))
@@ -322,9 +337,13 @@
(when (equal pacmacs-game-state 'play)
(pacmacs-step-object pacmacs-player-state)
(pacmacs--detect-pill-collision)
- (pacmacs--detect-ghost-collision)
- (when (equal pacmacs-game-state 'play)
- (pacmacs--step-ghosts))))
+ (if pacmacs-pills
+ (progn
+ (pacmacs--detect-ghost-collision)
+ (when (equal pacmacs-game-state 'play)
+ (pacmacs--step-ghosts)))
+ (pacmacs--switch-to-next-level)
+ (pacmacs--load-current-level))))
(defun pacmacs-death-state-logic ()
(pacmacs-anim-object-next-frame pacmacs-player-state