blob: ad1d9c3019d4eae37af718c684db19cb05cc529c (
plain)
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
|
(define-module (bonnie-bee game)
#:use-module (bonnie-bee actor)
#:use-module (bonnie-bee assets)
#:use-module (bonnie-bee bullet)
#:use-module (bonnie-bee common)
#:use-module (bonnie-bee flower)
#:use-module (bonnie-bee player)
#:use-module (chickadee data quadtree)
#:use-module (chickadee graphics color)
#:use-module (chickadee math rect)
#:use-module (chickadee math vector)
#:use-module (chickadee scripting)
#:use-module (oop goops)
#:use-module (starling kernel)
#:use-module (starling node)
#:use-module (starling node-2d)
#:use-module (starling scene)
#:export (<game>))
(define %game-bounds (make-rect 0.0 0.0 %game-width %game-height))
(define-class <game> (<scene-2d>)
(quadtree #:getter quadtree #:init-form (make-quadtree %game-bounds)))
(define-method (spawn (game <game>) (actor <actor>))
(set! (quadtree actor) (quadtree game))
(attach-to game actor))
(define-method (player (game <game>))
(& game player))
(define-method (bullets (game <game>))
(& game bullets))
(define-method (on-boot (game <game>))
(set! *random-state* (random-state-from-platform))
(set-cameras! game)
(attach-to game
(make <bullets>
#:name 'bullets
#:quadtree (quadtree game))))
(define-method (on-enter (game <game>))
(spawn game
(make <player>
#:name 'player
#:position (vec2 (/ %game-width 2.0) 20.0)
#:hitbox (make-rect -2.0 -2.0 4.0 4.0)))
(spawn game
(make <flower>
#:position (vec2 (/ %game-width 2.0)
(/ %game-height 2.0))
#:hitbox (make-rect -32.0 -32.0 64.0 64.0)
#:health 10)))
(define-method (on-key-press (game <game>) key modifiers repeat?)
(case key
((q)
(pop-scene (current-kernel)))
((left)
(set! (move-left? (player game)) #t))
((right)
(set! (move-right? (player game)) #t))
((down)
(set! (move-down? (player game)) #t))
((up)
(set! (move-up? (player game)) #t))
((z)
(set! (shoot? (player game)) #t))))
(define-method (on-key-release (game <game>) key modifiers)
(case key
((left)
(set! (move-left? (player game)) #f))
((right)
(set! (move-right? (player game)) #f))
((down)
(set! (move-down? (player game)) #f))
((up)
(set! (move-up? (player game)) #f))
((z)
(set! (shoot? (player game)) #f))))
(define-method (update (game <game>) dt)
(next-method)
(shoot-maybe (player game) (bullets game))
(for-each-child (lambda (child)
(when (and (is-a? child <damageable>)
(dead? child))
(on-death child (bullets game))
(quadtree-delete! (quadtree game)
(world-hitbox child)
child)
(detach child)))
game))
|