Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
muratkaanmesum committed May 3, 2024
1 parent cbaae16 commit c5695bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions Backend/static/scripts/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ function draw(data) {
ctx.beginPath();
ctx.arc(data.ball.x, data.ball.y, ballSize, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "red";
ctx.fillRect(data.player_one.paddle_x, data.player_one.paddle_y - paddleHeight / 2, paddleWidth, paddleHeight);
ctx.fillStyle = "blue";
ctx.fillRect(data.player_two.paddle_x, data.player_two.paddle_y - paddleHeight / 2, paddleWidth, paddleHeight);
ctx.restore(); // Restore the context state to what it was before translating the origin
}
Expand Down Expand Up @@ -127,7 +129,7 @@ function handleInitialState(state)
{
setCurrentPoints(state)
setPlayerData(state);
draw(state.game);
draw(state.game,"red","blue");
}
function printWinner(winner,socket){
let winnerHTML = `
Expand Down Expand Up @@ -218,17 +220,18 @@ async function connectToServer()
handleInitialState(data);
handleMovement(socket,data);
} else if (data.state_type === "score_state") {
draw(data.game);
draw(data.game,"red","blue");
setCurrentPoints(data);
printCountdown();
} else if (data.state_type === 'finish_state') {
draw(data.game);
draw(data.game,"red","blue");

setCurrentPoints(data);
printWinner(data.winner);
}
else if(data.state_type === "game_state")
{
draw(data.game);
draw(data.game,"red","blue");
setCurrentPoints(data);
handleParticipants(data);
}
Expand All @@ -253,6 +256,7 @@ function handleMovement(socket,data)
document.addEventListener("keydown", (event) => {
if (event.key === "w" || event.key === "s")
{
console.log("pressed")
currentPaddle.dy = event.key === "w" ? -10: 10;
socket.send(JSON.stringify(currentPaddle));
}
Expand Down
2 changes: 1 addition & 1 deletion Backend/static/scripts/matchmaking.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {loadPage} from "./spa.js";
import {getActiveUserNickname} from "./utils";
import {getActiveUserNickname} from "./utils.js";

function handleText() {
const BASE_TEXT = "FINDING A MATCH";
Expand Down

0 comments on commit c5695bc

Please sign in to comment.