Explorar el Código

Add working example based on cl-charms-paint

This includes some basic lisp code to start the game in dev or regular
mode as well. Dev mode not currently working do to possibly some issue
with sly/slynk.
Lily Carpenter hace 8 años
padre
commit
16ff447178
Se han modificado 4 ficheros con 53 adiciones y 5 borrados
  1. 47 4
      src/internal.lisp
  2. 1 1
      src/package.lisp
  3. 3 0
      start-dev.lisp
  4. 2 0
      start-game.lisp

+ 47 - 4
src/internal.lisp

@@ -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))

+ 1 - 1
src/package.lisp

@@ -7,7 +7,7 @@
7 7
 
8 8
 (defpackage #:forever-game-roguelike-internal
9 9
   (:use #:cl
10
-        #:cl-charms
10
+        #:charms
11 11
         #:alexandria
12 12
         #:split-sequence
13 13
         #:forever-game-roguelike))

+ 3 - 0
start-dev.lisp

@@ -0,0 +1,3 @@
1
+(ql:quickload :forever-game-roguelike)
2
+(defvar *game-state* (forever-game-roguelike:make-game-state))
3
+(forever-game-roguelike:start-dev *game-state*)

+ 2 - 0
start-game.lisp

@@ -0,0 +1,2 @@
1
+(ql:quickload :forever-game-roguelike)
2
+(forever-game-roguelike:start)