Buff Queen AKA "Ez egy fa?"
Because the first placeholder player model resembled a queen that's been to the gym a bit too much. Also, before she got her head and hands, she looked like a tree, legit.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
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
|
||||
const game = new Game()
|
||||
|
||||
app.use('/', express.static('public'))
|
||||
app.use('/three/', express.static('node_modules/three'))
|
||||
app.use(express.urlencoded({ extended: true }))
|
||||
|
||||
app.ws('/ws', async (req, res) => {
|
||||
const websocket = await res.accept()
|
||||
|
||||
const subscription = () => websocket.send(JSON.stringify(game))
|
||||
game.eventEmitter.on('tick', subscription)
|
||||
|
||||
websocket.on('close', () => {
|
||||
game.eventEmitter.removeListener('tick', subscription)
|
||||
})
|
||||
|
||||
websocket.on('message', (rawData) => {
|
||||
const message = JSON.parse(rawData)
|
||||
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)
|
||||
}
|
||||
|
||||
if (message.action == 'move') {
|
||||
const entity = game.entities.find((e) => e.id == message.id)
|
||||
entity.moveAction(message.x, message.y)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server started! Visit http://localhost:${port}`)
|
||||
|
||||
const entity = new Entity()
|
||||
entity.id = '1'
|
||||
entity.pos = new Victor(0, 0)
|
||||
entity.radius = 35
|
||||
game.spawn_entity(entity)
|
||||
|
||||
const entity2 = new Entity()
|
||||
entity2.id = '2'
|
||||
entity2.pos = new Victor(200, 100)
|
||||
entity2.radius = 35
|
||||
game.spawn_entity(entity2)
|
||||
|
||||
game.start()
|
||||
})
|
||||
Reference in New Issue
Block a user