AAAAAAAAAAAAAAAAAAAAAAAAH
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { Game } from "./Game.js";
|
||||
import { Point } from "./Point.js";
|
||||
|
||||
import { renderCube } from "../../3D/cube.js"
|
||||
|
||||
class Ball
|
||||
{
|
||||
@ -38,12 +38,23 @@ class Ball
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {CanvasRenderingContext2D} ctx
|
||||
* @param {CanvasRenderingContext2D} ctx ou pas ptdr
|
||||
*/
|
||||
draw(ctx)
|
||||
{
|
||||
ctx.rect(this.position_x, this.position_y, this.game.config.ball_size, this.game.config.ball_size);
|
||||
}
|
||||
if(ctx instanceof CanvasRenderingContext2D)
|
||||
{
|
||||
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, 0, this.position_y, 0, this.game.config.ball_size, this.game.config.ball_size, this.game.config.ball_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
alert('Unknown rendering context type (wtf)');
|
||||
}
|
||||
}
|
||||
|
||||
render()
|
||||
{
|
||||
@ -79,4 +90,4 @@ class Ball
|
||||
}
|
||||
}
|
||||
|
||||
export { Ball }
|
||||
export { Ball }
|
||||
|
@ -74,7 +74,10 @@ class Game
|
||||
*/
|
||||
draw(ctx)
|
||||
{
|
||||
ctx.clearRect(0, 0, this.config.size_x, this.config.size_y);
|
||||
if(ctx instanceof CanvasRenderingContext2D)
|
||||
{
|
||||
ctx.clearRect(0, 0, this.config.size_x, this.config.size_y);
|
||||
}
|
||||
this.draw_sides(ctx);
|
||||
this.ball.draw(ctx);
|
||||
}
|
||||
|
@ -79,23 +79,33 @@ class Player
|
||||
*/
|
||||
draw(ctx)
|
||||
{
|
||||
if (this.is_connected === false)
|
||||
{
|
||||
ctx.moveTo(this.rail.start.x, this.rail.start.y);
|
||||
ctx.lineTo(this.rail.stop.x, this.rail.stop.y);
|
||||
return;
|
||||
}
|
||||
let paddle_pos = new Point(this.rail.start.x + this.diff_x * this.position,
|
||||
this.rail.start.y + this.diff_y * this.position);
|
||||
if(ctx instanceof CanvasRenderingContext2D)
|
||||
{
|
||||
if (this.is_connected === false)
|
||||
{
|
||||
ctx.moveTo(this.rail.start.x, this.rail.start.y);
|
||||
ctx.lineTo(this.rail.stop.x, this.rail.stop.y);
|
||||
return;
|
||||
}
|
||||
let paddle_pos = new Point(this.rail.start.x + this.diff_x * this.position,
|
||||
this.rail.start.y + this.diff_y * this.position);
|
||||
|
||||
let start_x = paddle_pos.x - (this.diff_x * (this.paddle_size / 2 / this.rail_size)),
|
||||
start_y = paddle_pos.y - (this.diff_y * (this.paddle_size / 2 / this.rail_size)),
|
||||
stop_x = paddle_pos.x + (this.diff_x * (this.paddle_size / 2 / this.rail_size)),
|
||||
stop_y = paddle_pos.y + (this.diff_y * (this.paddle_size / 2 / this.rail_size));
|
||||
|
||||
|
||||
let start_x = paddle_pos.x - (this.diff_x * (this.paddle_size / 2 / this.rail_size)),
|
||||
start_y = paddle_pos.y - (this.diff_y * (this.paddle_size / 2 / this.rail_size)),
|
||||
stop_x = paddle_pos.x + (this.diff_x * (this.paddle_size / 2 / this.rail_size)),
|
||||
stop_y = paddle_pos.y + (this.diff_y * (this.paddle_size / 2 / this.rail_size));
|
||||
ctx.moveTo(start_x, start_y);
|
||||
ctx.lineTo(stop_x, stop_y);
|
||||
}
|
||||
else if(ctx instanceof WebGLRenderingContext)
|
||||
{
|
||||
|
||||
ctx.moveTo(start_x, start_y);
|
||||
ctx.lineTo(stop_x, stop_y);
|
||||
}
|
||||
else
|
||||
{
|
||||
alert('Unknown rendering context type (wtf)');
|
||||
}
|
||||
}
|
||||
|
||||
from_json(data)
|
||||
@ -149,4 +159,4 @@ class Player
|
||||
}
|
||||
}
|
||||
|
||||
export { Player }
|
||||
export { Player }
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Point } from "./Point.js"
|
||||
import { renderCube } from "../../3D/cube.js"
|
||||
|
||||
class Segment
|
||||
{
|
||||
@ -17,16 +18,19 @@ class Segment
|
||||
*/
|
||||
draw(ctx)
|
||||
{
|
||||
if(this.gl instanceof CanvasRenderingContext2D)
|
||||
if(ctx instanceof CanvasRenderingContext2D)
|
||||
{
|
||||
ctx.moveTo(this.start.x, this.start.y);
|
||||
ctx.lineTo(this.stop.x, this.stop.y);
|
||||
}
|
||||
else if(this.gl instanceof WebGLRenderingContext)
|
||||
else if(ctx instanceof WebGLRenderingContext)
|
||||
{
|
||||
renderCube(ctx, this.start.x, -3, this.start.y, 0, 0.5, 0.5, 0.5);
|
||||
}
|
||||
else
|
||||
{
|
||||
alert('Unknown rendering context type');
|
||||
}
|
||||
}
|
||||
|
||||
from_json(data)
|
||||
|
@ -14,8 +14,8 @@ class Wall
|
||||
}
|
||||
|
||||
draw(ctx)
|
||||
{
|
||||
this.rail.draw(ctx);
|
||||
{
|
||||
this.rail.draw(ctx);
|
||||
}
|
||||
|
||||
from_json(data)
|
||||
@ -26,4 +26,4 @@ class Wall
|
||||
}
|
||||
}
|
||||
|
||||
export { Wall }
|
||||
export { Wall }
|
||||
|
Reference in New Issue
Block a user