move entity definitions to templates

This commit is contained in:
2025-01-13 16:53:12 +09:00
parent ffbc4d9803
commit 9d3fbda494
8 changed files with 93 additions and 137 deletions
+65
View File
@@ -0,0 +1,65 @@
import { Vector2 } from 'three'
import Ability from './ability.js'
import Team from './team.js'
export default class Template {
static minion(team, options = {}) {
return {
abilities: [options.ranged ? Ability.rangedAttack : Ability.meleeAttack, null, null, null],
height: options.ranged ? 40 : 38,
logic: this.#minionLogic(team),
maxHealth: options.ranged ? 300 : 450,
position: team == Team.blue ? new Vector2(200, 200) : new Vector2(1800, 1800),
radius: options.ranged ? 46 : 48,
speed: 325,
team,
}
}
static player(overrides) {
return {
abilities: [
Ability.rangedAttack,
Ability.straightShot,
Ability.shieldThrow,
Ability.blink,
],
height: 80,
logic: this.#playerLogic,
maxHealth: 600,
spawnPosition: new Vector2(500, 150),
radius: 65,
...overrides,
}
}
static #minionLogic(team) {
const finalGoal = team == Team.blue ? new Vector2(1900, 1900) : new Vector2(100, 100)
const subGoal = new Vector2(850, 1150)
const subGoalCheck = team == Team.blue ? ((entity) => entity.position.x < 800 || entity.position.y < 1100) : ((entity) => entity.position.x > 900 || entity.position.y > 1200)
return function builtMinionLogic() {
const entity = this
if (entity.dead) { entity.despawn() }
let goal = finalGoal
if (subGoalCheck(entity)) {
goal = subGoal
}
const direction = goal.clone().sub(entity.position).normalize().multiplyScalar(100)
const fakeDestination = entity.position.clone().add(direction)
entity.attackAction(fakeDestination.x, fakeDestination.y)
}
}
// TODO: proper respawn
static #playerLogic() {
return function playerLogic() {
const entity = this
if (entity.dead) {
entity.respawn()
}
}
}
}