-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaves.factor
245 lines (224 loc) · 7.59 KB
/
waves.factor
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
USING: accessors combinators indices kernel math math.functions
namespaces random raylib sequences utils ;
IN: waves
INDEX: WAVE_NONE WAVE_1 WAVE_2 WAVE_3 ;
SYMBOL: Waves
TUPLE: Bullet
{ hitbox Rectangle }
{ direction Vector2 }
{ angle-direction float }
{ angle-facing float }
{ time-spawn float }
{ special-flag boolean } ;
C: <Bullet> Bullet
TUPLE: wave-vars
{ current-wave integer }
{ current-box Rectangle }
{ damage float }
{ wave-timer float }
{ box Rectangle }
{ leg-texture Texture2D }
{ pizza-texture Texture2D }
{ tower-texture Texture2D }
{ hurt-sound Sound }
{ pizza-explosion Sound }
{ bullet-list sequence }
{ box-size-changed boolean }
{ set-random-wave boolean }
{ change-menu boolean } ;
C: <wave-vars> wave-vars
: init-waves ( -- )
WAVE_NONE
100 300 get-screen-width 200 - 200 Rectangle boa
0.3
0.0
105 305 get-screen-width 210 - 190 Rectangle boa
"assets/graphics/Sicily_leg.png" load-texture
"assets/graphics/pizza.png" load-texture
"assets/graphics/pisa_tower.png" load-texture
"assets/sfx/it_hurts.wav" load-sound
"assets/sfx/pizza_explosion.wav" load-sound
0 { } new-sequence f f f <wave-vars> Waves set
Waves get
dup hurt-sound>> dup 1.4 set-sound-pitch 0.05 set-sound-volume
pizza-explosion>> 0.1 set-sound-volume ;
:: set-wave-1 ( -- )
Waves get
350 300 get-screen-width 700 - 200 Rectangle boa >>current-box
t >>box-size-changed
15.0 >>wave-timer drop
14
[| i |
Waves get
dup bullet-list>>
250 random 350 + get-screen-height 100 + 60 152 Rectangle boa
0 -250 <Vector2>
0.0 0.0
i 1.2 /
f
<Bullet> suffix
>>bullet-list drop
] each-integer ;
:: create-pizza ( i -- )
Waves get :> wave
250 random 350 + :> x
-50 :> y
! True pizza lovers know that real pizzas have 6 slices
wave
dup bullet-list>>
x 10 + y 8 + 15 15 Rectangle boa 250 250 <Vector2> 0.0 55.0 deg>rad i 1.2 / f <Bullet> suffix
x y 1 + 15 15 Rectangle boa 250 250 <Vector2> 0.0 0.0 deg>rad i 1.2 / f <Bullet> suffix
x 10 - y 8 + 15 15 Rectangle boa 250 250 <Vector2> 0.0 -55.0 deg>rad i 1.2 / f <Bullet> suffix
x 10 + y 23 + 15 15 Rectangle boa 250 250 <Vector2> 0.0 125.0 deg>rad i 1.2 / f <Bullet> suffix
x y 30 + 15 15 Rectangle boa 250 250 <Vector2> 0.0 180.0 deg>rad i 1.2 / f <Bullet> suffix
x 10 - y 23 + 15 15 Rectangle boa 250 250 <Vector2> 0.0 235.0 deg>rad i 1.2 / f <Bullet> suffix
>>bullet-list drop ;
: set-wave-2 ( -- )
Waves get
250 300 get-screen-width 500 - 200 Rectangle boa >>current-box
t >>box-size-changed
18.0 >>wave-timer drop
18 [ create-pizza ] each-integer ;
:: set-wave-3 ( -- )
Waves get
350 300 get-screen-width 700 - 200 Rectangle boa >>current-box
t >>box-size-changed
20.0 >>wave-timer drop
14
[| i |
Waves get
dup bullet-list>>
100 random :> rand-n
rand-n 2 mod 0 = 380 get-screen-width 480 - ? get-screen-height 200 + 56 339 Rectangle boa
0 -320 <Vector2>
0.0 rand-n 2 mod 0 = 3.97 -3.97 ?
i i +
f
<Bullet> suffix
>>bullet-list drop
] each-integer ;
:: change-box-size ( text-box-rect! player! -- )
Waves get :> wave
text-box-rect x>> wave current-box>> x>> - dup 0 =
[ text-box-rect [ swap sgn 10 * - ] change-x ] unless
text-box-rect width>> wave current-box>> width>> - dup 0 =
[ text-box-rect [ swap sgn 20 * - ] change-width ] unless
2drop
text-box-rect y>> wave current-box>> y>> - dup 0 =
[ text-box-rect [ swap sgn 10 * - ] change-y ] unless
text-box-rect height>> wave current-box>> height>> - dup 0 =
[ text-box-rect [ swap sgn 10 * - ] change-height ] unless
2drop
wave wave-timer>> 0 <= text-box-rect width>> get-screen-width 200 - >= and
[
wave
t >>change-menu
dup current-wave>> WAVE_3 =
[ t >>set-random-wave ] when
drop
player 480 450 40 40 Rectangle boa >>box drop
] when ;
:: update-bullet ( player! boss-is-flustered boss-is-annoyed -- )
Waves get :> wave
wave
{
{ [ boss-is-flustered ] [ 0.1 ] }
{ [ boss-is-annoyed ] [ 0.6 ] }
[ 0.3 ]
} cond >>damage drop
wave bullet-list>>
[| bullet i |
bullet time-spawn>> 0 >
[ bullet [ get-frame-time - ] change-time-spawn drop ]
[
bullet hitbox>>
[ bullet direction>> y>> get-frame-time * bullet angle-direction>> cos * + ] change-y
[ bullet direction>> x>> get-frame-time * bullet angle-direction>> sin * + ] change-x
bullet hitbox>> y>> get-screen-height 1.6 / > bullet special-flag>> not and wave current-wave>> WAVE_2 = and
[
wave pizza-explosion>> play-sound
bullet
t >>special-flag
dup angle-facing>> 10.0 deg>rad - >>angle-direction
drop
] when
player box>> x>> player box>> y>> player size>> x>> player size>> y>> Rectangle boa check-collision-recs
[
wave hurt-sound>> is-sound-playing [ wave hurt-sound>> play-sound ] unless
player [ wave damage>> - ] change-hp player!
] when
! drop
] if
] each-index
wave
[ get-frame-time - ] change-wave-timer
wave-timer>> 0 <=
[
wave
t >>box-size-changed
100 300 get-screen-width 200 - 200 Rectangle boa >>current-box
0 { } new-sequence >>bullet-list
drop
] when ;
:: update-wave ( text-box-rect! player! boss-is-flustered boss-is-annoyed -- )
Waves get :> wave
wave box-size-changed>> not
[
{
{ [ wave current-wave>> WAVE_1 = ] [ set-wave-1 ] }
{ [ wave current-wave>> WAVE_2 = ] [ set-wave-2 ] }
{ [ wave current-wave>> WAVE_3 = ] [ set-wave-3 ] }
[ ]
} cond
]
[ text-box-rect player change-box-size ] if
wave wave-timer>> 0 > [ player boss-is-flustered boss-is-annoyed update-bullet ] when ;
:: draw-wave-1 ( wave bullet -- )
wave leg-texture>>
0 0 60 152 Rectangle boa
bullet hitbox>>
0 0 <Vector2>
bullet angle-facing>> rad>deg
WHITE
draw-texture-pro ;
:: draw-wave-2 ( wave bullet -- )
wave pizza-texture>>
0 0 30 30 Rectangle boa
bullet hitbox>> x>> bullet hitbox>> y>> 30 30 Rectangle boa
15 15 <Vector2>
bullet angle-facing>> rad>deg
WHITE
draw-texture-pro ;
! bullet hitbox>> WHITE draw-rectangle-rec ;
:: draw-wave-3 ( wave bullet -- )
350 300 get-screen-width 700 - 200 begin-scissor-mode
wave tower-texture>>
0 0 112 339 Rectangle boa
bullet hitbox>> x>> bullet hitbox>> y>> 112 339 Rectangle boa
0 0 <Vector2>
bullet angle-facing>>
WHITE
draw-texture-pro
! bullet hitbox>> WHITE draw-rectangle-rec
end-scissor-mode ;
:: draw-waves ( -- )
Waves get :> wave
wave bullet-list>>
[| bullet |
bullet time-spawn>> 0 <=
[
{
{ [ wave current-wave>> WAVE_1 = ] [ wave bullet draw-wave-1 ] }
{ [ wave current-wave>> WAVE_2 = ] [ wave bullet draw-wave-2 ] }
{ [ wave current-wave>> WAVE_3 = ] [ wave bullet draw-wave-3 ] }
[ ]
} cond
] when
] each ;
: unload-waves ( -- )
Waves get
dup leg-texture>> unload-texture
dup pizza-texture>> unload-texture
dup tower-texture>> unload-texture
dup hurt-sound>> unload-sound
pizza-explosion>> unload-sound ;