[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/pacmacs 4bd94d2058 255/472: Merge branch 'master' into big
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/pacmacs 4bd94d2058 255/472: Merge branch 'master' into big-pills-81 |
Date: |
Thu, 6 Jan 2022 21:59:29 -0500 (EST) |
branch: elpa/pacmacs
commit 4bd94d2058c340cadfb7e82d6e374de5abc6eb95
Merge: 8f9b38b16e eab5b98b05
Author: rexim <reximkut@gmail.com>
Commit: rexim <reximkut@gmail.com>
Merge branch 'master' into big-pills-81
Taking all the latest features from the master
---
README.md | 8 ++-
maps/game-over.txt | 17 ++++---
pacmacs-image.el | 120 ++++++++++++++++++++++++++++++++++++++++++---
pacmacs-render.el | 9 ++--
pacmacs.el | 41 ++++++++++++----
test/pacmacs-image-test.el | 71 +++++++++++++++++++--------
test/test-helper.el | 20 ++++++++
tools/README.md | 12 +++++
tools/it-recorder.el | 3 ++
9 files changed, 247 insertions(+), 54 deletions(-)
diff --git a/README.md b/README.md
index 485cda138b..de932f8b58 100644
--- a/README.md
+++ b/README.md
@@ -6,11 +6,9 @@
Pacman for Emacs
-<p align="center">
- <img
src="https://cloud.githubusercontent.com/assets/5211845/10491579/9ba466b2-72a7-11e5-982c-579ed6abe1a5.gif"
href="https://www.reddit.com/r/emacs/comments/3opb5k/pacmacs_a_pacman_variant_for_emacs/"/>
-</p>
-
-(thanks to [@kaushalmodi](https://github.com/kaushalmodi) for the animation)
+<p align="center"><img src="http://i.imgur.com/CIf2XBc.png"
href="http://i.imgur.com/CIf2XBc.png" /></p>
+<p align="center"><img src="http://i.imgur.com/BXjXKnU.png"
href="http://i.imgur.com/BXjXKnU.png" /></p>
+<p align="center"><img src="http://i.imgur.com/nGhK9ih.png"
href="http://i.imgur.com/nGhK9ih.png" /></p>
## Requirements ##
diff --git a/maps/game-over.txt b/maps/game-over.txt
index f28cdbb21f..557947e49f 100644
--- a/maps/game-over.txt
+++ b/maps/game-over.txt
@@ -1,9 +1,10 @@
-### ### ##### ###
-# # # # # # # #
-# # ### # # # ##
-### # # # # # ##
+
+ ### ### ##### ###
+ # # # # # # # #
+ # # ### # # # ##
+ ### # # # # # ##
-### # # ### ###
-# # # # # # # #
-# # # # ## ####
-### # ## # #
+ ### # # ### ###
+ # # # # # # # #
+ # # # # ## ####
+ ### # ## # #
diff --git a/pacmacs-image.el b/pacmacs-image.el
index 25c30034a3..1043589560 100644
--- a/pacmacs-image.el
+++ b/pacmacs-image.el
@@ -32,6 +32,12 @@
;;; Code:
+(require 'dash)
+
+(defconst pacmacs--flip-xbm-bits (eq system-type 'windows-nt))
+(defvar pacmacs--wall-blocks
+ (make-hash-table))
+
(defun pacmacs-load-image (filename)
(create-image filename 'xpm nil :heuristic-mask t))
@@ -39,18 +45,116 @@
(insert-image resource " " nil resource-vector))
(defun pacmacs-create-color-block (width height color)
- (create-image
+ (apply
+ #'create-image
(make-vector
width (make-bool-vector height t))
'xbm t :width width :height height
- :foreground color
- :background color))
+ (if (not pacmacs--flip-xbm-bits)
+ (list
+ :foreground color
+ :background nil)
+ (list
+ :foreground nil
+ :background color))))
-(defun pacmacs-create-transparent-block (width height)
- (create-image
- (make-vector
- width (make-bool-vector height nil))
- 'xbm t :width width :height height))
+(defun pacmacs--put-bits-dot (bits row column weight)
+ (dotimes (i weight)
+ (dotimes (j weight)
+ (aset (aref bits (+ i row)) (+ j column) t))))
+
+(defun pacmacs--put-vertical-bar (bits column height weight)
+ (dotimes (w weight)
+ (dotimes (i height)
+ (aset (aref bits i) (+ column w) t))))
+
+(defun pacmacs--put-horizontal-bar (bits row width weight)
+ (dotimes (w weight)
+ (dotimes (i width)
+ (aset (aref bits (+ row w)) i t))))
+
+(defun pacmacs--bit-list-to-integer (bit-list)
+ (let ((result 0))
+ (dolist (bit bit-list)
+ (setq result (logior (lsh result 1)
+ (if bit 1 0))))
+ result))
+
+(defun pacmacs--bits-to-xpm (bits width height)
+ (concat
+ "/* XPM */\n"
+ "static char *tile[] = {\n"
+ "/**/\n"
+ (format "\"%d %d 2 1\",\n" width height)
+ "\" c None\",\n"
+ "\". c #5555ff\",\n"
+ "/* pixels */\n"
+ (mapconcat
+ (lambda (row)
+ (format "\"%s\""
+ (mapconcat (-lambda (bit) (if bit "." " ")) row "")))
+ bits
+ ",\n")
+ "\n};"))
+
+(defun pacmacs--create-wall-tile (width height
+
+ bottom right
+ top left
+ left-upper right-upper
+ left-bottom right-bottom)
+ (let ((cache-index
+ (pacmacs--bit-list-to-integer
+ (list bottom right top left
+ (and left-upper
+ (not left)
+ (not top))
+ (and right-upper
+ (not right)
+ (not top))
+ (and left-bottom
+ (not left)
+ (not bottom))
+ (and right-bottom
+ (not right)
+ (not bottom))))))
+ (-if-let (cached-tile (gethash cache-index pacmacs--wall-blocks))
+ cached-tile
+ (puthash cache-index
+ (let ((wall-block (make-vector
+ width nil))
+ (weight 3))
+
+ (dotimes (i width)
+ (aset wall-block i (make-vector height nil)))
+
+ (when left-upper
+ (pacmacs--put-bits-dot wall-block 0 0 weight))
+
+ (when right-upper
+ (pacmacs--put-bits-dot wall-block 0 (- width weight)
weight))
+
+ (when left-bottom
+ (pacmacs--put-bits-dot wall-block (- height weight) 0
weight))
+
+ (when right-bottom
+ (pacmacs--put-bits-dot wall-block (- height weight) (-
width weight) weight))
+
+ (when left
+ (pacmacs--put-vertical-bar wall-block 0 height weight))
+
+ (when right
+ (pacmacs--put-vertical-bar wall-block (- width weight)
height weight))
+
+ (when top
+ (pacmacs--put-horizontal-bar wall-block 0 width weight))
+
+ (when bottom
+ (pacmacs--put-horizontal-bar wall-block (- height weight)
width weight))
+
+ (create-image (pacmacs--bits-to-xpm wall-block width height)
+ 'xpm t))
+ pacmacs--wall-blocks))))
(provide 'pacmacs-image)
diff --git a/pacmacs-render.el b/pacmacs-render.el
index 0a7e6f4bad..3606baa326 100644
--- a/pacmacs-render.el
+++ b/pacmacs-render.el
@@ -36,13 +36,14 @@
(require 'pacmacs-anim)
(require 'pacmacs-board)
-(defvar pacmacs--empty-cell nil)
(defvar pacmacs--life-icon nil)
(defun pacmacs--render-empty-cell ()
- (when (not pacmacs--empty-cell)
- (setq pacmacs--empty-cell (pacmacs-create-transparent-block 40 40)))
- (pacmacs-insert-image pacmacs--empty-cell '(0 0 40 40)))
+ (pacmacs-insert-image (pacmacs--create-wall-tile
+ 40 40
+ nil nil nil nil
+ nil nil nil nil)
+ '(0 0 40 40)))
(defun pacmacs--render-life-icon ()
(when (not pacmacs--life-icon)
diff --git a/pacmacs.el b/pacmacs.el
index 86028da966..9187a45127 100644
--- a/pacmacs.el
+++ b/pacmacs.el
@@ -96,6 +96,7 @@
(defun pacmacs--initialize-game (tick-function)
(switch-to-buffer pacmacs-buffer-name)
+ (buffer-disable-undo pacmacs-buffer-name)
(setq pacmacs-lives 3)
(setq pacmacs-score 0)
@@ -125,8 +126,7 @@
(pacmacs--load-current-level))
(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"))
+ (list :current-animation nil
:row row
:column column
:type 'wall))
@@ -250,11 +250,17 @@
(pacmacs--put-object game-object)))
(plist-put game-object :speed-counter (1- speed-counter)))))
-(defun pacmacs--possible-ways (row column)
- (list (cons (1+ row) column)
- (cons row (1+ column))
- (cons (1- row) column)
- (cons row (1- column))))
+(defun pacmacs--possible-side-ways (row column)
+ (list (cons (1+ row) column) ;down
+ (cons row (1+ column)) ;right
+ (cons (1- row) column) ;up
+ (cons row (1- column)))) ;left
+
+(defun pacmacs--possible-diagonal-ways (row column)
+ (list (cons (1- row) (1- column))
+ (cons (1- row) (1+ column))
+ (cons (1+ row) (1- column))
+ (cons (1+ row) (1+ column))))
(defun pacmacs--filter-candidates (p)
(let ((row (car p))
@@ -287,7 +293,7 @@
(dolist (p wave)
(let* ((row (car p))
(column (cdr p))
- (possible-ways (pacmacs--possible-ways row column))
+ (possible-ways (pacmacs--possible-side-ways row column))
(candidate-ways
(cl-remove-if #'pacmacs--filter-candidates possible-ways)))
(dolist (candidate-way candidate-ways)
@@ -515,6 +521,14 @@
(-sort #'string-lessp)
(apply #'vector)))
+(defun pacmacs--wall-tile-at (row column)
+ (apply #'pacmacs--create-wall-tile
+ 40 40
+ (-map (-lambda ((row . column))
+ (not (pacmacs--wall-at-p row column)))
+ (append (pacmacs--possible-side-ways row column)
+ (pacmacs--possible-diagonal-ways row column)))))
+
(defun pacmacs--load-map (map-name)
(let* ((lines (split-string (->> map-name
(format "./maps/%s.txt")
@@ -551,7 +565,16 @@
((char-equal x ?g)
(add-to-list 'pacmacs--ghosts (pacmacs--make-ghost
row column))))))
- (pacmacs--fill-object-board)))
+
+ (pacmacs--fill-object-board)
+
+ (dolist (wall pacmacs--wall-cells)
+ (plist-bind ((row :row)
+ (column :column))
+ wall
+ (plist-put wall :current-animation
+ (pacmacs-make-anim (list (pacmacs-make-frame '(0 0 40 40)
100))
+ (pacmacs--wall-tile-at row column)))))))
(provide 'pacmacs)
diff --git a/test/pacmacs-image-test.el b/test/pacmacs-image-test.el
index a66a00d23c..aebc7999b6 100644
--- a/test/pacmacs-image-test.el
+++ b/test/pacmacs-image-test.el
@@ -20,26 +20,57 @@
(with-mock
(mock (make-bool-vector height t) => bool-vector-result :times 1)
(mock (make-vector width bool-vector-result) => make-vector-result :times
1)
- (mock (create-image make-vector-result
- 'xbm t
- :width width :height height
- :foreground color
- :background color) => create-image-result :times 1)
+
+ (if (not pacmacs--flip-xbm-bits)
+ (mock (create-image make-vector-result
+ 'xbm t
+ :width width :height height
+ :foreground color
+ :background nil) => create-image-result :times 1)
+ (mock (create-image make-vector-result
+ 'xbm t
+ :width width :height height
+ :foreground nil
+ :background color) => create-image-result :times 1))
+
(should (equal create-image-result
(pacmacs-create-color-block width height color))))))
-(ert-deftest pacmacs-create-transparent-block ()
- (let ((width 10)
- (height 20)
- (bool-vector-result 42)
- (make-vector-result 43)
- (create-image-result 44))
- (with-mock
- (mock (make-bool-vector height nil) => bool-vector-result :times 1)
- (mock (make-vector width bool-vector-result) => make-vector-result :times
1)
- (mock (create-image make-vector-result
- 'xbm t
- :width width
- :height height) => create-image-result :times 1)
- (should (equal create-image-result
- (pacmacs-create-transparent-block width height))))))
+(ert-deftest pacmacs--put-bits-dot-test ()
+ (let ((input-bits (pacmacs--construct-2d-bool-vector
+ '((nil nil nil)
+ (nil nil nil)
+ (nil nil nil))))
+ (expected-bits (pacmacs--construct-2d-bool-vector
+ '((t t nil)
+ (t t nil)
+ (nil nil nil)))))
+ (pacmacs--put-bits-dot input-bits 0 0 2)
+ (should (equal expected-bits
+ input-bits))))
+
+(ert-deftest pacmacs--put-vertical-bar-test ()
+ (let ((input-bits (pacmacs--construct-2d-bool-vector
+ '((nil nil nil)
+ (nil nil nil)
+ (nil nil nil))))
+ (expected-bits (pacmacs--construct-2d-bool-vector
+ '((t t nil)
+ (t t nil)
+ (t t nil)))))
+ (pacmacs--put-vertical-bar input-bits 0 3 2)
+ (should (equal (pacmacs--bits-to-lists expected-bits)
+ (pacmacs--bits-to-lists input-bits)))))
+
+(ert-deftest pacmacs--put-horizontal-bar-test ()
+ (let ((input-bits (pacmacs--construct-2d-bool-vector
+ '((nil nil nil)
+ (nil nil nil)
+ (nil nil nil))))
+ (expected-bits (pacmacs--construct-2d-bool-vector
+ '((t t t)
+ (t t t)
+ (nil nil nil)))))
+ (pacmacs--put-horizontal-bar input-bits 0 3 2)
+ (should (equal (pacmacs--bits-to-lists expected-bits)
+ (pacmacs--bits-to-lists input-bits)))))
diff --git a/test/test-helper.el b/test/test-helper.el
index 0115ca979d..acf0aa1e57 100644
--- a/test/test-helper.el
+++ b/test/test-helper.el
@@ -2,8 +2,28 @@
;this
(require 'el-mock)
(require 'undercover)
+(require 'dash)
(undercover "*.el")
+(defun pacmacs--list-to-bool-vector (xs)
+ (let* ((index 0)
+ (size (length xs))
+ (result (make-bool-vector (length xs) nil)))
+ (dolist (x xs)
+ (aset result index x)
+ (cl-incf index))
+ result))
+
+(defun pacmacs--bool-vector-to-list (xs)
+ (-map #'identity xs))
+
+(defun pacmacs--construct-2d-bool-vector (data)
+ (apply #'vector
+ (-map #'pacmacs--list-to-bool-vector data)))
+
+(defun pacmacs--bits-to-lists (bits)
+ (-map #'pacmacs--bool-vector-to-list bits))
+
(add-to-list 'load-path ".")
(load "pacmacs.el")
diff --git a/tools/README.md b/tools/README.md
new file mode 100644
index 0000000000..a19b055937
--- /dev/null
+++ b/tools/README.md
@@ -0,0 +1,12 @@
+# Project Tools #
+
+Tools that help to develop the game
+
+## compile.el ##
+
+Compiles all the source code, treats warnings as errors and exits with
+non-zero exit code on any error (which `cask build` does not yet).
+
+## it-recorder.el ##
+
+Tool for recording and replaying integration test cases.
diff --git a/tools/it-recorder.el b/tools/it-recorder.el
index 8570a505ac..fa5a73bf9e 100644
--- a/tools/it-recorder.el
+++ b/tools/it-recorder.el
@@ -75,6 +75,9 @@
(define-key pacmacs-it-recorder-mode-map (kbd "<left>") 'pacmacs-record-left)
(define-key pacmacs-it-recorder-mode-map (kbd "<right>")
'pacmacs-record-right))
+(defun pacmacs--average-tick-time ()
+ (/ (-sum pacmacs--tick-times) (length pacmacs--tick-times)))
+
(defun pacmacs--start-it-recorder ()
(interactive)
(pacmacs--initialize-game 'pacmacs-record-tick)
- [nongnu] elpa/pacmacs 775a2d3ec5 211/472: Convert recorder module to a tool (#115), (continued)
- [nongnu] elpa/pacmacs 775a2d3ec5 211/472: Convert recorder module to a tool (#115), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs a0d9c1bbbc 212/472: Reverse test case before saving (#115), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs d5bdd0b20a 025/472: Slightly refactored pacman-anim:, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 16b0d6583a 153/472: Get rid of the hardcoded level list. Close #109, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 68f6dc9a93 167/472: Update MELPA repo link, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs fe837b20fa 184/472: Implement victory animation for ghosts. Close #89, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 09ad044887 232/472: Better color for walls (#131), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 9c69162781 247/472: Rough implementation of XPM wall generation (#141), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 4a94a72dd4 250/472: Remove generate-wall-tiles script tool (#141), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs eab5b98b05 254/472: Add average-tick-time function, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 4bd94d2058 255/472: Merge branch 'master' into big-pills-81,
ELPA Syncer <=
- [nongnu] elpa/pacmacs b97248f316 258/472: Put regular and big pills to same list (#81), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 2473e65744 268/472: Remove dead left overs of #141, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 22355a4954 276/472: Add Terrified Ghost animation. Close #83, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 97973dd305 288/472: Rough implementaion of escaping for TGs (#153), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 3758d601d3 304/472: Fix blinking terrified ghost animation, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 27c7ba7bbb 314/472: Update README about minimal version of Emacs (#165), ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs d6b63ef5b9 317/472: Merge pull request #166 from codingteam/drop-emacs-24.3-165, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 3344de1bbe 322/472: Adapt render-track-board for new track board, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 481eb8bd37 326/472: Merge pull request #169 from codingteam/distances-instead-of-directions-159, ELPA Syncer, 2022/01/06
- [nongnu] elpa/pacmacs 31d7305439 331/472: Add 2nd big pill level (#162), ELPA Syncer, 2022/01/06