-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreflection.spd
More file actions
executable file
·256 lines (209 loc) · 5.48 KB
/
reflection.spd
File metadata and controls
executable file
·256 lines (209 loc) · 5.48 KB
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
246
247
248
249
250
251
252
253
254
255
#!/usr/local/bin/spd
import "GUI"
main
return Breakout().RunAsMain(2.0, 60)
// block nudge... for vibration on hit
class Breakout (Window)
|fpsview| FPS
|[vobject]| Blocks
|vobject| Bar
|[vobject]| Balls
|[vobject]| Explosions
|float| BallSpeed
|int| Hits
|[vobject]| Spirals
constructor
.bar = vobject.Box(nil, nil)
.fps = fpsview(self)
.reset
function AddBalls (|vec2| P, |vobject|)
Rz = vobject.Box(P, (16th, 16th))
rz.Velocity = vec3(0, -.ballspeed, 0)
.balls <~ rz
function reset (|string| msg="")
if msg
beep msg
.ballspeed = 0.13
.bar.pos = vec3(10.0, 0.5, 0)
.bar.size = vec3(2.0, 0.25, 1)
.balls.length = 0
.Blocks.Length = 0
.Explosions.Length = 0
for y in 2.0
.addballs((10.0, 6.0+y))
for y in 5.0
|| y2 = -1.0 + y*3th
for x in 10.0
|| pos = (2.0+x*(16.0/9.0), 9.0+y*0.5)
|| bl = vobject.Box(pos, (0.75, 0.2)*1.0)
bl.Health = 1.0 + y
.Blocks <~ bl
function BounceBar (|vobject| bar, |vobject| B, |bool|)
|| Hit = bar.OverlapsBlock(B)
require hit.Exists
|| v = b.Velocity
require v.y < 0.0
|| rr = bar.Box2D
|| D = math.RangeConvert(rr.x1, rr.x2, -1, 1).Convert(b.pos.x).spow2
v.y = -v.y
v.x = D*.ballspeed
b.Velocity = v.Normal*.ballspeed
return true
function Bounds (|vobject| b)
|| bvx = b.Velocity.x
if bvx < 0
if b.left <= 0
bvx = -bvx
else
if b.right >= 20.0
bvx = -bvx
b.Velocity.x = bvx
if b.y >= 12.0
b.Velocity.y = -b.Velocity.y
function Incr (|float|)
|| h = ++.Hits
|| add = 0.02 / h|float| pow 1.5
.BallSpeed += add
return .BallSpeed
function HitOne (|vobject| bl, |vec4| R, |vobject| ball, |bool|)
|| R2 = bl.OverlapsRect(R)
require r2.exists
|| Cn = r2.Center
.spirals <~ vobject.Box(cn, vec2(6), bl.Color)
if r2.Height > r2.Width
ball.Velocity.x = -ball.Velocity.x
else
ball.Velocity.y = -ball.Velocity.y
ball.Velocity = ball.Velocity.Normal * .incr
|| hp = bl.Health - ball.box2d.Width*8
bl.Health = hp
if (hp <= 0) or 0.5[]
|| pu = .PowerUp(8)
if !pu
0 //
elseif pu <= 2
if .balls < 4
|| b2 = .addballs(cn)
|| old = .Blocks.now!
b2.towards(old.pos, .BallSpeed)
b2.Velocity = -b2.Velocity
elseif pu <= 5
|| b2 = vobject.Box(ball.pos.xy, vec2(1+(pu-3))*0.3)
b2.Color = colors.Red //
.Explosions <~ b2
elseif pu <= 7
ball.Radius += 16th
ball.radius = ball.radius min vec3(0.5)
elseif pu == 8
|| b = (.Bar.radius.x + 8th) min 2.0
.bar.radius.x = b
return hp <= 0
// guidable flurry aura
function PowerUp (|float| n, |int|)
|| x = .Blocks.Length|float|
|| chance = 12.0 / x
if chance[]
return 1+random.float(n)|int|
function DoHits (|vobject| ball)
|| R = ball.Box2D
for (bl.backwards in .Blocks) (i)
if .HitOne(bl, r, ball)
.blocks.FastRemove(i)
if !.blocks
.reset( "Success! You beat level-1")
return
function MoveBar (|float| x)
require x
.bar.Pos.x += x
|| bl = .bar.left
if bl < 0
.bar.pos.x -= bl
bl = .bar.right
if bl > 20.0
.bar.pos.x -= (bl-20.0)
behaviour mousemove
.movebar(move.x|float|*0.02)
behaviour FrameStep
require GUIActive
|| MinSp = .BallSpeed/4
for (b.backwards in .explosions) (i)
b.Radius -= 0.03
if b.Radius <= 0.02
.explosions.fastRemove(i)
else
.Dohits(b)
for (b.backwards in .balls) (i)
|| y = b.Velocity.y
if y.length < minsp
b.Velocity.y = minsp.CopySign(y)
b.Step
.Bounds(b)
.Dohits(b)
.BounceBar(.bar, b)
if b.y <= 0
.balls.FastRemove(i)
if !.balls
.reset( "You failed")
exit
.movebar keys.Movement.x.sign * 0.2
for (s.backwards in .Spirals) (i)
s.Radius -= 0.03
if s.Radius.x < 0
.Spirals.Remove(i)
gui.Touch
behaviour Drawbackground
|| w = where.Width
|| src = where[0,0]
for x in .Width
src++[] = Colors.rainbow(x div w, 1, 0.5).px
src = where[0,0]
|| dest = src
for h in where.Height
dest.CopyFrom(src, w)
dest = dest - w
for b in .Blocks
|| H = (1.0-b.health)*12th
b.Color = colors.wheel(H, 0.8, 0.5)
where.DrawRect(b, b.color)
|| Col = colors.wheel(H, 1.0, 0.4)
where.DrawOutlineOnly(b, col.px)
where.DrawRect(.bar, colors.white)
|| L = 24s()
for (s in .Spirals) (i)
|| B = s.Screen
where.DrawSpiral(0.005*b.width|float|*vobject.drawscale, L, b.centervec2, s.color, (3s+i*1s)())
.BallDraw(where, .balls)
.BallDraw(where, .explosions)
function BallDraw (|image| where, |[vobject]| List)
for b in list
|| bx = b.Box2d.screenfloat ± -4.0
|| sh = bx.Width*4th
where.DrawSoftCircle(bx, b.Color, 2.0)
|| v = b.Velocity.Normal.xyxy
|| m = 1.0
|| ww = bx.Width*0.05
|| C = b.Color * (1.0, 1.0-ww, 1.0-ww*2.0, 1.0)
while bx.Width >= 1.0
where.DrawSoftCircle((bx ± 2) - v*(sh*m), C, 2.0)
c = (c - (0.1, 0.3, 0.5, 0.0)).clamp
bx = bx ± bx.width*0.1
m ++
function image.DrawSpiral (|float| Max, |float| angle, |vec2| XY, |vec4| Col, |float| Pulse)
|| sub = 24.0
max += sub/2
Pulse = Pulse * max
for j in max
if j <= sub
continue
|| i = j - sub
|| R = ((i*0.2123)+angle).SinCos
|| closeness = (i - Pulse + 4.0() ).length
|| strength = (-0.005*closeness.pow2).Exp * 5.0
|| P = R*(30.0+i+strength) + XY
|| Circle = (P-4.0, P+4.0)
|| A = ((Max-i)*2.0)/max
|| C = (i*0.005, 0, 0, A)+Col
.DrawSoftCircle(Circle, C)
function float.SPow2 (|float|)
return (self*self).CopySign(self)
// copy your favourite arkanoid examples. (any on sega megadrive?)