Skip to content

Commit 7682fbb

Browse files
Bug fixes
1 parent 15c7d79 commit 7682fbb

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

scripts/drawing/game.js

-8
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,3 @@ function drawGUI() {//A function to draw the graphical user interface of the pla
77
}
88
drawHealthCompass();//Draw the health compass.
99
}
10-
11-
function drawLoop() {//A game loop to do all of the drawing.
12-
"use strict";
13-
drawingContext.fillStyle = "black";//Set the colour of what to draw to black.
14-
drawingContext.fillRect(0, 0, 800, 400);//Fill the canvas with black.
15-
drawPlayers();//Draw all of the players.
16-
drawGUI();//Draw the GUI.
17-
}

scripts/logic/compass.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ function updateCompass() {//A function designed to update the compass.
1818
var distance = 0;//A variable to hold the distance to a point.
1919
if ((compassPoint.x === 0 && compassPoint.y === 0) === false) {//If the compass point isn't set at origin.
2020
compassPoint.distance = Math.floor(Math.sqrt(Math.pow(currentPlayer.x - compassPoint.x, 2) + Math.pow(currentPlayer.y - compassPoint.y, 2)));//Use the distance formula to calculate distance to the point.
21-
if (distance <= currentPlayer.stepSize) {//If the distance is less then the player's step size.
21+
console.log("THIS WORKS");
22+
if (compassPoint.distance <= currentPlayer.stepSize) {//If the distance is less then the player's step size.
2223
compassPoint.x = 0;//Set the compass point to origin so the compass objective no longer shows on the player's compass.
2324
compassPoint.y = 0;
2425
} else {//If the distance is greater than the player's step size.

scripts/logic/game.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ function getCoordinatesOfClick(event) {//A function to get coordinates on the ca
99
currentPlayer.angle = findAngleBetweenTwoPoints(x, y);//Set the angle of where the current player is facing to the angle between the click and the player coordinate.
1010
}
1111

12-
function logicLoop() {//A logic loop to do the logic of the game.
12+
function gameLoop() {//A logic loop to do the logic of the game.
1313
"use strict";
14-
if (connected) {//If the client is connected to the web socket server.
15-
updatePlayerInformation();//Update the player object information on the server.
16-
}
14+
drawingContext.fillStyle = "black";//Set the colour of what to draw to black.
15+
drawingContext.fillRect(0, 0, 800, 400);//Fill the canvas with black.
16+
drawPlayers();//Draw all of the players.
17+
drawGUI();//Draw the GUI.
1718
updateCompass();//Update the compass.
1819
if (currentPlayer.aiControlled && (compassPoint.x === 0 && compassPoint.y === 0) === false) {//If the current player is AI controlled and they have an objective.
1920
currentPlayer.angle = findAngleBetweenTwoPoints(compassPoint.x, compassPoint.y);//Set the current player's angle towards the compass.
@@ -46,8 +47,7 @@ function main() {
4647
canvas = document.getElementById("gameView");
4748
drawingContext = canvas.getContext("2d");
4849
players.push(currentPlayer);
49-
setInterval(drawLoop, 16);
50-
setInterval(logicLoop, 32);
50+
setInterval(gameLoop, 32);
5151
setInterval(updatePlayerInformation, 32);
5252
document.addEventListener("keydown", keyDownHandler);
5353
canvas.addEventListener("mousedown", getCoordinatesOfClick);

0 commit comments

Comments
 (0)