Skip to content

Commit

Permalink
show message when difficulty level increases
Browse files Browse the repository at this point in the history
  • Loading branch information
master-lincoln committed Feb 16, 2014
1 parent a09191d commit 48ce3cf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
34 changes: 33 additions & 1 deletion src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ define(['bird', 'pipe', 'score', 'difficulty', '../lib/promise-0.1.1.min'], func

var flash = false;
var showIntroScreen = true;
var levelPassed = false;

var bgCanvas = document.createElement('canvas');
bgCanvas.width = 640;
Expand Down Expand Up @@ -106,6 +107,7 @@ define(['bird', 'pipe', 'score', 'difficulty', '../lib/promise-0.1.1.min'], func

if ( bird.getLowerBound() >= groundLevel || collision ) {
score.resetPoints();
difficulty.reset();
bird.die();
flash = true;
}
Expand All @@ -118,6 +120,10 @@ define(['bird', 'pipe', 'score', 'difficulty', '../lib/promise-0.1.1.min'], func
pipeRightOuter <bird.getPosition().x) {
pipe.passed = true;
score.addPoint();
if ( difficulty.qualifiedForNextLevel(score.getPoints()) ) {
difficulty.advanceLevel();
levelPassed = true;
}
}
});
}
Expand Down Expand Up @@ -159,6 +165,29 @@ define(['bird', 'pipe', 'score', 'difficulty', '../lib/promise-0.1.1.min'], func
};
})();

var drawNextLevelText = (function() {
var frame = 0;
var maxFrames = 20;
return function(ctx) {
if (frame < maxFrames) {
ctx.save();
var fontSize = ~~(20+10*frame/maxFrames);
ctx.font = ""+fontSize+"px 'Press Start 2P'";
ctx.fillStyle = "white";
ctx.textAlign = 'center';
ctx.fillText("Next Level!", game.SIZE[0]/2, game.SIZE[1]/2);
ctx.lineWidth = 1;
ctx.strokeStyle = 'black';
ctx.strokeText("Next Level!", game.SIZE[0]/2, game.SIZE[1]/2);
ctx.restore();
frame++;
} else {
levelPassed = false;
frame = 0;
}
};
})();

function drawIntroScreen(ctx) {
var p = {x: 80, y:20, h:50, w:280};
// arrow
Expand Down Expand Up @@ -201,8 +230,11 @@ define(['bird', 'pipe', 'score', 'difficulty', '../lib/promise-0.1.1.min'], func
score.draw(ctx);
flashScreen(ctx);

if ( showIntroScreen )
if (showIntroScreen)
drawIntroScreen(ctx);

if (levelPassed)
drawNextLevelText(ctx);
}

return {
Expand Down
7 changes: 3 additions & 4 deletions src/score.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['difficulty'], function(difficulty) {
define([], function() {
"use strict";

var points = 0;
Expand Down Expand Up @@ -28,7 +28,6 @@ define(['difficulty'], function(difficulty) {
}

function resetPoints() {
difficulty.reset();
points = 0;
}

Expand All @@ -38,7 +37,6 @@ define(['difficulty'], function(difficulty) {
maxPoints = points;
save(maxPoints);
}
difficulty.setLevel(points);
}

function save() {
Expand All @@ -49,7 +47,8 @@ define(['difficulty'], function(difficulty) {
init: init,
draw: draw,
resetPoints: resetPoints,
addPoint: addPoint
addPoint: addPoint,
getPoints: function() { return points; }
};

});

0 comments on commit 48ce3cf

Please sign in to comment.