Skip to content

Commit

Permalink
chore(gameobjects): set enemy maxHP
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 22, 2025
1 parent 976a335 commit 6121b61
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/gameobjects/enemy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { Sprite, Tag } from '../constants'
import type { Player } from '../types'

enum Health {
Min = 20,
Max = 100,
}

export function addEnemy(x: number, y: number, player: Player) {
const speed = rand(100, 300)
const sprites = [Sprite.Bubbie, Sprite.Pokey]
const speed = rand(100, 300)
const hp = randi(Health.Min, Health.Max)

const enemy = add([
sprite(sprites[randi(sprites.length)]),
pos(x, y),
anchor('center'),
health(randi(20, 100)),
health(hp, hp),
opacity(1),
area(),
scale(0.75),
Expand All @@ -23,7 +29,7 @@ export function addEnemy(x: number, y: number, player: Player) {
})

enemy.onHurt(() => {
enemy.opacity = enemy.hp() / 100
enemy.opacity = enemy.hp() / enemy.maxHP()!
})

enemy.onDeath(() => {
Expand Down

0 comments on commit 6121b61

Please sign in to comment.