Files
42_INT_14_transcendence/src/client/pong.ts
LuckyLaszlo add08c216f authoritative server OK
+ TODO actual matchmaking
2022-11-21 19:46:25 +01:00

49 lines
1.2 KiB
TypeScript

import {GameArea} from "./class/GameArea.js";
import * as d from "./draw.js";
import {gameLoop} from "./gameLoop.js"
import * as c from "./constants.js"
import { GameComponentsClient } from "./class/GameComponentsClient.js";
import {countdown} from "./utils.js";
import {socket} from "./ws.js"; socket; // no-op
/* Keys
Racket 1: W/S
Racket 2: Up/Down
Grid On-Off: G
*/
export const pong = new GameArea();
export const gc = new GameComponentsClient(pong.ctx);
function matchmaking()
{
console.log("Searching an opponent..."); // PLACEHOLDER, todo draw
}
function matchmakingComplete()
{
console.log("Match Found !"); // PLACEHOLDER, TODO draw on canvas
}
function startGame() {
countdown(c.matchStartDelay/1000, resumeGame);
}
function resumeGame()
{
window.addEventListener('keydown', function (e) {
pong.addKey(e.key);
});
window.addEventListener('keyup', function (e) {
pong.deleteKey(e.key);
});
pong.interval = window.setInterval(gameLoop, c.gameLoopIntervalMS);
}
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
export {matchmaking, matchmakingComplete, startGame}