-
Notifications
You must be signed in to change notification settings - Fork 0
/
zone-tunnels.el
143 lines (128 loc) · 4.67 KB
/
zone-tunnels.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
;;; zone-tunnels.el --- A zone program inspired from the old DOS game
;; This file is not part of Emacs
;; Author: Mohammed Ismail Ansari <[email protected]>
;; Version: 1.0
;; Keywords: games
;; Maintainer: Mohammed Ismail Ansari <[email protected]>
;; Created: 2018/03/08
;; Package-Requires: ((emacs "24") (cl-lib "0.5"))
;; Description: A zone program inspired from the old DOS game
;; URL: http://ismail.teamfluxion.com
;; Compatibility: Emacs24
;; COPYRIGHT NOTICE
;;
;; This program is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by the Free
;; Software Foundation; either version 2 of the License, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
;; for more details.
;;
;;; Install:
;; Put this file on your Emacs-Lisp load path and add the following to your
;; ~/.emacs startup file
;;
;; (require 'zone-tunnels)
;;
;; Set 'zone-pgm-tunnels' as one of the zone programs
;;
;; (setq zone-programs
;; [zone-pgm-tunnels])
;;
;; and activate zoning by specifying a delay
;;
;; (zone-when-idle 30)
;;
;; Alternatively you can run 'zone-tunnels' directly
;;
;; (zone-tunnels)
;;
;;; Commentary:
;; A zone program inspired by the old DOS game
;;
;; Overview of features:
;;
;; o Zone out with tunnels
;;
;;; Code:
(require 'cl-lib)
;;;###autoload
(defun zone-pgm-tunnels ()
"Zone out with tunnels."
(cl-flet* ((draw-rect (canvas-width canvas-height rect-width rect-height)
(let ((start-x (/ (- canvas-width
rect-width)
2))
(start-y (/ (- canvas-height
rect-height)
2)))
(beginning-of-buffer)
(forward-line start-y)
(forward-char start-x)
(delete-char rect-width)
(insert (make-string rect-width ?*))
(dotimes (index (- rect-height
2))
(forward-line 1)
(move-beginning-of-line nil)
(forward-char start-x)
(delete-char 1)
(insert "*")
(backward-char 1)
(forward-char (1- rect-width))
(delete-char 1)
(insert "*"))
(forward-line 1)
(move-beginning-of-line nil)
(forward-char start-x)
(delete-char rect-width)
(insert (make-string rect-width ?*)))))
(delete-other-windows)
(erase-buffer)
(zone-fill-out-screen (window-width) (window-height))
(setq cursor-type nil)
(let ((render-index 10)
(aspect-ratio 2))
(while (not (input-pending-p))
(let ((canvas-width (window-width))
(canvas-height (1- (window-height))))
(dotimes (number canvas-height)
(insert (concat (make-string canvas-width
? )
"\n")))
(let ((width (- canvas-width
(* (% render-index
10)
aspect-ratio)))
(height (- canvas-height
(% render-index
10))))
(loop while
(and (> width 3)
(> height 3))
do
(zone-tunnels--draw-rect canvas-width
canvas-height
width
height)
(setq width (- width
(* 10
aspect-ratio)))
(setq height (- height
10))))
(sit-for 0.1)
(erase-buffer)
(setq render-index
(+ render-index
8)))))))
;;;###autoload
(defun zone-tunnels ()
"Zone out with tunnels."
(interactive)
(let ((zone-programs [zone-pgm-tunnels]))
(zone)))
(provide 'zone-tunnels)
;;; zone-tunnels.el ends here