Skip to content

Commit

Permalink
squashing bugs in games
Browse files Browse the repository at this point in the history
  • Loading branch information
leomcelroy committed Nov 7, 2022
1 parent 883550a commit d9004e4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 80 deletions.
75 changes: 34 additions & 41 deletions games/Call_911.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,21 +475,21 @@ addText("Level Select", {y: 9, color: color`3`});
//addText(moves.toString(), { x: 1, y: 1, color: color`3` });

onInput("w", () => {
if (moves >= 1) {
if (moves >= 1 && getFirst(firetruck)) {
getFirst(firetruck).y -= 1
moves -= 1;
}
});

onInput("a", () => {
if (moves >= 1) {
if (moves >= 1 && getFirst(firetruck)) {
getFirst(firetruck).x -= 1
moves -= 1;
}
});

onInput("d", () => {
if (moves >= 1) {
if (moves >= 1 && getFirst(firetruck)) {
getFirst(firetruck).x += 1
moves -= 1;
}
Expand Down Expand Up @@ -574,54 +574,47 @@ onInput("l", () => {

afterInput(() => {

try {
if (getFirst(firetruck).x == getFirst(shortcut1).x) {
if (getFirst(firetruck).y == getFirst(shortcut1).y) {
setSolids([house1,house2,pine,coconut,bushes]);
getFirst(firetruck).x = getFirst(shortcut).x;
getFirst(firetruck).y = getFirst(shortcut).y;
setSolids([firetruck,house1,house2,pine,coconut,bushes]);
}

if (getFirst(firetruck) && getFirst(shortcut1) && getFirst(firetruck).x == getFirst(shortcut1).x) {
if (getFirst(firetruck).y == getFirst(shortcut1).y) {
setSolids([house1,house2,pine,coconut,bushes]);
getFirst(firetruck).x = getFirst(shortcut).x;
getFirst(firetruck).y = getFirst(shortcut).y;
setSolids([firetruck,house1,house2,pine,coconut,bushes]);
}
else if (getFirst(firetruck).x == getFirst(shortcut).x) {
if (getFirst(firetruck).y == getFirst(shortcut).y) {
setSolids([house1,house2,pine,coconut,bushes]);
getFirst(firetruck).x = getFirst(shortcut1).x;
getFirst(firetruck).y = getFirst(shortcut1).y;
setSolids([firetruck,house1,house2,pine,coconut,bushes]);
}
}
else if (getFirst(firetruck) && getFirst(shortcut) && getFirst(firetruck).x == getFirst(shortcut).x) {
if (getFirst(firetruck).y == getFirst(shortcut).y) {
setSolids([house1,house2,pine,coconut,bushes]);
getFirst(firetruck).x = getFirst(shortcut1).x;
getFirst(firetruck).y = getFirst(shortcut1).y;
setSolids([firetruck,house1,house2,pine,coconut,bushes]);
}
} catch (error){
console.error(error);
}

try {
if (getFirst(firetruck).x == getFirst(blueWater).x) {
if (getFirst(firetruck).y == getFirst(blueWater).y) {
moves += 10;
let x = getFirst(firetruck).x;
let y = getFirst(firetruck).y;
playTune(extinguish);
clearTile(x, y);
addSprite(x, y, firetruck);
}

if (getFirst(firetruck) && getFirst(blueWater) && getFirst(firetruck).x == getFirst(blueWater).x) {
if (getFirst(firetruck).y == getFirst(blueWater).y) {
moves += 10;
let x = getFirst(firetruck).x;
let y = getFirst(firetruck).y;
playTune(extinguish);
clearTile(x, y);
addSprite(x, y, firetruck);
}
} catch (error) {
console.error(error);
}

try {
if (getFirst(firetruck).x == getFirst(fire).x) {
if (getFirst(firetruck).y == getFirst(fire).y) {
level += 1;
setMap(levels[level]);
moves = 20;
}


if (getFirst(firetruck) && getFirst(fire) && getFirst(firetruck).x == getFirst(fire).x) {
if (getFirst(firetruck).y == getFirst(fire).y) {
level += 1;
setMap(levels[level]);
moves = 20;
}
} catch (error) {
console.error(error);
}


if (level != 0 && level != 12) {
clearText();
addText(moves.toString(), { x: 1, y: 1, color: color`3` });
Expand Down
50 changes: 11 additions & 39 deletions games/among_us_maze.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@ const start = 's';
const end = 'e';
const colors = [ color`L`, color`1`, color`3`, color`C`, color`7`, color`5`, color`6`, color`F`, color`4`, color`D`, color`8`, color`H`, color`9` ]
var win = false;
var hasVirtualMouse = false;
var pointsInt = 0;
var notCheating = false;
var canvas = document.querySelector("canvas.game-canvas")
var text = addText("points: ", { y: 14, x: 2, color: color`0` });

// functions

function handleMovement(coords) {
if (hasVirtualMouse) coords = getFirst(virtualMouse)
var tileSize = canvas.getBoundingClientRect().width / row
var x = hasVirtualMouse ? coords.x : Math.floor(coords.x / tileSize)
var y = hasVirtualMouse ? coords.y : Math.floor(coords.y / tileSize)
const inTile = getTile(x, y)
coords = getFirst(virtualMouse)
var x = coords.x;
var y = coords.y;
const inTile = getTile(x, y);

if ((!hasVirtualMouse && inTile.length != 0) || (inTile.length > 1)) {
if (inTile.length > 1) {
text = addText("points: ", { y: 14, x: 2, color: colors[Math.floor(Math.random() * colors.length)] });
//text.style.color = [0,0,255];
if (win) return
pointsInt = hasVirtualMouse ? pointsInt - 100 : pointsInt - 5
pointsInt = pointsInt - 100;
addText(pointsInt.toString(), { y: 14, x: 10, color: colors[Math.floor(Math.random() * colors.length)] });
}

Expand Down Expand Up @@ -185,58 +182,33 @@ let level = 0;
//displaying the map
setMap(levels[level]);

//calling the function to get mouse position
getMousePos(canvas, coords => {
})

//function to track mouse position
function getMousePos(canvas, evt) {
var rect = canvas.getBoundingClientRect();
return {
x: evt.clientX - rect.left,
y: evt.clientY - rect.top
};
}

onInput("w", () => {
if (!hasVirtualMouse) return


getFirst(virtualMouse).y -= 1
handleMovement()
})

onInput("a", () => {
if (!hasVirtualMouse) return


getFirst(virtualMouse).x -= 1
handleMovement()
})

onInput("s", () => {
if (!hasVirtualMouse) return


getFirst(virtualMouse).y += 1
handleMovement()
})

onInput("d", () => {
if (!hasVirtualMouse) return


getFirst(virtualMouse).x += 1
handleMovement()
})

onInput("i", () => {
if (hasVirtualMouse) return

addSprite(2, 1, virtualMouse)
hasVirtualMouse = true
})

//using mouse position to check if mouse hits a wall/ calculate points
//checks if mouse touches the end element
canvas.addEventListener("mousemove", () => {
if (hasVirtualMouse) return
var coords = getMousePos(canvas, event)
handleMovement(coords)
}, false);
addSprite(2, 1, virtualMouse)
1 change: 1 addition & 0 deletions games/mini_maze_and_puzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ setInterval(() => {
}, 130);

const shake = () => {
if (typeof document === "undefined") return;
const gameCanvasContainer = document.querySelector(".game-canvas-container");

gameCanvasContainer.classList.add("shake");
Expand Down

0 comments on commit d9004e4

Please sign in to comment.