first commit! 🎉
This commit is contained in:
commit
c35c18bbbc
19 changed files with 1046 additions and 0 deletions
13
common/log.js
Normal file
13
common/log.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
export default class Log {
|
||||
static info(message) {
|
||||
console.log('[' + new Date().toISOString() + '] ' + message);
|
||||
}
|
||||
|
||||
static warn(message) {
|
||||
console.warn('[' + new Date().toISOString() + '] WARN: ' + message);
|
||||
}
|
||||
|
||||
static error(message) {
|
||||
console.error('[' + new Date().toISOString() + '] FATAL: ' + message);
|
||||
}
|
||||
}
|
20
common/player.js
Normal file
20
common/player.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
export default class Player {
|
||||
static SPEED = 400.0;
|
||||
static SIZE = 50.0;
|
||||
|
||||
constructor(name, x, y, colour) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.in_x = 0.0;
|
||||
this.in_y = 0.0;
|
||||
this.draw_x = x;
|
||||
this.draw_y = y;
|
||||
this.name = name;
|
||||
this.colour = colour;
|
||||
}
|
||||
|
||||
update(delta) {
|
||||
if (this.in_x != 0) this.x += this.in_x * Player.SPEED * delta;
|
||||
if (this.in_y != 0) this.y += this.in_y * Player.SPEED * delta;
|
||||
}
|
||||
}
|
48
common/prop.js
Normal file
48
common/prop.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
import Player from "./player.js";
|
||||
import { WORLD_SIZE } from "./world.js";
|
||||
|
||||
export default class Prop {
|
||||
static SIZE = 50.0;
|
||||
|
||||
constructor(name, x, y, colour, sprite) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.xv = 0.0;
|
||||
this.yv = 0.0;
|
||||
this.draw_x = x;
|
||||
this.draw_y = y;
|
||||
this.name = name;
|
||||
this.colour = colour;
|
||||
this.sprite = sprite;
|
||||
}
|
||||
|
||||
update(delta, players) {
|
||||
players.forEach(player => {
|
||||
if (this.x - Prop.SIZE / 2 < player.x + Player.SIZE / 2 &&
|
||||
this.x + Prop.SIZE / 2 > player.x - Player.SIZE / 2 &&
|
||||
this.y - Prop.SIZE / 2 < player.y + Player.SIZE / 2 &&
|
||||
this.y + Prop.SIZE / 2 > player.y - Player.SIZE / 2) {
|
||||
this.xv += player.in_x * Player.SPEED * delta * 20.0;
|
||||
this.yv += player.in_y * Player.SPEED * delta * 20.0;
|
||||
}
|
||||
});
|
||||
|
||||
if (this.xv != 0) this.x += this.xv * delta;
|
||||
if (this.yv != 0) this.y += this.yv * delta;
|
||||
|
||||
this.xv *= 0.95;
|
||||
this.yv *= 0.95;
|
||||
|
||||
// bounce off walls
|
||||
if (this.x + Prop.SIZE / 2 > WORLD_SIZE ||
|
||||
this.x - Prop.SIZE / 2 < 0.0) {
|
||||
this.x = Math.min(Math.max(this.x, 0.0), WORLD_SIZE);
|
||||
this.xv *= -1;
|
||||
}
|
||||
if (this.y + Prop.SIZE / 2 > WORLD_SIZE ||
|
||||
this.y - Prop.SIZE / 2 < 0.0) {
|
||||
this.y = Math.min(Math.max(this.y, 0.0), WORLD_SIZE);
|
||||
this.yv *= -1;
|
||||
}
|
||||
}
|
||||
}
|
1
common/world.js
Normal file
1
common/world.js
Normal file
|
@ -0,0 +1 @@
|
|||
export const WORLD_SIZE = 500;
|
Loading…
Add table
Add a link
Reference in a new issue