game: add: class: point and segment, add: type docstring
This commit is contained in:
@ -1,22 +1,45 @@
|
||||
import { Game } from "./Game.js";
|
||||
import { Point } from "./Point.js";
|
||||
|
||||
|
||||
class Ball
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @param {Game} game
|
||||
* @param {Number} position_x
|
||||
* @param {Number} position_y
|
||||
* @param {Number} velocity_x
|
||||
* @param {Number} velocity_y
|
||||
*/
|
||||
constructor(game, position_x, position_y, velocity_x, velocity_y)
|
||||
{
|
||||
/**
|
||||
* @type {Game}
|
||||
*/
|
||||
this.game = game;
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
this.position_x = position_x;
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
this.position_y = position_y;
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
this.velocity_x = velocity_x;
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
this.velocity_y = velocity_y;
|
||||
}
|
||||
|
||||
_collision(old_pos_x, old_pos_y, new_pos_x, new_pos_y)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {CanvasRenderingContext2D} ctx
|
||||
*/
|
||||
draw(ctx)
|
||||
{
|
||||
ctx.rect(this.position_x, this.position_y, this.game.config.ball_size, this.game.config.ball_size);
|
||||
@ -24,8 +47,14 @@ class Ball
|
||||
|
||||
render()
|
||||
{
|
||||
new_pos_x = this.position_x + this.velocity_x * this.game.time.deltaTime();
|
||||
new_pos_y = this.position_y + this.velocity_y * this.game.time.deltaTime();
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
let new_pos_x = this.position_x + this.velocity_x * this.game.time.deltaTime();
|
||||
/**
|
||||
* @type {Number}
|
||||
*/
|
||||
let new_pos_y = position_y + this.velocity_y * this.game.time.deltaTime();
|
||||
|
||||
if (this._collision(this.position_x, this.position_y, new_pos_x, new_pos_y))
|
||||
{
|
||||
|
Reference in New Issue
Block a user