game: core: use server game calulation form
This commit is contained in:
@ -3,30 +3,29 @@ import { Player } from "./Player.js";
|
||||
|
||||
class MyPlayer extends Player
|
||||
{
|
||||
constructor(client, pos, nb_goal, game, time, rail_start_x, rail_start_y, rail_stop_x, rail_stop_y)
|
||||
constructor(client, game, rail_start_x, rail_start_y, rail_stop_x, rail_stop_y, nb_goal, positon)
|
||||
{
|
||||
super(client.me.id, pos, nb_goal, game, rail_start_x, rail_start_y, rail_stop_x, rail_stop_y);
|
||||
this.time = time;
|
||||
super(client.me.id, game, rail_start_x, rail_start_y, rail_stop_x, rail_stop_y, nb_goal, positon);
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
update_paddle(keys_pressed)
|
||||
{
|
||||
let new_pos = this.pos;
|
||||
let new_pos = this.positon;
|
||||
|
||||
if (keys_pressed.includes("s"))
|
||||
new_pos -= this.game.config.paddle_speed_per_second_max * this.time.deltaTimeSecond() * 1.0;
|
||||
new_pos -= this.game.config.paddle_speed_per_second_max * this.game.time.deltaTimeSecond() * 1.0;
|
||||
if (keys_pressed.includes("w"))
|
||||
new_pos += this.game.config.paddle_speed_per_second_max * this.time.deltaTimeSecond() * 1.0;
|
||||
new_pos += this.game.config.paddle_speed_per_second_max * this.game.time.deltaTimeSecond() * 1.0;
|
||||
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);
|
||||
|
||||
if (this.pos === new_pos)
|
||||
if (this.positon === new_pos)
|
||||
return;
|
||||
console.log(this.client.me.id)
|
||||
this.pos = new_pos;
|
||||
|
||||
this.game._send_paddle(this.pos, this.time._current_frame);
|
||||
this.positon = new_pos;
|
||||
|
||||
this.game._send_paddle(this.positon, this.game.time._current_frame);
|
||||
}
|
||||
|
||||
update_pos(new_position, time)
|
||||
@ -37,14 +36,14 @@ class MyPlayer extends Player
|
||||
|
||||
let sign = this - new_position >= 0 ? 1 : -1;
|
||||
|
||||
let distance = Math.abs(this.pos - new_position);
|
||||
let distance = Math.abs(this.positon - new_position);
|
||||
|
||||
let distance_max = time_diff * this.game.config.paddle_speed_per_second_max;
|
||||
|
||||
if (distance > distance_max)
|
||||
position_verified = distance_max * sign;
|
||||
|
||||
this.pos = position_verified;
|
||||
this.positon = position_verified;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user