Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
@ -97,15 +97,9 @@ export class AGame extends AExchangeable
|
||||
*/
|
||||
send(data)
|
||||
{
|
||||
console.log(this._socket)
|
||||
if (this._socket === undefined || this._socket.readyState !== WebSocket.OPEN)
|
||||
{
|
||||
console.log("bozo pas confirme")
|
||||
return ;
|
||||
}
|
||||
console.log("j'essaye de send")
|
||||
this._socket.send(data);
|
||||
console.log("j'ai passer le send")
|
||||
return;
|
||||
this._socket.send(data);
|
||||
}
|
||||
|
||||
async join()
|
||||
|
@ -2,6 +2,7 @@ import { AExchangeable } from "../../AExchangable.js";
|
||||
import { PongGame } from "./PongGame.js";
|
||||
import { renderCube} from "../../../3D/cube.js"
|
||||
import { Position } from "./Position.js";
|
||||
import { Point } from "./Point.js";
|
||||
|
||||
export class PongBall extends AExchangeable
|
||||
{
|
||||
@ -13,7 +14,7 @@ export class PongBall extends AExchangeable
|
||||
* @param {Number} speed
|
||||
* @param {Number} size
|
||||
*/
|
||||
constructor(game, size, position = new Position(), angle, speed)
|
||||
constructor(game, size, position = new Position(new Point(game.config.CENTER_X, game.config.CENTER_Y), 0), angle, speed)
|
||||
{
|
||||
super();
|
||||
|
||||
|
@ -67,12 +67,12 @@ export class PongConfig extends AExchangeable
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
this.CENTER_X;
|
||||
this.MAP_CENTER_X;
|
||||
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
this.CENTER_Y;
|
||||
this.MAP_CENTER_Y;
|
||||
}
|
||||
|
||||
async init()
|
||||
|
@ -79,9 +79,9 @@ export class PongGame extends AGame
|
||||
|
||||
let response_data = await response.json();
|
||||
|
||||
console.log(response_data.players[0])
|
||||
response_data.players.forEach((player_data) => {
|
||||
this.players.push(new PongPlayer(this.client, this));
|
||||
let player = new PongPlayer(this.client, this)
|
||||
this.players.push(player);
|
||||
});
|
||||
|
||||
this.import(response_data);
|
||||
@ -160,7 +160,7 @@ export class PongGame extends AGame
|
||||
else if (data.detail === "update_ball")
|
||||
this._updateBall(data);
|
||||
else if (data.detail === "goal")
|
||||
await this._receiveGoal(data);
|
||||
await this._goalHandler(data); // TODO fix: extract goal data in separate function
|
||||
else if (data.detail === "finish")
|
||||
await this._finishHandler(data);
|
||||
}
|
||||
@ -169,7 +169,7 @@ export class PongGame extends AGame
|
||||
{
|
||||
let player = this.players.find((player) => player.id === data.user_id);
|
||||
|
||||
player.from_json(data);
|
||||
player.import(data);
|
||||
}
|
||||
|
||||
_updateBall(data)
|
||||
|
@ -13,7 +13,7 @@ export class MyPlayer extends PongPlayer
|
||||
* @param {[Number]} score
|
||||
* @param {Position} position
|
||||
*/
|
||||
constructor(client, game, score, rail, position = new Position())
|
||||
constructor(client, game, score, rail, position = new Position(0.5))
|
||||
{
|
||||
super(client, game, client.me.id, client.me.username, client.me.avatar, score, rail, position, true);
|
||||
/**
|
||||
@ -62,22 +62,22 @@ export class MyPlayer extends PongPlayer
|
||||
*/
|
||||
updatePaddle(keys_pressed)
|
||||
{
|
||||
let new_pos = this.position;
|
||||
let new_location = this.position.location;
|
||||
|
||||
keys_pressed.forEach(key => {
|
||||
if (this.downKeys.includes(key))
|
||||
new_pos += this.game.config.paddle_speed_per_second_max * this.game.time.deltaTimeSecond();
|
||||
new_location += this.game.config.PADDLE_SPEED_PER_SECOND_MAX * this.game.time.deltaTimeSecond();
|
||||
if (this.upKeys.includes(key))
|
||||
new_pos -= this.game.config.paddle_speed_per_second_max * this.game.time.deltaTimeSecond();
|
||||
new_location -= this.game.config.PADDLE_SPEED_PER_SECOND_MAX * this.game.time.deltaTimeSecond();
|
||||
});
|
||||
|
||||
new_pos = Math.max(0 + this.game.config.paddle_ratio / 2, new_pos);
|
||||
new_pos = Math.min(1 - this.game.config.paddle_ratio / 2, new_pos);
|
||||
new_location = Math.max(0 + this.game.config.PADDLE_RATIO / 2, new_location);
|
||||
new_location = Math.min(1 - this.game.config.PADDLE_RATIO / 2, new_location);
|
||||
|
||||
if (this.position === new_pos)
|
||||
if (this.position.location === new_location)
|
||||
return;
|
||||
|
||||
this.position = new_pos;
|
||||
this.position.location = new_location;
|
||||
|
||||
this._sendPaddlePosition();
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ export class PongPlayer extends APlayer
|
||||
* @param {String} avatar
|
||||
* @param {Client} client
|
||||
*/
|
||||
constructor(client, game, id, username, avatar, score = [], rail = new Segment(game), position = new Position(), isConnected)
|
||||
constructor(client, game, id, username, avatar, score = [], rail = new Segment(game), position = new Position(0.5), isConnected)
|
||||
{
|
||||
super(client, game, id, username, avatar, isConnected)
|
||||
|
||||
@ -47,7 +47,7 @@ export class PongPlayer extends APlayer
|
||||
*
|
||||
* @param {Number} new_position
|
||||
*/
|
||||
updatePos(new_position, time)
|
||||
updatePos(new_position)
|
||||
{
|
||||
this.position = new_position;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ export class Position extends AExchangeable
|
||||
* @param {Point | Number} location
|
||||
* @param {Number} time
|
||||
*/
|
||||
constructor(location, time)
|
||||
constructor(location = new Point(), time)
|
||||
{
|
||||
super();
|
||||
/**
|
||||
|
@ -58,8 +58,8 @@ class Segment extends AExchangeable
|
||||
{
|
||||
const size = this.game.config.BALL_SIZE * 2;
|
||||
const sizex = this.len() / 2;
|
||||
const posx = (this.start.x - this.game.config.CENTER_X);
|
||||
const posy = (this.start.y - this.game.config.CENTER_Y);
|
||||
const posx = (this.start.x - this.game.config.MAP_CENTER_X);
|
||||
const posy = (this.start.y - this.game.config.MAP_CENTER_Y);
|
||||
renderCube(ctx, posx, 0, posy, -this.angle(), sizex, size, size);
|
||||
}
|
||||
else
|
||||
|
@ -32,8 +32,8 @@ export class Wall extends Segment
|
||||
{
|
||||
const size = this.game.config.BALL_SIZE * 2;
|
||||
const sizeX = this.len() / 2;
|
||||
const posX = (this.start.x - this.game.config.CENTER_X);
|
||||
const posY = (this.start.y - this.game.config.CENTER_Y);
|
||||
const posX = (this.start.x - this.game.config.MAP_CENTER_X);
|
||||
const posY = (this.start.y - this.game.config.MAP_CENTER_Y);
|
||||
renderCube(ctx, posX, 0, posY, -this.angle(), sizeX, size, size);
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user