lots of fixes
This commit is contained in:
parent
7c02a9f18a
commit
cb85e6ff11
290
snowdogs.p8
290
snowdogs.p8
@ -14,8 +14,8 @@ function _update()
|
||||
if mode == "title" then
|
||||
update_title()
|
||||
elseif mode == "game" then
|
||||
handle_input()
|
||||
update_trees()
|
||||
sled_upd()
|
||||
trees_upd()
|
||||
end
|
||||
end
|
||||
|
||||
@ -25,10 +25,9 @@ function _draw()
|
||||
draw_snow()
|
||||
elseif mode == "game" then
|
||||
draw_game()
|
||||
draw_snow()
|
||||
--pdebug()
|
||||
draw_collide()
|
||||
draw_hud()
|
||||
--draw_snow()
|
||||
--draw_hud()
|
||||
--draw_bounds()
|
||||
end
|
||||
end
|
||||
|
||||
@ -37,11 +36,51 @@ function draw_game()
|
||||
cls(6)
|
||||
-- grey transparency
|
||||
palt(0b000001000000000)
|
||||
draw_trees()
|
||||
draw_dogs()
|
||||
trees_dr()
|
||||
sled_dr()
|
||||
palt()
|
||||
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
|
||||
-- snow
|
||||
|
||||
@ -78,61 +117,8 @@ end
|
||||
-->8
|
||||
-- game entities
|
||||
|
||||
function draw_dogs()
|
||||
local d = {[0]=5, 6, 5, 7, 7, 6}
|
||||
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
|
||||
goal = 10000
|
||||
mode = "title"
|
||||
|
||||
function draw_hud()
|
||||
rectfill(14,0,114,4,7)
|
||||
@ -151,32 +137,25 @@ function draw_hud()
|
||||
local mtg = ceil((goal-distance)/1000)*100
|
||||
print(mtg.." miles to go!", 30, 64)
|
||||
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
|
||||
-->8
|
||||
-- global state
|
||||
-- sled
|
||||
|
||||
goal = 10000
|
||||
mode = "title"
|
||||
steering = 0
|
||||
speed = 1
|
||||
distance = 0 -- 10ths of mile
|
||||
sled_x = 64
|
||||
dogs = 6
|
||||
|
||||
left_wall = {
|
||||
22, 20, 20, 18,
|
||||
18, 16, 16, 16,
|
||||
}
|
||||
|
||||
right_wall = {
|
||||
112, 112, 114, 114,
|
||||
116, 118, 118, 118
|
||||
}
|
||||
|
||||
-->8
|
||||
-- update logic
|
||||
function handle_input()
|
||||
function sled_upd()
|
||||
if btn(0) then
|
||||
steering = -1
|
||||
elseif btn(1) then
|
||||
@ -185,17 +164,20 @@ function handle_input()
|
||||
steering = 0
|
||||
end
|
||||
|
||||
if btn(2) then
|
||||
speed = 20
|
||||
else
|
||||
speed = 1
|
||||
speed = 1 + (distance / 3000)
|
||||
|
||||
if btnp(4) then
|
||||
speed *= 3
|
||||
--steering = rnd({-2, 2})
|
||||
end
|
||||
|
||||
distance += speed
|
||||
sled_x += steering * speed
|
||||
|
||||
l, r = bounds()
|
||||
if sled_x-5 < l or sled_x+5 > r then
|
||||
sl, sr = sled_bounds()
|
||||
tl, tr = tree_bounds()
|
||||
--printh(tl.." "..sl..","..sr.." "..tr)
|
||||
if sl < tl or sr > tr then
|
||||
crash()
|
||||
end
|
||||
|
||||
@ -204,77 +186,119 @@ function handle_input()
|
||||
end
|
||||
end
|
||||
|
||||
function bounds()
|
||||
-- return left, right
|
||||
w = {8, 8, 7, 7, 6, 6}
|
||||
w = w[dogs]
|
||||
return left_wall[w],
|
||||
right_wall[w]
|
||||
function sled_bounds()
|
||||
if dogs % 2 == 0 then
|
||||
return sled_x-8, sled_x+8
|
||||
else
|
||||
return sled_x, sled_x+8
|
||||
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()
|
||||
sfx(4)
|
||||
dogs -= 1
|
||||
if dogs == 0 then
|
||||
mode = "gameover"
|
||||
end
|
||||
sled_x = (left_wall[8]+right_wall[8])/2
|
||||
sled_x = tree_wall[8].l + tree_wall[8].w / 2
|
||||
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
|
||||
-- title
|
||||
-- trees
|
||||
|
||||
title_y = 0
|
||||
title_stretch = 0
|
||||
title_rainbow = 0
|
||||
title_susan = -40
|
||||
title_89 = 40
|
||||
-- left & width
|
||||
tree_wall = {
|
||||
{l=5, w=80},
|
||||
{l=5, w=80},
|
||||
{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()
|
||||
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
|
||||
function draw_tree(x, y)
|
||||
spr(11, x, y, 1, 2)
|
||||
end
|
||||
|
||||
if btnp(4) then
|
||||
mode = "game"
|
||||
function screenx(x)
|
||||
-- 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
|
||||
|
||||
function draw_title()
|
||||
cls(0)
|
||||
|
||||
if title_susan then
|
||||
print("susan butcher's",
|
||||
title_susan,
|
||||
title_susan + 10, 12)
|
||||
function trees_upd()
|
||||
local new_dist = distance + speed
|
||||
if flr(new_dist / 16) > flr(distance / 16) then
|
||||
add_next_tree()
|
||||
end
|
||||
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)
|
||||
function add_next_tree()
|
||||
local pct = (goal - distance) / goal
|
||||
-- TODO: adjust difficulty
|
||||
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
|
||||
|
||||
tree_wall[idx] =
|
||||
{
|
||||
l=tree_wall[cur_tree()].l + rnd(8)-4 + steering,
|
||||
w=max(min(nw, maxw), minw)
|
||||
}
|
||||
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__
|
||||
00000000644444466444444667c7c7c6666666666666666666666666666666660000000000033000666666666666666600000000666666666666666600000000
|
||||
000000006499994664999946c777777c666666666666666666666666556666550000000000033000666336666663766600000000466666646666666600000000
|
||||
|
Loading…
Reference in New Issue
Block a user