diff --git a/sketch.js b/sketch.js index 15a22f6..4136cdb 100644 --- a/sketch.js +++ b/sketch.js @@ -78,7 +78,7 @@ function startGame(full_start, update_objects) { ], curGroundPosYIndex: 0, - draw: function() { + draw: function () { push(); strokeWeight(1); stroke(1); @@ -248,10 +248,10 @@ function startGame(full_start, update_objects) { this.y_step /= this.scale; pop(); }, - getCurGroundPosY: function() { + getCurGroundPosY: function () { return this.possibleGroundPosY[this.curGroundPosYIndex]; }, - goUp: function() { + goUp: function () { memorizedIndex = this.curGroundPosYIndex; this.curGroundPosYIndex = max(0, this.curGroundPosYIndex - 1); if (memorizedIndex != this.curGroundPosYIndex) { @@ -259,7 +259,7 @@ function startGame(full_start, update_objects) { gameChar.scale -= 0.1; } }, - goDown: function() { + goDown: function () { memorizedIndex = this.curGroundPosYIndex; this.curGroundPosYIndex = min( this.possibleGroundPosY.length - 1, @@ -347,6 +347,7 @@ function startGame(full_start, update_objects) { if (collectables[i - 1].x + 200 > finish_position_x) { break; } + collectables[i] = { x: collectables[i - 1].x + 50 + 100 * random(0.5, 1), y: gameChar.possibleGroundPosY[ @@ -355,6 +356,17 @@ function startGame(full_start, update_objects) { size: 75, isFound: false, }; + // Checking whether the coin is over a canyon; + // marking it as isFound (making it disabled) in case if. + for (k = 0; k < canyons.length; k++) { + if ( + canyons[k].x - canyons[k].width / 2 < collectables[i].x + && + canyons[k].x + canyons[k].width / 2 > collectables[i].x + ) { + collectables[i].isFound = true; + } + } } } } @@ -519,7 +531,7 @@ function drawGround() { ); stroke(1); translate(-cameraPosX, 0); - for (i = -width/2; i < finish_position_x + width/2; i += 20) { + for (i = -width / 2; i < finish_position_x + width / 2; i += 20) { line( i, floorPos_y + (2 * (height - floorPos_y)) / 6, @@ -834,4 +846,4 @@ function keyReleased() { console.log(frameCount + " released " + key + " " + keyCode); if (keyCode == 65 /*A*/) gameChar.isLeft = false; if (keyCode == 68 /*D*/) gameChar.isRight = false; -} \ No newline at end of file +}