pico8-moonbus/moonbus.p8

414 lines
24 KiB
Plaintext
Raw Normal View History

pico-8 cartridge // http://www.pico-8.com
version 42
__lua__
-- MoonBus
-- by Dejvino
2024-08-09 18:23:58 +00:00
function reset()
plr_alive=true
plr_win=false
plr_docked=false
plr_pos={x=5,y=8}
plr_speed={x=0.5,y=0}
plr_static=false
plr_engine=-1
plr_fuel=1
2024-08-09 19:12:25 +00:00
plr_landings=0
plr_transed=0
plr_money=0
plr_target={x=8,y=2}
2024-08-09 18:23:58 +00:00
telem_spd={}
gravity=0.02
engine_power=0.1
2024-08-09 19:53:57 +00:00
fuel_cons=0.005
2024-08-09 18:23:58 +00:00
land_speed_limit=1
maph=8
2024-08-09 19:12:25 +00:00
bonus_docked=1
2024-08-09 18:23:58 +00:00
cam={}
2024-08-09 19:41:35 +00:00
next_target()
2024-08-09 18:23:58 +00:00
end
function _init()
reset()
end
function _update()
debug_points={}
2024-08-09 18:23:58 +00:00
if not plr_alive and btn(❎) then
reset()
end
-- controlls
plr_engine=-1
if plr_alive and plr_fuel>0 then
2024-08-09 07:22:18 +00:00
if not plr_docked then
if btn(⬆️) then plr_engine=⬆️ end
if btn(⬇️) then plr_engine=⬇️ end
if btn(⬅️) then plr_engine=⬅️ end
if btn(➡️) then plr_engine=➡️ end
end
if plr_docked and btn(❎) then
plr_docked=false
plr_static=false
plr_engine=⬆️
plr_speed={x=0,y=0.5}
sfx(4)
2024-08-09 07:22:18 +00:00
end
end
-- engine
if plr_engine==⬆️ then
plr_speed.y+=engine_power
2024-08-09 07:22:18 +00:00
elseif plr_engine==⬇️ then
plr_speed.y-=engine_power
elseif plr_engine==⬅️ then
plr_speed.x-=engine_power
elseif plr_engine==➡️ then
plr_speed.x+=engine_power
end
2024-08-09 06:30:36 +00:00
if plr_engine != -1 then
sfx(2,2)
plr_fuel=max(0,plr_fuel-fuel_cons)
2024-08-09 06:30:36 +00:00
else
sfx(-1,2)
end
if plr_docked then
plr_fuel=min(1,plr_fuel+fuel_cons)
end
-- move objects
move(plr_pos,plr_speed,0.1)
-- gravity pull
if not plr_static then
plr_speed.y-=gravity
end
-- crash detection
local pc=plus(plr_pos,{x=0.5,y=-0.5})
2024-08-09 07:22:18 +00:00
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)
2024-08-09 19:41:35 +00:00
local dock=fget(pmaps,7)
local target=dist(plr_pos,plr_target)<=1
local solid=fget(pmaps,0)
2024-08-09 19:41:35 +00:00
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)}
2024-08-09 07:22:18 +00:00
plr_docked=true
plr_static=true
2024-08-09 19:12:25 +00:00
plr_landings+=1
2024-08-09 19:41:35 +00:00
if target then
plr_money+=bonus_docked
next_target()
end
2024-08-09 06:30:36 +00:00
sfx(1)
break
elseif solid or plr_pos.y<=0 then
plr_speed.y*=-0.75
2024-08-09 18:23:58 +00:00
plr_speed.x*=0.5
plr_alive=false
if (dist(plr_speed) > 1) then
2024-08-09 06:30:36 +00:00
sfx(0)
else
plr_speed.x=0
plr_speed.y=0
plr_static=true
2024-08-09 07:22:18 +00:00
sfx(3)
end
break
end
end
end
2024-08-09 06:54:52 +00:00
if plr_alive then
telem_spd=mul(plr_speed,1)
end
cam={x=plr_pos.x*8-60, y=0}
end
function _draw()
cls()
2024-08-09 07:22:18 +00:00
camera(cam.x,cam.y)
map(0, 0, 0, 128-maph*8)
local px,py=to_scrn(plr_pos)
local img=0
2024-08-09 07:22:18 +00:00
if plr_docked then
img=5
elseif not plr_alive then
img=4
elseif plr_engine==⬆️ then
img=2
2024-08-09 07:22:18 +00:00
elseif plr_engine==⬇️ then
img=2
elseif plr_engine==⬅️ then
img=3
elseif plr_engine==➡️ then
img=1
end
spr(img,px,py)
for p in all(debug_points) do
local px,py=to_scrn(p)
pset(px,py,8)
end
2024-08-09 19:12:25 +00:00
-- target
if plr_alive then
local tx,ty=to_scrn(plr_target)
local dst=dist(plr_pos,plr_target)
local c=flr(t())%2==0 and 3 or 11
if dst > 8 then
local dir=atan2(tx-px,ty-py)
line(px+4+cos(dir)*10,py+4+sin(dir)*10,tx+4,ty+4,c)
end
if dst > 3 then
print("웃",tx,ty+2,c)
else
print("__",tx,ty+4,c)
end
end
--
2024-08-09 07:22:18 +00:00
-- HUD
2024-08-09 19:12:25 +00:00
--
2024-08-09 07:22:18 +00:00
camera(0,0)
-- fuel
local fw=20
local fh=6
local fx=85
local fy=0
rect(fx,fy,fx+fw,fy+fh,5)
rectfill(fx+1,fy+1,fx+plr_fuel*(fw-1),fy+fh-1,plr_fuel > 0.25 and 13 or 8)
print("fuel", fx+3,fy+1,1)
2024-08-09 06:54:52 +00:00
-- telemetry
local cr=10
2024-08-09 07:22:18 +00:00
local cp={x=127-cr,y=cr}
2024-08-09 06:54:52 +00:00
local spd={x=limit(telem_spd.x,1),y=limit(telem_spd.y,1)}
circ(cp.x,cp.y,cr,3)
line(cp.x,cp.y,cp.x+spd.x*cr,cp.y,11)
line(cp.x,cp.y,cp.x,cp.y-spd.y*cr,11)
circ(cp.x+spd.x*cr,cp.y-spd.y*cr,1,dist(telem_spd)<land_speed_limit and 3 or 8)
if not plr_alive then
line(cp.x+(-0.3*cr),cp.y+(-0.6*cr),cp.x,cp.y,5)
line(cp.x+(-0.7*cr),cp.y+(-0.3*cr),cp.x,cp.y,5)
line(cp.x,cp.y,cp.x+0.6*cr,cp.y+0.3*cr,5)
line(cp.x+0.6*cr,cp.y+0.3*cr,cp.x+0.2*cr,cp.y+0.8*cr,5)
end
2024-08-09 07:22:18 +00:00
if plr_alive then
if plr_docked then
2024-08-09 18:23:58 +00:00
print("smooth! you docked.", 0,0,3)
print("press ❎ to undock.", 32,60,11)
2024-08-09 07:22:18 +00:00
else
print("land gently to dock.", 0,0,3)
end
else
print("oops! you crashed.", 0,0,8)
2024-08-09 18:23:58 +00:00
print("press ❎ to reset.", 32,60,11)
2024-08-09 07:22:18 +00:00
end
2024-08-09 19:12:25 +00:00
print("⌂"..plr_landings, fx,fy+fh+2+0,3)
print("웃"..plr_transed, fx,fy+fh+2+8,3)
print("✽"..plr_money, fx,fy+fh+2+16,3)
end
2024-08-09 19:41:35 +00:00
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
return x,y
end
function move(p,d,a)
a=a or 1
p.x+=d.x*a
p.y+=d.y*a
end
function plus(p,d,a)
a=a or 1
return {
x=p.x+d.x*a,
y=p.y+d.y*a
}
end
function clearx(p)
return {
x=0,
y=p.y
}
end
function cleary(p)
return {
x=p.x,
y=0
}
end
function mul(p,a)
return {
x=p.x*a,
y=p.y*a
}
end
function neg(p)
return mul(p,-1)
end
2024-08-09 19:12:25 +00:00
function dist(p,p2)
p2=p2 or {x=0,y=0}
return abs(p.x-p2.x) + abs(p.y-p2.y)
end
function unit(p,u)
u=u or 1
local x = 0
local y = 0
if p.x>0 then x=u end
if p.x<0 then x=-u end
if p.y>0 then y=u end
if p.y<0 then y=-u end
return {x=x,y=y}
end
2024-08-09 06:54:52 +00:00
function limit(val,lim)
if (abs(val) > lim) then
return val*lim/abs(val)
end
return val
end
__gfx__
000000000000000000000000000000000000aa00000000000000b000000000000000000000000000000000000000000000000000000000000000000000000000
00a9a90000a9a90000a9a90000a9a90000a9000000a9a9000000b000000000000000000000000000000000000000000000000000000000000000000000000000
001111000011110000111100001111000001000000111100008bb800000000000000000000000000000000000000000000000000000000000000000000000000
01111110011111100111111001111110010010100111111000b00bbb000000000000000000000000000000000000000000000000000000000000000000000000
0a9999400a9999400a9999400a9999400a9990400a776540bbb00b00000000000000000000000000000000000000000000000000000000000000000000000000
5a9999458a9999455a9999455a999948000909555a7c5645008bb800000000000000000000000000000000000000000000000000000000000000000000000000
594944458949444559494445594944485949044059671545000b0000000000000000000000000000000000000000000000000000000000000000000000000000
0055550000555500008888000055550050555500007c5600000b0000000000000000000000000000000000000000000000000000000000000000000000000000
66566665000000000000000560000000d8ddddbd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
666666660000000000000006660000005d7c56d50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
56666657000000000000005756600000566715570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
66756666000000000000066666750000667c56660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
66666666000000000000666666666000666715660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
66666665006600000006666566666600667c55650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
65666657076567600066665765666650656556570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
67656666666666566765666667656666666566660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2024-08-09 06:30:36 +00:00
00000007777777777d8ddbd770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000767676767676dddd7665000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000077666666666661166665000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000007661116116616d161655000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000776d161dd66d166dd665000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000076666666666666666655000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000076656565656565656565000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000005555555555555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
6460000677c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
545646666611cc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
6555456661d111500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
5455556661dd15650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
65554566666656550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
54555566666565550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
55511166565655500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
11100006555555000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__gff__
2024-08-09 06:30:36 +00:00
0000000000000000000000000000000001000000810000000000000000000000000181000000000000000000000000000101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__map__
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2024-08-09 19:53:57 +00:00
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000011001100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000011110000000000000000000000000000000000001210141000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2024-08-09 19:53:57 +00:00
0000111100000000000000001210101300000000000000000000000000000000121010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001100000000000000000000000000110000000000000000000000000000110000
0012101013000000000000121010101000000000000000000000000000000012101010101013000000000000000000000000000000000000000000000000000011000000000000000000000020212123202123000000000000000000110000121010130000000000000000202122101300000000000000000000000012101300
1210101010130000000012101010101011001100000000110000000000121010101010101010130011000000000012141300000000000000000000000000001110130000000000000000000020212121212123000000000011001210101010101010101300001100000000202121101013000012101300000000001210101013
1010101010101010141010101010101010101010101010101010141010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010141010101010101010101010101010101010101010101010101010101010101010101010101010101010101010212221101010101010
__sfx__
2024-08-09 06:54:52 +00:00
000400002c2501f250132503365036650396503765035650316502f6502c650246501d6501b6501b65019650126500e65010650116500c6500d6500e6500c6500a65007650016500065000000000000000000000
010800000a4500a4500a4503d0502d0503d0502645026050264503d61421630216301d6201c6101a6150000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0001002005750087500b7500b7500a750067500375005750087500a7500b7500a75009750047500475006750097500a7500a75009750087500675006750087500a7500a75008750067500675008750097500a750
2024-08-09 07:22:18 +00:00
00080000161501915026150241501d150161500e1500c150061500315001150001500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
010800003d61421630264502605026450216302162021610216102161600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
002000001885000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000