game: add: class: point and segment, add: type docstring
This commit is contained in:
@ -1,17 +1,35 @@
|
||||
import { Player } from "./Player.js";
|
||||
|
||||
import { Client } from "../client.js"
|
||||
import { Game } from "./Game.js";
|
||||
import { Segment } from "./Segment.js";
|
||||
|
||||
class MyPlayer extends Player
|
||||
{
|
||||
constructor(client, game, rail_start_x, rail_start_y, rail_stop_x, rail_stop_y, nb_goal, positon)
|
||||
/**
|
||||
*
|
||||
* @param {Client} client
|
||||
* @param {Game} game
|
||||
* @param {Segment} rail
|
||||
* @param {Number} nb_goal
|
||||
* @param {Number} position
|
||||
*/
|
||||
constructor(client, game, rail, nb_goal, position)
|
||||
{
|
||||
super(client.me.id, game, rail_start_x, rail_start_y, rail_stop_x, rail_stop_y, nb_goal, positon, true);
|
||||
super(game, client.me.id, rail, nb_goal, position, true);
|
||||
/**
|
||||
* @type {Client}
|
||||
*/
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {[string]} keys_pressed
|
||||
* @returns
|
||||
*/
|
||||
update_paddle(keys_pressed)
|
||||
{
|
||||
let new_pos = this.positon;
|
||||
let new_pos = this.position;
|
||||
|
||||
if (keys_pressed.includes("s"))
|
||||
new_pos -= this.game.config.paddle_speed_per_second_max * this.game.time.deltaTimeSecond() * 1.0;
|
||||
@ -20,14 +38,19 @@ class MyPlayer extends Player
|
||||
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.positon === new_pos)
|
||||
if (this.position === new_pos)
|
||||
return;
|
||||
|
||||
this.positon = new_pos;
|
||||
this.position = new_pos;
|
||||
|
||||
this.game._send_paddle_position(this.positon, this.game.time._current_frame);
|
||||
this.game._send_paddle_position(this.position, this.game.time._current_frame);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Number} new_position
|
||||
* @param {Number} time
|
||||
*/
|
||||
update_pos(new_position, time)
|
||||
{
|
||||
let position_verified = new_position;
|
||||
@ -36,14 +59,14 @@ class MyPlayer extends Player
|
||||
|
||||
let sign = this - new_position >= 0 ? 1 : -1;
|
||||
|
||||
let distance = Math.abs(this.positon - new_position);
|
||||
let distance = Math.abs(this.position - 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.positon = position_verified;
|
||||
this.position = position_verified;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user