changes in Game.svelte
+ playerOne is always in left + kick players after match end + slow down ball and player + re in Makefile
This commit is contained in:
@@ -4,7 +4,7 @@ import * as ev from "../../shared_js/class/Event.js"
|
||||
import * as c from "../constants.js"
|
||||
import { ClientPlayer, ClientSpectator } from "./Client";
|
||||
import { GameComponentsServer } from "./GameComponentsServer.js";
|
||||
import { clientInputListener } from "../wsServer.js";
|
||||
import { clientInputListener, clientTerminate } from "../wsServer.js";
|
||||
import { random } from "../utils.js";
|
||||
import { Ball } from "../../shared_js/class/Rectangle.js";
|
||||
import { wallsMovements } from "../../shared_js/wallsMovement.js";
|
||||
@@ -246,6 +246,16 @@ export class GameSession {
|
||||
})
|
||||
});
|
||||
|
||||
const gameSession = this;
|
||||
setTimeout(function kickRemainingClients() {
|
||||
gameSession.spectatorsMap.forEach((client) => {
|
||||
clientTerminate(client);
|
||||
});
|
||||
gameSession.playersMap.forEach((client) => {
|
||||
clientTerminate(client);
|
||||
});
|
||||
}, 15000);
|
||||
|
||||
// logs
|
||||
if (winner === en.PlayerSide.left) {
|
||||
console.log("Player Left WIN");
|
||||
|
||||
@@ -202,19 +202,21 @@ function createGameSession(playersArr: ClientPlayer[], matchOptions: en.MatchOpt
|
||||
client.gameSession = gameSession;
|
||||
gameSession.playersMap.set(client.id, client);
|
||||
gameSession.unreadyPlayersMap.set(client.id, client);
|
||||
});
|
||||
|
||||
// WIP: Not pretty, hardcoded two players.
|
||||
// Could be done in gameSession maybe ?
|
||||
playersArr[0].racket = gameSession.components.playerRight;
|
||||
playersArr[1].racket = gameSession.components.playerLeft;
|
||||
|
||||
playersArr.forEach((client) => {
|
||||
client.socket.once("message", playerReadyConfirmationListener);
|
||||
});
|
||||
|
||||
playersArr[0].socket.send(JSON.stringify( new ev.EventMatchmakingComplete(en.PlayerSide.right) ));
|
||||
playersArr[1].socket.send(JSON.stringify( new ev.EventMatchmakingComplete(en.PlayerSide.left) ));
|
||||
// REFACTORING: Not pretty, hardcoded two players.
|
||||
// Could be done in gameSession maybe ?
|
||||
const gameSessionPlayersIterator = gameSession.playersMap.values();
|
||||
let player: ClientPlayer;
|
||||
player = (<ClientPlayer>gameSessionPlayersIterator.next().value);
|
||||
player.racket = gameSession.components.playerLeft;
|
||||
player.socket.send(JSON.stringify( new ev.EventMatchmakingComplete(en.PlayerSide.left) ));
|
||||
|
||||
player = (<ClientPlayer>gameSessionPlayersIterator.next().value);
|
||||
player.racket = gameSession.components.playerRight;
|
||||
player.socket.send(JSON.stringify( new ev.EventMatchmakingComplete(en.PlayerSide.right) ));
|
||||
// REFACTORING
|
||||
|
||||
setTimeout(function abortMatch() {
|
||||
if (gameSession.unreadyPlayersMap.size !== 0)
|
||||
@@ -335,7 +337,7 @@ const pingInterval = setInterval( () => {
|
||||
}, 4200);
|
||||
|
||||
|
||||
function clientTerminate(client: Client)
|
||||
export function clientTerminate(client: Client)
|
||||
{
|
||||
client.socket.terminate();
|
||||
if (client.gameSession)
|
||||
|
||||
@@ -11,8 +11,8 @@ export const pw = Math.floor(w*0.017);
|
||||
export const ph = pw*6;
|
||||
export const ballSize = pw;
|
||||
export const wallSize = Math.floor(w*0.01);
|
||||
export const racketSpeed = Math.floor(w*0.66); // pixel per second
|
||||
export const ballSpeed = Math.floor(w*0.66); // pixel per second
|
||||
export const racketSpeed = Math.floor(w*0.60); // pixel per second
|
||||
export const ballSpeed = Math.floor(w*0.55); // pixel per second
|
||||
export const ballSpeedIncrease = Math.floor(ballSpeed*0.05); // pixel per second
|
||||
|
||||
export const normalizedSpeed = false; // for consistency in speed independent of direction
|
||||
|
||||
Reference in New Issue
Block a user