[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/pacmacs de66c1ce17 112/472: Refactor out pacmacs--step-poi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/pacmacs de66c1ce17 112/472: Refactor out pacmacs--step-point (#74) |
Date: |
Thu, 6 Jan 2022 21:59:17 -0500 (EST) |
branch: elpa/pacmacs
commit de66c1ce17b74bfe1c4971403efcbf64b3ecca4b
Author: rexim <reximkut@gmail.com>
Commit: rexim <reximkut@gmail.com>
Refactor out pacmacs--step-point (#74)
---
pacmacs-board.el | 12 ++++++++++++
pacmacs-utils.el | 7 +++++++
pacmacs.el | 15 ++++-----------
test/pacmacs-board-test.el | 13 +++++++++++++
4 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/pacmacs-board.el b/pacmacs-board.el
index 894bd5d245..33934a1acd 100644
--- a/pacmacs-board.el
+++ b/pacmacs-board.el
@@ -32,6 +32,8 @@
;;; Code:
+(require 'pacmacs-utils)
+
(defun pacmacs--make-board (width height)
(let ((board (make-vector height nil)))
(dotimes (row height)
@@ -70,6 +72,16 @@
(cons row column)))
objects))))
+(defun pacmacs--step-point (board row column direction)
+ (plist-bind ((width :width)
+ (height :heigth))
+ board
+ (let* ((velocity (pacmacs--direction-vector direction))
+ (d-row (car velocity))
+ (d-column (cdr velocity)))
+ (cons (mod (+ row d-row) height)
+ (mod (+ column d-column) width)))))
+
(provide 'pacmacs-board)
;;; pacmacs-board.el ends here
diff --git a/pacmacs-utils.el b/pacmacs-utils.el
index a0631cdf51..9d649bcb5a 100644
--- a/pacmacs-utils.el
+++ b/pacmacs-utils.el
@@ -50,6 +50,13 @@ side-effects."
(plist-put plist property
(funcall transformer value))))
+(defun pacmacs--direction-vector (direction)
+ (let ((direction-table (list 'left (cons 0 -1)
+ 'right (cons 0 1)
+ 'up (cons -1 0)
+ 'down (cons 1 0))))
+ (plist-get direction-table direction)))
+
(provide 'pacmacs-utils)
;;; pacmacs.el ends here
diff --git a/pacmacs.el b/pacmacs.el
index 5186c7695c..244def47c9 100644
--- a/pacmacs.el
+++ b/pacmacs.el
@@ -52,12 +52,7 @@
(defvar pacmacs-board-height 10)
(defvar pacmacs-score 0)
-(defvar pacmacs-direction-table nil)
-(setq pacmacs-direction-table
- (list 'left (cons -1 0)
- 'right (cons 1 0)
- 'up (cons 0 -1)
- 'down (cons 0 1)))
+
(defvar pacmacs-inversed-direction-table nil)
(setq pacmacs-inversed-direction-table
@@ -182,11 +177,9 @@
(speed :speed))
game-object
(if (zerop speed-counter)
- (let* ((velocity (plist-get pacmacs-direction-table direction))
- (new-row (mod (+ row (cdr velocity))
- pacmacs-board-height))
- (new-column (mod (+ column (car velocity))
- pacmacs-board-width)))
+ (let* ((new-point (pacmacs--step-point pacmacs-board row column))
+ (new-row (car new-point))
+ (new-column (cdr new-point)))
(plist-put game-object :speed-counter speed)
(when (not (pacmacs--wall-at-p new-row new-column))
(plist-put game-object :row new-row)
diff --git a/test/pacmacs-board-test.el b/test/pacmacs-board-test.el
index 162887571d..fa81b026ce 100644
--- a/test/pacmacs-board-test.el
+++ b/test/pacmacs-board-test.el
@@ -41,3 +41,16 @@
(should (not (pacmacs--object-at-p board 0 1 objects)))
(should (pacmacs--object-at-p board 0 5 objects))
(should (not (pacmacs--object-at-p board 1 5 objects)))))
+
+(ert-deftest pacmacs--step-point-test ()
+ (let ((board (list :width 3
+ :heigth 2))
+ (row 0)
+ (column 0))
+ (should (equal (cons 0 1) (pacmacs--step-point board
+ row column
+ 'right)))
+ (should (equal (cons 0 2) (pacmacs--step-point board
+ row column
+ 'left)))))
+
- [nongnu] elpa/pacmacs 298b950310 062/472: Rename pacman-resources to pacman-image (#51), (continued)
- [nongnu] elpa/pacmacs 298b950310 062/472: Rename pacman-resources to pacman-image (#51), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs e9703e9ba2 061/472: Rename function for loading images (#51), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 0a65793037 071/472: Use plist-bind for pacman-anim-object-next-frame (#54), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 7f706e2159 074/472: Add UTs for plist-map (#54), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 69d47fbb9a 075/472: Merge branch 'pacman-utils-ut-54'. Close #54, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 7d16738069 077/472: Implement custom map format. Close #61, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 6d1831c746 081/472: Implement ghost mechanics. Close #62, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 427b4f823e 088/472: Add edebug specs for plist-bind macro (#68), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 1ed7f14e30 099/472: UTs for pacmacs--init-board-test (#75), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs a802074eea 109/472: Add set/get functions for board (#74), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs de66c1ce17 112/472: Refactor out pacmacs--step-point (#74),
ELPA Syncer <=
- [nongnu] elpa/pacmacs b0561eb59f 111/472: Refactor pacmacs--cell-tracked-p (#74), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 317f9b85b7 114/472: Refactor pacmacs--track-point (#74), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 5233bac0c5 105/472: UT for pacmacs--put-object-test (#75), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs d2c449734e 124/472: Merge branch 'pacman-death-69'. Close #69, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 1ed9c057cc 127/472: Add padding above the lives, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 9e7f67e368 126/472: Implement live mechanics. Close #86, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 86d701a167 131/472: Introduce pacmacs--load-next-level, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 3d49405193 136/472: Reset the score on start, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs a0e3b6fe73 138/472: Implement level is beaten state. Close #99, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 359a0facc5 140/472: Optimize empty cell rendering, ELPA Syncer, 2022/01/06