Added difficulty option, score-keeping, and better levels.
This commit is contained in:
@ -2,9 +2,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<link href='http://fonts.googleapis.com/css?family=Press+Start+2P' rel='stylesheet' type='text/css'>
|
||||
<link href='http://fonts.googleapis.com/css?family=Press+Start+2P|PT+Mono' rel='stylesheet' type='text/css'>
|
||||
<link href="snake.css" type="text/css" rel="stylesheet">
|
||||
<script src="snake.js" type="application/javascript"></script>
|
||||
<script src="snake-levels.js" type="application/javascript"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class=corner></div><div class=corner></div><div class=corner></div><div class=corner></div>
|
||||
@ -70,6 +71,10 @@
|
||||
<label>Growth</label><input type=text id=growthFactor>
|
||||
<label>Growth Increase</label><!--
|
||||
--><input type=text id=growthFactorIncrease>
|
||||
</section><!--
|
||||
|
||||
--><section id=score>
|
||||
<h4>Score</h4>
|
||||
</section>
|
||||
</div>
|
||||
<div class=debug-aspect>
|
||||
@ -88,39 +93,31 @@
|
||||
|
||||
<script type="application/javascript">
|
||||
var canvas = document.getElementById("snakeCanvas");
|
||||
var scoreValue = document.querySelector("#score span.value");
|
||||
canvas.width = canvas.clientWidth;
|
||||
canvas.height = canvas.clientHeight;
|
||||
|
||||
var loadLevel = function(event) {
|
||||
var levelEl = event.target;
|
||||
var loadLevel = function(ev) {
|
||||
var levelEl = ev.target;
|
||||
document.querySelector("#levelSelect li.selected").className = "";
|
||||
levelEl.className = "selected";
|
||||
var levelNum = parseInt(levelEl.getAttribute("levelNum"));
|
||||
Snake.initialize(levelData[levelNum]); };
|
||||
|
||||
var levelData = [
|
||||
// Level 1: Hello Snake!
|
||||
{"board":[1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,2,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1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0,1,0,0,1,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],"rows":17,"cols":17,"fps":3}];
|
||||
var nextLevel = function() {
|
||||
|
||||
};
|
||||
|
||||
var updateScore = function(ev) {
|
||||
var curScore = parseInt(scoreValue.textContent);
|
||||
curScore += ev.detail.bodyLength;
|
||||
curScore.textContent = curScore;
|
||||
|
||||
if (evDetail.score == Snake.currentLevel.targetScore)
|
||||
nextLevel(); };
|
||||
|
||||
canvas.addEventListener('score', updateScore);
|
||||
|
||||
|
||||
// Add listeners for each of the level list items.
|
||||
var levelLis = document.querySelectorAll("#levelSelect li");
|
||||
|
Reference in New Issue
Block a user