multiplayer-test/common/player.js

26 lines
661 B
JavaScript

import { WORLD_SIZE } from "./world.js";
export default class Player {
static SPEED = 200.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;
this.x = Math.min(Math.max(this.x, 0.0), WORLD_SIZE);
this.y = Math.min(Math.max(this.y, 0.0), WORLD_SIZE);
}
}