-
Notifications
You must be signed in to change notification settings - Fork 0
/
bounce.p8
60 lines (57 loc) · 1.63 KB
/
bounce.p8
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
pico-8 cartridge // http://www.pico-8.com
version 35
__lua__
balls={}
function make_ball()
return {x=rnd(128),
y=rnd(128),
vx=rnd(50)-25,
vy=0,--rnd(100)-50,
col=rnd(15),
r=4,
}
end
function _init()
for x=0,20 do
add(balls, make_ball())
end
end
gravity=10
elast=0.8
dt=1/30
function _update()
if btnp(0) then
for b in all(balls) do
b.vx = -b.vx
end
end
if btnp(1) then
for b in all(balls) do
gravity = -gravity
end
end
for b in all(balls) do
b.vy = b.vy + gravity*dt
if b.x < b.r or b.x > 128-b.r then
b.vx = -elast*b.vx
end
if b.y < b.r or b.y > 128-b.r then
b.vy = -elast*b.vy
end
b.x = b.x + b.vx * dt
b.y = b.y + b.vy * dt
end
end
function _draw()
cls(0)
for b in all(balls) do
circfill(b.x, b.y, b.r, b.col)
end
end
__gfx__
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000