input desynchro, rollback to instant handle.
This commit is contained in:
@@ -66,7 +66,7 @@ class EventMatchEnd extends ServerEvent {
|
||||
|
||||
/* From Client */
|
||||
class ClientEvent {
|
||||
type: en.EventTypes;
|
||||
type: en.EventTypes; // readonly ?
|
||||
constructor(type: en.EventTypes = 0) {
|
||||
this.type = type;
|
||||
}
|
||||
@@ -74,21 +74,21 @@ class ClientEvent {
|
||||
|
||||
class ClientAnnounce extends ClientEvent {
|
||||
role: en.ClientRole;
|
||||
id: string;
|
||||
constructor(role: en.ClientRole, id: string = "") {
|
||||
clientId: string;
|
||||
constructor(role: en.ClientRole, clientId: string = "") {
|
||||
super(en.EventTypes.clientAnnounce);
|
||||
this.role = role;
|
||||
this.id = id;
|
||||
this.clientId = clientId;
|
||||
}
|
||||
}
|
||||
|
||||
class EventInput extends ClientEvent {
|
||||
input: en.InputEnum;
|
||||
inputId: number;
|
||||
constructor(input: en.InputEnum = 0, inputId: number = 0) {
|
||||
id: number;
|
||||
constructor(input: en.InputEnum = en.InputEnum.noInput, id: number = 0) {
|
||||
super(en.EventTypes.clientInput);
|
||||
this.input = input;
|
||||
this.inputId = inputId;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,10 +44,15 @@ class MovingRectangle extends Rectangle implements Moving {
|
||||
}
|
||||
move(delta: number) { // Math.floor WIP until VectorInteger debug
|
||||
// console.log(`delta: ${delta}, speed: ${this.speed}, speed*delta: ${this.speed * delta}`);
|
||||
this.pos.x += Math.floor(this.dir.x * this.speed * delta);
|
||||
this.pos.y += Math.floor(this.dir.y * this.speed * delta);
|
||||
// this.pos.x += Math.floor(this.dir.x * this.speed * delta);
|
||||
// this.pos.y += Math.floor(this.dir.y * this.speed * delta);
|
||||
this.pos.x += this.dir.x * this.speed * delta;
|
||||
this.pos.y += this.dir.y * this.speed * delta;
|
||||
}
|
||||
moveAndCollide(delta: number, colliderArr: Rectangle[]) {
|
||||
this._moveAndCollideAlgo(delta, colliderArr);
|
||||
}
|
||||
protected _moveAndCollideAlgo(delta: number, colliderArr: Rectangle[]) {
|
||||
let oldPos = new VectorInteger(this.pos.x, this.pos.y);
|
||||
this.move(delta);
|
||||
if (colliderArr.some(this.collision, this)) {
|
||||
@@ -60,6 +65,11 @@ class Racket extends MovingRectangle {
|
||||
constructor(pos: VectorInteger, width: number, height: number, baseSpeed: number) {
|
||||
super(pos, width, height, baseSpeed);
|
||||
}
|
||||
moveAndCollide(delta: number, colliderArr: Rectangle[]) {
|
||||
// let oldPos = new VectorInteger(this.pos.x, this.pos.y); // debug
|
||||
this._moveAndCollideAlgo(delta, colliderArr);
|
||||
// console.log(`y change: ${this.pos.y - oldPos.y}`);
|
||||
}
|
||||
}
|
||||
|
||||
class Ball extends MovingRectangle {
|
||||
|
||||
@@ -22,8 +22,9 @@ enum EventTypes {
|
||||
}
|
||||
|
||||
enum InputEnum {
|
||||
noInput = 0,
|
||||
up = 1,
|
||||
down
|
||||
down,
|
||||
}
|
||||
|
||||
enum PlayerSide {
|
||||
|
||||
Reference in New Issue
Block a user