You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
3.0 KiB

pico-8 cartridge // http://www.pico-8.com
version 32
__lua__
-- 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
-- game code
bg = blue
function _init()
-- button-press initial delay
poke(0x5f5c, 2)
-- button-press repeat
poke(0x5f5d, 2)
init_world()
end
function init_world()
player = {}
player.x = 64
player.y = 16
player.spr = 1
drops = {}
ramps = {}
add_ramp(50,20,15,10)
add_ramp(60,50,15,-15)
add_ramp(48,60,20,0)
add_ramp(45,75,10,30)
end
function add_ramp(x,y,dx,dy)
r = {}
r.x = x
r.y = y
r.dx = dx
r.dy = dy
add(ramps, r)
end
function _update()
update_player()
update_drops()
end
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
if (player.y < 0) player.y = 0
if (player.y > 127) player.y = 127
if (player.x < 0) player.x = 0
if (player.x > 127) player.x = 127
if btnp(🅾) then
drop = {}
drop.x = player.x
drop.y = player.y
add(drops, drop)
end
end
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
function update_drops()
draw_world()
new_drops = {}
for i=1,#drops do
d = drops[i]
update_drop(d)
if d.y < 128 then
add(new_drops, d)
end
end
drops = new_drops
end
function _draw()
draw_world()
spr(player.spr,player.x-1,player.y-1)
print("drops: "..#drops, 1, 6, white)
end
function draw_world()
cls(bg)
foreach(drops, draw_drop)
foreach(ramps, draw_ramp)
end
function draw_ramp(r)
line(r.x,r.y,r.x+r.dx,r.y+r.dy,brown)
end
function draw_drop(drop)
pset(drop.x, drop.y, white)
end
__gfx__
000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000aaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
007007000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000