WIP, tout est en chantier, très content :)

This commit is contained in:
LuckyLaszlo
2022-11-20 15:46:45 +01:00
parent 023b5ed485
commit 48665cfe30
22 changed files with 580 additions and 302 deletions

View File

@@ -1,6 +1,6 @@
import * as g from "./global.js"
import {pong, gc, clientInfo} from "./global.js"
import * as d from "./draw.js";
import {random} from "../shared_js/utils.js";
import {random} from "./utils.js";
import {handleInput} from "./handleInput.js";
let ballInPlay = false;
@@ -23,17 +23,17 @@ function gameLoop()
if (ballInPlay)
{
g.ball.moveAndBounce(delta_time, [g.wall_top, g.wall_bottom, g.player1, g.player2]);
if (g.ball.pos.x > g.pong.canvas.width) {
gc.ball.moveAndBounce(delta_time, [gc.wallTop, gc.wallBottom, gc.playerLeft, gc.playerRight]);
if (gc.ball.pos.x > pong.canvas.width) {
ballInPlay = false;
g.score1.clear();
++g.score1.value;
gc.score1.clear();
++gc.score1.value;
setTimeout(newRound, 1500);
}
else if (g.ball.pos.x < 0 - g.ball.width) {
else if (gc.ball.pos.x < 0 - gc.ball.width) {
ballInPlay = false;
g.score2.clear();
++g.score2.value;
gc.score2.clear();
++gc.score2.value;
setTimeout(newRound, 1500);
}
}
@@ -44,12 +44,12 @@ function gameLoop()
function newRound()
{
// https://fr.wikipedia.org/wiki/Tennis_de_table#Nombre_de_manches
if (g.score1.value >= 11
|| g.score2.value >= 11)
if (gc.score1.value >= 11
|| gc.score2.value >= 11)
{
if (Math.abs(g.score1.value - g.score2.value) >= 2)
if (Math.abs(gc.score1.value - gc.score2.value) >= 2)
{
if (g.score1.value > g.score2.value) {
if (gc.score1.value > gc.score2.value) {
alert("Player 1 WIN");
}
else {
@@ -58,9 +58,9 @@ function newRound()
return;
}
}
g.ball.pos.x = Math.floor(g.pong.canvas.width/2);
g.ball.pos.y = Math.floor((g.pong.canvas.height * 0.1) + random() * (g.pong.canvas.height * 0.8));
g.ball.speed = g.ball.baseSpeed;
gc.ball.pos.x = Math.floor(pong.canvas.width/2);
gc.ball.pos.y = Math.floor((pong.canvas.height * 0.1) + random() * (pong.canvas.height * 0.8));
gc.ball.speed = gc.ball.baseSpeed;
ballInPlay = true;
}