move entity definitions to templates
This commit is contained in:
+21
-124
@@ -1,11 +1,12 @@
|
||||
import express from 'express'
|
||||
import { WebSocketExpress } from 'websocket-express'
|
||||
import Game from './game.js'
|
||||
import Entity from './entity.js'
|
||||
import Terrain from './terrain.js'
|
||||
import { Vector2 } from 'three'
|
||||
import Team from './team.js'
|
||||
import { WebSocketExpress } from 'websocket-express'
|
||||
import Ability from './ability.js'
|
||||
import Entity from './entity.js'
|
||||
import express from 'express'
|
||||
import Game from './game.js'
|
||||
import Team from './team.js'
|
||||
import Template from './template.js'
|
||||
import Terrain from './terrain.js'
|
||||
|
||||
const app = new WebSocketExpress()
|
||||
const port = 1280
|
||||
@@ -58,39 +59,22 @@ app.ws('/ws', async (req, res) => {
|
||||
})
|
||||
|
||||
function laneScenario() {
|
||||
// TODO: proper respawn
|
||||
const playerLogic = function playerLogic() {
|
||||
const entity = this
|
||||
if (entity.dead) {
|
||||
entity.respawn()
|
||||
}
|
||||
}
|
||||
|
||||
const playerTemplate = {
|
||||
height: 80,
|
||||
logic: playerLogic,
|
||||
maxHealth: 600,
|
||||
spawnPosition: new Vector2(500, 150),
|
||||
radius: 65,
|
||||
}
|
||||
|
||||
const entity1 = new Entity({
|
||||
...playerTemplate,
|
||||
const player1 = new Entity(Template.player({
|
||||
id: '1',
|
||||
spawnPosition: new Vector2(500, 150),
|
||||
team: Team.blue,
|
||||
})
|
||||
}))
|
||||
game.spawnEntity(player1)
|
||||
|
||||
game.spawnEntity(entity1)
|
||||
|
||||
const entity2 = new Entity({
|
||||
...playerTemplate,
|
||||
const player2 = new Entity(Template.player({
|
||||
id: '2',
|
||||
spawnPosition: new Vector2(1600, 1800),
|
||||
team: Team.red,
|
||||
})
|
||||
}))
|
||||
game.spawnEntity(player2)
|
||||
|
||||
game.spawnEntity(entity2)
|
||||
player1.attackAction(500, 150)
|
||||
player2.attackAction(1600, 1800)
|
||||
|
||||
const midWallStart = new Vector2(400, 400)
|
||||
const midWallEnd = new Vector2(1600, 1600)
|
||||
@@ -117,106 +101,19 @@ function laneScenario() {
|
||||
midSouthWall.id = 'midSouthWall'
|
||||
game.addTerrain(midSouthWall)
|
||||
|
||||
const 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)
|
||||
}
|
||||
}
|
||||
|
||||
const minionTemplate = {
|
||||
height: 40,
|
||||
maxHealth: 300,
|
||||
radius: 48,
|
||||
speed: 325,
|
||||
}
|
||||
|
||||
const meleeMinionTemplate = {
|
||||
...minionTemplate,
|
||||
height: 38,
|
||||
radius: 46,
|
||||
maxHealth: 450,
|
||||
}
|
||||
|
||||
const gameLogic = function gameLogic() {
|
||||
const game = this
|
||||
|
||||
const blueMinion = new Entity({
|
||||
...minionTemplate,
|
||||
logic: minionLogic(Team.blue),
|
||||
team: Team.blue,
|
||||
position: new Vector2(200, 200),
|
||||
})
|
||||
|
||||
const blueMeleeMinion = new Entity({
|
||||
...meleeMinionTemplate,
|
||||
logic: minionLogic(Team.blue),
|
||||
team: Team.blue,
|
||||
position: new Vector2(200, 200),
|
||||
})
|
||||
blueMeleeMinion.abilities[0] = Ability.meleeAttack
|
||||
|
||||
const redMinion = new Entity({
|
||||
...minionTemplate,
|
||||
logic: minionLogic(Team.red),
|
||||
team: Team.red,
|
||||
position: new Vector2(1800, 1800),
|
||||
})
|
||||
|
||||
const redMeleeMinion = new Entity({
|
||||
...meleeMinionTemplate,
|
||||
logic: minionLogic(Team.red),
|
||||
team: Team.red,
|
||||
position: new Vector2(1800, 1800),
|
||||
})
|
||||
redMeleeMinion.abilities[0] = Ability.meleeAttack
|
||||
|
||||
if (game.currentTick % (30 * game.tickRate) == (0 * game.tickRate)) {
|
||||
game.spawnEntity(blueMeleeMinion)
|
||||
game.spawnEntity(redMeleeMinion)
|
||||
if ([(0 * game.tickRate), (1 * game.tickRate), (2 * game.tickRate)].includes(game.currentTick % (30 * game.tickRate))) {
|
||||
game.spawnEntity(new Entity(Template.minion(Team.blue, { ranged: false })))
|
||||
game.spawnEntity(new Entity(Template.minion(Team.red, { ranged: false })))
|
||||
}
|
||||
|
||||
if (game.currentTick % (30 * game.tickRate) == (1 * game.tickRate)) {
|
||||
game.spawnEntity(blueMeleeMinion)
|
||||
game.spawnEntity(redMeleeMinion)
|
||||
}
|
||||
|
||||
if (game.currentTick % (30 * game.tickRate) == (2 * game.tickRate)) {
|
||||
game.spawnEntity(blueMeleeMinion)
|
||||
game.spawnEntity(redMeleeMinion)
|
||||
}
|
||||
|
||||
if (game.currentTick % (30 * game.tickRate) == (3 * game.tickRate)) {
|
||||
game.spawnEntity(blueMinion)
|
||||
game.spawnEntity(redMinion)
|
||||
}
|
||||
|
||||
if (game.currentTick % (30 * game.tickRate) == (4 * game.tickRate)) {
|
||||
game.spawnEntity(blueMinion)
|
||||
game.spawnEntity(redMinion)
|
||||
}
|
||||
|
||||
if (game.currentTick % (30 * game.tickRate) == (5 * game.tickRate)) {
|
||||
game.spawnEntity(blueMinion)
|
||||
game.spawnEntity(redMinion)
|
||||
if ([(3 * game.tickRate), (4 * game.tickRate), (5 * game.tickRate)].includes(game.currentTick % (30 * game.tickRate))) {
|
||||
game.spawnEntity(new Entity(Template.minion(Team.blue, { ranged: true })))
|
||||
game.spawnEntity(new Entity(Template.minion(Team.red, { ranged: true })))
|
||||
}
|
||||
}
|
||||
|
||||
entity2.attackAction(1600, 1800)
|
||||
entity1.attackAction(500, 150)
|
||||
game.logic = gameLogic
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user