Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Code4Community/jewel-thief
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico-242 committed Oct 7, 2024
2 parents c0b6369 + 1c7c617 commit d035f84
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 34 deletions.
13 changes: 11 additions & 2 deletions create1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
var guards = []

function create1() {

guards = []

document.getElementById("nextLevel").addEventListener("click", (event) => {
switchLevel("3");
});
Expand All @@ -26,7 +30,7 @@ function create1() {
// GENERATE WALLS ---------------------------------------------------------------------
// Create the horizontal walls and the vertical walls
wall = this.physics.add.staticGroup();

guardIndex = 0;
for(i=0; i<arr1.length; i++){
for(j=0;j<arr1[i].length;j++){
if(arr1[i][j]==9){
Expand All @@ -52,14 +56,19 @@ function create1() {
}
}
}
player.setDepth(2);
jewel.setDepth(1);
for (i = 0; i < guards.length; i++){
guards[i].setDepth(3);
}

const LEVEL_TWO_BOTTOM = 2 * CENTER_VERTICAL - 100;

// Input Events
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
14 changes: 12 additions & 2 deletions create2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
arr2 = getLevel(2);
var guards = []

function create2() {

guards = []

document.getElementById("nextLevel").addEventListener("click", (event) => {
switchLevel("4");
Expand All @@ -23,6 +26,7 @@ function create2() {
wall = this.physics.add.staticGroup();


guardIndex = 0;

for(i=0; i<arr2.length; i++){
for(j=0;j<arr2[i].length;j++){
Expand All @@ -34,7 +38,8 @@ function create2() {
}
//adding guard to that position
else if(arr2[i][j]==3){
guards = this.physics.add.sprite(j*40+20,i*40+8, "guard").setScale(guardScale);
guards[guardIndex] = this.physics.add.sprite(j*40+20,i*40+8, "guard").setScale(guardScale);
guardIndex++;
}
//adding gem to that position
else if(arr2[i][j]==4){
Expand All @@ -53,14 +58,19 @@ function create2() {
}
}
}
player.setDepth(2);
for (i = 0; i < guards.length; i++){
guards[i].setDepth(3);
}
jewel.setDepth(1);

const LEVEL_TWO_BOTTOM = 2 * CENTER_VERTICAL - 100;

// Input Events
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
13 changes: 10 additions & 3 deletions create3.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

arr3 = getLevel(3);
var guards = []

function create3() {

guards = []
array_lev3 = getLevel(3);
generateCheckerboard(this, 8); // Generate background
setup(this);
Expand All @@ -24,8 +27,7 @@ function create3() {
wall = this.physics.add.staticGroup();

//Sets framework for multiple guards, adds them to an array to be used in collisions
var guards = []
guardIndex = 0;
guardIndex = 0;

for (i = 0; i < arr3.length; i++){
for(j=0; j < arr3[i].length; j++){
Expand Down Expand Up @@ -58,10 +60,15 @@ function create3() {
}
}
}
player.setDepth(2);
for (i = 0; i < guards.length; i++){
guards[i].setDepth(3);
}
jewel.setDepth(1);

// Input Events
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);
}
9 changes: 8 additions & 1 deletion create4.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
arr4 = getLevel(4);
var guards = []

function create4() {
guards = []
generateCheckerboard(this, 8); // Generate background
setup(this)

Expand Down Expand Up @@ -51,12 +53,17 @@ function create4() {
}
}
}
player.setDepth(2);
for (i = 0; i < guards.length; i++){
guards[i].setDepth(3);
}
jewel.setDepth(1);

// Input Events
cursors = this.input.keyboard.createCursorKeys();

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);
}
15 changes: 10 additions & 5 deletions create5.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
arr5 = getLevel(5);
var guards = []

function create5() {
guards = []
generateCheckerboard(this, 8); // Generate background
setup(this);

Expand All @@ -20,8 +22,7 @@ function create5() {
wall = this.physics.add.staticGroup();

//Sets framework for multiple guards, adds them to an array to be used in collisions
var guards = []
guardIndex = 0;
guardIndex = 0;

//Sets framework for the laser, adds them to an array to be used in collisions
var lasers = []
Expand Down Expand Up @@ -78,13 +79,17 @@ function create5() {
}
}
}

player.setDepth(2);
for (i = 0; i < guards.length; i++){
guards[i].setDepth(3);
}
jewel.setDepth(1);
// Input Events
cursors = this.input.keyboard.createCursorKeys();

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);
}
11 changes: 8 additions & 3 deletions createDemo.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

arr0 = getLevel(0);
var guards = []

function createDemo() {

guards = []
document.getElementById("nextLevel").addEventListener("click", (event) => {
switchLevel("2");
});
Expand Down Expand Up @@ -30,7 +31,6 @@ function createDemo() {
wall = this.physics.add.staticGroup();

//Sets framework for multiple guards, adds them to an array to be used in collisions
var guards = []
guardIndex = 0;

for (i = 0; i < arr0.length; i++){
Expand Down Expand Up @@ -65,6 +65,11 @@ function createDemo() {
}
}
}
player.setDepth(2);
for (i = 0; i < guards.length; i++){
guards[i].setDepth(3);
}
jewel.setDepth(1);

avoidGuard = this.physics.add.staticGroup();
avoidGuard.create(400, CENTER_VERTICAL + 175, "AvoidGuards").setScale(1);
Expand All @@ -75,7 +80,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
58 changes: 40 additions & 18 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ for (i = 0; i < 5; i++) {

document.getElementById("enableCommands").addEventListener("click", (event) => {
// document.getElementById("enableCommands").disabled = true;
player.x = player_start_current_level[0];
player.y = player_start_current_level[1];

playerCol = Math.floor(player.x / 40);
playerRow = Math.floor(player.y / 40);
programText = C4C.Editor.getText();
// HERE'S THE IMPORTANT PART!!
// C4C.Interpreter.run(programText);
Expand Down Expand Up @@ -272,9 +277,9 @@ function move(dir, scene) {
targetY = Math.round(player.y);
playerCol += 1;
targetX = Math.round(playerCol * moveIncrement+20);


}

adjust_guards_depth(scene);
console.log("CURRENT: " + player.x + " " + player.y);
console.log("TARGET: " + targetX + " " + targetY);
scene.physics.moveTo(player, targetX, targetY, SPEED);
Expand All @@ -283,6 +288,18 @@ function move(dir, scene) {

}

function adjust_guards_depth(scene) {
for (i = 0; i < guards.length; i++){
guardRow = Math.floor(guards[i].y / 40);
if (playerRow == guardRow + 1) {
guards[i].setDepth(1);
}
else {
guards[i].setDepth(3);
}
}
}

//Checks if the player's next move will hit a wall bounding box
//returns false if the path is clear
function checkBounds(dir) {
Expand All @@ -293,6 +310,7 @@ function checkBounds(dir) {
wrongMove = true;
} else {
checkGuard(playerRow - 1, playerCol);
checkJewel(playerRow - 1, playerCol);
}

}
Expand All @@ -301,27 +319,30 @@ function checkBounds(dir) {
wrongMove = true;
} else {
checkGuard(playerRow + 1, playerCol);
checkJewel(playerRow + 1, playerCol);
}
}
else if (dir == "left"){
if (currentBoard[playerRow][playerCol - 1] == 9){
wrongMove = true;
} else {
checkGuard(playerRow, playerCol - 1);
checkJewel(playerRow, playerCol - 1);
}
}
else if (dir == "right"){
if (currentBoard[playerRow][playerCol + 1] == 9){
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 @@ -330,30 +351,43 @@ function collectJewel(player, jewel) {
gameOver = true;
finishedLevels[current_level] = 1;
if (current_level < 5) {
document.getElementById("level-select").options[current_level].disabled = false;
document.getElementById("level-select").options[current_level+1].disabled = false;
document.getElementById("nextLevel").disabled = false;
}

}

function hitGuard() {
for (i = 0; i < guards.length; i++){
guards[i].setDepth(3);
}
player.setTint(0xff0000);

guardHit = true;
gameOver = true;



}

function checkGuard(playerRow, playerCol) {
if (currentBoard[playerRow][playerCol] == 3){
if (currentBoard[playerRow][playerCol] == 3 || currentBoard[playerRow][playerCol] == 6 || currentBoard[playerRow][playerCol] == 7 || currentBoard[playerRow][playerCol] == 5){
this.hitGuard();
}
}

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


//Plays player animations
function animatedMovement(dir, player) {
if (dir == "up") {
Expand Down Expand Up @@ -483,19 +517,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 d035f84

Please sign in to comment.