-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpong.lisp
62 lines (50 loc) · 1.91 KB
/
pong.lisp
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
;;;; pong.lisp
(in-package :com.eliasfeijo.pong)
(register-resource-package :com.eliasfeijo.pong (asdf:system-relative-pathname :pong "assets/"))
(defgame pong ()
((game-state))
(:viewport-width *canvas-width*)
(:viewport-height *canvas-height*)
(:viewport-title "Battle Pong")
(:prepare-resources nil))
(defmethod post-initialize :after ((app pong))
(with-slots (game-state) app
(setf game-state (make-instance 'resource-preparation))
(labels ((%bind-button (button)
(bind-button button :pressed
(lambda ()
(press-key game-state button)))
(bind-button button :released
(lambda ()
(release-key game-state button)))))
(%bind-button :w)
(%bind-button :s)
(%bind-button :space)
(%bind-button :up)
(%bind-button :down)
(%bind-button :enter)
(%bind-button :escape)))
(prepare-resources 'player-red 'player-green 'player-blue 'red-skill 'green-skill 'blue-skill 'samurai-bob 'data))
(defmethod notice-resources ((this pong) &rest resource-names)
(declare (ignore resource-names))
(with-slots (game-state) this
(labels
((color-selection-screen ()
(setf game-state (make-instance 'color-selection :start #'start-game)))
(game-over (winner)
(setf
(game-over-p game-state) t
(winner-of game-state) winner))
(start-game (&key player1-color player2-color)
(setf game-state (make-instance 'game :game-over #'game-over :color-selection-callback #'color-selection-screen))
(setf (color-of (player1-of game-state)) player1-color)
(setf (color-of (player2-of game-state)) player2-color)))
(setf game-state (make-instance 'initial-screen :color-selection #'color-selection-screen)))))
(defmethod draw ((this pong))
(with-slots (game-state) this
(render game-state)))
(defmethod act ((this pong))
(with-slots (game-state) this
(act game-state)))
(defun play-game ()
(start 'pong))