Browse Source

make drops flow a little better

main
Colin McMillen 3 years ago
parent
commit
14189a67ae
  1. 52
      drip.p8

52
drip.p8

@ -13,9 +13,9 @@ end
function _init()
-- button-press initial delay
poke(0x5f5c, 2)
poke(0x5f5c, 1)
-- button-press repeat
poke(0x5f5d, 2)
poke(0x5f5d, 1)
init_world()
end
@ -25,16 +25,16 @@ function _update()
end
function update_player()
if (btn(0)) then
if btn(0) then
player.x -= 1
end
if (btn(1)) then
if btn(1) then
player.x += 1
end
if (btn(2)) then
if btn(2) then
player.y -= 1
end
if (btn(3)) then
if btn(3) then
player.y += 1
end
if (player.y < 0) player.y = 0
@ -46,6 +46,7 @@ function update_player()
drop = {}
drop.x = player.x
drop.y = player.y
drop.momentum = 0
found_drop = false
for i=1,#drops do
if (drops[i].x == player.x and drops[i].y == player.y) then
@ -59,20 +60,31 @@ function update_player()
end
end
function update_drop(drop)
drop.y += 1
return drop.y < 128
end
function update_drops()
new_drops = {}
cls()
draw_drops()
for i=1,#drops do
result = update_drop(drops[i])
if result then
add(new_drops, drops[i])
end
drop = drops[i]
try_left = rnd() < 0.5
if pget(drop.x, drop.y+1) == black then
drop.y += 1
elseif try_left and drop.x > 0 then
if pget(drop.x-1, drop.y+1) == black then
drop.x -= 1
drop.y += 1
elseif pget(drop.x-1, drop.y) == black then
drop.x -= 1
end
elseif drop.x < 127 then
if pget(drop.x+1, drop.y+1) == black then
drop.x += 1
drop.y += 1
elseif pget(drop.x+1, drop.y) == black then
drop.x += 1
end
end
if drop.y > 127 then drop.y = 127 end
end
drops = new_drops
end
function _draw()
@ -89,6 +101,12 @@ end
function draw_drops()
foreach(drops,draw_drop)
circfill(94, 94, 3, green)
line(20, 20, 90, 60)
line(20, 21, 90, 61)
print("hello there", 63, 63, yellow)
end
function draw_drop(drop)

Loading…
Cancel
Save