fix: game: 2d work

This commit is contained in:
2024-04-10 15:40:54 +00:00
parent 8b9c4d7c1c
commit 0b7e72d8e2
10 changed files with 41 additions and 39 deletions

View File

@ -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()

View File

@ -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();

View File

@ -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);

View File

@ -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();
}

View File

@ -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;
}

View File

@ -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();
/**