add momentum to sideways movement

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

37
drip.p8
View File

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