Skip to content

Commit

Permalink
better jewel overlap and guard overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
SamanthaSmith04 committed Apr 16, 2024
1 parent 80655ae commit 480e2c5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion create1.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function create1() {
cursors = this.input.keyboard.createCursorKeys();

// Checks to see if the player overlaps with any of the stars, if he does call the collectStar function
this.physics.add.overlap(player, jewel, collectJewel, null, this);
// this.physics.add.overlap(player, jewel, collectJewel, null, this);

//this.hitGuard = hitGuard.bind(this);

Expand Down
2 changes: 1 addition & 1 deletion create2.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const LEVEL_TWO_BOTTOM = 2 * CENTER_VERTICAL - 100;
cursors = this.input.keyboard.createCursorKeys();

// Checks to see if the player overlaps with any of the stars, if he does call the collectStar function
this.physics.add.overlap(player, jewel, collectJewel, null, this);
// this.physics.add.overlap(player, jewel, collectJewel, null, this);

//this.hitGuard = hitGuard.bind(this);

Expand Down
2 changes: 1 addition & 1 deletion create3.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ function create3() {
cursors = this.input.keyboard.createCursorKeys();

// Checks to see if the player overlaps with any of the stars, if he does call the collectStar function
this.physics.add.overlap(player, jewel, collectJewel, null, this);
// this.physics.add.overlap(player, jewel, collectJewel, null, this);
}
2 changes: 1 addition & 1 deletion create4.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ function create4() {
this.physics.add.collider(guards, wall);

// Checks to see if the player overlaps with any of the stars, if he does call the collectStar function
this.physics.add.overlap(player, jewel, collectJewel, null, this);
// this.physics.add.overlap(player, jewel, collectJewel, null, this);
}
4 changes: 2 additions & 2 deletions create5.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function create5() {

this.physics.add.collider(guards, wall);

this.physics.add.overlap(player, jewel, collectJewel, null, this);
// this.physics.add.overlap(player, jewel, collectJewel, null, this);

this.physics.add.collider(player, lasers, hitGuard, null, this);
// this.physics.add.collider(player, lasers, hitGuard, null, this);
}
2 changes: 1 addition & 1 deletion createDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function createDemo() {
this.physics.add.collider(guards, wall);

// Checks to see if the player overlaps with any of the stars, if he does call the collectStar function
this.physics.add.overlap(player, jewel, collectJewel, null, this);
// this.physics.add.overlap(player, jewel, collectJewel, null, this);

// this.hitGuard = hitGuard.bind(this);

Expand Down
33 changes: 18 additions & 15 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ function checkBounds(dir) {
wrongMove = true;
} else {
checkGuard(playerRow - 1, playerCol);
checkJewel(playerRow - 1, playerCol);
}

}
Expand All @@ -300,27 +301,30 @@ function checkBounds(dir) {
wrongMove = true;
} else {
checkGuard(playerRow + 1, playerCol);
checkJewel(playerRow + 1, playerCol);
}
}
else if (dir == "left"){
if (currentBoard[playerRow][playerCol - 1] == 1){
wrongMove = true;
} else {
checkGuard(playerRow, playerCol - 1);
checkJewel(playerRow, playerCol - 1);
}
}
else if (dir == "right"){
if (currentBoard[playerRow][playerCol + 1] == 1){
wrongMove = true;
} else {
checkGuard(playerRow, playerCol + 1);
checkJewel(playerRow, playerCol + 1);
}
}
return wrongMove;
}


function collectJewel(player, jewel) {
function collectJewel() {
jewel.disableBody(true, true);
//TODO RUN GAMEOVER CODE
player.setTint(0x00ff00);
Expand All @@ -344,15 +348,26 @@ function hitGuard() {
}

function checkGuard(playerRow, playerCol) {
if (currentBoard[playerRow][playerCol] == 3){
if (currentBoard[playerRow][playerCol] == 3 || currentBoard[playerRow][playerCol] == 6){
this.hitGuard();
} else if (playerRow > 0) {
if (currentBoard[playerRow+1][playerCol] == 3){
if (currentBoard[playerRow+1][playerCol] == 3 || currentBoard[playerRow][playerCol] == 6){
this.hitGuard();
}
}
}

function checkJewel(playerRow, playerCol) {
if (currentBoard[playerRow][playerCol] == 4){
this.collectJewel();
} else if (playerRow > 0) {
if (currentBoard[playerRow+1][playerCol] == 4){
this.collectJewel();
}
}
}


//Plays player animations
function animatedMovement(dir, player) {
if (dir == "up") {
Expand Down Expand Up @@ -482,19 +497,7 @@ function setup(g){
move("down", g);
console.log("down")
});
/**
// Create some interface to running the interpreter.
logo = g.add.image(400, 150, 'jewelg');
logo.setInteractive();
logo.on("pointerdown", () => {
const programText = C4C.Editor.getText();
// HERE'S THE IMPORTANT PART!!
// C4C.Interpreter.run(programText);
runner.setProgram(programText);
runner.reset();

}); */
console.log(C4C);

let programText;
Expand Down

0 comments on commit 480e2c5

Please sign in to comment.