/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cube = Container.expand(function () {
var self = Container.call(this);
// Glow effect (bottom layer)
var cubeGlow = self.attachAsset('cubeGlow', {
anchorX: 0.5,
anchorY: 1.0
});
cubeGlow.alpha = 0.4;
// Main cube body
var cubeGraphics = self.attachAsset('cube', {
anchorX: 0.5,
anchorY: 1.0
});
// Highlight layer
var cubeHighlight = self.attachAsset('cubeHighlight', {
anchorX: 0.5,
anchorY: 1.0
});
cubeHighlight.alpha = 0.6;
// Core layer
var cubeCore = self.attachAsset('cubeCore', {
anchorX: 0.5,
anchorY: 1.0
});
// Inner detail
var cubeInner = self.attachAsset('cubeInner', {
anchorX: 0.5,
anchorY: 1.0
});
cubeInner.alpha = 0.8;
self.velocityY = 0;
self.gravity = 0; // No gravity for ethereal floating
self.jumpForce = 0; // No jumping needed
self.maxJumpForce = 0;
self.isGrounded = false;
self.groundY = 2400;
self.etherealRotation = 0; // Track ethereal rotation separately
self.update = function () {
// Graceful ethereal rotation - slow and mesmerizing
var baseRotation = 0.008; // Very slow base rotation
var breathingRotation = Math.sin(LK.ticks * 0.02) * 0.003; // Subtle breathing effect
self.rotation += baseRotation + breathingRotation;
// Ethereal floating motion - gentle up and down
var floatAmplitude = 15; // How much it moves up/down
var floatSpeed = 0.015; // How fast it floats
var baseY = 2350; // Floating height above ground
self.y = baseY + Math.sin(LK.ticks * floatSpeed) * floatAmplitude;
// Mesmerizing glow with ambient light reflection
var glowPulse = Math.sin(LK.ticks * 0.05) * 0.2 + 0.6; // Slow, deep breathing glow
cubeGlow.alpha = glowPulse;
var glowScale = 1 + Math.sin(LK.ticks * 0.03) * 0.15; // Gentle glow scaling
cubeGlow.scaleX = glowScale;
cubeGlow.scaleY = glowScale;
// Individual layer rotations for complex light play
cubeHighlight.rotation = self.rotation * 0.7; // Slightly different rotation
cubeCore.rotation = self.rotation * 1.3; // Counter-rotating core
cubeInner.rotation = -self.rotation * 0.5; // Opposite rotation for inner detail
// Shimmer effects on highlights
cubeHighlight.alpha = 0.4 + Math.sin(LK.ticks * 0.08) * 0.3;
cubeInner.alpha = 0.6 + Math.cos(LK.ticks * 0.12) * 0.4;
// Continuous ethereal particles
if (LK.ticks % 15 === 0) {
if (typeof particles !== 'undefined') {
var trailParticle = new Particle('trail', self.x + (Math.random() - 0.5) * 60, self.y + (Math.random() - 0.5) * 40);
particles.push(trailParticle);
game.addChild(trailParticle);
}
}
// No ground collision - cube floats freely
self.isGrounded = false;
self.velocityY = 0; // No gravity or velocity
};
self.enchantedPulse = function () {
// Create an enchanting pulse effect when touched
tween(cubeGlow, {
scaleX: 2.0,
scaleY: 2.0,
alpha: 1.0
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(cubeGlow, {
scaleX: 1.2,
scaleY: 1.2,
alpha: 0.6
}, {
duration: 1200,
easing: tween.easeInOut
});
}
});
// Sparkle particles for magical effect
if (typeof particles !== 'undefined') {
for (var i = 0; i < 20; i++) {
var sparkle = new Particle('jump', self.x + (Math.random() - 0.5) * 80, self.y + (Math.random() - 0.5) * 60);
particles.push(sparkle);
game.addChild(sparkle);
}
}
};
return self;
});
var Ground = Container.expand(function () {
var self = Container.call(this);
// Shadow layer (bottom)
var groundShadow = self.attachAsset('groundShadow', {
anchorX: 0,
anchorY: 0
});
groundShadow.y = 32;
// Main ground body
var groundGraphics = self.attachAsset('ground', {
anchorX: 0,
anchorY: 0
});
// Pattern layer
var groundPattern = self.attachAsset('groundPattern', {
anchorX: 0,
anchorY: 0
});
groundPattern.x = 10;
groundPattern.y = 10;
// Highlight layer (top)
var groundHighlight = self.attachAsset('groundHighlight', {
anchorX: 0,
anchorY: 0
});
groundHighlight.x = 5;
groundHighlight.y = 2;
self.speed = -5;
self.update = function () {
self.x += self.speed;
};
return self;
});
var LevelButton = Container.expand(function (levelNum, config, unlocked) {
var self = Container.call(this);
self.levelNum = levelNum;
self.unlocked = unlocked;
// Button background
var buttonBg = self.attachAsset('ground', {
anchorX: 0.5,
anchorY: 0.5
});
buttonBg.width = 300;
buttonBg.height = 120;
if (!unlocked) {
buttonBg.tint = 0x666666;
}
// Level number text
var levelText = new Text2(levelNum.toString(), {
size: 60,
fill: unlocked ? 0xFFFFFF : 0x999999
});
levelText.anchor.set(0.5, 0.3);
self.addChild(levelText);
// Level name text
var nameText = new Text2(config.name, {
size: 30,
fill: unlocked ? 0xFFFFFF : 0x999999
});
nameText.anchor.set(0.5, 0.7);
self.addChild(nameText);
self.down = function (x, y, obj) {
if (self.unlocked) {
selectedLevel = self.levelNum;
startLevel(selectedLevel);
}
};
return self;
});
var Obstacle = Container.expand(function (type) {
var self = Container.call(this);
var obstacleGraphics;
self.type = type || 'spike';
self.speed = -5;
if (self.type === 'spike') {
// Glow effect for spike
var spikeGlow = self.attachAsset('spikeGlow', {
anchorX: 0.5,
anchorY: 1.0
});
spikeGlow.alpha = 0.3;
// Create triangular spike using layered shapes
var spikeBottom = self.attachAsset('spikeBottom', {
anchorX: 0.5,
anchorY: 1.0
});
var spikeMiddle = self.attachAsset('spikeMiddle', {
anchorX: 0.5,
anchorY: 1.0
});
spikeMiddle.y = -20;
var spikeTop = self.attachAsset('spikeTop', {
anchorX: 0.5,
anchorY: 1.0
});
spikeTop.y = -40;
// Core crystal effect
var spikeCore = self.attachAsset('spikeCore', {
anchorX: 0.5,
anchorY: 1.0
});
spikeCore.y = -35;
spikeCore.alpha = 0.9;
} else if (self.type === 'barrier') {
// Glow effect for barrier
var barrierGlow = self.attachAsset('barrierGlow', {
anchorX: 0.5,
anchorY: 0.5
});
barrierGlow.alpha = 0.4;
// Main barrier
obstacleGraphics = self.attachAsset('barrier', {
anchorX: 0.5,
anchorY: 0.5
});
// Highlight layer
var barrierHighlight = self.attachAsset('barrierHighlight', {
anchorX: 0.5,
anchorY: 0.5
});
// Core metallic layer
var barrierCore = self.attachAsset('barrierCore', {
anchorX: 0.5,
anchorY: 0.5
});
barrierCore.alpha = 0.8;
}
self.update = function () {
self.x += self.speed;
// Add pulsing glow animation
if (self.type === 'spike' && spikeGlow) {
spikeGlow.alpha = 0.2 + Math.sin(LK.ticks * 0.08) * 0.15;
spikeCore.alpha = 0.7 + Math.sin(LK.ticks * 0.12) * 0.3;
} else if (self.type === 'barrier' && barrierGlow) {
barrierGlow.alpha = 0.3 + Math.sin(LK.ticks * 0.06) * 0.1;
barrierCore.alpha = 0.6 + Math.sin(LK.ticks * 0.1) * 0.2;
}
};
return self;
});
var Particle = Container.expand(function (type, startX, startY) {
var self = Container.call(this);
self.type = type;
self.lifespan = 60; // 1 second at 60fps
self.age = 0;
var particleGraphics;
if (type === 'jump') {
particleGraphics = self.attachAsset('jumpParticle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = (Math.random() - 0.5) * 8;
self.velocityY = Math.random() * -6 - 2;
} else if (type === 'land') {
particleGraphics = self.attachAsset('landParticle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = (Math.random() - 0.5) * 12;
self.velocityY = Math.random() * -4 - 1;
} else if (type === 'trail') {
particleGraphics = self.attachAsset('trailParticle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = (Math.random() - 0.5) * 4 - 5;
self.velocityY = (Math.random() - 0.5) * 4;
}
self.x = startX;
self.y = startY;
self.update = function () {
self.age++;
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += 0.2; // gravity
// Fade out over time
var fadeProgress = self.age / self.lifespan;
self.alpha = 1 - fadeProgress;
// Scale down over time
var scale = 1 - fadeProgress * 0.5;
self.scaleX = scale;
self.scaleY = scale;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1e3c72
});
/****
* Game Code
****/
// Particle effects assets
// Enhanced spike assets with crystal-like appearance
// Enhanced barrier assets with metallic appearance
// Enhanced ground assets with texture and depth
// Enhanced cube assets with glow effects
var cube;
var obstacles = [];
var groundTiles = [];
var particles = [];
var isJumping = false;
var jumpStartTime = 0;
var gameSpeed = 5;
var distance = 0;
var obstacleTimer = 0;
var groundTimer = 0;
// Game state management
var gameState = 'menu'; // 'menu' or 'playing'
var selectedLevel = 1;
var maxUnlockedLevel = 5;
var levelButtons = [];
// Level configurations
var levelConfigs = [{
name: "Easy Jump",
speed: 3,
obstacleFreq: 120,
gravity: 0.3
}, {
name: "Medium Hop",
speed: 5,
obstacleFreq: 90,
gravity: 0.5
}, {
name: "Hard Leap",
speed: 7,
obstacleFreq: 70,
gravity: 0.7
}, {
name: "Expert Dash",
speed: 9,
obstacleFreq: 50,
gravity: 0.9
}, {
name: "Master Jump",
speed: 12,
obstacleFreq: 40,
gravity: 1.2
}];
function createMenu() {
gameState = 'menu';
// Clear any existing game elements
clearGameElements();
// Title
var titleText = new Text2('DASH JUMP', {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.x = 2048 / 2;
titleText.y = 400;
game.addChild(titleText);
// Level selection title
var selectText = new Text2('SELECT LEVEL', {
size: 60,
fill: 0xFFFFFF
});
selectText.anchor.set(0.5, 0);
selectText.x = 2048 / 2;
selectText.y = 600;
game.addChild(selectText);
// Create level buttons
levelButtons = [];
for (var i = 0; i < levelConfigs.length; i++) {
var levelNum = i + 1;
var unlocked = true; // All levels are now unlocked
var button = game.addChild(new LevelButton(levelNum, levelConfigs[i], unlocked));
var row = Math.floor(i / 2);
var col = i % 2;
button.x = 2048 / 2 + (col - 0.5) * 350;
button.y = 800 + row * 200;
levelButtons.push(button);
}
}
function clearGameElements() {
// Remove all children except GUI elements
for (var i = game.children.length - 1; i >= 0; i--) {
game.children[i].destroy();
}
// Clear arrays
obstacles = [];
groundTiles = [];
levelButtons = [];
particles = [];
}
function startLevel(levelNum) {
gameState = 'playing';
var config = levelConfigs[levelNum - 1];
// Clear menu
clearGameElements();
// Apply level configuration
gameSpeed = config.speed;
// Initialize cube with ethereal floating settings
cube = game.addChild(new Cube());
cube.x = 1024; // Center horizontally for dramatic effect
cube.y = 2350; // Floating above ground
cube.gravity = 0; // No gravity for ethereal floating
// Initialize ground tiles
for (var i = 0; i < 15; i++) {
var groundTile = game.addChild(new Ground());
groundTile.x = i * 200;
groundTile.y = 2440;
groundTile.speed = -gameSpeed;
groundTiles.push(groundTile);
}
// Reset game variables
distance = 0;
obstacleTimer = 0;
groundTimer = 0;
isJumping = false;
// Update score display
scoreTxt.setText('Level ' + levelNum + ' - Distance: 0');
}
// Initialize menu instead of game
createMenu();
// Score display
var scoreTxt = new Text2('Distance: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
function spawnObstacle() {
var obstacleType = Math.random() < 0.7 ? 'spike' : 'barrier';
var obstacle = game.addChild(new Obstacle(obstacleType));
obstacle.x = 2200;
obstacle.speed = -gameSpeed;
if (obstacleType === 'spike') {
obstacle.y = 2400;
} else {
obstacle.y = Math.random() < 0.5 ? 2300 : 2200;
}
obstacles.push(obstacle);
}
function spawnGround() {
var groundTile = game.addChild(new Ground());
groundTile.x = 2200;
groundTile.y = 2440;
groundTile.speed = -gameSpeed;
groundTiles.push(groundTile);
}
game.down = function (x, y, obj) {
if (gameState === 'playing' && cube) {
// Trigger enchanted pulse effect on touch
cube.enchantedPulse();
}
};
game.up = function (x, y, obj) {
// No jump release needed for ethereal floating cube
};
game.update = function () {
if (gameState !== 'playing') return;
// Update distance
distance += 0.1;
scoreTxt.setText('Level ' + selectedLevel + ' - Distance: ' + Math.floor(distance));
// Check level completion (every 200 distance units)
if (Math.floor(distance) >= 200) {
// Level completed - return to menu
createMenu();
return;
}
var config = levelConfigs[selectedLevel - 1];
// Spawn obstacles
obstacleTimer++;
if (obstacleTimer >= config.obstacleFreq + Math.random() * 30) {
spawnObstacle();
obstacleTimer = 0;
}
// Spawn ground tiles
groundTimer++;
if (groundTimer >= 25) {
spawnGround();
groundTimer = 0;
}
// Update and check obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
if (obstacle.lastX === undefined) obstacle.lastX = obstacle.x;
// Remove off-screen obstacles
if (obstacle.lastX >= -100 && obstacle.x < -100) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
// Check collision with cube
if (obstacle.intersects(cube)) {
LK.getSound('death').play();
LK.effects.flashScreen(0xff0000, 500);
createMenu();
return;
}
obstacle.lastX = obstacle.x;
}
// Update and check ground tiles
for (var j = groundTiles.length - 1; j >= 0; j--) {
var ground = groundTiles[j];
if (ground.lastX === undefined) ground.lastX = ground.x;
// Remove off-screen ground tiles
if (ground.lastX >= -200 && ground.x < -200) {
ground.destroy();
groundTiles.splice(j, 1);
continue;
}
ground.lastX = ground.x;
}
// Update and manage particles
for (var k = particles.length - 1; k >= 0; k--) {
var particle = particles[k];
if (particle.age >= particle.lifespan) {
particle.destroy();
particles.splice(k, 1);
}
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cube = Container.expand(function () {
var self = Container.call(this);
// Glow effect (bottom layer)
var cubeGlow = self.attachAsset('cubeGlow', {
anchorX: 0.5,
anchorY: 1.0
});
cubeGlow.alpha = 0.4;
// Main cube body
var cubeGraphics = self.attachAsset('cube', {
anchorX: 0.5,
anchorY: 1.0
});
// Highlight layer
var cubeHighlight = self.attachAsset('cubeHighlight', {
anchorX: 0.5,
anchorY: 1.0
});
cubeHighlight.alpha = 0.6;
// Core layer
var cubeCore = self.attachAsset('cubeCore', {
anchorX: 0.5,
anchorY: 1.0
});
// Inner detail
var cubeInner = self.attachAsset('cubeInner', {
anchorX: 0.5,
anchorY: 1.0
});
cubeInner.alpha = 0.8;
self.velocityY = 0;
self.gravity = 0; // No gravity for ethereal floating
self.jumpForce = 0; // No jumping needed
self.maxJumpForce = 0;
self.isGrounded = false;
self.groundY = 2400;
self.etherealRotation = 0; // Track ethereal rotation separately
self.update = function () {
// Graceful ethereal rotation - slow and mesmerizing
var baseRotation = 0.008; // Very slow base rotation
var breathingRotation = Math.sin(LK.ticks * 0.02) * 0.003; // Subtle breathing effect
self.rotation += baseRotation + breathingRotation;
// Ethereal floating motion - gentle up and down
var floatAmplitude = 15; // How much it moves up/down
var floatSpeed = 0.015; // How fast it floats
var baseY = 2350; // Floating height above ground
self.y = baseY + Math.sin(LK.ticks * floatSpeed) * floatAmplitude;
// Mesmerizing glow with ambient light reflection
var glowPulse = Math.sin(LK.ticks * 0.05) * 0.2 + 0.6; // Slow, deep breathing glow
cubeGlow.alpha = glowPulse;
var glowScale = 1 + Math.sin(LK.ticks * 0.03) * 0.15; // Gentle glow scaling
cubeGlow.scaleX = glowScale;
cubeGlow.scaleY = glowScale;
// Individual layer rotations for complex light play
cubeHighlight.rotation = self.rotation * 0.7; // Slightly different rotation
cubeCore.rotation = self.rotation * 1.3; // Counter-rotating core
cubeInner.rotation = -self.rotation * 0.5; // Opposite rotation for inner detail
// Shimmer effects on highlights
cubeHighlight.alpha = 0.4 + Math.sin(LK.ticks * 0.08) * 0.3;
cubeInner.alpha = 0.6 + Math.cos(LK.ticks * 0.12) * 0.4;
// Continuous ethereal particles
if (LK.ticks % 15 === 0) {
if (typeof particles !== 'undefined') {
var trailParticle = new Particle('trail', self.x + (Math.random() - 0.5) * 60, self.y + (Math.random() - 0.5) * 40);
particles.push(trailParticle);
game.addChild(trailParticle);
}
}
// No ground collision - cube floats freely
self.isGrounded = false;
self.velocityY = 0; // No gravity or velocity
};
self.enchantedPulse = function () {
// Create an enchanting pulse effect when touched
tween(cubeGlow, {
scaleX: 2.0,
scaleY: 2.0,
alpha: 1.0
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(cubeGlow, {
scaleX: 1.2,
scaleY: 1.2,
alpha: 0.6
}, {
duration: 1200,
easing: tween.easeInOut
});
}
});
// Sparkle particles for magical effect
if (typeof particles !== 'undefined') {
for (var i = 0; i < 20; i++) {
var sparkle = new Particle('jump', self.x + (Math.random() - 0.5) * 80, self.y + (Math.random() - 0.5) * 60);
particles.push(sparkle);
game.addChild(sparkle);
}
}
};
return self;
});
var Ground = Container.expand(function () {
var self = Container.call(this);
// Shadow layer (bottom)
var groundShadow = self.attachAsset('groundShadow', {
anchorX: 0,
anchorY: 0
});
groundShadow.y = 32;
// Main ground body
var groundGraphics = self.attachAsset('ground', {
anchorX: 0,
anchorY: 0
});
// Pattern layer
var groundPattern = self.attachAsset('groundPattern', {
anchorX: 0,
anchorY: 0
});
groundPattern.x = 10;
groundPattern.y = 10;
// Highlight layer (top)
var groundHighlight = self.attachAsset('groundHighlight', {
anchorX: 0,
anchorY: 0
});
groundHighlight.x = 5;
groundHighlight.y = 2;
self.speed = -5;
self.update = function () {
self.x += self.speed;
};
return self;
});
var LevelButton = Container.expand(function (levelNum, config, unlocked) {
var self = Container.call(this);
self.levelNum = levelNum;
self.unlocked = unlocked;
// Button background
var buttonBg = self.attachAsset('ground', {
anchorX: 0.5,
anchorY: 0.5
});
buttonBg.width = 300;
buttonBg.height = 120;
if (!unlocked) {
buttonBg.tint = 0x666666;
}
// Level number text
var levelText = new Text2(levelNum.toString(), {
size: 60,
fill: unlocked ? 0xFFFFFF : 0x999999
});
levelText.anchor.set(0.5, 0.3);
self.addChild(levelText);
// Level name text
var nameText = new Text2(config.name, {
size: 30,
fill: unlocked ? 0xFFFFFF : 0x999999
});
nameText.anchor.set(0.5, 0.7);
self.addChild(nameText);
self.down = function (x, y, obj) {
if (self.unlocked) {
selectedLevel = self.levelNum;
startLevel(selectedLevel);
}
};
return self;
});
var Obstacle = Container.expand(function (type) {
var self = Container.call(this);
var obstacleGraphics;
self.type = type || 'spike';
self.speed = -5;
if (self.type === 'spike') {
// Glow effect for spike
var spikeGlow = self.attachAsset('spikeGlow', {
anchorX: 0.5,
anchorY: 1.0
});
spikeGlow.alpha = 0.3;
// Create triangular spike using layered shapes
var spikeBottom = self.attachAsset('spikeBottom', {
anchorX: 0.5,
anchorY: 1.0
});
var spikeMiddle = self.attachAsset('spikeMiddle', {
anchorX: 0.5,
anchorY: 1.0
});
spikeMiddle.y = -20;
var spikeTop = self.attachAsset('spikeTop', {
anchorX: 0.5,
anchorY: 1.0
});
spikeTop.y = -40;
// Core crystal effect
var spikeCore = self.attachAsset('spikeCore', {
anchorX: 0.5,
anchorY: 1.0
});
spikeCore.y = -35;
spikeCore.alpha = 0.9;
} else if (self.type === 'barrier') {
// Glow effect for barrier
var barrierGlow = self.attachAsset('barrierGlow', {
anchorX: 0.5,
anchorY: 0.5
});
barrierGlow.alpha = 0.4;
// Main barrier
obstacleGraphics = self.attachAsset('barrier', {
anchorX: 0.5,
anchorY: 0.5
});
// Highlight layer
var barrierHighlight = self.attachAsset('barrierHighlight', {
anchorX: 0.5,
anchorY: 0.5
});
// Core metallic layer
var barrierCore = self.attachAsset('barrierCore', {
anchorX: 0.5,
anchorY: 0.5
});
barrierCore.alpha = 0.8;
}
self.update = function () {
self.x += self.speed;
// Add pulsing glow animation
if (self.type === 'spike' && spikeGlow) {
spikeGlow.alpha = 0.2 + Math.sin(LK.ticks * 0.08) * 0.15;
spikeCore.alpha = 0.7 + Math.sin(LK.ticks * 0.12) * 0.3;
} else if (self.type === 'barrier' && barrierGlow) {
barrierGlow.alpha = 0.3 + Math.sin(LK.ticks * 0.06) * 0.1;
barrierCore.alpha = 0.6 + Math.sin(LK.ticks * 0.1) * 0.2;
}
};
return self;
});
var Particle = Container.expand(function (type, startX, startY) {
var self = Container.call(this);
self.type = type;
self.lifespan = 60; // 1 second at 60fps
self.age = 0;
var particleGraphics;
if (type === 'jump') {
particleGraphics = self.attachAsset('jumpParticle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = (Math.random() - 0.5) * 8;
self.velocityY = Math.random() * -6 - 2;
} else if (type === 'land') {
particleGraphics = self.attachAsset('landParticle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = (Math.random() - 0.5) * 12;
self.velocityY = Math.random() * -4 - 1;
} else if (type === 'trail') {
particleGraphics = self.attachAsset('trailParticle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = (Math.random() - 0.5) * 4 - 5;
self.velocityY = (Math.random() - 0.5) * 4;
}
self.x = startX;
self.y = startY;
self.update = function () {
self.age++;
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += 0.2; // gravity
// Fade out over time
var fadeProgress = self.age / self.lifespan;
self.alpha = 1 - fadeProgress;
// Scale down over time
var scale = 1 - fadeProgress * 0.5;
self.scaleX = scale;
self.scaleY = scale;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1e3c72
});
/****
* Game Code
****/
// Particle effects assets
// Enhanced spike assets with crystal-like appearance
// Enhanced barrier assets with metallic appearance
// Enhanced ground assets with texture and depth
// Enhanced cube assets with glow effects
var cube;
var obstacles = [];
var groundTiles = [];
var particles = [];
var isJumping = false;
var jumpStartTime = 0;
var gameSpeed = 5;
var distance = 0;
var obstacleTimer = 0;
var groundTimer = 0;
// Game state management
var gameState = 'menu'; // 'menu' or 'playing'
var selectedLevel = 1;
var maxUnlockedLevel = 5;
var levelButtons = [];
// Level configurations
var levelConfigs = [{
name: "Easy Jump",
speed: 3,
obstacleFreq: 120,
gravity: 0.3
}, {
name: "Medium Hop",
speed: 5,
obstacleFreq: 90,
gravity: 0.5
}, {
name: "Hard Leap",
speed: 7,
obstacleFreq: 70,
gravity: 0.7
}, {
name: "Expert Dash",
speed: 9,
obstacleFreq: 50,
gravity: 0.9
}, {
name: "Master Jump",
speed: 12,
obstacleFreq: 40,
gravity: 1.2
}];
function createMenu() {
gameState = 'menu';
// Clear any existing game elements
clearGameElements();
// Title
var titleText = new Text2('DASH JUMP', {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.x = 2048 / 2;
titleText.y = 400;
game.addChild(titleText);
// Level selection title
var selectText = new Text2('SELECT LEVEL', {
size: 60,
fill: 0xFFFFFF
});
selectText.anchor.set(0.5, 0);
selectText.x = 2048 / 2;
selectText.y = 600;
game.addChild(selectText);
// Create level buttons
levelButtons = [];
for (var i = 0; i < levelConfigs.length; i++) {
var levelNum = i + 1;
var unlocked = true; // All levels are now unlocked
var button = game.addChild(new LevelButton(levelNum, levelConfigs[i], unlocked));
var row = Math.floor(i / 2);
var col = i % 2;
button.x = 2048 / 2 + (col - 0.5) * 350;
button.y = 800 + row * 200;
levelButtons.push(button);
}
}
function clearGameElements() {
// Remove all children except GUI elements
for (var i = game.children.length - 1; i >= 0; i--) {
game.children[i].destroy();
}
// Clear arrays
obstacles = [];
groundTiles = [];
levelButtons = [];
particles = [];
}
function startLevel(levelNum) {
gameState = 'playing';
var config = levelConfigs[levelNum - 1];
// Clear menu
clearGameElements();
// Apply level configuration
gameSpeed = config.speed;
// Initialize cube with ethereal floating settings
cube = game.addChild(new Cube());
cube.x = 1024; // Center horizontally for dramatic effect
cube.y = 2350; // Floating above ground
cube.gravity = 0; // No gravity for ethereal floating
// Initialize ground tiles
for (var i = 0; i < 15; i++) {
var groundTile = game.addChild(new Ground());
groundTile.x = i * 200;
groundTile.y = 2440;
groundTile.speed = -gameSpeed;
groundTiles.push(groundTile);
}
// Reset game variables
distance = 0;
obstacleTimer = 0;
groundTimer = 0;
isJumping = false;
// Update score display
scoreTxt.setText('Level ' + levelNum + ' - Distance: 0');
}
// Initialize menu instead of game
createMenu();
// Score display
var scoreTxt = new Text2('Distance: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
function spawnObstacle() {
var obstacleType = Math.random() < 0.7 ? 'spike' : 'barrier';
var obstacle = game.addChild(new Obstacle(obstacleType));
obstacle.x = 2200;
obstacle.speed = -gameSpeed;
if (obstacleType === 'spike') {
obstacle.y = 2400;
} else {
obstacle.y = Math.random() < 0.5 ? 2300 : 2200;
}
obstacles.push(obstacle);
}
function spawnGround() {
var groundTile = game.addChild(new Ground());
groundTile.x = 2200;
groundTile.y = 2440;
groundTile.speed = -gameSpeed;
groundTiles.push(groundTile);
}
game.down = function (x, y, obj) {
if (gameState === 'playing' && cube) {
// Trigger enchanted pulse effect on touch
cube.enchantedPulse();
}
};
game.up = function (x, y, obj) {
// No jump release needed for ethereal floating cube
};
game.update = function () {
if (gameState !== 'playing') return;
// Update distance
distance += 0.1;
scoreTxt.setText('Level ' + selectedLevel + ' - Distance: ' + Math.floor(distance));
// Check level completion (every 200 distance units)
if (Math.floor(distance) >= 200) {
// Level completed - return to menu
createMenu();
return;
}
var config = levelConfigs[selectedLevel - 1];
// Spawn obstacles
obstacleTimer++;
if (obstacleTimer >= config.obstacleFreq + Math.random() * 30) {
spawnObstacle();
obstacleTimer = 0;
}
// Spawn ground tiles
groundTimer++;
if (groundTimer >= 25) {
spawnGround();
groundTimer = 0;
}
// Update and check obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
if (obstacle.lastX === undefined) obstacle.lastX = obstacle.x;
// Remove off-screen obstacles
if (obstacle.lastX >= -100 && obstacle.x < -100) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
// Check collision with cube
if (obstacle.intersects(cube)) {
LK.getSound('death').play();
LK.effects.flashScreen(0xff0000, 500);
createMenu();
return;
}
obstacle.lastX = obstacle.x;
}
// Update and check ground tiles
for (var j = groundTiles.length - 1; j >= 0; j--) {
var ground = groundTiles[j];
if (ground.lastX === undefined) ground.lastX = ground.x;
// Remove off-screen ground tiles
if (ground.lastX >= -200 && ground.x < -200) {
ground.destroy();
groundTiles.splice(j, 1);
continue;
}
ground.lastX = ground.x;
}
// Update and manage particles
for (var k = particles.length - 1; k >= 0; k--) {
var particle = particles[k];
if (particle.age >= particle.lifespan) {
particle.destroy();
particles.splice(k, 1);
}
}
};