From efc5e37c8ec50fe0450b56e5961c9cfb5bf56fc0 Mon Sep 17 00:00:00 2001 From: Dejvino Date: Fri, 9 Aug 2024 21:41:35 +0200 Subject: [PATCH] moonbus: random target selection --- moonbus.p8 | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/moonbus.p8 b/moonbus.p8 index 3349c0b..8b67c52 100644 --- a/moonbus.p8 +++ b/moonbus.p8 @@ -27,6 +27,8 @@ function reset() maph=8 bonus_docked=1 cam={} + + next_target() end function _init() @@ -92,15 +94,20 @@ function _update() if pc.y <= maph and not plr_static then for p in all({plus(pc,clearx(unit(plr_speed,0.4))), plus(pc,cleary(unit(plr_speed,0.4)))}) do local pmaps=mget(p.x,maph-p.y) - local target=fget(pmaps,7) + local dock=fget(pmaps,7) + local target=dist(plr_pos,plr_target)<=1 local solid=fget(pmaps,0) - if target and dist(plr_speed) < land_speed_limit and p.y < pc.y then - plr_win=true + local slow=dist(plr_speed) < land_speed_limit + if dock and slow and p.y < pc.y then plr_speed={x=0,y=0} plr_pos={x=flr(plr_pos.x+0.5),y=flr(plr_pos.y+0.5)} plr_docked=true plr_static=true plr_landings+=1 + if target then + plr_money+=bonus_docked + next_target() + end sfx(1) break elseif solid or plr_pos.y<=0 then @@ -216,6 +223,23 @@ function _draw() print("✽"..plr_money, fx,fy+fh+2+16,3) end +function next_target() + local docks={} + for x=0,127 do + for y=0,maph do + local m=mget(x,y) + local dock=fget(m,7) + local new=x!=plr_target.x and y!=plr_target.y + if dock and new then + add(docks,{x=x,y=y}) + end + end + end + local di=flr(rnd(#docks))+1 + local mp=docks[di] + plr_target={x=mp.x,y=maph-mp.y+1} +end + function to_scrn(p) local x=p.x*8 local y=128-p.y*8