minors changes

This commit is contained in:
LuckyLaszlo
2022-10-22 11:47:37 +02:00
parent af3d885f12
commit d76d6def47

View File

@@ -1,4 +1,10 @@
/* Keys
Player 1: W/S
Player 2: Up/Down
Grid On-Off: G
*/
// import {component, score, line} from "./class.js";
// @ts-check
@@ -26,7 +32,7 @@ let h_grid_d1: Rectangle;
function startGame()
{
pong = new gameArea();
// Const
const w = pong.canvas.width;
const h = pong.canvas.height;
@@ -42,48 +48,50 @@ function startGame()
const playerSpeed = Math.floor(w/75);
const ballSpeed = Math.floor(w/75);
let pos = new VectorInteger();
// Component
pos.x = 0; pos.y = 0;
let pos = new VectorInteger;
// Component
pos.assign(0, 0);
wall_top = new Rectangle(pos, "grey", w, wallSize);
pos.x = 0; pos.y = h-wallSize;
pos.assign(0, h-wallSize);
wall_bottom = new Rectangle(pos, "grey", w, wallSize);
pos.x = 0+pw; pos.y = h_mid-ph/2;
pos.assign(0+pw, h_mid-ph/2);
player1 = new Player(pos, "white", pw, ph);
pos.x = w-pw-pw; pos.y = h_mid-ph/2;
pos.assign(w-pw-pw, h_mid-ph/2);
player2 = new Player(pos, "white", pw, ph);
player1.speed = playerSpeed;
player2.speed = playerSpeed;
pos.x = w_mid-ballSize/2; pos.y = h_mid-ballSize/2;
pos.assign(w_mid-ballSize/2, h_mid-ballSize/2);
ball = new Ball(pos, "white", ballSize);
ball.speed = ballSpeed;
ball.dir.x = -0.8;
ball.dir.y = +0.2;
pos.x = w_mid-w/8; pos.y = w/12;
// w = w/8
// h = w/12
pos.assign(w_mid-scoreSize*1.6, scoreSize*1.5);
score1 = new TextNumericValue(pos, "white", scoreSize);
pos.x = w_mid+w/8-scoreSize/2; pos.y = w/12;
pos.assign(w_mid+scoreSize*1.1, scoreSize*1.5);
score2 = new TextNumericValue(pos, "white", scoreSize);
score1.value = 0;
score2.value = 0;
pos.x = w_mid-midLineSize/2; pos.y = 0+wallSize;
pos.assign(w_mid-midLineSize/2, 0+wallSize);
midLine = new Line(pos, "white", midLineSize, h-wallSize*2, 15);
// Grid
pos.x = 0; pos.y = h_mid;
pos.assign(0, h_mid);
w_grid_mid = new Rectangle(pos, "darkgreen", w, gridSize);
pos.x = 0; pos.y = h/4;
pos.assign(0, h/4);
w_grid_u1 = new Rectangle(pos, "darkgreen", w, gridSize);
pos.x = 0; pos.y = h-h/4;
pos.assign(0, h-h/4);
w_grid_d1 = new Rectangle(pos, "darkgreen", w, gridSize);
pos.x = w_mid; pos.y = 0;
pos.assign(w_mid, 0);
h_grid_mid = new Rectangle(pos, "darkgreen", gridSize, h);
pos.x = w/4; pos.y = 0;
pos.assign(w/4, 0);
h_grid_u1 = new Rectangle(pos, "darkgreen", gridSize, h);
pos.x = w-w/4; pos.y = 0;
pos.assign(w-w/4, 0);
h_grid_d1 = new Rectangle(pos, "darkgreen", gridSize, h);
score1.update(); // first Text draw init the custom font (graphic leftover ortherwise) (a better solution ?)
@@ -284,6 +292,10 @@ class Vector {
this.x = x;
this.y = y;
}
assign(x: number, y: number) {
this.x = x;
this.y = y;
}
}
class VectorInteger extends Vector {
@@ -377,7 +389,7 @@ interface Moving {
class MovingRectangle extends Rectangle implements Moving {
dir: Vector = {x: 0.0, y: 0.0};
dir: Vector = new Vector(0,0);
speed: number = 1;
constructor(pos: VectorInteger, color: string, width: number, height: number) {
super(pos, color, width, height);
@@ -515,7 +527,7 @@ class Line extends Rectangle {
update() {
let ctx = pong.ctx;
ctx.fillStyle = this.color;
let pos: Vector = {x: 0, y: 0};
let pos: VectorInteger = new VectorInteger;
let i = 0;
while (i < this.segmentCount)
{