Skip to content

Commit

Permalink
Game update1
Browse files Browse the repository at this point in the history
  • Loading branch information
ZafeerA123 committed Oct 30, 2023
1 parent b421ef6 commit 12f5c7d
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 16 deletions.
106 changes: 90 additions & 16 deletions _posts/2023-10-25-Game.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ import {Display, subDisplay} from "/Group/myScripts/GameScripts/Displays.js";
boxstackImage.src = "/Group/images/Game/box2.png"
var boxstackObject1 = new Object("box",boxstackImage,[20,28],[120,168],[850,500],1,1);
var boxstackObject2 = new Object("box",boxstackImage,[20,28],[100,140],[575,500],1,1);
//E key animation
var EkeyImage = new Image ();
EkeyImage.src = "/Group/images/Game/EKeySprite.png"
var Ekey= new Object ("Ekey" ,EkeyImage, [400,354],[80,100],[190,300],2,1);
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 (checkForOverlap(myCharacterObject, boxObject2)) {
// Make boxObject2 disappear
boxObject2.scale = [0, 0];
}
}
});



Expand Down Expand Up @@ -154,6 +170,56 @@ var sec = 0;
var mouseX = 0;
var mouseY = 0;

function checkForOverlap(object1, object2) {
var pos1 = object1.ReturnPosition().slice();
var scale1 = object1.ReturnScale().slice();
var xRange1 = [pos1[0], pos1[0] + scale1[0]];
var yRange1 = [pos1[1], pos1[1] + scale1[1]];

var pos2 = object2.ReturnPosition().slice();
var scale2 = object2.ReturnScale().slice();
var xRange2 = [pos2[0], pos2[0] + scale2[0]];
var yRange2 = [pos2[1], pos2[1] + scale2[1]];

if (
xRange1[0] >= xRange2[0] &&
xRange1[0] <= xRange2[1] &&
yRange1[0] >= yRange2[0] &&
yRange1[0] <= yRange2[1]
) {
return true;
}

if (
xRange1[0] >= xRange2[0] &&
xRange1[0] <= xRange2[1] &&
yRange1[1] >= yRange2[0] &&
yRange1[1] <= yRange2[1]
) {
return true;
}

if (
xRange1[1] >= xRange2[0] &&
xRange1[1] <= xRange2[1] &&
yRange1[0] >= yRange2[0] &&
yRange1[0] <= yRange2[1]
) {
return true;
}

if (
xRange1[1] >= xRange2[0] &&
xRange1[1] <= xRange2[1] &&
yRange1[1] >= yRange2[0] &&
yRange1[1] <= yRange2[1]
) {
return true;
}

return false;
}


var fadingFrame = 0;
var fadingCtx = fadingCanvas.getContext("2d")
Expand Down Expand Up @@ -211,43 +277,51 @@ function Room1frame(){
pos = [pos.x,500-pos.y]; //fix position

//console.log(pos)
if (myCharacter.directionX == 1){
myCharacterObject.state = 0;
}
else {
myCharacterObject.state = 1;
}

if(pos[0]>=-64 && pos[0]<1360){
myCharacterObject.OverridePosition(pos); //update character position
if(myCharacter.moving == true){ //if charavter is moving then animate
if (currentFrame % Math.round(fps/12)==0){
myCharacterObject.UpdateFrame();
}
myCharacterObject.OverridePosition(pos); //update character position
if(myCharacter.moving == true){ //if charavter is moving then animate
if (currentFrame % Math.round(fps/12)==0){
myCharacterObject.UpdateFrame()
}
}
}
else{
if(pos[0]<-64){
myCharacter.position = {x:-64,y:0};
myCharacter.position = {x:-64,y:0}
}
else{
myCharacter.position = {x:1360,y:0};
myCharacter.position = {x:1360,y:0}
}
}

if (pos[0]>=0 && pos[0]<1000){
part1Room1ObjectDisplay.OverrideScroll([-pos[0],0]); //scroll everything
part1Room1ShadowDisplay.OverrideScroll([-pos[0],0]);
}
if(currentFrame % Math.round(fps/4)==0){ //update lighting
light([[50,15,2.5],[450,15,2.5],[850,15,2.5],[1250,15,2.5]],lightObject,part1Room1ShadowCanvas,true);
}

if (checkForOverlap(myCharacterObject, boxObject1) || checkForOverlap(myCharacterObject, boxObject2)) {
console.log("Now press the E key");
showEKeySprite = true;
}


part1Room1ObjectDisplay.draw(1); //objects

part1Room1Display.draw(1); //update room

// Drawing the EKey sprite
if (showEKeySprite) {
if (currentFrame % Math.round(fps/2)==0){
Ekey.UpdateFrame()
}
//Ekey.OverridePosition([boxObject1.ReturnPosition()[0], boxObject1.ReturnPosition()[1] - Ekey.ReturnScale()[1]]);
Ekey.draw(part1Room1Display.canvas.getContext("2d"),[0,0]); // Draw the EKey sprite with camera offset
}




part1Display.draw(1); //update section display

mainDisplay.draw(1); //update Main Canvas
Expand Down
4 changes: 4 additions & 0 deletions _posts/2023-10-26-MiniGametest3.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ function frame(){ //when a frame is updated
windowObject3.UpdateFrame();
windowObject4.UpdateFrame();
windowObject5.UpdateFrame();
if ((currentFrame % Math.round(fps/4)) == 0){
//run elevator frame
elevatorObject.UpdateFrame();
}

//run monster walking animation
monsterObject.UpdateFrame();
Expand Down
Binary file modified scripts/__pycache__/convert_notebooks.cpython-310.pyc
Binary file not shown.

0 comments on commit 12f5c7d

Please sign in to comment.