moonbus: random target selection

This commit is contained in:
Dejvino 2024-08-09 21:41:35 +02:00
parent 7b0fd5c3ef
commit efc5e37c8e

View File

@ -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