Skip to content

Commit

Permalink
chore(gameobjects): add body to player
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 23, 2025
1 parent 8e54bfb commit 0929058
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/events/cursors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,22 @@ export function addCursorKeys(player: Player) {
case 'left':
case 'a':
player.move(-SPEED, 0)
setCameraPosition(player)
break

case 'right':
case 'd':
player.move(SPEED, 0)
setCameraPosition(player)
break

case 'up':
case 'w':
player.move(0, -SPEED)
setCameraPosition(player)
break

case 'down':
case 's':
player.move(0, SPEED)
setCameraPosition(player)
break
}
})
}

function setCameraPosition(player: Player) {
setCamPos(player.worldPos()!)
}
1 change: 1 addition & 0 deletions src/gameobjects/enemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function addEnemy(x: number, y: number, player: Player) {
health(hp, hp),
opacity(1),
area(),
body(),
scale(0.75),
Tag.Enemy,
{ damage, speed },
Expand Down
5 changes: 5 additions & 0 deletions src/gameobjects/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ export function addPlayer(x = center().x, y = center().y) {
rotate(0),
anchor('center'),
area(),
body(),
health(HEALTH, HEALTH),
Tag.Player,
])

addCursorKeys(player)
addAttack(player)

player.onUpdate(() => {
setCamPos(player.worldPos()!)
})

player.onCollide(Tag.Enemy, (enemy) => {
const currentEnemy = enemy as Enemy
player.hurt(currentEnemy.damage)
Expand Down

0 comments on commit 0929058

Please sign in to comment.