From 0d902cb2bdffdf5245e89c9b321ad437bf280e98 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Wed, 9 Jun 2021 17:38:32 -0400 Subject: [PATCH] add momentum to sideways movement --- drip.p8 | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/drip.p8 b/drip.p8 index d8f068c..8527916 100644 --- a/drip.p8 +++ b/drip.p8 @@ -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,22 +66,35 @@ 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 - end + else + drop.momentum = 0 + end end if drop.y > 127 then drop.y = 127 end end