/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Particle class for jump/dash effects
var Particle = Container.expand(function () {
var self = Container.call(this);
var p = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
self.life = 30 + Math.random() * 20;
self.vx = (Math.random() - 0.5) * 16;
self.vy = -8 - Math.random() * 8;
self.alpha = 1;
self.update = function () {
self.x += self.vx;
self.y += self.vy;
self.vy += 1.2;
self.life--;
self.alpha -= 0.03;
if (self.life <= 0 || self.alpha <= 0) {
self.destroy();
}
};
return self;
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var cube = self.attachAsset('playerCube', {
anchorX: 0.5,
anchorY: 1
});
self.width = cube.width;
self.height = cube.height;
self.velY = 0;
self.isGrounded = false;
self.jumpPower = -62; // Balanced jump: high but not too floaty
self.gravity = 3.7; // Slightly stronger gravity for snappier feel
self.alive = true;
self.jumpQueued = false;
// For jump effect
self.jumpEffect = function () {
tween(self, {
scaleX: 1.2,
scaleY: 0.8
}, {
duration: 80,
easing: tween.cubicOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 120,
easing: tween.cubicIn
});
}
});
};
// Called every tick
self.update = function () {
if (!self.alive) return;
// Gravity
self.velY += self.gravity;
self.y += self.velY;
// Clamp to ground
if (self.y > groundY) {
if (!self.isGrounded && Math.abs(self.velY) > 10) {
// Only trigger on real landings, not just standing
// Enhanced squash and stretch on landing for beauty
tween(self, {
scaleX: 1.32,
scaleY: 0.62
}, {
duration: 70,
easing: tween.elasticOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 140,
easing: tween.cubicIn
});
}
});
// Screen feedback effect (flash as shake is not available)
LK.effects.flashScreen(0x00eaff, 120);
// Landing particles
for (var i = 0; i < 8; i++) {
var p = new Particle();
p.x = self.x;
p.y = groundY + 10;
p.vx = (Math.random() - 0.5) * 18;
p.vy = -6 - Math.random() * 6;
p.alpha = 0.7 + Math.random() * 0.3;
particles.push(p);
game.addChild(p);
}
}
self.y = groundY;
self.velY = 0;
self.isGrounded = true;
} else {
self.isGrounded = false;
}
// Jump if queued
if (self.jumpQueued && self.isGrounded) {
self.velY = self.jumpPower;
self.isGrounded = false;
self.jumpQueued = false;
// Extra squash before jump for beauty and juice
tween(self, {
scaleX: 1.18,
scaleY: 0.82
}, {
duration: 48,
easing: tween.cubicOut,
onFinish: function onFinish() {
self.jumpEffect();
}
});
// Burst of particles for jump
for (var i = 0; i < 10; i++) {
var p = new Particle();
p.x = self.x;
p.y = self.y - self.height / 2;
p.vx = (Math.random() - 0.5) * 22;
p.vy = -10 - Math.random() * 12;
p.alpha = 1;
particles.push(p);
game.addChild(p);
}
}
};
// Call to queue a jump
self.jump = function () {
// Allow jumping at any height as long as player is grounded and alive
if (self.isGrounded && self.alive) {
self.jumpQueued = true;
}
};
// Call on death
self.die = function () {
self.alive = false;
// Big screen feedback effect (flash as shake is not available)
LK.effects.flashScreen(0xff2d55, 400);
// Particle burst
for (var i = 0; i < 24; i++) {
var p = new Particle();
p.x = self.x;
p.y = self.y - self.height / 2;
p.vx = (Math.random() - 0.5) * 32;
p.vy = -12 - Math.random() * 18;
p.alpha = 1;
particles.push(p);
game.addChild(p);
}
tween(self, {
rotation: Math.PI * 2,
alpha: 0
}, {
duration: 600,
easing: tween.cubicIn
});
};
return self;
});
// Obstacle (spike) class
var Spike = Container.expand(function () {
var self = Container.call(this);
var spike = self.attachAsset('spike', {
anchorX: 0.5,
anchorY: 1
});
self.width = spike.width;
self.height = spike.height;
self.speed = 22;
self.update = function () {
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181c2a
});
/****
* Game Code
****/
// Music
// Particle (small circle)
// Background effect (ellipse)
// Obstacle (spike)
// Ground platform
// Main player cube
// Game constants
var groundY = 2200;
var playerStartX = 420;
var playerStartY = groundY;
var gameSpeed = 22;
var spikeMinGap = 420;
var spikeMaxGap = 820;
var spikeTimer = 0;
var spikeGap = 0;
var score = 0;
var isGameActive = false;
var particles = [];
var spikes = [];
var bgEllipses = [];
var lastTick = 0;
// Background ellipses for visual effect
for (var i = 0; i < 3; i++) {
var bg = LK.getAsset('bgEllipse', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 + (i - 1) * 900,
y: 1200 + i * 200,
scaleX: 1.2 + i * 0.2,
scaleY: 1.1 + i * 0.1,
alpha: 0.18 + i * 0.07
});
game.addChild(bg);
bgEllipses.push(bg);
}
// Ground
var ground = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: groundY
});
game.addChild(ground);
// Player
var player = new Player();
player.x = playerStartX;
player.y = playerStartY;
game.addChild(player);
// Score text
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Section/difficulty display
var sectionNames = ["Very Easy", "Easy", "Medium", "Hard", "Very Hard", "Impossible"];
var sectionThresholds = [0, 5, 12, 20, 26, 30]; // Score at which each section starts
var currentSection = 0;
var sectionTxt = new Text2('Section: Very Easy', {
size: 80,
fill: 0xFFD700
});
sectionTxt.anchor.set(0.5, 0);
sectionTxt.x = 1024;
sectionTxt.y = 120;
LK.gui.top.addChild(sectionTxt);
// Animated title for menu
var titleTxt = new Text2('Dash of Geometry', {
size: 160,
fill: 0x00EAFF
});
titleTxt.anchor.set(0.5, 0.5);
titleTxt.x = 1024;
titleTxt.y = 900;
titleTxt.alpha = 1;
LK.gui.center.addChild(titleTxt);
// Tap to start text
var tapTxt = new Text2('Tap to Start', {
size: 80,
fill: 0xFFFFFF
});
tapTxt.anchor.set(0.5, 0.5);
tapTxt.x = 1024;
tapTxt.y = 1200;
tapTxt.alpha = 0.8;
LK.gui.center.addChild(tapTxt);
// Animate menu texts
tween(titleTxt, {
y: 820
}, {
duration: 900,
easing: tween.elasticOut
});
tween(tapTxt, {
alpha: 1
}, {
duration: 800,
easing: tween.cubicInOut
});
// Hide score at menu
scoreTxt.visible = false;
sectionTxt.visible = false;
// Start game function
function startGame() {
// Remove menu
LK.gui.center.removeChild(titleTxt);
LK.gui.center.removeChild(tapTxt);
// Reset state
isGameActive = true;
score = 0;
scoreTxt.setText(score);
scoreTxt.visible = true;
sectionTxt.visible = true;
// Reset player
player.x = playerStartX;
player.y = playerStartY;
player.velY = 0;
player.alive = true;
player.rotation = 0;
player.alpha = 1;
player.scaleX = 1;
player.scaleY = 1;
// Remove spikes
for (var i = spikes.length - 1; i >= 0; i--) {
spikes[i].destroy();
spikes.splice(i, 1);
}
// Remove particles
for (var i = particles.length - 1; i >= 0; i--) {
particles[i].destroy();
particles.splice(i, 1);
}
// Reset spike timer
spikeTimer = 0;
currentSection = 0;
sectionTxt.setText("Section: " + sectionNames[0]);
spikeMinGap = 470;
spikeMaxGap = 820;
spikeGap = spikeMinGap + Math.random() * (spikeMaxGap - spikeMinGap);
// Play music
LK.playMusic('bgmusic', {
fade: {
start: 0,
end: 1,
duration: 1200
}
});
}
// End game function
function endGame() {
isGameActive = false;
player.die();
LK.effects.flashScreen(0xff2d55, 600);
LK.stopMusic();
LK.setTimeout(function () {
LK.showGameOver();
}, 900);
}
// Particle spawn on jump
function spawnJumpParticles(x, y) {
for (var i = 0; i < 8; i++) {
var p = new Particle();
p.x = x;
p.y = y + 40;
particles.push(p);
game.addChild(p);
}
}
// Particle spawn on score
function spawnScoreParticles(x, y) {
for (var i = 0; i < 12; i++) {
var p = new Particle();
p.x = x;
p.y = y;
p.vx = (Math.random() - 0.5) * 24;
p.vy = -12 - Math.random() * 10;
p.alpha = 1;
particles.push(p);
game.addChild(p);
}
}
// Main game update
game.update = function () {
// Animate background ellipses
for (var i = 0; i < bgEllipses.length; i++) {
var bg = bgEllipses[i];
bg.x -= 0.7 + i * 0.2;
if (bg.x < -400) {
bg.x = 2048 + 400;
}
}
// Menu animation
if (!isGameActive) {
// Pulse tap text
tapTxt.alpha = 0.7 + 0.3 * Math.sin(LK.ticks / 20);
titleTxt.rotation = Math.sin(LK.ticks / 60) * 0.04;
return;
}
// Player update
player.update();
// Spikes update
for (var i = spikes.length - 1; i >= 0; i--) {
var s = spikes[i];
s.update();
// Remove off-screen spikes
if (s.x < -s.width) {
s.destroy();
spikes.splice(i, 1);
continue;
}
// Collision with player
if (player.alive && player.intersects(s)) {
endGame();
return;
}
// Score when passed
if (!s.scored && s.x + s.width / 2 < player.x - player.width / 2) {
s.scored = true;
score++;
scoreTxt.setText(score);
spawnScoreParticles(player.x, player.y - player.height / 2);
// Update section/difficulty if needed
for (var sec = sectionThresholds.length - 1; sec >= 0; sec--) {
if (score >= sectionThresholds[sec]) {
if (currentSection !== sec) {
currentSection = sec;
sectionTxt.setText("Section: " + sectionNames[sec]);
// Optional: flash section text for feedback
tween(sectionTxt, {
alpha: 0.2
}, {
duration: 80,
onFinish: function onFinish() {
tween(sectionTxt, {
alpha: 1
}, {
duration: 180
});
}
});
}
break;
}
}
// Adjust spike gap for difficulty
if (currentSection === 0) {
spikeMinGap = 470;
spikeMaxGap = 820;
} else if (currentSection === 1) {
spikeMinGap = 370;
spikeMaxGap = 700;
} else if (currentSection === 2) {
spikeMinGap = 290;
spikeMaxGap = 600;
} else if (currentSection === 3) {
spikeMinGap = 210;
spikeMaxGap = 480;
} else if (currentSection === 4) {
spikeMinGap = 140;
spikeMaxGap = 340;
} else {
spikeMinGap = 90;
spikeMaxGap = 220;
}
// Win condition
if (score >= 30) {
LK.effects.flashScreen(0x00eaff, 800);
LK.showYouWin();
return;
}
}
}
// Particles update
for (var i = particles.length - 1; i >= 0; i--) {
var p = particles[i];
p.update();
if (p.life <= 0 || p.alpha <= 0) {
p.destroy();
particles.splice(i, 1);
}
}
// Spawn spikes
spikeTimer += gameSpeed;
if (spikeTimer > spikeGap) {
spikeTimer = 0;
spikeGap = spikeMinGap + Math.random() * (spikeMaxGap - spikeMinGap);
var s = new Spike();
s.x = 2048 + s.width / 2;
s.y = groundY;
s.scored = false;
spikes.push(s);
game.addChild(s);
}
};
// Tap to jump or start
game.down = function (x, y, obj) {
if (!isGameActive) {
startGame();
} else {
player.jump();
}
};
// Prevent drag
game.move = function (x, y, obj) {};
// On game over, show menu again
LK.on('gameover', function () {
// Show menu
LK.gui.center.addChild(titleTxt);
LK.gui.center.addChild(tapTxt);
scoreTxt.visible = false;
sectionTxt.visible = false;
tween(titleTxt, {
y: 900
}, {
duration: 600,
easing: tween.elasticOut
});
tween(tapTxt, {
alpha: 1
}, {
duration: 600,
easing: tween.cubicInOut
});
});
// On win, show menu again
LK.on('youwin', function () {
LK.gui.center.addChild(titleTxt);
LK.gui.center.addChild(tapTxt);
scoreTxt.visible = false;
sectionTxt.visible = false;
tween(titleTxt, {
y: 900
}, {
duration: 600,
easing: tween.elasticOut
});
tween(tapTxt, {
alpha: 1
}, {
duration: 600,
easing: tween.cubicInOut
});
}); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Particle class for jump/dash effects
var Particle = Container.expand(function () {
var self = Container.call(this);
var p = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
self.life = 30 + Math.random() * 20;
self.vx = (Math.random() - 0.5) * 16;
self.vy = -8 - Math.random() * 8;
self.alpha = 1;
self.update = function () {
self.x += self.vx;
self.y += self.vy;
self.vy += 1.2;
self.life--;
self.alpha -= 0.03;
if (self.life <= 0 || self.alpha <= 0) {
self.destroy();
}
};
return self;
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var cube = self.attachAsset('playerCube', {
anchorX: 0.5,
anchorY: 1
});
self.width = cube.width;
self.height = cube.height;
self.velY = 0;
self.isGrounded = false;
self.jumpPower = -62; // Balanced jump: high but not too floaty
self.gravity = 3.7; // Slightly stronger gravity for snappier feel
self.alive = true;
self.jumpQueued = false;
// For jump effect
self.jumpEffect = function () {
tween(self, {
scaleX: 1.2,
scaleY: 0.8
}, {
duration: 80,
easing: tween.cubicOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 120,
easing: tween.cubicIn
});
}
});
};
// Called every tick
self.update = function () {
if (!self.alive) return;
// Gravity
self.velY += self.gravity;
self.y += self.velY;
// Clamp to ground
if (self.y > groundY) {
if (!self.isGrounded && Math.abs(self.velY) > 10) {
// Only trigger on real landings, not just standing
// Enhanced squash and stretch on landing for beauty
tween(self, {
scaleX: 1.32,
scaleY: 0.62
}, {
duration: 70,
easing: tween.elasticOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 140,
easing: tween.cubicIn
});
}
});
// Screen feedback effect (flash as shake is not available)
LK.effects.flashScreen(0x00eaff, 120);
// Landing particles
for (var i = 0; i < 8; i++) {
var p = new Particle();
p.x = self.x;
p.y = groundY + 10;
p.vx = (Math.random() - 0.5) * 18;
p.vy = -6 - Math.random() * 6;
p.alpha = 0.7 + Math.random() * 0.3;
particles.push(p);
game.addChild(p);
}
}
self.y = groundY;
self.velY = 0;
self.isGrounded = true;
} else {
self.isGrounded = false;
}
// Jump if queued
if (self.jumpQueued && self.isGrounded) {
self.velY = self.jumpPower;
self.isGrounded = false;
self.jumpQueued = false;
// Extra squash before jump for beauty and juice
tween(self, {
scaleX: 1.18,
scaleY: 0.82
}, {
duration: 48,
easing: tween.cubicOut,
onFinish: function onFinish() {
self.jumpEffect();
}
});
// Burst of particles for jump
for (var i = 0; i < 10; i++) {
var p = new Particle();
p.x = self.x;
p.y = self.y - self.height / 2;
p.vx = (Math.random() - 0.5) * 22;
p.vy = -10 - Math.random() * 12;
p.alpha = 1;
particles.push(p);
game.addChild(p);
}
}
};
// Call to queue a jump
self.jump = function () {
// Allow jumping at any height as long as player is grounded and alive
if (self.isGrounded && self.alive) {
self.jumpQueued = true;
}
};
// Call on death
self.die = function () {
self.alive = false;
// Big screen feedback effect (flash as shake is not available)
LK.effects.flashScreen(0xff2d55, 400);
// Particle burst
for (var i = 0; i < 24; i++) {
var p = new Particle();
p.x = self.x;
p.y = self.y - self.height / 2;
p.vx = (Math.random() - 0.5) * 32;
p.vy = -12 - Math.random() * 18;
p.alpha = 1;
particles.push(p);
game.addChild(p);
}
tween(self, {
rotation: Math.PI * 2,
alpha: 0
}, {
duration: 600,
easing: tween.cubicIn
});
};
return self;
});
// Obstacle (spike) class
var Spike = Container.expand(function () {
var self = Container.call(this);
var spike = self.attachAsset('spike', {
anchorX: 0.5,
anchorY: 1
});
self.width = spike.width;
self.height = spike.height;
self.speed = 22;
self.update = function () {
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181c2a
});
/****
* Game Code
****/
// Music
// Particle (small circle)
// Background effect (ellipse)
// Obstacle (spike)
// Ground platform
// Main player cube
// Game constants
var groundY = 2200;
var playerStartX = 420;
var playerStartY = groundY;
var gameSpeed = 22;
var spikeMinGap = 420;
var spikeMaxGap = 820;
var spikeTimer = 0;
var spikeGap = 0;
var score = 0;
var isGameActive = false;
var particles = [];
var spikes = [];
var bgEllipses = [];
var lastTick = 0;
// Background ellipses for visual effect
for (var i = 0; i < 3; i++) {
var bg = LK.getAsset('bgEllipse', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024 + (i - 1) * 900,
y: 1200 + i * 200,
scaleX: 1.2 + i * 0.2,
scaleY: 1.1 + i * 0.1,
alpha: 0.18 + i * 0.07
});
game.addChild(bg);
bgEllipses.push(bg);
}
// Ground
var ground = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: groundY
});
game.addChild(ground);
// Player
var player = new Player();
player.x = playerStartX;
player.y = playerStartY;
game.addChild(player);
// Score text
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Section/difficulty display
var sectionNames = ["Very Easy", "Easy", "Medium", "Hard", "Very Hard", "Impossible"];
var sectionThresholds = [0, 5, 12, 20, 26, 30]; // Score at which each section starts
var currentSection = 0;
var sectionTxt = new Text2('Section: Very Easy', {
size: 80,
fill: 0xFFD700
});
sectionTxt.anchor.set(0.5, 0);
sectionTxt.x = 1024;
sectionTxt.y = 120;
LK.gui.top.addChild(sectionTxt);
// Animated title for menu
var titleTxt = new Text2('Dash of Geometry', {
size: 160,
fill: 0x00EAFF
});
titleTxt.anchor.set(0.5, 0.5);
titleTxt.x = 1024;
titleTxt.y = 900;
titleTxt.alpha = 1;
LK.gui.center.addChild(titleTxt);
// Tap to start text
var tapTxt = new Text2('Tap to Start', {
size: 80,
fill: 0xFFFFFF
});
tapTxt.anchor.set(0.5, 0.5);
tapTxt.x = 1024;
tapTxt.y = 1200;
tapTxt.alpha = 0.8;
LK.gui.center.addChild(tapTxt);
// Animate menu texts
tween(titleTxt, {
y: 820
}, {
duration: 900,
easing: tween.elasticOut
});
tween(tapTxt, {
alpha: 1
}, {
duration: 800,
easing: tween.cubicInOut
});
// Hide score at menu
scoreTxt.visible = false;
sectionTxt.visible = false;
// Start game function
function startGame() {
// Remove menu
LK.gui.center.removeChild(titleTxt);
LK.gui.center.removeChild(tapTxt);
// Reset state
isGameActive = true;
score = 0;
scoreTxt.setText(score);
scoreTxt.visible = true;
sectionTxt.visible = true;
// Reset player
player.x = playerStartX;
player.y = playerStartY;
player.velY = 0;
player.alive = true;
player.rotation = 0;
player.alpha = 1;
player.scaleX = 1;
player.scaleY = 1;
// Remove spikes
for (var i = spikes.length - 1; i >= 0; i--) {
spikes[i].destroy();
spikes.splice(i, 1);
}
// Remove particles
for (var i = particles.length - 1; i >= 0; i--) {
particles[i].destroy();
particles.splice(i, 1);
}
// Reset spike timer
spikeTimer = 0;
currentSection = 0;
sectionTxt.setText("Section: " + sectionNames[0]);
spikeMinGap = 470;
spikeMaxGap = 820;
spikeGap = spikeMinGap + Math.random() * (spikeMaxGap - spikeMinGap);
// Play music
LK.playMusic('bgmusic', {
fade: {
start: 0,
end: 1,
duration: 1200
}
});
}
// End game function
function endGame() {
isGameActive = false;
player.die();
LK.effects.flashScreen(0xff2d55, 600);
LK.stopMusic();
LK.setTimeout(function () {
LK.showGameOver();
}, 900);
}
// Particle spawn on jump
function spawnJumpParticles(x, y) {
for (var i = 0; i < 8; i++) {
var p = new Particle();
p.x = x;
p.y = y + 40;
particles.push(p);
game.addChild(p);
}
}
// Particle spawn on score
function spawnScoreParticles(x, y) {
for (var i = 0; i < 12; i++) {
var p = new Particle();
p.x = x;
p.y = y;
p.vx = (Math.random() - 0.5) * 24;
p.vy = -12 - Math.random() * 10;
p.alpha = 1;
particles.push(p);
game.addChild(p);
}
}
// Main game update
game.update = function () {
// Animate background ellipses
for (var i = 0; i < bgEllipses.length; i++) {
var bg = bgEllipses[i];
bg.x -= 0.7 + i * 0.2;
if (bg.x < -400) {
bg.x = 2048 + 400;
}
}
// Menu animation
if (!isGameActive) {
// Pulse tap text
tapTxt.alpha = 0.7 + 0.3 * Math.sin(LK.ticks / 20);
titleTxt.rotation = Math.sin(LK.ticks / 60) * 0.04;
return;
}
// Player update
player.update();
// Spikes update
for (var i = spikes.length - 1; i >= 0; i--) {
var s = spikes[i];
s.update();
// Remove off-screen spikes
if (s.x < -s.width) {
s.destroy();
spikes.splice(i, 1);
continue;
}
// Collision with player
if (player.alive && player.intersects(s)) {
endGame();
return;
}
// Score when passed
if (!s.scored && s.x + s.width / 2 < player.x - player.width / 2) {
s.scored = true;
score++;
scoreTxt.setText(score);
spawnScoreParticles(player.x, player.y - player.height / 2);
// Update section/difficulty if needed
for (var sec = sectionThresholds.length - 1; sec >= 0; sec--) {
if (score >= sectionThresholds[sec]) {
if (currentSection !== sec) {
currentSection = sec;
sectionTxt.setText("Section: " + sectionNames[sec]);
// Optional: flash section text for feedback
tween(sectionTxt, {
alpha: 0.2
}, {
duration: 80,
onFinish: function onFinish() {
tween(sectionTxt, {
alpha: 1
}, {
duration: 180
});
}
});
}
break;
}
}
// Adjust spike gap for difficulty
if (currentSection === 0) {
spikeMinGap = 470;
spikeMaxGap = 820;
} else if (currentSection === 1) {
spikeMinGap = 370;
spikeMaxGap = 700;
} else if (currentSection === 2) {
spikeMinGap = 290;
spikeMaxGap = 600;
} else if (currentSection === 3) {
spikeMinGap = 210;
spikeMaxGap = 480;
} else if (currentSection === 4) {
spikeMinGap = 140;
spikeMaxGap = 340;
} else {
spikeMinGap = 90;
spikeMaxGap = 220;
}
// Win condition
if (score >= 30) {
LK.effects.flashScreen(0x00eaff, 800);
LK.showYouWin();
return;
}
}
}
// Particles update
for (var i = particles.length - 1; i >= 0; i--) {
var p = particles[i];
p.update();
if (p.life <= 0 || p.alpha <= 0) {
p.destroy();
particles.splice(i, 1);
}
}
// Spawn spikes
spikeTimer += gameSpeed;
if (spikeTimer > spikeGap) {
spikeTimer = 0;
spikeGap = spikeMinGap + Math.random() * (spikeMaxGap - spikeMinGap);
var s = new Spike();
s.x = 2048 + s.width / 2;
s.y = groundY;
s.scored = false;
spikes.push(s);
game.addChild(s);
}
};
// Tap to jump or start
game.down = function (x, y, obj) {
if (!isGameActive) {
startGame();
} else {
player.jump();
}
};
// Prevent drag
game.move = function (x, y, obj) {};
// On game over, show menu again
LK.on('gameover', function () {
// Show menu
LK.gui.center.addChild(titleTxt);
LK.gui.center.addChild(tapTxt);
scoreTxt.visible = false;
sectionTxt.visible = false;
tween(titleTxt, {
y: 900
}, {
duration: 600,
easing: tween.elasticOut
});
tween(tapTxt, {
alpha: 1
}, {
duration: 600,
easing: tween.cubicInOut
});
});
// On win, show menu again
LK.on('youwin', function () {
LK.gui.center.addChild(titleTxt);
LK.gui.center.addChild(tapTxt);
scoreTxt.visible = false;
sectionTxt.visible = false;
tween(titleTxt, {
y: 900
}, {
duration: 600,
easing: tween.elasticOut
});
tween(tapTxt, {
alpha: 1
}, {
duration: 600,
easing: tween.cubicInOut
});
});