fixing merge
This commit is contained in:
parent
faed2a027d
commit
6639f562b8
@ -1,92 +1,76 @@
|
|||||||
import { Game } from "./Game.js";
|
import { Game } from "./Game.js";
|
||||||
import { Point } from "./Point.js";
|
import { Point } from "./Point.js";
|
||||||
import { renderCube } from "../../3D/cube.js"
|
|
||||||
|
|
||||||
class Ball
|
class Ball
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Game} game
|
* @param {Game} game
|
||||||
* @param {Number} position_x
|
* @param {Point} position
|
||||||
* @param {Number} position_y
|
* @param {Number} angle
|
||||||
* @param {Number} velocity_x
|
* @param {Number} speed
|
||||||
* @param {Number} velocity_y
|
* @param {Number} size
|
||||||
*/
|
*/
|
||||||
constructor(game, position_x, position_y, velocity_x, velocity_y)
|
constructor(game, size, position, angle, speed)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @type {Game}
|
* @type {Game}
|
||||||
*/
|
*/
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Point}
|
||||||
|
*/
|
||||||
|
this.position = position === undefined ? new Point() : position;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.position_x = position_x;
|
this.size = size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.position_y = position_y;
|
this.angle = angle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Number}
|
* @type {Number}
|
||||||
*/
|
*/
|
||||||
this.velocity_x = velocity_x;
|
this.speed = speed;
|
||||||
/**
|
|
||||||
* @type {Number}
|
|
||||||
*/
|
|
||||||
this.velocity_y = velocity_y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {CanvasRenderingContext2D} ctx ou pas ptdr
|
* @param {CanvasRenderingContext2D} ctx
|
||||||
*/
|
*/
|
||||||
draw(ctx)
|
draw(ctx)
|
||||||
{
|
{
|
||||||
if(ctx instanceof CanvasRenderingContext2D)
|
ctx.rect(this.position.x - this.size / 2, this.position.y - this.size / 2, this.size, this.size);
|
||||||
{
|
|
||||||
ctx.rect(this.position_x, this.position_y, this.game.config.ball_size, this.game.config.ball_size);
|
|
||||||
}
|
|
||||||
else if(ctx instanceof WebGLRenderingContext)
|
|
||||||
{
|
|
||||||
renderCube(ctx, this.position_x / 1000, 0, this.position_y / 1000, 0, this.game.config.ball_size, this.game.config.ball_size, this.game.config.ball_size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
alert('Unknown rendering context type (wtf)');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render()
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @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))
|
|
||||||
{
|
|
||||||
this.velocity_x = -this.velocity_x;
|
|
||||||
this.velocity_y = -this.velocity_y;
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
this.position_x = new_pos_x
|
|
||||||
this.position_y = new_pos_y
|
|
||||||
|
|
||||||
this.velocity_x = this.velocity_x + this.game.config.ball_speed_inc;
|
|
||||||
this.velocity_y = this.velocity_y + this.game.config.ball_speed_inc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
update (position_x, position_y, velocity_x, velocity_y)
|
/**
|
||||||
|
*
|
||||||
|
* @param {CanvasRenderingContext2D} ctx
|
||||||
|
*/
|
||||||
|
render(ctx)
|
||||||
{
|
{
|
||||||
this.position_x = position_x;
|
let distance = this.speed * (this.game.time.deltaTime() / 1000)
|
||||||
this.position_y = position_y;
|
|
||||||
this.velocity_x = velocity_x;
|
this.position.x = this.position.x + distance * Math.cos(this.angle);
|
||||||
this.velocity_y = velocity_y;
|
this.position.y = this.position.y - distance * Math.sin(this.angle);
|
||||||
|
|
||||||
|
this.draw(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
from_json (data)
|
||||||
|
{
|
||||||
|
this.position = this.position.from_json(data.position);
|
||||||
|
this.size = data.size;
|
||||||
|
this.angle = data.angle;
|
||||||
|
this.speed = data.speed;
|
||||||
|
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user