From 6f8caec6fbadecc88466bb88a6f31220ef0f1fe8 Mon Sep 17 00:00:00 2001 From: ZafeerA123 Date: Tue, 31 Oct 2023 21:16:03 +0000 Subject: [PATCH] BOXES WORKING --- _posts/2023-10-19-Gametest1.md | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/_posts/2023-10-19-Gametest1.md b/_posts/2023-10-19-Gametest1.md index 6f6f660..aa415a0 100644 --- a/_posts/2023-10-19-Gametest1.md +++ b/_posts/2023-10-19-Gametest1.md @@ -83,42 +83,42 @@ document.addEventListener("keyup",myCharacter.handleKeyup.bind(myCharacter)); var showEKeySprite = false; // Add the "E" key press event listener to handle the interaction with boxObject2 window.addEventListener('keydown', function (e) { - // Check if the pressed key is "E" (key code 69) - if (e.keyCode == 69) { - // Check if the player character is in contact with boxObject2 + if (e.keyCode === 69) { + // Check for overlap with boxObject2 if (checkForOverlap(myCharacterObject, boxObject2)) { // Make boxObject2 disappear boxObject2.scale = [0, 0]; - } - if (!checkForOverlap(myCharacterObject, boxObject2)) { - // Make the E key related to boxObject1 disappear + } else { + // Make the E key related to boxObject2 disappear if no overlap showEKeySprite = false; } - // Check if the player character is in contact with boxObject1 + + // Check for overlap with boxObject1 if (checkForOverlap(myCharacterObject, boxObject1)) { // Make boxObject1 disappear boxObject1.scale = [0, 0]; - if (!checkForOverlap(myCharacterObject, boxObject1)) { - // Make the E key related to boxObject1 disappear + } else { + // Make the E key related to boxObject1 disappear if no overlap showEKeySprite = false; } - if (!checkForOverlap (myCharacterObject, boxstackObject2)) { - //Boxstackobject 1 dissapear - boxstackObject2.scale = [0, 0] - } - if (!checkForOverlap(myCharacterObject, boxstackObject2)) { - // Make the E key related to boxObject1 disappear + + // Check for overlap with boxstackObject2 + if (checkForOverlap(myCharacterObject, boxstackObject2)) { + // Make boxstackObject2 disappear + boxstackObject2.scale = [0, 0]; + } else { + // Make the E key related to boxstackObject2 disappear if no overlap showEKeySprite = false; } - if (!checkForOverlap (myCharacterObject, boxstackObject1)) { - //Boxstackobject 1 dissapear - boxstackObject1.scale = [0, 0] - } - if (!checkForOverlap(myCharacterObject, boxstackObject1)) { - // Make the E key related to boxObject1 disappear + + // Check for overlap with boxstackObject1 + if (checkForOverlap(myCharacterObject, boxstackObject1)) { + // Make boxstackObject1 disappear + boxstackObject1.scale = [0, 0]; + } else { + // Make the E key related to boxstackObject1 disappear if no overlap showEKeySprite = false; } - } } }); //text