diff --git a/snowdogs.p8 b/snowdogs.p8 index 4060932..a588877 100644 --- a/snowdogs.p8 +++ b/snowdogs.p8 @@ -9,6 +9,7 @@ function _init() create_particles() mode = "title" goal = 10000 + start_time = 0 music(0) end @@ -56,7 +57,7 @@ function draw_game() trees_dr() sled_dr() if npc.draw != nil then - npc.draw(npc.x, npc.y) + npc.draw(npc.x, npc_y()) end end @@ -81,6 +82,7 @@ function title_upd() if btnp(4) then mode = "game" + start_time = t() end if t() > 10 and t() < 20 then @@ -188,6 +190,10 @@ end -->8 -- game entities +function disp_time() + return flr(t() - start_time) +end + function draw_hud() rectfill(14,0,114,4,7) local d = 14+distance/goal*100 @@ -196,6 +202,7 @@ function draw_hud() for l=1,dogs do print("🐱", 1, (l-1)*7, 7) end + print(disp_time(), 3, 45) print("▒", 108, 0, 0) if distance >= goal then @@ -209,9 +216,13 @@ end function draw_bounds() sl, sr = sled_bounds() - rect(screenx(sl), 128-16*3, screenx(sr), 128) + rect(screenx(sl), sled_top(), screenx(sr), 128) tl, tr = tree_bounds() rect(screenx(tl), 100, screenx(tr), 128) + + if npc.collide != nil then + rect(npc.x-8, npc_y(), npc.x+8, npc_y()+16) + end end -->8 -- sled @@ -223,6 +234,10 @@ sled_x = 64 dogs = 6 mush_time = 0 +function sled_top() + return 128-16*ceil(dogs/2) +end + function sled_upd() if btn(0) then steering = -1 @@ -232,6 +247,7 @@ function sled_upd() steering = 0 end + speed = 2 + (distance / 3000) if btnp(4) and t() - mush_time > 1 then @@ -240,9 +256,12 @@ function sled_upd() --steering = rnd({-2, 2}) end - if t() - mush_time < 0.2 then + if t() - mush_time < 0.3 then speed *= 3 end + if btn(3) then + speed *= 0.2 + end distance += speed sled_x += steering * speed @@ -255,6 +274,8 @@ function sled_upd() if distance >= goal then state = "win" + end_time = disp_time() + music(0) end end @@ -262,7 +283,7 @@ function sled_bounds() if dogs % 2 == 0 then return sled_x-8, sled_x+8 else - return sled_x, sled_x+8 + return sled_x-8, sled_x end end @@ -400,7 +421,6 @@ end npc = { x=0, - y=0, dx=0, dy=0, last=0, @@ -409,6 +429,10 @@ npc = { sound=nil, } +function npc_y() + return (distance - npc.last) +end + function npc_upd() -- every 200, roll for new npc if distance - npc.last > 200 then @@ -431,9 +455,9 @@ function npc_upd() npc.sound = 7 else npc.draw = nil + npc.collide = nil end npc.last = distance - npc.y = rnd(40) npc.x = -10 npc.dx = rnd(1)+1 npc.dy = rnd(2) @@ -441,15 +465,18 @@ function npc_upd() npc.x += 140 npc.dx *= -1 end + if npc_y() > 120 then + npc.collide = nil + end end -- update npc npc.x += npc.dx - npc.y += npc.dy -- check collision l, r = sled_bounds() - if npc.y > 80 and npc.x+8 > l and npc.x < r and npc.collide != nil then + if npc_y()+16 > sled_top() and npc.x+8 > l and npc.x < r and npc.collide != nil then + printh("collide ") npc.collide() npc.collide = nil sfx(npc.sound) @@ -507,10 +534,10 @@ function draw_flag(loser) if loser then print("better luck next year", 20, 115, 9) else - music(0) local scale = (sin(t()) + 2)*2.5 * 8 sspr(32, 24, 8, 8, 80-scale/2, 48-scale/2, scale, scale) - print("see you again in '84!", 20, 115, 9) + print(end_time .. " !!! a world record!", 20, 110, 9) + print("see you again in '84!", 20, 120, 9) end end