diff --git a/src/boss-registry.js b/src/boss-registry.js index 9efc971..2c47ceb 100644 --- a/src/boss-registry.js +++ b/src/boss-registry.js @@ -3,7 +3,7 @@ // Boss classes are discovered from src/bosses/*.js by export name, so a new boss needs no import here. const B = Object.assign({}, ...Object.values(import.meta.glob("./bosses/*.js", { eager: true }))); const registry = () => ({ - rooftop: null, + rooftop: B.PizzaBoss, lobby: null, alley: null, }); diff --git a/src/bosses/pizzaBoss.js b/src/bosses/pizzaBoss.js new file mode 100644 index 0000000..e54331d --- /dev/null +++ b/src/bosses/pizzaBoss.js @@ -0,0 +1,31 @@ +export class PizzaBoss extends Boss { + hp = 12; + throwEvery = 1.4; + projectile = "pizza"; + art = "ogre"; + volley = 0; + + // every third throw is a fan of three slices + throw(w) { + this.volley = (this.volley + 1) % 3; + if (this.volley !== 0) return super.throw(w); + for (const spread of [-24, 0, 24]) { + // aim left of, at, and right of the cat + const tx = (w.player ? w.player.x : 40) + spread; + w.projectiles.push({ + kind: "pizza", + x: this.x + 4, + y: this.y - 4, + vx: (tx - this.x) / 1.5, + vy: -80 - w.rand() * 20, + r: 0, + spin: 8, + life: 4, + }); + } + if (w.level.shake) w.shake = Math.max(w.shake, w.level.shake); + } +} + +// imports are hoisted, so the class reads first +import { Boss } from "./boss.js"; diff --git a/src/levels/rooftop.js b/src/levels/rooftop.js index 6879c1e..bed78d6 100644 --- a/src/levels/rooftop.js +++ b/src/levels/rooftop.js @@ -2,6 +2,7 @@ // Roof tops are one-way platforms. The door on the left roof leads down to the lobby; walk off the left edge for the alley. import { PAL } from "../palette.js"; import { blit } from "../sprites.js"; +import { PizzaBoss } from "../bosses/pizzaBoss.js"; const BLOCKS = [ { x: 0, y: 96, w: 80, h: 84, rows: 5 }, @@ -18,9 +19,11 @@ export default { bossAt: { x: 262, y: 92 }, exits: { left: { to: "alley", at: { x: 300, y: 150 } } }, doors: [{ x: 52, y: 84, to: "lobby", at: { x: 40, y: 150 } }], - boss: null, - spawn: [], - music: "rooftop-a", + boss: new PizzaBoss({ x: 262, y: 92 }), + spawn: ["pizza"], + music: "rooftop-boss", + bossIntro: true, + shake: 0.2, draw(g) { for (const b of BLOCKS) { g.fillStyle = PAL.wall; g.fillRect(b.x, b.y, b.w, b.h);