[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/pacmacs 05e30ca856 076/472: Implement support for frame du
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/pacmacs 05e30ca856 076/472: Implement support for frame duration. Close #23 |
Date: |
Thu, 6 Jan 2022 21:59:14 -0500 (EST) |
branch: elpa/pacmacs
commit 05e30ca856949f77d8e521549428e644d29a4dc5
Author: rexim <reximkut@gmail.com>
Commit: rexim <reximkut@gmail.com>
Implement support for frame duration. Close #23
---
pacman-anim.el | 38 ++++++++++++++++++++++++++------------
pacman.el | 37 ++++++++++++++++++++-----------------
test/pacman-anim-test.el | 35 +++++++++++++++++++++++------------
3 files changed, 69 insertions(+), 41 deletions(-)
diff --git a/pacman-anim.el b/pacman-anim.el
index de2f09a726..8cb26396e0 100644
--- a/pacman-anim.el
+++ b/pacman-anim.el
@@ -40,8 +40,13 @@
(defun pacman-make-anim (frames sprite-sheet)
(list :frames frames
:current-frame 0
+ :duration-counter 0
:sprite-sheet sprite-sheet))
+(defun pacman-make-frame (frame duration)
+ (list :frame frame
+ :duration duration))
+
(defun pacman-load-anim (animation-name)
(let* ((aseprite-json-file (format "sprites/%s.json" animation-name))
(sprite-sheet-file (format "sprites/%s.xpm" animation-name))
@@ -65,10 +70,12 @@
(< order1 order2)))
(defun pacman-convert-aseprite-frame (aseprite-frame)
- (let* ((frame (cdr (assoc 'frame (cdr aseprite-frame)))))
- (mapcar (lambda (n)
- (cdr (assoc n frame)))
- '(x y w h))))
+ (let* ((frame (cdr (assoc 'frame (cdr aseprite-frame))))
+ (duration (cdr (assoc 'duration (cdr aseprite-frame)))))
+ (pacman-make-frame (mapcar (lambda (n)
+ (cdr (assoc n frame)))
+ '(x y w h))
+ duration)))
(defun pacman-anim-get-frame (anim)
(plist-bind ((frames :frames)
@@ -76,16 +83,23 @@
anim
(nth current-frame frames)))
-(defun pacman-anim-next-frame (anim)
+(defun pacman-anim-next-frame (anim time)
(plist-bind ((frames :frames)
- (current-frame :current-frame))
+ (current-frame :current-frame)
+ (duration-counter :duration-counter))
anim
- (let ((new-current-frame (mod (+ current-frame 1)
- (length frames))))
- (plist-put anim :current-frame new-current-frame))))
-
-(defun pacman-anim-object-next-frame (anim-object)
- (plist-map anim-object :animation #'pacman-anim-next-frame))
+ (let ((duration (plist-get (pacman-anim-get-frame anim) :duration)))
+ (if (<= duration (+ duration-counter time))
+ (let ((new-current-frame (mod (+ current-frame 1)
+ (length frames))))
+ (plist-put anim :duration-counter 0)
+ (plist-put anim :current-frame new-current-frame))
+ (plist-put anim :duration-counter (+ duration-counter time))))))
+
+(defun pacman-anim-object-next-frame (anim-object time)
+ (plist-map anim-object :animation
+ #'(lambda (anim)
+ (pacman-anim-next-frame anim time))))
(provide 'pacman-anim)
diff --git a/pacman.el b/pacman.el
index 23507e240b..701b7f833e 100644
--- a/pacman.el
+++ b/pacman.el
@@ -40,6 +40,7 @@
(require 'pacman-utils)
(defconst pacman-buffer-name "*Pacman*")
+(defconst pacman-tick-duration-ms 100)
(defvar pacman-timer nil)
(defvar pacman-counter 0)
@@ -52,19 +53,21 @@
(list :row 0
:column 0
:direction 'right
- :animation (pacman-load-anim "Pacman-Chomping-Right")))
-
-(defvar pacman-direction-table
- (list 'left (cons -1 0)
- 'right (cons 1 0)
- 'up (cons 0 -1)
- 'down (cons 0 1)))
-
-(defvar pacman-direction-animation-table
- (list 'left (pacman-load-anim "Pacman-Chomping-Left")
- 'right (pacman-load-anim "Pacman-Chomping-Right")
- 'up (pacman-load-anim "Pacman-Chomping-Up")
- 'down (pacman-load-anim "Pacman-Chomping-Down")))
+ :animation (pacman-load-anim "Red-Ghost-Right")))
+
+(defvar pacman-direction-table nil)
+(setq pacman-direction-table
+ (list 'left (cons -1 0)
+ 'right (cons 1 0)
+ 'up (cons 0 -1)
+ 'down (cons 0 1)))
+
+(defvar pacman-direction-animation-table nil)
+(setq pacman-direction-animation-table
+ (list 'left (pacman-load-anim "Red-Ghost-Left")
+ 'right (pacman-load-anim "Red-Ghost-Right")
+ 'up (pacman-load-anim "Red-Ghost-Up")
+ 'down (pacman-load-anim "Red-Ghost-Down")))
(defvar pacman-empty-cell nil)
(setq pacman-empty-cell
@@ -122,7 +125,7 @@
(switch-to-buffer-other-window pacman-buffer-name)
(pacman-mode)
(unless pacman-timer
- (setq pacman-timer (run-at-time nil 0.1 'pacman-tick))))
+ (setq pacman-timer (run-at-time nil (* pacman-tick-duration-ms 0.001)
'pacman-tick))))
(defun pacman-destroy ()
(when pacman-timer
@@ -175,9 +178,9 @@
(interactive)
(with-current-buffer pacman-buffer-name
(let ((inhibit-read-only t))
- (pacman-anim-object-next-frame pacman-player-state)
+ (pacman-anim-object-next-frame pacman-player-state
pacman-tick-duration-ms)
(dolist (pill pacman-pills)
- (pacman-anim-object-next-frame pill))
+ (pacman-anim-object-next-frame pill pacman-tick-duration-ms))
(pacman-step-object pacman-player-state)
(let* ((direction (plist-get pacman-player-state :direction))
@@ -205,7 +208,7 @@
(defun pacman-render-object (anim-object)
(let* ((anim (plist-get anim-object :animation))
(sprite-sheet (plist-get anim :sprite-sheet))
- (current-frame (pacman-anim-get-frame anim)))
+ (current-frame (plist-get (pacman-anim-get-frame anim) :frame)))
(pacman-insert-image sprite-sheet current-frame)))
(defun pacman-clear-board ()
diff --git a/test/pacman-anim-test.el b/test/pacman-anim-test.el
index 09ea407a75..cf157506a5 100644
--- a/test/pacman-anim-test.el
+++ b/test/pacman-anim-test.el
@@ -1,6 +1,7 @@
(ert-deftest pacman-make-anim-test ()
(should (equal (list :frames (list 1 2 3 4 5)
:current-frame 0
+ :duration-counter 0
:sprite-sheet 42)
(pacman-make-anim (number-sequence 1 5) 42))))
@@ -10,19 +11,22 @@
(should (equal 3 (pacman-anim-get-frame anim)))))
(ert-deftest pacman-anim-next-frame-test ()
- (let ((anim (list :frames (number-sequence 1 4)
- :current-frame 2)))
- (pacman-anim-next-frame anim)
+ (let ((anim (list :frames (mapcar (lambda (x)
+ (pacman-make-frame (+ 41 x) 100))
+ (number-sequence 1 4))
+ :current-frame 2
+ :duration-counter 0)))
+ (pacman-anim-next-frame anim 100)
(should (equal 3 (plist-get anim :current-frame)))
- (pacman-anim-next-frame anim)
+ (pacman-anim-next-frame anim 100)
(should (equal 0 (plist-get anim :current-frame)))))
(ert-deftest pacman-anim-object-next-frame-test ()
(with-mock
(stub pacman-anim-next-frame => 42)
(let ((anim-object '(:animation 41)))
- (pacman-anim-object-next-frame anim-object)
+ (pacman-anim-object-next-frame anim-object 100)
(should (equal '(:animation 42)
anim-object)))))
@@ -33,8 +37,10 @@
(x . 1)
(y . 2)
(h . 3)
- (w . 4))))
- (expected-frame (list 1 2 4 3)))
+ (w . 4))
+ (duration . 100)))
+ (expected-frame (list :frame (list 1 2 4 3)
+ :duration 100)))
(should (equal expected-frame
(pacman-convert-aseprite-frame aseprite-frame)))))
@@ -68,14 +74,19 @@
(ert-deftest pacman-load-anim-test ()
(let* ((input-aseprite-format '((frames
- (frame-3\.ase (frame (h . 3) (w . 3) (y .
3) (x . 3)))
- (frame-2\.ase (frame (h . 2) (w . 2) (y .
2) (x . 2)))
- (frame-1\.ase (frame (h . 1) (w . 1) (y .
1) (x . 1)))
- (frame-0\.ase (frame (h . 0) (w . 0) (y .
0) (x . 0))))))
+ (frame-3\.ase (frame (h . 3) (w . 3) (y .
3) (x . 3))
+ (duration . 400))
+ (frame-2\.ase (frame (h . 2) (w . 2) (y .
2) (x . 2))
+ (duration . 300))
+ (frame-1\.ase (frame (h . 1) (w . 1) (y .
1) (x . 1))
+ (duration . 200))
+ (frame-0\.ase (frame (h . 0) (w . 0) (y .
0) (x . 0))
+ (duration . 100)))))
(input-sprite-sheet 42)
(expected-output (pacman-make-anim
(mapcar #'(lambda (x)
- (make-list 4 x))
+ (pacman-make-frame (make-list 4 x)
+ (* (1+ x) 100)))
(number-sequence 0 3))
input-sprite-sheet)))
(with-mock
- [nongnu] elpa/pacmacs db03c57347 158/472: Add autoload cookie for pacmacs-start function, (continued)
- [nongnu] elpa/pacmacs db03c57347 158/472: Add autoload cookie for pacmacs-start function, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 7285f61d45 164/472: Require pacmacs-board in the pacmacs-render module, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs b00db2f7fa 240/472: Use hashmap for tile cache instead of vector (#131), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 838833da41 414/472: Go to the beginning if score is not featured, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 75f7ddd459 418/472: Add UT for position-of-new-score func (#134), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs fb4885d0fc 420/472: Add UT for make-submit-nickname-action func (#134), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs f53a6d57b7 451/472: Fix the compilation error (#203), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 9d839d08c6 460/472: Bottom padding for object board (#203), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs c6436982fe 462/472: Merge pull request #207 from codingteam/feature/awesome-score-sign-203, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 67660062fd 042/472: Add LICENSE files (#28), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 05e30ca856 076/472: Implement support for frame duration. Close #23,
ELPA Syncer <=
- [nongnu] elpa/pacmacs 05c88e5eef 100/472: UTs for pacmacs--object-at-p (#75), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 01388a06a0 104/472: UTs for pacmacs--track-object (#75), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs d9ddd5dab4 132/472: Refactor pacmacs--detect-ghost-collision (#97), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 7601c1ae5c 143/472: Rename board vars to buffers (#105), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs e69a35e2b3 168/472: Small typo in the README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 63e41ffe23 169/472: Fix the dev workflow in the README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 9525cd168b 172/472: Update README about the pause feature, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 98599015bb 229/472: Fix UTs broken by #133 implementation, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs e294101a92 231/472: Fix Game Over sign for connected walls (#131), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs a7a4146732 234/472: Fix the wall corner gaps (#131), ELPA Syncer, 2022/01/06