add momentum to sideways movement

This commit is contained in:
Colin McMillen 2021-06-09 17:38:32 -04:00
parent 14189a67ae
commit 0d902cb2bd

31
drip.p8
View File

@ -15,7 +15,7 @@ function _init()
-- button-press initial delay -- button-press initial delay
poke(0x5f5c, 1) poke(0x5f5c, 1)
-- button-press repeat -- button-press repeat
poke(0x5f5d, 1) poke(0x5f5d, 2)
init_world() init_world()
end end
@ -66,21 +66,34 @@ function update_drops()
for i=1,#drops do for i=1,#drops do
drop = drops[i] drop = drops[i]
try_left = rnd() < 0.5 try_left = rnd() < 0.5
if drop.momentum == 0 then
if try_left then
drop.momentum = -1
else
drop.momentum = 1
end
end
if pget(drop.x, drop.y+1) == black then if pget(drop.x, drop.y+1) == black then
drop.y += 1 drop.y += 1
elseif try_left and drop.x > 0 then elseif try_left and drop.x > 0 and
if pget(drop.x-1, drop.y+1) == black then pget(drop.x-1, drop.y+1) == black then
drop.x -= 1 drop.x -= 1
drop.y += 1 drop.y += 1
elseif pget(drop.x-1, drop.y) == black then elseif drop.x < 127 and
pget(drop.x+1, drop.y+1) == black then
drop.x += 1
drop.y += 1
elseif drop.momentum == -1 then
if drop.x > 0 and pget(drop.x-1, drop.y) == black then
drop.x -= 1 drop.x -= 1
else
drop.momentum = 0
end end
elseif drop.x < 127 then elseif drop.momentum == 1 then
if pget(drop.x+1, drop.y+1) == black then if drop.x < 127 and pget(drop.x+1, drop.y) == black then
drop.x += 1
drop.y += 1
elseif pget(drop.x+1, drop.y) == black then
drop.x += 1 drop.x += 1
else
drop.momentum = 0
end end
end end
if drop.y > 127 then drop.y = 127 end if drop.y > 127 then drop.y = 127 end