Snake: Added scoring and display.
This commit is contained in:
parent
07d55910d0
commit
a4c3cec462
@ -59,6 +59,7 @@ var loadLevel = function(levelSetName, levelNum) {
|
|||||||
// TODO: Show start overlay UI
|
// TODO: Show start overlay UI
|
||||||
|
|
||||||
// Initialize the board using the level data.
|
// Initialize the board using the level data.
|
||||||
|
$scoreValue.text("0");
|
||||||
Snake.initialize(levelData);
|
Snake.initialize(levelData);
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -66,9 +67,9 @@ var loadLevel = function(levelSetName, levelNum) {
|
|||||||
var nextLevel = function() { };
|
var nextLevel = function() { };
|
||||||
|
|
||||||
var updateScore = function(ev) {
|
var updateScore = function(ev) {
|
||||||
var curScore = parseInt($scoreValue.textContent);
|
var evDetail = ev.originalEvent.detail;
|
||||||
curScore += ev.detail.bodyLength;
|
var curScore = parseInt($scoreValue.text());
|
||||||
curScore.textContent = curScore;
|
$scoreValue.text(curScore + (evDetail.bodyLength * evDetail.fps));
|
||||||
|
|
||||||
if (evDetail.score == Snake.currentLevel.targetScore)
|
if (evDetail.score == Snake.currentLevel.targetScore)
|
||||||
nextLevel(); };
|
nextLevel(); };
|
||||||
|
@ -234,9 +234,12 @@
|
|||||||
growthCounter += growthFactor;
|
growthCounter += growthFactor;
|
||||||
growthFactor += growthFactorIncrease;
|
growthFactor += growthFactorIncrease;
|
||||||
|
|
||||||
|
var scoreDetails = collectLevelData();
|
||||||
|
scoreDetails.score = score;
|
||||||
|
scoreDetails.bodyLength = body.length;
|
||||||
|
|
||||||
// Alert anyone listening to us.
|
// Alert anyone listening to us.
|
||||||
var scoreEvent = new CustomEvent('score',
|
var scoreEvent = new CustomEvent('score', {detail: scoreDetails});
|
||||||
{detail: {'score': score, 'bodyLength': body.length}});
|
|
||||||
|
|
||||||
canvas.dispatchEvent(scoreEvent); }
|
canvas.dispatchEvent(scoreEvent); }
|
||||||
|
|
||||||
@ -363,14 +366,19 @@
|
|||||||
|
|
||||||
// Write out the editor level data as a JSON string to the textarea.
|
// Write out the editor level data as a JSON string to the textarea.
|
||||||
function emitEditorLevelData() {
|
function emitEditorLevelData() {
|
||||||
editorDataTextarea.value = JSON.stringify({
|
editorDataTextarea.value = JSON.stringify(collectLevelData()); }
|
||||||
|
|
||||||
|
function collectLevelData() {
|
||||||
|
return {
|
||||||
board: board,
|
board: board,
|
||||||
rows: ROWS,
|
rows: ROWS,
|
||||||
cols: COLS,
|
cols: COLS,
|
||||||
growthFactor: startGrowthFactor,
|
growthFactor: startGrowthFactor,
|
||||||
growthFactorIncrease: startGFIncrease,
|
growthFactorIncrease: startGFIncrease,
|
||||||
targetScore: targetScore,
|
targetScore: targetScore,
|
||||||
fps: fps}); }
|
fps: fps
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Load the editor data as a JSON string from the textarea.
|
// Load the editor data as a JSON string from the textarea.
|
||||||
function loadEditorLevelData() { }
|
function loadEditorLevelData() { }
|
||||||
|
@ -142,6 +142,8 @@ button {
|
|||||||
bottom: -0.25rem; left: -0.25rem;
|
bottom: -0.25rem; left: -0.25rem;
|
||||||
border-width: 0 0 0.25rem 0.25rem; } } }
|
border-width: 0 0 0.25rem 0.25rem; } } }
|
||||||
|
|
||||||
|
#score .value { margin-left: 1rem; }
|
||||||
|
|
||||||
@include forAspect(wide) {
|
@include forAspect(wide) {
|
||||||
body {
|
body {
|
||||||
margin-top: 2rem;
|
margin-top: 2rem;
|
||||||
@ -175,8 +177,8 @@ button {
|
|||||||
section#controls { left: 0.5rem; top: 13.5rem; }
|
section#controls { left: 0.5rem; top: 13.5rem; }
|
||||||
section#options { left: 0.5rem; top: 20rem; }
|
section#options { left: 0.5rem; top: 20rem; }
|
||||||
|
|
||||||
|
section#score { right: 0.5rem; top: 3rem; }
|
||||||
section#levelSelect { right: 0.5rem; top: 8rem; }
|
section#levelSelect { right: 0.5rem; top: 8rem; }
|
||||||
section#score { right: 0.5rem; }
|
|
||||||
|
|
||||||
section#levelSelect { height: 25rem; }
|
section#levelSelect { height: 25rem; }
|
||||||
section#levelSelect h5 { margin-top: 1rem; } } }
|
section#levelSelect h5 { margin-top: 1rem; } } }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user