add skillshots
This commit is contained in:
+20
-2
@@ -2,6 +2,8 @@ import { Vector2 } from 'three'
|
||||
import SAT from 'sat'
|
||||
import SATX from './satx.js'
|
||||
import Pathfind from './pathfind.js'
|
||||
import Ability from './ability.js'
|
||||
import Effect from './effect.js'
|
||||
|
||||
export default class Entity {
|
||||
id = crypto.randomUUID()
|
||||
@@ -9,6 +11,13 @@ export default class Entity {
|
||||
radius = 0
|
||||
health = 1
|
||||
maxHealth = 1
|
||||
abilities = [
|
||||
() => {},
|
||||
Ability.skillshot({ range: 800, radius: 5, speed: 3000, onCollide: Effect.damage({ despawn: true }) }),
|
||||
() => {},
|
||||
() => {},
|
||||
() => {},
|
||||
]
|
||||
|
||||
#position = new Vector2()
|
||||
#dest = null
|
||||
@@ -59,6 +68,10 @@ export default class Entity {
|
||||
])
|
||||
}
|
||||
|
||||
castAction(slot, x, y) {
|
||||
this.abilities[slot].bind(this)(x, y)
|
||||
}
|
||||
|
||||
collidables() {
|
||||
const entityColliders = (this.game?.entities ?? []).filter((e) => e.id != this.id).map((e) => e.collider)
|
||||
const terrainColliders = (this.game?.terrains ?? []).map((t) => t.colliders).flat()
|
||||
@@ -74,6 +87,10 @@ export default class Entity {
|
||||
return entityColliders.concat(terrainColliders)
|
||||
}
|
||||
|
||||
despawn() {
|
||||
this.game?.despawn(this)
|
||||
}
|
||||
|
||||
fixPosition() {
|
||||
this.#position = SATX.fixCollisions(this.#position, this.collidables(), this.radius, this.game?.width, this.game?.height)
|
||||
}
|
||||
@@ -122,8 +139,9 @@ export default class Entity {
|
||||
|
||||
if (this.#path.length > 0) {
|
||||
const destination = this.#path.at(0)
|
||||
const distance = this.position.clone().sub(destination).length()
|
||||
const direction = destination.clone().sub(this.position).normalize()
|
||||
const difference = destination.clone().sub(this.position)
|
||||
const distance = difference.length()
|
||||
const direction = difference.clone().normalize()
|
||||
const stepTaken = this.position.clone().add(direction.multiplyScalar(speed))
|
||||
const position = distance <= speed ? destination : stepTaken
|
||||
|
||||
|
||||
Reference in New Issue
Block a user