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 maph=8
bonus_docked=1 bonus_docked=1
cam={} cam={}
next_target()
end end
function _init() function _init()
@ -92,15 +94,20 @@ function _update()
if pc.y <= maph and not plr_static then 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 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 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) local solid=fget(pmaps,0)
if target and dist(plr_speed) < land_speed_limit and p.y < pc.y then local slow=dist(plr_speed) < land_speed_limit
plr_win=true if dock and slow and p.y < pc.y then
plr_speed={x=0,y=0} plr_speed={x=0,y=0}
plr_pos={x=flr(plr_pos.x+0.5),y=flr(plr_pos.y+0.5)} plr_pos={x=flr(plr_pos.x+0.5),y=flr(plr_pos.y+0.5)}
plr_docked=true plr_docked=true
plr_static=true plr_static=true
plr_landings+=1 plr_landings+=1
if target then
plr_money+=bonus_docked
next_target()
end
sfx(1) sfx(1)
break break
elseif solid or plr_pos.y<=0 then elseif solid or plr_pos.y<=0 then
@ -216,6 +223,23 @@ function _draw()
print("✽"..plr_money, fx,fy+fh+2+16,3) print("✽"..plr_money, fx,fy+fh+2+16,3)
end 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) function to_scrn(p)
local x=p.x*8 local x=p.x*8
local y=128-p.y*8 local y=128-p.y*8