diff --git a/docs/demo/fort/fort.js b/docs/demo/fort/fort.js
index 4c4e00a..cd7d844 100644
--- a/docs/demo/fort/fort.js
+++ b/docs/demo/fort/fort.js
@@ -3,6 +3,12 @@ let loose = false;
let greenSpots = [];
let redSpots = [];
+const defaultDecayInterval = 60;
+let decayInterval = defaultDecayInterval;
+
+const defaultPlaceInterval = 60;
+let placeInterval = defaultDecayInterval;
+
function placeGreen() {
if (greenSpots.length > score) {
return;
@@ -23,7 +29,7 @@ function placeGreen() {
continue placeGreenLoop;
}
}
- const randomHealth = randomRange(15, 50);
+ const randomHealth = randomRange(1, 15);
greencoordinates = { column: random.column, row: random.row, health: randomHealth };
}
greenSpots.push(greencoordinates);
@@ -49,7 +55,7 @@ function placeRed() {
continue placeRedLoop;
}
}
- const randomHealth = randomRange(25, 50);
+ const randomHealth = randomRange(2, 20);
redcoordinates = { column: random.column, row: random.row, health: randomHealth };
}
redSpots.push(redcoordinates);
@@ -90,7 +96,7 @@ function init() {
placeRed();
}
-function update() {
+function update(delta) {
if (loose === true) {
// Crashed!
// Flush the screen.
@@ -103,6 +109,9 @@ function update() {
greenSpots = [];
redSpots = [];
+ decayInterval = defaultDecayInterval;
+ placeInterval = defaultPlaceInterval;
+
placeGreen();
placeRed();
@@ -111,18 +120,27 @@ function update() {
return;
}
- // Randomly place a counter.
- let actions = [
- placeGreen,
- placeRed,
- ];
- shuffle(actions);
- actions[0]();
+ decayInterval -= (delta * 60);
- decreaseHealth();
+ if (decayInterval <= 0) {
+ decreaseHealth();
+ decayInterval = Math.max(5, defaultDecayInterval - score);
+ }
+
+ placeInterval -= (1 + delta);
+ if (placeInterval <= 0) {
+ // Randomly place a counter.
+ let actions = [
+ placeGreen,
+ placeRed,
+ ];
+ shuffle(actions);
+ actions[0]();
+ placeInterval = Math.max(5, defaultPlaceInterval - score);
+ }
}
-function draw() {
+function draw(delta) {
cls();
for (let i = 0; i < gridMaxX; i += 1) {
for (let j = 0; j < gridMaxY; j += 1) {
diff --git a/docs/demo/forward/forward.js b/docs/demo/forward/forward.js
index 6c609ef..a431868 100644
--- a/docs/demo/forward/forward.js
+++ b/docs/demo/forward/forward.js
@@ -1,7 +1,8 @@
// Set up variables for the forward game.
let loose = false;
let playercoordinates = {};
-let wallTimeout;
+const defaultMovementInterval = 60;
+let moveInterval = defaultMovementInterval;
const shapes = [];
shapes[0] = [
@@ -34,7 +35,6 @@ let wall = [];
let wallCoordinates;
function moveWall() {
- wallTimeout = setTimeout(moveWall, Math.max(1000 - (score * 100), 250));
if (wallIsActive) {
if (wallCoordinates === -1) {
wallIsActive = false;
@@ -52,9 +52,6 @@ function moveWall() {
function placePlayer() {
playercoordinates = { column: 0, row: 2 };
- if (typeof wallTimeout !== 'number') {
- wallTimeout = setTimeout(moveWall, 1000);
- }
}
function userActionKeyPress(direction) {
@@ -69,6 +66,9 @@ function userActionKeyPress(direction) {
playercoordinates.row += 1;
}
break;
+ default:
+ // Do nothing.
+ break;
}
}
@@ -76,7 +76,7 @@ function init() {
placePlayer();
}
-function update() {
+function update(delta) {
if (loose === true) {
// Crashed!
// Flush the screen.
@@ -85,6 +85,12 @@ function update() {
displayScore(score);
// Reset some variables.
score = 0;
+ moveInterval = defaultMovementInterval;
+
+ wallIsActive = false;
+ wall = [];
+ wallCoordinates = 0;
+
// Set the game up again.
placePlayer();
@@ -93,13 +99,21 @@ function update() {
return;
}
+ moveInterval -= (delta * 60);
+
+ if (moveInterval <= 0) {
+ moveWall();
+ moveInterval = Math.max(5, defaultMovementInterval - score);
+ }
+
+ // Check loose state.
for (let i = 0; i < gridMaxX; i += 1) {
for (let j = 0; j < gridMaxY; j += 1) {
const element = grid[i][j];
if (element.column === wallCoordinates) {
for (let wallpart = 0; wallpart < wall.length; wallpart += 1) {
if (wall[wallpart] === 1 && element.row === wallpart) {
- if (element.column === playercoordinates.column
+ if (element.column === playercoordinates.column
&& element.row === playercoordinates.row) {
loose = true;
return;
@@ -111,7 +125,7 @@ function update() {
}
}
-function draw() {
+function draw(delta) {
cls();
for (let i = 0; i < gridMaxX; i += 1) {
diff --git a/docs/demo/forward/index.html b/docs/demo/forward/index.html
index f79af07..5edc38a 100644
--- a/docs/demo/forward/index.html
+++ b/docs/demo/forward/index.html
@@ -32,7 +32,7 @@
Four Demo: Forward
- An implementation of flappy bird. Use the up and down arrows to move your box up and down and avoid the walls.
+ An implementation of flappy bird, without the gravity. Use the up and down arrows to move your box up and down and avoid the walls.