pico-8/picogora.p8

193 lines
3.5 KiB
Plaintext
Raw Normal View History

2021-06-10 20:17:14 +00:00
pico-8 cartridge // http://www.pico-8.com
version 32
__lua__
2021-06-10 20:54:45 +00:00
-- library
black = 0
dark_blue = 1
dark_purple = 2
dark_green = 3
brown = 4
dark_gray = 5
light_gray = 6
white = 7
red = 8
orange = 9
yellow = 10
green = 11
blue = 12
indigo = 13
pink = 14
peach = 15
function print_ctr(s,y,c)
print(s,64 - #s * 2,y,c)
end
-->8
2021-06-10 20:17:14 +00:00
-- game code
2021-06-10 21:28:26 +00:00
bg = blue
function _init()
-- button-press initial delay
poke(0x5f5c, 2)
-- button-press repeat
poke(0x5f5d, 2)
init_world()
end
2021-06-10 20:53:56 +00:00
2021-06-10 20:17:14 +00:00
function init_world()
player = {}
player.x = 36
2021-06-10 20:17:14 +00:00
player.y = 16
player.spr = 1
2021-06-10 20:34:33 +00:00
drops = {}
2021-06-10 20:53:56 +00:00
ramps = {}
2021-06-10 23:02:14 +00:00
levers = {}
add_ramp(70,25,40,-5)
2021-06-10 20:53:56 +00:00
add_ramp(50,20,15,10)
add_ramp(60,50,15,-15)
2021-06-10 23:02:14 +00:00
add_ramp(52,60,14,0)
2021-06-10 21:28:26 +00:00
add_ramp(45,75,10,30)
2021-06-10 22:04:02 +00:00
2021-06-10 23:02:14 +00:00
add_ramp(64,76,0,10)
add_ramp(64,86,6,0)
2021-06-10 22:04:02 +00:00
add_ramp(70,76,0,10)
2021-06-10 23:02:14 +00:00
add_lever(30,30,20)
2021-06-10 20:17:14 +00:00
end
2021-06-10 20:53:56 +00:00
function add_ramp(x,y,dx,dy)
r = {}
r.x = x
r.y = y
r.dx = dx
r.dy = dy
add(ramps, r)
end
2021-06-10 23:02:14 +00:00
function add_lever(x,y,len)
l = {}
l.x = x
l.y = y
l.len = len
l.angle = 0
add(levers, l)
end
2021-06-10 21:28:26 +00:00
function _update()
update_player()
update_drops()
foreach(levers, update_lever)
2021-06-10 21:28:26 +00:00
end
2021-06-10 20:17:14 +00:00
function update_player()
if btn(0) then
player.x -= 1
end
if btn(1) then
player.x += 1
end
if btn(2) then
player.y -= 1
end
if btn(3) then
player.y += 1
end
player.x = mid(0, player.x, 127)
player.y = mid(0, player.y, 127)
2021-06-10 20:17:14 +00:00
2021-06-10 20:34:33 +00:00
if btnp(🅾️) then
2021-06-10 20:17:14 +00:00
drop = {}
drop.x = player.x
drop.y = player.y
2021-06-10 20:34:33 +00:00
add(drops, drop)
2021-06-10 20:17:14 +00:00
end
end
2021-06-10 23:02:14 +00:00
function update_lever(l)
l.angle -= 0.0005
2021-06-10 23:02:14 +00:00
end
2021-06-10 21:28:26 +00:00
function update_drop(d)
if d.y == 127 or pget(d.x,d.y+1) == bg then
d.y += 1
return
end
left = pget(d.x-1,d.y) == bg and pget(d.x-1,d.y+1) == bg
right = pget(d.x+1,d.y) == bg and pget(d.x+1,d.y+1) == bg
if left and right then
d.y += 1
if rnd() < 0.5 then
d.x -= 1
else
d.x += 1
end
elseif left then
d.y += 1
d.x -= 1
elseif right then
d.y += 1
d.x += 1
end
end
2021-06-10 20:17:14 +00:00
function update_drops()
2021-06-10 20:53:56 +00:00
draw_world()
2021-06-10 20:17:14 +00:00
new_drops = {}
for i=1,#drops do
2021-06-10 21:28:26 +00:00
d = drops[i]
2021-06-10 23:06:50 +00:00
oldx = d.x
oldy = d.y
2021-06-10 21:28:26 +00:00
update_drop(d)
if d.y < 128 then
add(new_drops, d)
2021-06-10 20:17:14 +00:00
end
2021-06-10 23:06:50 +00:00
pset(oldx, oldy, bg)
pset(d.x, d.y, white)
2021-06-10 20:17:14 +00:00
end
drops = new_drops
end
function _draw()
2021-06-10 20:53:56 +00:00
draw_world()
2021-06-10 20:17:14 +00:00
spr(player.spr,player.x-1,player.y-1)
2021-06-10 23:02:14 +00:00
print("("..player.x..","..player.y..")", 1, 1, white)
print("drops: "..#drops, 1, 7, white)
2021-06-10 20:17:14 +00:00
end
2021-06-10 20:53:56 +00:00
function draw_world()
cls(bg)
foreach(drops, draw_drop)
foreach(ramps, draw_ramp)
2021-06-10 23:02:14 +00:00
foreach(levers, draw_lever)
end
function draw_drop(drop)
pset(drop.x, drop.y, white)
2021-06-10 20:53:56 +00:00
end
function draw_ramp(r)
line(r.x,r.y,r.x+r.dx,r.y+r.dy,brown)
end
2021-06-10 23:02:14 +00:00
function draw_lever(l)
dx = l.len * cos(l.angle)
dy = l.len * sin(l.angle)
line(l.x,l.y,l.x+dx,l.y+dy,brown)
circ(l.x,l.y,1,black)
2021-06-10 20:17:14 +00:00
end
__gfx__
000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000aaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
007007000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000