emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/pacmacs b5078d2632 141/472: Move most of the rendering stu


From: ELPA Syncer
Subject: [nongnu] elpa/pacmacs b5078d2632 141/472: Move most of the rendering stuff to pacman-render
Date: Thu, 6 Jan 2022 21:59:19 -0500 (EST)

branch: elpa/pacmacs
commit b5078d2632130f4cd782613e89d3bc100c32816b
Author: rexim <reximkut@gmail.com>
Commit: rexim <reximkut@gmail.com>

    Move most of the rendering stuff to pacman-render
---
 pacmacs-render.el | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 pacmacs.el        | 50 +++-----------------------------
 2 files changed, 90 insertions(+), 46 deletions(-)

diff --git a/pacmacs-render.el b/pacmacs-render.el
new file mode 100644
index 0000000000..12c65638e1
--- /dev/null
+++ b/pacmacs-render.el
@@ -0,0 +1,86 @@
+;;; pacmacs-render.el --- Pacman for Emacs
+
+;; Copyright (C) 2015 Codingteam
+
+;; Author: Codingteam <codingteam@conference.jabber.ru>
+;; Maintainer: Alexey Kutepov <reximkut@gmail.com>
+;; URL: http://github.com/rexim/pacmacs.el
+
+;; Permission is hereby granted, free of charge, to any person
+;; obtaining a copy of this software and associated documentation
+;; files (the "Software"), to deal in the Software without
+;; restriction, including without limitation the rights to use, copy,
+;; modify, merge, publish, distribute, sublicense, and/or sell copies
+;; of the Software, and to permit persons to whom the Software is
+;; furnished to do so, subject to the following conditions:
+
+;; The above copyright notice and this permission notice shall be
+;; included in all copies or substantial portions of the Software.
+
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+;; SOFTWARE.
+
+;;; Commentary:
+
+;; Routines for working with rendering
+
+;;; Code:
+
+(require 'pacmacs-image)
+(require 'pacmacs-anim)
+
+(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)))
+
+(defun pacmacs--render-life-icon ()
+  (when (not pacmacs--life-icon)
+    (setq pacmacs--life-icon
+          (pacmacs-load-anim "Pacman-Chomping-Right"))
+    (plist-put pacmacs--life-icon :current-frame 2))
+  (pacmacs--render-anim pacmacs--life-icon))
+
+(defun pacmacs--render-anim (anim)
+  (let* ((sprite-sheet (plist-get anim :sprite-sheet))
+         (current-frame (plist-get (pacmacs-anim-get-frame anim) :frame)))
+    (pacmacs-insert-image sprite-sheet current-frame)))
+
+(defun pacmacs--render-object (anim-object)
+  (if anim-object
+      (let* ((anim (plist-get anim-object :current-animation)))
+        (pacmacs--render-anim anim))
+    (pacmacs--render-empty-cell)))
+
+(defun pacmacs--render-track-board (track-board)
+  (plist-bind ((width :width)
+               (height :height))
+      track-board
+    (dotimes (row height)
+      (dotimes (column width)
+        (let ((x (pacmacs--cell-get track-board row column)))
+          (cond
+           ((null x)
+            (insert "."))
+           ((equal x 'left)
+            (insert "<"))
+           ((equal x 'right)
+            (insert ">"))
+           ((equal x 'up)
+            (insert "^"))
+           ((equal x 'down)
+            (insert "v")))))
+      (insert "\n"))))
+
+(provide 'pacmacs-render)
+
+;;; pacmacs-render.el ends here
diff --git a/pacmacs.el b/pacmacs.el
index e109270cab..1fb313b1ec 100644
--- a/pacmacs.el
+++ b/pacmacs.el
@@ -41,6 +41,7 @@
 (require 'pacmacs-board)
 (require 'pacmacs-image)
 (require 'pacmacs-utils)
+(require 'pacmacs-render)
 
 (defconst pacmacs-buffer-name "*Pacmacs*")
 (defconst pacmacs-tick-duration-ms 100)
@@ -59,8 +60,6 @@
 (defvar pacmacs-wall-cells nil)
 (defvar pacmacs-pills nil)
 
-(defvar pacmacs--empty-cell nil)
-
 (defvar pacmacs-board nil)
 (defvar pacmacs-track-board nil)
 
@@ -68,7 +67,7 @@
 (defvar pacmacs-game-state 'play)
 
 (defvar pacmacs-lives 3)
-(defvar pacmacs-life-icon nil)
+
 
 (defvar pacmacs-levels ["map01" "map02" "map03"
                         "map04" "map05" "map06"])
@@ -198,18 +197,6 @@
     (plist-put game-object :direction direction)
     (plist-put game-object :current-animation (plist-get direction-animations 
direction))))
 
-(defun pacmacs--render-life-icon ()
-  (when (not pacmacs-life-icon)
-    (setq pacmacs-life-icon
-          (pacmacs-load-anim "Pacman-Chomping-Right"))
-    (plist-put pacmacs-life-icon :current-frame 2))
-  (pacmacs-render-anim pacmacs-life-icon))
-
-(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)))
-
 (defun pacmacs-step-object (game-object)
   (plist-bind ((row :row)
                (column :column)
@@ -362,16 +349,7 @@
     (decf pacmacs-waiting-counter
           pacmacs-tick-duration-ms)))
 
-(defun pacmacs-render-anim (anim)
-  (let* ((sprite-sheet (plist-get anim :sprite-sheet))
-         (current-frame (plist-get (pacmacs-anim-get-frame anim) :frame)))
-    (pacmacs-insert-image sprite-sheet current-frame)))
 
-(defun pacmacs-render-object (anim-object)
-  (if anim-object
-      (let* ((anim (plist-get anim-object :current-animation)))
-        (pacmacs-render-anim anim))
-    (pacmacs--render-empty-cell)))
 
 (defun pacmacs--put-object (anim-object)
   (when anim-object
@@ -405,31 +383,11 @@
   (setq pacmacs-game-state 'level-beaten)
   (setq pacmacs-waiting-counter 1000))
 
-(defun pacmacs-render-track-board ()
-  (plist-bind ((width :width)
-               (height :height))
-      pacmacs-board
-    (dotimes (row height)
-      (dotimes (column width)
-        (let ((x (pacmacs--cell-get pacmacs-track-board row column)))
-          (cond
-           ((null x)
-            (insert "."))
-           ((equal x 'left)
-            (insert "<"))
-           ((equal x 'right)
-            (insert ">"))
-           ((equal x 'up)
-            (insert "^"))
-           ((equal x 'down)
-            (insert "v")))))
-      (insert "\n"))))
-
 (defun pacmacs-render-state ()
   (insert (format "Score: %d\n" pacmacs-score))
 
   (when pacmacs-debug-output
-    (pacmacs-render-track-board))
+    (pacmacs--render-track-board pacmacs-track-board))
 
   (pacmacs--fill-board pacmacs-board nil)
 
@@ -450,7 +408,7 @@
     (dotimes (row height)
       (dotimes (column width)
         (let ((anim-object (pacmacs--cell-get pacmacs-board row column)))
-          (pacmacs-render-object anim-object)))
+          (pacmacs--render-object anim-object)))
       (insert "\n")))
   (insert "\n")
   (dotimes (i pacmacs-lives)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]