game: multiplayer: work
This commit is contained in:
@ -149,8 +149,6 @@ export class PongGame extends AGame
|
||||
*/
|
||||
async _receive(data)
|
||||
{
|
||||
console.log(data)
|
||||
|
||||
if (this._inited === false && data.detail === "init_game")
|
||||
{
|
||||
this._initGame(data);
|
||||
@ -167,6 +165,16 @@ export class PongGame extends AGame
|
||||
await this._receiveFinish(data);
|
||||
else if (data.detail === "start")
|
||||
await this._receiveStart();
|
||||
else if (data.detail === "eliminated")
|
||||
await this._receiveEliminated(data)
|
||||
}
|
||||
|
||||
async _receiveEliminated(data)
|
||||
{
|
||||
console.log('bozo')
|
||||
let eliminated = this.players.find(player => player.id === data.eliminated_id)
|
||||
eliminated.isEliminated = true;
|
||||
console.log(eliminated)
|
||||
}
|
||||
|
||||
async _receiveFinish(data)
|
||||
@ -194,7 +202,6 @@ export class PongGame extends AGame
|
||||
}
|
||||
|
||||
player.score.push(data.timestamp)
|
||||
console.log(player)
|
||||
|
||||
await this._goalHandler(player);
|
||||
}
|
||||
|
@ -12,10 +12,11 @@ export class PongMyPlayer extends PongPlayer
|
||||
* @param {Segment} rail
|
||||
* @param {[Number]} score
|
||||
* @param {Position} position
|
||||
* @param {Boolean} isEliminated
|
||||
*/
|
||||
constructor(client, game, score, rail, position = new Position(0.5))
|
||||
constructor(client, game, score, rail, position = new Position(0.5), isEliminated)
|
||||
{
|
||||
super(client, game, client.me.id, client.me.username, client.me.avatar, score, rail, position, true);
|
||||
super(client, game, client.me.id, client.me.username, client.me.avatar, score, rail, position, true, isEliminated);
|
||||
/**
|
||||
* @type {Client}
|
||||
*/
|
||||
|
@ -65,8 +65,7 @@ export class PongPlayer extends APlayer
|
||||
{
|
||||
if (this.isConnected === false || this.isEliminated === true)
|
||||
{
|
||||
ctx.moveTo(this.rail.start.x, this.rail.start.y);
|
||||
ctx.lineTo(this.rail.stop.x, this.rail.stop.y);
|
||||
this.rail.draw(ctx)
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -71,6 +71,7 @@ export default class PongOnlineView extends AbstractAuthenticatedView
|
||||
myPlayer.score,
|
||||
myPlayer.rail,
|
||||
myPlayer.position,
|
||||
myPlayer.isEliminated
|
||||
);
|
||||
|
||||
myPlayer = this.myPlayer;
|
||||
@ -87,7 +88,6 @@ export default class PongOnlineView extends AbstractAuthenticatedView
|
||||
|
||||
keyPressHandler(event)
|
||||
{
|
||||
console.log("bozo")
|
||||
if (!this.keysPressed.includes(event.key))
|
||||
this.keysPressed.push(event.key);
|
||||
}
|
||||
|
Reference in New Issue
Block a user