diff --git a/src/com/Enemy.ts b/src/com/Enemy.ts new file mode 100644 index 0000000..89cf7e3 --- /dev/null +++ b/src/com/Enemy.ts @@ -0,0 +1,37 @@ +import { k } from '../kaboom'; +import { + AreaComp, + GameObj, + PosComp, + SpriteComp, +} from 'kaboom'; + +const { + add, + anchor, + area, + pos, + Rect, + sprite, + vec2, + z, +} = k; + +type EnemyType = 'hotdog' | 'pickle' | 'egg'; + +export interface Enemy extends GameObj { + type: EnemyType; +} + +export function enemy(type: EnemyType, position = vec2(-10)): Enemy { + return add([ + sprite('enemies', { anim: `${type}-walk` }), + anchor('center'), + pos(position), + area({ shape: new Rect(vec2(0), 7, 15), offset: vec2(0), collisionIgnore: ['powerup'] }), + z(20), + type, + { type }, + "enemy", + ]); +} diff --git a/src/scenes/GameScene.ts b/src/scenes/GameScene.ts index 4923afa..b95f621 100644 --- a/src/scenes/GameScene.ts +++ b/src/scenes/GameScene.ts @@ -6,6 +6,7 @@ import { } from 'kaboom'; import { k } from '../kaboom'; import { powerup } from '../com/Powerup'; +import { enemy } from '../com/Enemy'; import { peter, PeterComp } from '../com/Peter'; import { canSalt, SaltComp } from '../com/Salt'; import { canScore, ScoreComp } from '../com/Score'; @@ -125,6 +126,9 @@ export default function(levelNumber = 0) { const player: GameObj = level.spawn("p", 16, 21.625); player.setObjects({ floors, stairs, stairtops }); + // Enemy Setup + enemy('hotdog', vec2(160, 173)); + // Powerups function waitSpawnPowerup() { // Wait 20-60 seconds