Browse Source

drops can fall left or right

main
Colin McMillen 3 years ago
parent
commit
cc338a6dc4
  1. 65
      picogora.p8

65
picogora.p8

@ -26,7 +26,15 @@ end
-->8
-- game code
bg = 12
bg = blue
function _init()
-- button-press initial delay
poke(0x5f5c, 2)
-- button-press repeat
poke(0x5f5d, 2)
init_world()
end
function init_world()
player = {}
@ -38,20 +46,8 @@ function init_world()
ramps = {}
add_ramp(50,20,15,10)
add_ramp(60,50,15,-15)
add_ramp(50,60,20,0)
end
function _init()
-- button-press initial delay
poke(0x5f5c, 1)
-- button-press repeat
poke(0x5f5d, 2)
init_world()
end
function _update()
update_player()
update_drops()
add_ramp(48,60,20,0)
add_ramp(45,75,10,30)
end
function add_ramp(x,y,dx,dy)
@ -63,6 +59,11 @@ function add_ramp(x,y,dx,dy)
add(ramps, r)
end
function _update()
update_player()
update_drops()
end
function update_player()
if btn(0) then
player.x -= 1
@ -89,14 +90,39 @@ function update_player()
end
end
function update_drop(d)
if d.y == 127 or pget(d.x,d.y+1) == bg then
d.y += 1
return
end
left = pget(d.x-1,d.y) == bg and pget(d.x-1,d.y+1) == bg
right = pget(d.x+1,d.y) == bg and pget(d.x+1,d.y+1) == bg
if left and right then
d.y += 1
if rnd() < 0.5 then
d.x -= 1
else
d.x += 1
end
elseif left then
d.y += 1
d.x -= 1
elseif right then
d.y += 1
d.x += 1
end
end
function update_drops()
draw_world()
new_drops = {}
for i=1,#drops do
drop = drops[i]
drop.y += 1
if drop.y < 128 then
add(new_drops, drop)
d = drops[i]
update_drop(d)
if d.y < 128 then
add(new_drops, d)
end
end
drops = new_drops
@ -122,7 +148,6 @@ function draw_drop(drop)
pset(drop.x, drop.y, white)
end
__gfx__
000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000aaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Loading…
Cancel
Save