clean restart for picogora

This commit is contained in:
Colin McMillen 2021-06-10 16:34:33 -04:00
parent bc0a76c495
commit f715861f14

View File

@ -4,12 +4,12 @@ __lua__
-- game code
function init_world()
drops = {}
frozen_drops = {}
player = {}
player.x = 64
player.y = 16
player.spr = 1
drops = {}
end
function _init()
@ -21,8 +21,8 @@ function _init()
end
function _update()
update_drops()
update_player()
update_drops()
end
function update_player()
@ -43,76 +43,20 @@ function update_player()
if (player.x < 0) player.x = 0
if (player.x > 127) player.x = 127
if (btnp(🅾️)) then
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
add(drops, drop)
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
drop.y += 1
if drop.y < 128 then
add(new_drops, drop)
end
end
@ -120,52 +64,17 @@ function update_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()
cls(blue)
foreach(drops, draw_drop)
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)
print("drops: "..#drops, 1, 6, white)
end
function draw_drop(drop)
pset(drop.x, drop.y, blue)
pset(drop.x, drop.y, white)
end
-->8
-- library