Commit d01e10a6 by Alexander Bazo

Inital commit

parents
# dev
node_modules
# test
loadtest
# Star Gazer Server
StarGazer is a multiplayer game using gaze data as an input source. This demo showcases the eye tracking classroom's abilities to utilize gaze based real time collaboration.
## Dependencies
StarGazer is based on the colyseus game server framework. To install all dependencies, run `npm install`.
## Requirements
To play the game using gaze data for input a local [gaze-server](https://lab.las3.de/gitlab/eye-tracking-classroom/gaze-server.cs) must be running at `ws://localhost:8001`.
## Building and Testing
- Run `npm install` to install dependencies and build game to `build/`
- Run `npm start` to run the game server
- See [this repository]() for client code
\ No newline at end of file
const http = require("http");
const express = require("express");
const cors = require("cors");
const colyseus = require("colyseus");
const monitor = require("@colyseus/monitor").monitor;
const socialRoutes = require("@colyseus/social/express").default;
const StarGazerRoom = require("./lib/rooms/StarGazerRoom");
const port = process.env.PORT || 2567;
const app = express()
app.use(cors());
app.use(express.json());
const server = http.createServer(app);
const gameServer = new colyseus.Server({
server: server,
express: app,
});
// register your room handlers
gameServer.define("star_gazer_lab", StarGazerRoom);
// register @colyseus/social routes
app.use("/", socialRoutes);
// register colyseus monitor AFTER registering your room handlers
app.use("/colyseus", monitor(gameServer));
gameServer.listen(port);
console.log(`Listening on ws://localhost:${ port }`)
const schema = require("@colyseus/schema"),
GameObject = require("./GameObject.js");
const DEFAULT_VELOCITY = 1,
DEFAULT_HEALTH = 100,
DEFAULT_WIDTH = 50,
DEFAULT_HEIGHT = 50,
DEFAULT_DAMAGE = 10,
DEFAULT_HIT_BOX_RADIUS = 30,
DEFAULT_ENEMY_COLOR = "#3f0d76",
DEFAULT_ENEMEY_TIP_COLOR = "#d2ccf3",
DEFAULT_ENEMY_HEALTH_COLOR = "#d2ccf3",
DEFAULT_ENEMY_HEALTH_WIDTH = 10,
DEFAULT_ENEMY_HEALTH_RADIUS = 50;
class Enemy extends GameObject {
constructor(x, y, width, height, hitBoxRadius, velocity, direction, color) {
super(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_HIT_BOX_RADIUS,
DEFAULT_VELOCITY, direction, DEFAULT_ENEMY_COLOR);
this.lp = 100;
}
static createEnemy(rangeX, rangeY, targetX, targetY) {
let xPos = parseInt(Math.random() * rangeX),
yPos = parseInt(Math.random() * rangeY),
direction = Math.atan2(targetY - yPos, targetX - xPos) * 180 / Math.PI;
return new Enemy(xPos, yPos, direction);
}
}
schema.defineTypes(Enemy, {
lp: "number"
});
module.exports = Enemy;
\ No newline at end of file
const schema = require('@colyseus/schema');
const Schema = schema.Schema;
class GameObject extends Schema {
constructor(x, y, width, height, hitBoxRadius, velocity, direction, color) {
super();
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.hitBoxRadius = hitBoxRadius;
this.velocity = velocity;
this.direction = direction;
this.color = color;
}
update(delta) {
if(this.velocity === 0) {
return;
}
this.x += this.velocity * Math.cos(this.direction * Math.PI / 180);
this.y += this.velocity * Math.sin(this.direction * Math.PI / 180);
}
isHitBy(object) {
let distance = this.distanceTo(object);
if (distance <= this.hitBoxRadius) {
return true;
}
return false;
}
distanceTo(target) {
let deltaX = Math.abs(this.x - target.x),
deltaY = Math.abs(this.y - target.y);
return Math.sqrt(deltaX * deltaX + deltaY * deltaY);
}
}
schema.defineTypes(GameObject, {
x: "number",
y: "number",
width: "number",
height: "number",
velocity: "number",
direction: "number",
color: "string"
});
module.exports = GameObject;
\ No newline at end of file
const schema = require("@colyseus/schema"),
Enemy = require("./Enemy.js"),
Schema = schema.Schema,
ArraySchema = schema.ArraySchema,
MAX_ENEMIES = 10,
ENEMY_SPAWN_DELAY = 1000;
var lastEnemySpawn;
class StarGazerState extends Schema {
constructor() {
console.log("Initalizing game state");
super();
this.stateType = "idle";
this.width = 1920;
this.height = 1080;
this.enemies = new ArraySchema();
}
update(deltaTime) {
this.spawnEnemy();
}
spawnEnemy() {
let now = Date.now();
if (lastEnemySpawn === undefined) {
this.addEnemy();
lastEnemySpawn = now;
return;
}
if ((now - lastEnemySpawn) > ENEMY_SPAWN_DELAY) {
this.addEnemy();
lastEnemySpawn = now;
}
}
addEnemy() {
if (this.enemies.length < MAX_ENEMIES) {
this.enemies.push(new Enemy());
}
}
}
schema.defineTypes(StarGazerState, {
stateType: "string",
width: "number",
height: "number",
enemies: [Enemy],
});
module.exports = StarGazerState;
\ No newline at end of file
const schema = require('@colyseus/schema');
const Schema = schema.Schema;
class World extends Schema {
constructor(width, height) {
super();
this.width = width;
this.height = height;
}
}
schema.defineTypes(GameObject, {
x: "number",
y: "number",
width: "number",
height: "number",
velocity: "number",
direction: "number",
color: "string"
});
module.exports = GameObject;
\ No newline at end of file
const colyseus = require("colyseus"),
StarGazerState = require("../game/StarGazerState.js");
var deltaTime;
class StarGazerRoom extends colyseus.Room {
onCreate(options) {
console.log("in: onCreate");
console.log(this);
this.setSimulationInterval(this.update.bind(this));
this.setState(new StarGazerState());
}
onJoin(client, options) {
console.log("in: onJoin");
}
onMessage(client, message) {
console.log("in: onMessage");
}
onLeave(client, consented) {
console.log("in: onLeave");
}
onDispose() {
console.log("in: onDispose");
}
startGame() {
}
update(deltaTime) {
console.log("in: update");
this.state.update(deltaTime);
}
}
module.exports = StarGazerRoom;
\ No newline at end of file
{
"name": "my-app",
"version": "1.0.0",
"description": "npm init template for bootstraping an empty Colyseus project",
"main": "index.js",
"scripts": {
"start": "node index.js",
"loadtest": "colyseus-loadtest loadtest/example.js --room my_room --numClients 2",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "UNLICENSED",
"bugs": {
"url": "https://github.com/colyseus/create-colyseus/issues"
},
"homepage": "https://github.com/colyseus/create-colyseus#readme",
"devDependencies": {
"@colyseus/loadtest": "^0.11.0"
},
"dependencies": {
"@colyseus/monitor": "^0.11.0",
"@colyseus/social": "^0.10.2",
"colyseus": "^0.11.0",
"cors": "^2.8.5",
"express": "^4.16.4",
"express-jwt": "^5.3.1"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment