199 lines
4.3 KiB
Plaintext
199 lines
4.3 KiB
Plaintext
|
pico-8 cartridge // http://www.pico-8.com
|
||
|
version 32
|
||
|
__lua__
|
||
|
-- game code
|
||
|
|
||
|
function init_world()
|
||
|
drops = {}
|
||
|
frozen_drops = {}
|
||
|
player = {}
|
||
|
player.x = 64
|
||
|
player.y = 16
|
||
|
player.spr = 1
|
||
|
end
|
||
|
|
||
|
function _init()
|
||
|
-- button-press initial delay
|
||
|
poke(0x5f5c, 1)
|
||
|
-- button-press repeat
|
||
|
poke(0x5f5d, 2)
|
||
|
init_world()
|
||
|
end
|
||
|
|
||
|
function _update()
|
||
|
update_drops()
|
||
|
update_player()
|
||
|
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
|
||
|
drop.momentum = 0
|
||
|
drop.fall_time = 0
|
||
|
found_drop = false
|
||
|
for i=1,#drops do
|
||
|
if (drops[i].x == player.x and drops[i].y == player.y) then
|
||
|
found_drop = true
|
||
|
break
|
||
|
end
|
||
|
end
|
||
|
if (not found_drop) then
|
||
|
add(drops, drop)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function update_drops()
|
||
|
cls()
|
||
|
draw_drops()
|
||
|
for i=1,#drops do
|
||
|
drop = drops[i]
|
||
|
try_left = rnd() < 0.5
|
||
|
if drop.momentum == 0 then
|
||
|
if try_left then
|
||
|
drop.momentum = -1
|
||
|
else
|
||
|
drop.momentum = 1
|
||
|
end
|
||
|
end
|
||
|
if pget(drop.x, drop.y+1) == black then
|
||
|
drop.y += 1
|
||
|
drop.momentum = 0
|
||
|
drop.fall_time = 0
|
||
|
elseif try_left and drop.x > 0 and
|
||
|
pget(drop.x-1, drop.y+1) == black then
|
||
|
drop.x -= 1
|
||
|
drop.y += 1
|
||
|
drop.fall_time = 0
|
||
|
elseif drop.x < 127 and
|
||
|
pget(drop.x+1, drop.y+1) == black then
|
||
|
drop.x += 1
|
||
|
drop.y += 1
|
||
|
drop.fall_time = 0
|
||
|
elseif drop.momentum == -1 then
|
||
|
drop.fall_time += 1
|
||
|
if drop.x > 0 and pget(drop.x-1, drop.y) == black then
|
||
|
drop.x -= 1
|
||
|
else
|
||
|
drop.momentum = 0
|
||
|
end
|
||
|
elseif drop.momentum == 1 then
|
||
|
drop.fall_time += 1
|
||
|
if drop.x < 127 and pget(drop.x+1, drop.y) == black then
|
||
|
drop.x += 1
|
||
|
else
|
||
|
drop.momentum = 0
|
||
|
end
|
||
|
end
|
||
|
if drop.y > 127 then drop.y = 127 end
|
||
|
end
|
||
|
|
||
|
new_drops = {}
|
||
|
for i=1,#drops do
|
||
|
drop = drops[i]
|
||
|
if drop.fall_time > 64 then
|
||
|
add(frozen_drops, drop)
|
||
|
else
|
||
|
add(new_drops, drop)
|
||
|
end
|
||
|
end
|
||
|
drops = new_drops
|
||
|
end
|
||
|
|
||
|
function _draw()
|
||
|
cls()
|
||
|
draw_drops()
|
||
|
draw_player()
|
||
|
--print("cpu: "..stat(1), 0, 0, light_gray)
|
||
|
--print("drops: "..#drops, 0, 6, light_gray)
|
||
|
--print("frozen: "..#frozen_drops, 0, 12, light_gray)
|
||
|
end
|
||
|
|
||
|
function draw_player()
|
||
|
spr(player.spr,player.x-1,player.y-1)
|
||
|
end
|
||
|
|
||
|
function draw_drops()
|
||
|
foreach(frozen_drops,draw_drop)
|
||
|
foreach(drops,draw_drop)
|
||
|
circfill(94, 94, 3, green)
|
||
|
circfill(98, 105, 2, orange)
|
||
|
line(98, 115, 98, 122, pink)
|
||
|
line(105, 122)
|
||
|
line(105, 115)
|
||
|
|
||
|
line(70, 64, 90, 60, dark_purple)
|
||
|
line(70, 65, 90, 61, dark_purple)
|
||
|
|
||
|
line(60, 30, 80, 50, indigo)
|
||
|
line(60, 31, 80, 51, indigo)
|
||
|
|
||
|
line(64, 90, 74, 90)
|
||
|
line(70, 86)
|
||
|
line(68, 86, 64, 90)
|
||
|
|
||
|
ovalfill(54, 95, 74, 100, pink)
|
||
|
|
||
|
line(70, 116, 93, 112, green)
|
||
|
line(70, 115, 93, 111, green)
|
||
|
line(70, 116, 60, 112, green)
|
||
|
line(70, 115, 60, 111, green)
|
||
|
|
||
|
print("hello everybody", 63, 58, yellow)
|
||
|
|
||
|
end
|
||
|
|
||
|
function draw_drop(drop)
|
||
|
pset(drop.x, drop.y, blue)
|
||
|
end
|
||
|
|
||
|
-->8
|
||
|
-- 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
|
||
|
__gfx__
|
||
|
000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
|
00000000aaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
|
007007000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
|
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
|
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
|
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|