diff --git a/snowdogs.p8 b/snowdogs.p8 index 8f87c58..1b70a62 100644 --- a/snowdogs.p8 +++ b/snowdogs.p8 @@ -20,6 +20,7 @@ function _update() elseif mode == "game" then sled_upd() trees_upd() + npc_upd() end end @@ -51,6 +52,9 @@ function draw_game() snowbg() trees_dr() sled_dr() + if npc.draw != nil then + npc.draw(npc.x, npc.y) + end end -->8 @@ -98,6 +102,8 @@ function title_dr() sspr(104, 24, 16, 16, 70+title_89, 100+title_89, 48, 48) + pal(8, 8) + pal(12, 12) end @@ -263,6 +269,18 @@ function crash() local ti = (cur_tree() + 8) % #tree_wall + 1 l, r = tree_bounds() sled_x = (l + r) / 2 + + -- reset npc + --npc.draw = nil + npc.collide = nil +end + +function heart() + npc.draw = draw_heart + if dogs < 6 then + dogs += 1 + end + npc.collide = nil end function sled_dr() @@ -374,11 +392,67 @@ end -->8 --npcs +npc = { + x=0, + y=0, + dx=0, + dy=0, + last=0, + draw=nil, +} + +function npc_upd() + -- every 200, roll for new npc + if distance - npc.last > 200 then + local r = rnd() + printh("npc roll: "..r) + if r < 0.03 then + npc.draw = draw_siren + npc.collide = crash + elseif r < 0.1 then + npc.draw = draw_yeti + npc.collide = crash + elseif r < 0.2 then + npc.draw = draw_moose + npc.collide = crash + elseif r < 0.4 then + npc.draw = draw_fan + npc.collide = heart + 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) + if rnd() < 0.5 then + npc.x += 140 + npc.dx *= -1 + end + end + + -- update npc + npc.x += npc.dx + npc.y += npc.dy + + -- check collision + l, r = sled_bounds() + if npc.y > 50 and npc.x > l and npc.x < r and npc.collide then + npc.collide() + end +end + function draw_fan(x, y) spr(flr(1+(t() % 2)), x, y, 1, 2, flr(t()) % 3 == 1) spr(33, x, y+16) end +function draw_heart(x, y) + spr(36, x, y) +end + function draw_yeti(x, y) spr(35, x, y, 1, 2) spr(35, x-8, y, 1, 2, true)