|
@@ -1,5 +1,5 @@
|
1
|
1
|
;;;; internal.lisp
|
2
|
|
-;;;; Copyright (C) 2015 Lily Carpenter
|
|
2
|
+;;;; Copyright (C) 2016 Lily Carpenter
|
3
|
3
|
|
4
|
4
|
;;;; This program is free software: you can redistribute it and/or modify
|
5
|
5
|
;;;; it under the terms of the GNU Affero General Public License as published by
|
|
@@ -17,11 +17,54 @@
|
17
|
17
|
|
18
|
18
|
(in-package #:forever-game-roguelike-internal)
|
19
|
19
|
|
20
|
|
-(defun start ())
|
|
20
|
+(defstruct game-state
|
|
21
|
+ (cursor-x 0 :type fixnum)
|
|
22
|
+ (cursor-y 0 :type fixnum)
|
|
23
|
+ (quit? nil :type boolean))
|
21
|
24
|
|
22
|
|
-(defun start-dev ()
|
|
25
|
+(defun player-up (state)
|
|
26
|
+ (decf (game-state-cursor-y state)))
|
|
27
|
+
|
|
28
|
+(defun player-down (state)
|
|
29
|
+ (incf (game-state-cursor-y state)))
|
|
30
|
+
|
|
31
|
+(defun player-left (state)
|
|
32
|
+ (decf (game-state-cursor-x state)))
|
|
33
|
+
|
|
34
|
+(defun player-right (state)
|
|
35
|
+ (incf (game-state-cursor-x state)))
|
|
36
|
+
|
|
37
|
+(defun quit-game (state)
|
|
38
|
+ (setf (game-state-quit? state) t))
|
|
39
|
+
|
|
40
|
+(defun handle-input (char state)
|
|
41
|
+ (case char
|
|
42
|
+ ((nil) nil)
|
|
43
|
+ ((#\w) (player-up state))
|
|
44
|
+ ((#\s) (player-down state))
|
|
45
|
+ ((#\a) (player-left state))
|
|
46
|
+ ((#\d) (player-right state))
|
|
47
|
+ ((#\q #\Q) (quit-game state))))
|
|
48
|
+
|
|
49
|
+(defun start (&optional (state (make-game-state)))
|
|
50
|
+ (with-curses ()
|
|
51
|
+ (disable-echoing)
|
|
52
|
+ (enable-raw-input :interpret-control-characters t)
|
|
53
|
+ (enable-non-blocking-mode *standard-window*)
|
|
54
|
+ (loop named game-loop
|
|
55
|
+ for char := (get-char *standard-window* :ignore-error t) do
|
|
56
|
+ (refresh-window *standard-window*)
|
|
57
|
+ (handle-input char state)
|
|
58
|
+ (multiple-value-bind (width height) (window-dimensions *standard-window*)
|
|
59
|
+ (setf (game-state-cursor-x state) (mod (game-state-cursor-x state) width))
|
|
60
|
+ (setf (game-state-cursor-y state) (mod (game-state-cursor-y state) height)))
|
|
61
|
+ (move-cursor *standard-window* (game-state-cursor-x state) (game-state-cursor-y state))
|
|
62
|
+ until (game-state-quit? state))))
|
|
63
|
+
|
|
64
|
+(defun start-dev (state)
|
23
|
65
|
(ql:quickload :slynk)
|
24
|
66
|
(uiop:symbol-call :slynk
|
25
|
67
|
:create-server
|
26
|
68
|
:port 6666
|
27
|
|
- :dont-close t))
|
|
69
|
+ :dont-close t)
|
|
70
|
+ (start state))
|