Skip to content

Commit

Permalink
wip: Enemy
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuacurtiss committed Jun 2, 2024
1 parent 45ee690 commit c494548
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/com/Enemy.ts
Original file line number Diff line number Diff line change
@@ -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<SpriteComp & AreaComp & PosComp> {
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",
]);
}
4 changes: 4 additions & 0 deletions src/scenes/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -125,6 +126,9 @@ export default function(levelNumber = 0) {
const player: GameObj<PeterComp & PosComp & SpriteComp & SaltComp & ScoreComp & WalkComp> = 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
Expand Down

0 comments on commit c494548

Please sign in to comment.