Compare commits

...

2 Commits

Author SHA1 Message Date
0d902cb2bd add momentum to sideways movement 2021-06-09 17:38:32 -04:00
14189a67ae make drops flow a little better 2021-06-09 17:22:05 -04:00

61
drip.p8
View File

@ -13,7 +13,7 @@ end
function _init() function _init()
-- button-press initial delay -- button-press initial delay
poke(0x5f5c, 2) poke(0x5f5c, 1)
-- button-press repeat -- button-press repeat
poke(0x5f5d, 2) poke(0x5f5d, 2)
init_world() init_world()
@ -25,16 +25,16 @@ function _update()
end end
function update_player() function update_player()
if (btn(0)) then if btn(0) then
player.x -= 1 player.x -= 1
end end
if (btn(1)) then if btn(1) then
player.x += 1 player.x += 1
end end
if (btn(2)) then if btn(2) then
player.y -= 1 player.y -= 1
end end
if (btn(3)) then if btn(3) then
player.y += 1 player.y += 1
end end
if (player.y < 0) player.y = 0 if (player.y < 0) player.y = 0
@ -46,6 +46,7 @@ function update_player()
drop = {} drop = {}
drop.x = player.x drop.x = player.x
drop.y = player.y drop.y = player.y
drop.momentum = 0
found_drop = false found_drop = false
for i=1,#drops do for i=1,#drops do
if (drops[i].x == player.x and drops[i].y == player.y) then if (drops[i].x == player.x and drops[i].y == player.y) then
@ -59,20 +60,44 @@ function update_player()
end end
end end
function update_drop(drop)
drop.y += 1
return drop.y < 128
end
function update_drops() function update_drops()
new_drops = {} cls()
draw_drops()
for i=1,#drops do for i=1,#drops do
result = update_drop(drops[i]) drop = drops[i]
if result then try_left = rnd() < 0.5
add(new_drops, drops[i]) if drop.momentum == 0 then
if try_left then
drop.momentum = -1
else
drop.momentum = 1
end end
end end
drops = new_drops if pget(drop.x, drop.y+1) == black then
drop.y += 1
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
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
end
end end
function _draw() function _draw()
@ -89,6 +114,12 @@ end
function draw_drops() function draw_drops()
foreach(drops,draw_drop) 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 end
function draw_drop(drop) function draw_drop(drop)