|
@@ -0,0 +1,31 @@
|
|
1
|
+(in-package :bearlibterminal-examples)
|
|
2
|
+
|
|
3
|
+(defun help-msg (player-char)
|
|
4
|
+ (terminal-print 0 0 (format nil "Use arrow keys to move your character represented by ~C!" player-char))
|
|
5
|
+ (terminal-print 0 1 "Exit with the escape button."))
|
|
6
|
+
|
|
7
|
+(defun movement (&key (player-codepoint #x2638) (window-x 80) (window-y 25))
|
|
8
|
+ (let ((player-char (code-char player-codepoint)))
|
|
9
|
+ (terminal-open)
|
|
10
|
+ (terminal-set (format nil "window: size=~Dx~D, title='BearLibTerminal movement example';" window-x window-y))
|
|
11
|
+ ;; Set separately so the other settings take even if the font isn't found
|
|
12
|
+ ;; Make sure you are in the right directory/change the font path if it doesn't load.
|
|
13
|
+ (terminal-set "font: ./fonts/DejaVuSansMono.ttf, size=12")
|
|
14
|
+ (help-msg player-char)
|
|
15
|
+ (terminal-put 5 5 player-codepoint)
|
|
16
|
+ (terminal-refresh)
|
|
17
|
+ (loop with player-x = 5
|
|
18
|
+ with player-y = 5
|
|
19
|
+ as key = (terminal-read) do
|
|
20
|
+ (cond
|
|
21
|
+ ((= key bearlibterminal-ffi:+tk-left+) (decf player-x))
|
|
22
|
+ ((= key bearlibterminal-ffi:+tk-right+) (incf player-x))
|
|
23
|
+ ((= key bearlibterminal-ffi:+tk-down+) (incf player-y))
|
|
24
|
+ ((= key bearlibterminal-ffi:+tk-up+) (decf player-y)))
|
|
25
|
+ (terminal-clear)
|
|
26
|
+ (help-msg player-char)
|
|
27
|
+ (terminal-put player-x player-y player-codepoint)
|
|
28
|
+ (terminal-refresh)
|
|
29
|
+ until (or (= key bearlibterminal-ffi:+tk-escape+)
|
|
30
|
+ (= key bearlibterminal-ffi:+tk-close+)))
|
|
31
|
+ (terminal-close)))
|