2021-06-09 20:35:27 +00:00
|
|
|
pico-8 cartridge // http://www.pico-8.com
|
|
|
|
version 32
|
|
|
|
__lua__
|
|
|
|
-- game code
|
|
|
|
|
|
|
|
function init_world()
|
|
|
|
drops = {}
|
2021-06-10 18:22:10 +00:00
|
|
|
frozen_drops = {}
|
2021-06-09 20:35:27 +00:00
|
|
|
player = {}
|
|
|
|
player.x = 64
|
|
|
|
player.y = 16
|
2021-06-10 20:12:27 +00:00
|
|
|
player.spr = 1
|
2021-06-09 20:35:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function _init()
|
|
|
|
-- button-press initial delay
|
2021-06-09 21:22:05 +00:00
|
|
|
poke(0x5f5c, 1)
|
2021-06-09 20:35:27 +00:00
|
|
|
-- button-press repeat
|
2021-06-09 21:38:32 +00:00
|
|
|
poke(0x5f5d, 2)
|
2021-06-09 20:35:27 +00:00
|
|
|
init_world()
|
|
|
|
end
|
|
|
|
|
|
|
|
function _update()
|
|
|
|
update_drops()
|
|
|
|
update_player()
|
|
|
|
end
|
|
|
|
|
|
|
|
function update_player()
|
2021-06-09 21:22:05 +00:00
|
|
|
if btn(0) then
|
2021-06-09 20:35:27 +00:00
|
|
|
player.x -= 1
|
|
|
|
end
|
2021-06-09 21:22:05 +00:00
|
|
|
if btn(1) then
|
2021-06-09 20:35:27 +00:00
|
|
|
player.x += 1
|
|
|
|
end
|
2021-06-10 17:37:38 +00:00
|
|
|
if btn(2) then
|
|
|
|
player.y -= 1
|
|
|
|
end
|
|
|
|
if btn(3) then
|
|
|
|
player.y += 1
|
|
|
|
end
|
2021-06-09 20:35:27 +00:00
|
|
|
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
|
2021-06-09 21:22:05 +00:00
|
|
|
drop.momentum = 0
|
2021-06-10 14:47:40 +00:00
|
|
|
drop.fall_time = 0
|
2021-06-09 20:35:27 +00:00
|
|
|
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()
|
2021-06-09 21:22:05 +00:00
|
|
|
cls()
|
|
|
|
draw_drops()
|
2021-06-09 20:35:27 +00:00
|
|
|
for i=1,#drops do
|
2021-06-09 21:22:05 +00:00
|
|
|
drop = drops[i]
|
|
|
|
try_left = rnd() < 0.5
|
2021-06-09 21:38:32 +00:00
|
|
|
if drop.momentum == 0 then
|
|
|
|
if try_left then
|
|
|
|
drop.momentum = -1
|
|
|
|
else
|
|
|
|
drop.momentum = 1
|
|
|
|
end
|
|
|
|
end
|
2021-06-09 21:22:05 +00:00
|
|
|
if pget(drop.x, drop.y+1) == black then
|
|
|
|
drop.y += 1
|
2021-06-10 14:47:40 +00:00
|
|
|
drop.momentum = 0
|
|
|
|
drop.fall_time = 0
|
2021-06-09 21:38:32 +00:00
|
|
|
elseif try_left and drop.x > 0 and
|
|
|
|
pget(drop.x-1, drop.y+1) == black then
|
|
|
|
drop.x -= 1
|
|
|
|
drop.y += 1
|
2021-06-10 14:47:40 +00:00
|
|
|
drop.fall_time = 0
|
2021-06-10 17:37:38 +00:00
|
|
|
elseif drop.x < 127 and
|
2021-06-09 21:38:32 +00:00
|
|
|
pget(drop.x+1, drop.y+1) == black then
|
|
|
|
drop.x += 1
|
|
|
|
drop.y += 1
|
2021-06-10 14:47:40 +00:00
|
|
|
drop.fall_time = 0
|
2021-06-09 21:38:32 +00:00
|
|
|
elseif drop.momentum == -1 then
|
2021-06-10 14:47:40 +00:00
|
|
|
drop.fall_time += 1
|
2021-06-10 18:22:10 +00:00
|
|
|
if drop.x > 0 and pget(drop.x-1, drop.y) == black then
|
2021-06-09 21:22:05 +00:00
|
|
|
drop.x -= 1
|
2021-06-09 21:38:32 +00:00
|
|
|
else
|
|
|
|
drop.momentum = 0
|
|
|
|
end
|
|
|
|
elseif drop.momentum == 1 then
|
2021-06-10 14:47:40 +00:00
|
|
|
drop.fall_time += 1
|
2021-06-10 18:22:10 +00:00
|
|
|
if drop.x < 127 and pget(drop.x+1, drop.y) == black then
|
2021-06-09 21:22:05 +00:00
|
|
|
drop.x += 1
|
2021-06-09 21:38:32 +00:00
|
|
|
else
|
|
|
|
drop.momentum = 0
|
|
|
|
end
|
2021-06-10 18:22:10 +00:00
|
|
|
end
|
2021-06-09 21:22:05 +00:00
|
|
|
if drop.y > 127 then drop.y = 127 end
|
2021-06-09 20:35:27 +00:00
|
|
|
end
|
2021-06-10 18:22:10 +00:00
|
|
|
|
|
|
|
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
|
2021-06-09 20:35:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function _draw()
|
|
|
|
cls()
|
|
|
|
draw_drops()
|
|
|
|
draw_player()
|
2021-06-10 14:47:40 +00:00
|
|
|
--print("cpu: "..stat(1), 0, 0, light_gray)
|
|
|
|
--print("drops: "..#drops, 0, 6, light_gray)
|
2021-06-10 18:22:10 +00:00
|
|
|
--print("frozen: "..#frozen_drops, 0, 12, light_gray)
|
2021-06-09 20:35:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function draw_player()
|
|
|
|
spr(player.spr,player.x-1,player.y-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
function draw_drops()
|
2021-06-10 18:22:10 +00:00
|
|
|
foreach(frozen_drops,draw_drop)
|
2021-06-09 20:35:27 +00:00
|
|
|
foreach(drops,draw_drop)
|
2021-06-10 18:22:10 +00:00
|
|
|
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)
|
2021-06-09 21:22:05 +00:00
|
|
|
|
2021-06-10 18:22:10 +00:00
|
|
|
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)
|
2021-06-09 21:22:05 +00:00
|
|
|
|
2021-06-09 20:35:27 +00:00
|
|
|
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__
|
2021-06-10 20:12:27 +00:00
|
|
|
000000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
|
|
00000000aaa000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
|
|
007007000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
|
|
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
|
|
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
|
|
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|