-
Notifications
You must be signed in to change notification settings - Fork 9
/
pacmacs-render.el
101 lines (79 loc) · 3.46 KB
/
pacmacs-render.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
;;; pacmacs-render.el --- Pacman for Emacs -*- lexical-binding: t -*-
;; Copyright (C) 2015-2016 Codingteam
;; Author: Codingteam <[email protected]>
;; Maintainer: Alexey Kutepov <[email protected]>
;; URL: http://github.com/codingteam/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-walls)
(require 'pacmacs-anim)
(require 'pacmacs-board)
(defvar pacmacs--life-icon nil)
(defmacro with-render-target (render-target-buffer &rest body)
(declare (indent 1) (debug (sexp &rest form)))
`(with-current-buffer ,render-target-buffer
(let ((inhibit-read-only t))
,@body)))
(defun pacmacs-insert-image (resource resource-vector)
(insert-image resource " " nil resource-vector))
(defun pacmacs--render-empty-cell ()
(pacmacs-insert-image (pacmacs--create-wall-tile
40 40
(make-list 8 nil))
'(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-cell (track-cell)
(insert "\t")
(if track-cell
(insert (int-to-string track-cell))
(insert ".")))
(defun pacmacs--render-board (board cell-renderer)
(plist-bind ((width :width)
(height :height))
board
(dotimes (row height)
(dotimes (column width)
(let ((cell (pacmacs--cell-wrapped-get board row column)))
(funcall cell-renderer cell)))
(insert "\n"))))
(defun pacmacs--render-track-board (track-board)
(pacmacs--render-board track-board
#'pacmacs--render-track-cell))
(defun pacmacs--render-object-board (object-board)
(pacmacs--render-board object-board
(-compose #'pacmacs--render-object #'car))
(insert "\n"))
(provide 'pacmacs-render)
;;; pacmacs-render.el ends here