lots of fixes

This commit is contained in:
James Turk 2023-03-08 21:24:15 -06:00
parent 7c02a9f18a
commit cb85e6ff11

View File

@ -14,8 +14,8 @@ function _update()
if mode == "title" then if mode == "title" then
update_title() update_title()
elseif mode == "game" then elseif mode == "game" then
handle_input() sled_upd()
update_trees() trees_upd()
end end
end end
@ -25,10 +25,9 @@ function _draw()
draw_snow() draw_snow()
elseif mode == "game" then elseif mode == "game" then
draw_game() draw_game()
draw_snow() --draw_snow()
--pdebug() --draw_hud()
draw_collide() --draw_bounds()
draw_hud()
end end
end end
@ -37,11 +36,51 @@ function draw_game()
cls(6) cls(6)
-- grey transparency -- grey transparency
palt(0b000001000000000) palt(0b000001000000000)
draw_trees() trees_dr()
draw_dogs() sled_dr()
palt() palt()
end end
-->8
-- title
title_y = 0
title_stretch = 0
title_rainbow = 0
title_susan = -40
title_89 = 40
function update_title()
if title_y < 50 then
title_y += 1
elseif title_stretch < 16 then
title_stretch += 1
end
if title_stretch == 16 and title_susan < 30 then
title_susan += 1
title_89 -= 1
end
if btnp(4) then
mode = "game"
end
end
function draw_title()
cls(0)
if title_susan then
print("susan butcher's", title_susan, title_susan + 10, 12)
end
pal(8, 8+t()%6)
pal(12, 8+(t()+4)%6)
sspr(48, 24, 54, 16,
40-title_stretch, title_y,
54+title_stretch*2, 16+title_stretch)
sspr(104, 24, 16, 16,
70+title_89, 100+title_89,
48, 48)
end
-->8 -->8
-- snow -- snow
@ -78,61 +117,8 @@ end
-->8 -->8
-- game entities -- game entities
function draw_dogs() goal = 10000
local d = {[0]=5, 6, 5, 7, 7, 6} mode = "title"
for x=0,1 do
for y=0,2 do
local dx = 64 - (10 * x) +
(steering*4*y)
if y*2+x < dogs then
spr(d[y*2+x], dx,
128-(16*(y+1)), 1, 2)
end
end
end
end
function draw_tree(x, y)
spr(11, x, y, 1, 2)
end
function draw_trees()
for i=1,8 do
draw_tree(
left_wall[i]-8 - sled_x + 64,
(i-1)*16
)
draw_tree(
right_wall[i] - sled_x + 64,
(i-1)*16
)
end
end
function tree_spread()
-- ret: 2 vals, 15 to 60
-- width of field
local diff = 15+((goal - distance) / goal)*45
shift = rnd(60-diff)*rnd({-1, 1})
diff += rnd(diff*0.2)-diff*0.1
return left_wall[1]+shift, left_wall[1]+shift+diff
end
function update_trees()
local new_dist = distance + speed
if flr(new_dist / 16) > flr(distance / 16) then
-- shift 'em down
for i = 8,2,-1 do
left_wall[i] = left_wall[i-1]
right_wall[i] = right_wall[i-1]
end
-- new tree at back
l, r = tree_spread()
left_wall[1] = l
right_wall[1] = r
end
end
function draw_hud() function draw_hud()
rectfill(14,0,114,4,7) rectfill(14,0,114,4,7)
@ -151,32 +137,25 @@ function draw_hud()
local mtg = ceil((goal-distance)/1000)*100 local mtg = ceil((goal-distance)/1000)*100
print(mtg.." miles to go!", 30, 64) print(mtg.." miles to go!", 30, 64)
end end
end
function draw_bounds()
sl, sr = sled_bounds()
rect(screenx(sl), 128-16*3, screenx(sr), 128)
tl, tr = tree_bounds()
rect(screenx(tl), 100, screenx(tr), 128)
end end
-->8 -->8
-- global state -- sled
goal = 10000
mode = "title"
steering = 0 steering = 0
speed = 1 speed = 1
distance = 0 -- 10ths of mile distance = 0 -- 10ths of mile
sled_x = 64 sled_x = 64
dogs = 6 dogs = 6
left_wall = {
22, 20, 20, 18,
18, 16, 16, 16,
}
right_wall = { function sled_upd()
112, 112, 114, 114,
116, 118, 118, 118
}
-->8
-- update logic
function handle_input()
if btn(0) then if btn(0) then
steering = -1 steering = -1
elseif btn(1) then elseif btn(1) then
@ -185,18 +164,21 @@ function handle_input()
steering = 0 steering = 0
end end
if btn(2) then speed = 1 + (distance / 3000)
speed = 20
else if btnp(4) then
speed = 1 speed *= 3
--steering = rnd({-2, 2})
end end
distance += speed distance += speed
sled_x += steering * speed sled_x += steering * speed
l, r = bounds() sl, sr = sled_bounds()
if sled_x-5 < l or sled_x+5 > r then tl, tr = tree_bounds()
crash() --printh(tl.." "..sl..","..sr.." "..tr)
if sl < tl or sr > tr then
crash()
end end
if distance >= goal then if distance >= goal then
@ -204,77 +186,119 @@ function handle_input()
end end
end end
function bounds() function sled_bounds()
-- return left, right if dogs % 2 == 0 then
w = {8, 8, 7, 7, 6, 6} return sled_x-8, sled_x+8
w = w[dogs] else
return left_wall[w], return sled_x, sled_x+8
right_wall[w] end
end end
function draw_collide()
rect(52, 108, 72, 128)
l, r = bounds()
line(l, 90, l, 128, 3)
line(r, 90, r, 128, 3)
end
function crash() function crash()
sfx(4) sfx(4)
dogs -= 1 dogs -= 1
if dogs == 0 then if dogs == 0 then
mode = "gameover" mode = "gameover"
end end
sled_x = (left_wall[8]+right_wall[8])/2 sled_x = tree_wall[8].l + tree_wall[8].w / 2
end end
function sled_dr()
local d = {[0]=5, 6, 5, 7, 7, 6}
for x=0,1 do
for y=0,2 do
if y*2+x < dogs then
-- draw dogs centered
local dx = screenx(sled_x + steering*4*y) + (8 * (x-1))
spr(d[y*2+x], dx, 128-(16*(y+1)), 1, 2)
end
end
end
end
-->8 -->8
-- title -- trees
title_y = 0 -- left & width
title_stretch = 0 tree_wall = {
title_rainbow = 0 {l=5, w=80},
title_susan = -40 {l=5, w=80},
title_89 = 40 {l=5, w=80},
{l=5, w=80},
{l=10, w=80},
{l=15, w=80},
{l=20, w=80},
{l=17, w=80},
{l=23, w=80},
{l=25, w=80},
} -- 1..10
function update_title() function draw_tree(x, y)
if title_y < 50 then spr(11, x, y, 1, 2)
title_y += 1 end
elseif title_stretch < 16 then
title_stretch += 1
end
if title_stretch == 16 and title_susan < 30 then
title_susan += 1
title_89 -= 1
end
if btnp(4) then function screenx(x)
mode = "game" -- world x to screen x
return x + 64 - sled_x
end
function cur_tree()
--
return #tree_wall - flr((distance / 16) % #tree_wall)
end
function trees_dr()
local ct=cur_tree()
for i=-2,8 do
tree = tree_wall[(ct+i) % #tree_wall + 1]
draw_tree(
screenx(tree.l),
i*16 + (distance % 16)
)
draw_tree(
screenx(tree.l + tree.w),
i*16 + (distance % 16)
)
end end
end end
function draw_title() function trees_upd()
cls(0) local new_dist = distance + speed
if flr(new_dist / 16) > flr(distance / 16) then
add_next_tree()
end
end
if title_susan then function add_next_tree()
print("susan butcher's", local pct = (goal - distance) / goal
title_susan, -- TODO: adjust difficulty
title_susan + 10, 12) local minw = 70 + 45 * pct
local maxw = 90 - 50 * pct
local nw = tree_wall[1].w + rnd(8)-4
local idx = cur_tree() - 1
if idx == 0 then
idx = #tree_wall
end end
pal(8, 8+t()%6) tree_wall[idx] =
pal(12, 8+(t()+4)%6) {
sspr(48, 24, 54, 16, l=tree_wall[cur_tree()].l + rnd(8)-4 + steering,
40-title_stretch, w=max(min(nw, maxw), minw)
title_y, }
54+title_stretch*2,
16+title_stretch)
sspr(104, 24, 16, 16,
70+title_89,
100+title_89,
48, 48)
end end
function tree_bounds()
-- return left, right
-- use wall based on dogs
-- remaining
w = {8, 8, 7, 7, 6, 6}
w = w[dogs]
l = tree_wall[w].l
-- middle of tree is bound
return l+8, l+tree_wall[w].w+8
end
__gfx__ __gfx__
00000000644444466444444667c7c7c6666666666666666666666666666666660000000000033000666666666666666600000000666666666666666600000000 00000000644444466444444667c7c7c6666666666666666666666666666666660000000000033000666666666666666600000000666666666666666600000000
000000006499994664999946c777777c666666666666666666666666556666550000000000033000666336666663766600000000466666646666666600000000 000000006499994664999946c777777c666666666666666666666666556666550000000000033000666336666663766600000000466666646666666600000000