replace most systems with THREE

This commit is contained in:
2024-12-22 23:52:56 +09:00
parent 14212afd70
commit 054d22d01a
7 changed files with 107 additions and 87 deletions
+5 -7
View File
@@ -2,7 +2,6 @@ import express from 'express'
import { WebSocketExpress } from 'websocket-express'
import Game from './game.js'
import Entity from './entity.js'
import Victor from 'victor'
const app = new WebSocketExpress()
const port = 1280
@@ -15,7 +14,7 @@ app.use(express.urlencoded({ extended: true }))
app.ws('/ws', async (req, res) => {
const websocket = await res.accept()
const subscription = () => websocket.send(JSON.stringify(game))
const subscription = () => websocket.send(JSON.stringify(game.state()))
game.eventEmitter.on('tick', subscription)
websocket.on('close', () => {
@@ -24,15 +23,14 @@ app.ws('/ws', async (req, res) => {
websocket.on('message', (rawData) => {
const message = JSON.parse(rawData)
const entity = message.id != null ? game.entities.find((e) => e.id == message.id) : null
console.log(message)
if (message.action == 'teleport') {
const entity = game.entities.find((e) => e.id == message.id)
entity.pos = new Victor(message.x, message.y)
entity.teleport(message.x, message.y)
}
if (message.action == 'move') {
const entity = game.entities.find((e) => e.id == message.id)
entity.moveAction(message.x, message.y)
}
})
@@ -43,13 +41,13 @@ app.listen(port, () => {
const entity = new Entity()
entity.id = '1'
entity.pos = new Victor(0, 0)
entity.teleport(0, 0)
entity.radius = 35
game.spawn_entity(entity)
const entity2 = new Entity()
entity2.id = '2'
entity2.pos = new Victor(200, 100)
entity.teleport(200, 100)
entity2.radius = 35
game.spawn_entity(entity2)