/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 1.0 }); var leftEye = self.attachAsset('enemyEye', { anchorX: 0.5, anchorY: 0.5, x: -10, y: -35 }); var rightEye = self.attachAsset('enemyEye', { anchorX: 0.5, anchorY: 0.5, x: 10, y: -35 }); var spike1 = self.attachAsset('enemySpike', { anchorX: 0.5, anchorY: 1.0, x: -15, y: -45 }); var spike2 = self.attachAsset('enemySpike', { anchorX: 0.5, anchorY: 1.0, x: 0, y: -50 }); var spike3 = self.attachAsset('enemySpike', { anchorX: 0.5, anchorY: 1.0, x: 15, y: -45 }); self.velocityX = 3; self.direction = 1; self.startX = 0; self.patrolDistance = 200; self.update = function () { self.x += self.velocityX * self.direction; // Patrol behavior if (Math.abs(self.x - self.startX) > self.patrolDistance) { self.direction *= -1; } // Check collision with hero if (self.intersects(hero)) { // Check if hero jumped on enemy if (hero.velocityY > 0 && hero.y < self.y - 25) { self.defeat(); hero.velocityY = -15; // Bounce } else { hero.die(); } } // Check collision with projectiles for (var i = projectiles.length - 1; i >= 0; i--) { var projectile = projectiles[i]; if (self.intersects(projectile)) { self.defeat(); projectile.destroy(); projectiles.splice(i, 1); break; } } }; self.defeat = function () { LK.setScore(LK.getScore() + 100); scoreText.setText(LK.getScore()); LK.getSound('defeat').play(); // Flash effect when defeating enemy LK.effects.flashScreen(0xff1744, 300); // Remove from enemies array for (var i = enemies.length - 1; i >= 0; i--) { if (enemies[i] === self) { enemies.splice(i, 1); break; } } self.destroy(); }; return self; }); var Hero = Container.expand(function () { var self = Container.call(this); var heroBody = self.attachAsset('heroBody', { anchorX: 0.5, anchorY: 1.0 }); var heroHead = self.attachAsset('heroHead', { anchorX: 0.5, anchorY: 1.0, x: 0, y: -45 }); var heroGraphics = heroBody; self.velocityX = 0; self.velocityY = 0; self.speed = 8; self.jumpPower = -30; self.gravity = 1; self.onGround = false; self.facingRight = true; self.jumpsRemaining = 0; self.maxJumps = 3; self.jumpCooldown = 0; self.update = function () { // Apply gravity self.velocityY += self.gravity; // Apply velocity self.x += self.velocityX; self.y += self.velocityY; // Apply friction self.velocityX *= 0.8; // Decrease jump cooldown if (self.jumpCooldown > 0) { self.jumpCooldown--; } // Check platform collisions self.onGround = false; for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; if (self.intersects(platform)) { // Landing on top of platform if (self.velocityY > 0 && self.y - 60 < platform.y) { self.y = platform.y; self.velocityY = 0; self.onGround = true; self.jumpsRemaining = self.maxJumps; // Reset jumps when landing } } } // Keep hero on screen horizontally if (self.x < 30) self.x = 30; if (self.x > 2018) self.x = 2018; // Check if fallen off screen if (self.y > 2800) { self.die(); } // Update sprite direction if (self.velocityX > 1 && !self.facingRight) { heroGraphics.scaleX = 1; self.facingRight = true; } else if (self.velocityX < -1 && self.facingRight) { heroGraphics.scaleX = -1; self.facingRight = false; } }; self.jump = function () { // Can jump if on ground or have remaining air jumps, and no cooldown if ((self.onGround || self.jumpsRemaining > 0) && self.jumpCooldown <= 0) { self.velocityY = self.jumpPower; if (self.onGround) { self.onGround = false; self.jumpsRemaining = self.maxJumps - 1; // Use one jump, have 2 remaining } else { self.jumpsRemaining--; // Use an air jump } self.jumpCooldown = 10; // 10 frame cooldown between jumps LK.getSound('jump').play(); } }; self.moveLeft = function () { self.velocityX = -self.speed; }; self.moveRight = function () { self.velocityX = self.speed; }; self.shoot = function () { var newProjectile = new Projectile(); newProjectile.x = self.x; newProjectile.y = self.y - 30; newProjectile.velocityX = self.facingRight ? 15 : -15; projectiles.push(newProjectile); game.addChild(newProjectile); LK.getSound('shoot').play(); }; self.die = function () { lives--; if (lives <= 0) { LK.showGameOver(); } else { self.respawn(); } }; self.respawn = function () { self.x = 200; self.y = 2000; self.velocityX = 0; self.velocityY = 0; self.jumpsRemaining = self.maxJumps; self.jumpCooldown = 0; }; return self; }); var Platform = Container.expand(function (width, height) { var self = Container.call(this); var platformGraphics = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5, width: width || 300, height: height || 40 }); var leftEdge = self.attachAsset('platformEdge', { anchorX: 1.0, anchorY: 0.5, x: -(width || 300) / 2, y: 0 }); var rightEdge = self.attachAsset('platformEdge', { anchorX: 0.0, anchorY: 0.5, x: (width || 300) / 2, y: 0 }); var grass = self.attachAsset('platformGrass', { anchorX: 0.5, anchorY: 1.0, width: width || 300, x: 0, y: -(height || 40) / 2 }); return self; }); var PowerUp = Container.expand(function () { var self = Container.call(this); var powerupGlow = self.attachAsset('powerupGlow', { anchorX: 0.5, anchorY: 0.5 }); var powerupGraphics = self.attachAsset('powerup', { anchorX: 0.5, anchorY: 0.5 }); var powerupCore = self.attachAsset('powerupCore', { anchorX: 0.5, anchorY: 0.5 }); self.bobOffset = 0; self.startY = 0; self.update = function () { // Bobbing animation self.bobOffset += 0.1; self.y = self.startY + Math.sin(self.bobOffset) * 10; // Check collision with hero if (self.intersects(hero)) { self.collect(); } }; self.collect = function () { LK.setScore(LK.getScore() + 50); scoreText.setText(LK.getScore()); LK.getSound('collect').play(); // Flash effect when collecting LK.effects.flashScreen(0xffd700, 300); // Remove from powerups array for (var i = powerups.length - 1; i >= 0; i--) { if (powerups[i] === self) { powerups.splice(i, 1); break; } } self.destroy(); }; return self; }); var Projectile = Container.expand(function () { var self = Container.call(this); var projectileGlow = self.attachAsset('projectileGlow', { anchorX: 0.5, anchorY: 0.5 }); var projectileGraphics = self.attachAsset('projectile', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.gravity = 0.5; self.update = function () { self.velocityY += self.gravity; self.x += self.velocityX; self.y += self.velocityY; // Remove if off screen if (self.x < -50 || self.x > 2098 || self.y > 2800) { // Remove from projectiles array for (var i = projectiles.length - 1; i >= 0; i--) { if (projectiles[i] === self) { projectiles.splice(i, 1); break; } } self.destroy(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Game variables var hero; var platforms = []; var enemies = []; var powerups = []; var projectiles = []; var lives = 3; // UI Elements var scoreText = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreText.anchor.set(0, 0); scoreText.x = 150; scoreText.y = 50; LK.gui.topLeft.addChild(scoreText); var livesText = new Text2('Lives: 3', { size: 60, fill: 0xFFFFFF }); livesText.anchor.set(1, 0); LK.gui.topRight.addChild(livesText); // Create hero hero = game.addChild(new Hero()); hero.x = 200; hero.y = 2000; // Create platforms var platformData = [{ x: 150, y: 2200, width: 300 }, { x: 600, y: 2050, width: 200 }, { x: 1000, y: 1920, width: 250 }, { x: 1400, y: 1790, width: 300 }, { x: 1800, y: 1660, width: 200 }, { x: 300, y: 1530, width: 200 }, { x: 700, y: 1400, width: 300 }, { x: 1200, y: 1270, width: 250 }, { x: 1600, y: 1140, width: 200 }, { x: 400, y: 1010, width: 300 }, { x: 900, y: 880, width: 200 }, { x: 1300, y: 750, width: 250 }, { x: 500, y: 620, width: 300 }, { x: 1000, y: 490, width: 400 }]; for (var i = 0; i < platformData.length; i++) { var pData = platformData[i]; var platform = game.addChild(new Platform(pData.width, 40)); platform.x = pData.x; platform.y = pData.y; platforms.push(platform); } ; // Start background music LK.playMusic('bgmusic'); // Create enemies var enemyData = [{ x: 600, y: 2010, startX: 600 }, { x: 1000, y: 1880, startX: 1000 }, { x: 1400, y: 1750, startX: 1400 }, { x: 700, y: 1360, startX: 700 }, { x: 1200, y: 1230, startX: 1200 }, { x: 500, y: 580, startX: 500 }]; for (var i = 0; i < enemyData.length; i++) { var eData = enemyData[i]; var enemy = game.addChild(new Enemy()); enemy.x = eData.x; enemy.y = eData.y; enemy.startX = eData.startX; enemies.push(enemy); } // Create power-ups var powerupData = [{ x: 1000, y: 1880 }, { x: 1800, y: 1620 }, { x: 300, y: 1490 }, { x: 1200, y: 1230 }, { x: 900, y: 840 }, { x: 1000, y: 450 }]; for (var i = 0; i < powerupData.length; i++) { var pData = powerupData[i]; var powerup = game.addChild(new PowerUp()); powerup.x = pData.x; powerup.y = pData.y; powerup.startY = pData.y; powerups.push(powerup); } // Touch controls var leftPressed = false; var rightPressed = false; // Control buttons with visual indicators var leftButton = game.addChild(new Container()); var leftButtonBorder = leftButton.attachAsset('controlButtonBorder', { anchorX: 0.5, anchorY: 0.5 }); var leftButtonGraphics = leftButton.attachAsset('controlButton', { anchorX: 0.5, anchorY: 0.5 }); leftButton.x = 150; leftButton.y = 2550; var rightButton = game.addChild(new Container()); var rightButtonBorder = rightButton.attachAsset('controlButtonBorder', { anchorX: 0.5, anchorY: 0.5 }); var rightButtonGraphics = rightButton.attachAsset('controlButton', { anchorX: 0.5, anchorY: 0.5 }); rightButton.x = 350; rightButton.y = 2550; var jumpButton = game.addChild(new Container()); var jumpButtonBorder = jumpButton.attachAsset('jumpButtonBorder', { anchorX: 0.5, anchorY: 0.5 }); var jumpButtonGraphics = jumpButton.attachAsset('jumpButton', { anchorX: 0.5, anchorY: 0.5 }); jumpButton.x = 1848; jumpButton.y = 2550; var shootButton = game.addChild(new Container()); var shootButtonBorder = shootButton.attachAsset('shootButtonBorder', { anchorX: 0.5, anchorY: 0.5 }); var shootButtonGraphics = shootButton.attachAsset('shootButton', { anchorX: 0.5, anchorY: 0.5 }); shootButton.x = 1524; shootButton.y = 2550; // Add button labels var leftLabel = new Text2('<', { size: 80, fill: 0xFFFFFF }); leftLabel.anchor.set(0.5, 0.5); leftLabel.x = 0; leftLabel.y = 0; leftButton.addChild(leftLabel); var rightLabel = new Text2('>', { size: 80, fill: 0xFFFFFF }); rightLabel.anchor.set(0.5, 0.5); rightLabel.x = 0; rightLabel.y = 0; rightButton.addChild(rightLabel); var jumpLabel = new Text2('JUMP', { size: 40, fill: 0xFFFFFF }); jumpLabel.anchor.set(0.5, 0.5); jumpLabel.x = 0; jumpLabel.y = 0; jumpButton.addChild(jumpLabel); var shootLabel = new Text2('SHOOT', { size: 30, fill: 0xFFFFFF }); shootLabel.anchor.set(0.5, 0.5); shootLabel.x = 0; shootLabel.y = 0; shootButton.addChild(shootLabel); leftButton.down = function () { leftPressed = true; leftButtonGraphics.alpha = 0.5; }; leftButton.up = function () { leftPressed = false; leftButtonGraphics.alpha = 1.0; }; rightButton.down = function () { rightPressed = true; rightButtonGraphics.alpha = 0.5; }; rightButton.up = function () { rightPressed = false; rightButtonGraphics.alpha = 1.0; }; jumpButton.down = function () { hero.jump(); jumpButtonGraphics.alpha = 0.5; }; jumpButton.up = function () { jumpButtonGraphics.alpha = 1.0; }; shootButton.down = function () { hero.shoot(); shootButtonGraphics.alpha = 0.5; }; shootButton.up = function () { shootButtonGraphics.alpha = 1.0; }; game.update = function () { // Handle continuous movement if (leftPressed) { hero.moveLeft(); } if (rightPressed) { hero.moveRight(); } // Update lives display livesText.setText('Lives: ' + lives); // Update progress display var progressText = 'Enemies: ' + enemies.length + ' | Coins: ' + powerups.length; if (!game.progressDisplay) { game.progressDisplay = new Text2(progressText, { size: 50, fill: 0xFFFFFF }); game.progressDisplay.anchor.set(0.5, 0); game.progressDisplay.x = 0; game.progressDisplay.y = 50; LK.gui.top.addChild(game.progressDisplay); } game.progressDisplay.setText(progressText); // Check win condition - must kill all enemies and collect all powerups if (enemies.length === 0 && powerups.length === 0) { LK.showYouWin(); } // Clean up destroyed projectiles for (var i = projectiles.length - 1; i >= 0; i--) { if (!projectiles[i].parent) { projectiles.splice(i, 1); } } // Clean up destroyed enemies for (var i = enemies.length - 1; i >= 0; i--) { if (!enemies[i].parent) { enemies.splice(i, 1); } } // Clean up destroyed powerups for (var i = powerups.length - 1; i >= 0; i--) { if (!powerups[i].parent) { powerups.splice(i, 1); } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 1.0
});
var leftEye = self.attachAsset('enemyEye', {
anchorX: 0.5,
anchorY: 0.5,
x: -10,
y: -35
});
var rightEye = self.attachAsset('enemyEye', {
anchorX: 0.5,
anchorY: 0.5,
x: 10,
y: -35
});
var spike1 = self.attachAsset('enemySpike', {
anchorX: 0.5,
anchorY: 1.0,
x: -15,
y: -45
});
var spike2 = self.attachAsset('enemySpike', {
anchorX: 0.5,
anchorY: 1.0,
x: 0,
y: -50
});
var spike3 = self.attachAsset('enemySpike', {
anchorX: 0.5,
anchorY: 1.0,
x: 15,
y: -45
});
self.velocityX = 3;
self.direction = 1;
self.startX = 0;
self.patrolDistance = 200;
self.update = function () {
self.x += self.velocityX * self.direction;
// Patrol behavior
if (Math.abs(self.x - self.startX) > self.patrolDistance) {
self.direction *= -1;
}
// Check collision with hero
if (self.intersects(hero)) {
// Check if hero jumped on enemy
if (hero.velocityY > 0 && hero.y < self.y - 25) {
self.defeat();
hero.velocityY = -15; // Bounce
} else {
hero.die();
}
}
// Check collision with projectiles
for (var i = projectiles.length - 1; i >= 0; i--) {
var projectile = projectiles[i];
if (self.intersects(projectile)) {
self.defeat();
projectile.destroy();
projectiles.splice(i, 1);
break;
}
}
};
self.defeat = function () {
LK.setScore(LK.getScore() + 100);
scoreText.setText(LK.getScore());
LK.getSound('defeat').play();
// Flash effect when defeating enemy
LK.effects.flashScreen(0xff1744, 300);
// Remove from enemies array
for (var i = enemies.length - 1; i >= 0; i--) {
if (enemies[i] === self) {
enemies.splice(i, 1);
break;
}
}
self.destroy();
};
return self;
});
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroBody = self.attachAsset('heroBody', {
anchorX: 0.5,
anchorY: 1.0
});
var heroHead = self.attachAsset('heroHead', {
anchorX: 0.5,
anchorY: 1.0,
x: 0,
y: -45
});
var heroGraphics = heroBody;
self.velocityX = 0;
self.velocityY = 0;
self.speed = 8;
self.jumpPower = -30;
self.gravity = 1;
self.onGround = false;
self.facingRight = true;
self.jumpsRemaining = 0;
self.maxJumps = 3;
self.jumpCooldown = 0;
self.update = function () {
// Apply gravity
self.velocityY += self.gravity;
// Apply velocity
self.x += self.velocityX;
self.y += self.velocityY;
// Apply friction
self.velocityX *= 0.8;
// Decrease jump cooldown
if (self.jumpCooldown > 0) {
self.jumpCooldown--;
}
// Check platform collisions
self.onGround = false;
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
if (self.intersects(platform)) {
// Landing on top of platform
if (self.velocityY > 0 && self.y - 60 < platform.y) {
self.y = platform.y;
self.velocityY = 0;
self.onGround = true;
self.jumpsRemaining = self.maxJumps; // Reset jumps when landing
}
}
}
// Keep hero on screen horizontally
if (self.x < 30) self.x = 30;
if (self.x > 2018) self.x = 2018;
// Check if fallen off screen
if (self.y > 2800) {
self.die();
}
// Update sprite direction
if (self.velocityX > 1 && !self.facingRight) {
heroGraphics.scaleX = 1;
self.facingRight = true;
} else if (self.velocityX < -1 && self.facingRight) {
heroGraphics.scaleX = -1;
self.facingRight = false;
}
};
self.jump = function () {
// Can jump if on ground or have remaining air jumps, and no cooldown
if ((self.onGround || self.jumpsRemaining > 0) && self.jumpCooldown <= 0) {
self.velocityY = self.jumpPower;
if (self.onGround) {
self.onGround = false;
self.jumpsRemaining = self.maxJumps - 1; // Use one jump, have 2 remaining
} else {
self.jumpsRemaining--; // Use an air jump
}
self.jumpCooldown = 10; // 10 frame cooldown between jumps
LK.getSound('jump').play();
}
};
self.moveLeft = function () {
self.velocityX = -self.speed;
};
self.moveRight = function () {
self.velocityX = self.speed;
};
self.shoot = function () {
var newProjectile = new Projectile();
newProjectile.x = self.x;
newProjectile.y = self.y - 30;
newProjectile.velocityX = self.facingRight ? 15 : -15;
projectiles.push(newProjectile);
game.addChild(newProjectile);
LK.getSound('shoot').play();
};
self.die = function () {
lives--;
if (lives <= 0) {
LK.showGameOver();
} else {
self.respawn();
}
};
self.respawn = function () {
self.x = 200;
self.y = 2000;
self.velocityX = 0;
self.velocityY = 0;
self.jumpsRemaining = self.maxJumps;
self.jumpCooldown = 0;
};
return self;
});
var Platform = Container.expand(function (width, height) {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5,
width: width || 300,
height: height || 40
});
var leftEdge = self.attachAsset('platformEdge', {
anchorX: 1.0,
anchorY: 0.5,
x: -(width || 300) / 2,
y: 0
});
var rightEdge = self.attachAsset('platformEdge', {
anchorX: 0.0,
anchorY: 0.5,
x: (width || 300) / 2,
y: 0
});
var grass = self.attachAsset('platformGrass', {
anchorX: 0.5,
anchorY: 1.0,
width: width || 300,
x: 0,
y: -(height || 40) / 2
});
return self;
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerupGlow = self.attachAsset('powerupGlow', {
anchorX: 0.5,
anchorY: 0.5
});
var powerupGraphics = self.attachAsset('powerup', {
anchorX: 0.5,
anchorY: 0.5
});
var powerupCore = self.attachAsset('powerupCore', {
anchorX: 0.5,
anchorY: 0.5
});
self.bobOffset = 0;
self.startY = 0;
self.update = function () {
// Bobbing animation
self.bobOffset += 0.1;
self.y = self.startY + Math.sin(self.bobOffset) * 10;
// Check collision with hero
if (self.intersects(hero)) {
self.collect();
}
};
self.collect = function () {
LK.setScore(LK.getScore() + 50);
scoreText.setText(LK.getScore());
LK.getSound('collect').play();
// Flash effect when collecting
LK.effects.flashScreen(0xffd700, 300);
// Remove from powerups array
for (var i = powerups.length - 1; i >= 0; i--) {
if (powerups[i] === self) {
powerups.splice(i, 1);
break;
}
}
self.destroy();
};
return self;
});
var Projectile = Container.expand(function () {
var self = Container.call(this);
var projectileGlow = self.attachAsset('projectileGlow', {
anchorX: 0.5,
anchorY: 0.5
});
var projectileGraphics = self.attachAsset('projectile', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.gravity = 0.5;
self.update = function () {
self.velocityY += self.gravity;
self.x += self.velocityX;
self.y += self.velocityY;
// Remove if off screen
if (self.x < -50 || self.x > 2098 || self.y > 2800) {
// Remove from projectiles array
for (var i = projectiles.length - 1; i >= 0; i--) {
if (projectiles[i] === self) {
projectiles.splice(i, 1);
break;
}
}
self.destroy();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var hero;
var platforms = [];
var enemies = [];
var powerups = [];
var projectiles = [];
var lives = 3;
// UI Elements
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
scoreText.x = 150;
scoreText.y = 50;
LK.gui.topLeft.addChild(scoreText);
var livesText = new Text2('Lives: 3', {
size: 60,
fill: 0xFFFFFF
});
livesText.anchor.set(1, 0);
LK.gui.topRight.addChild(livesText);
// Create hero
hero = game.addChild(new Hero());
hero.x = 200;
hero.y = 2000;
// Create platforms
var platformData = [{
x: 150,
y: 2200,
width: 300
}, {
x: 600,
y: 2050,
width: 200
}, {
x: 1000,
y: 1920,
width: 250
}, {
x: 1400,
y: 1790,
width: 300
}, {
x: 1800,
y: 1660,
width: 200
}, {
x: 300,
y: 1530,
width: 200
}, {
x: 700,
y: 1400,
width: 300
}, {
x: 1200,
y: 1270,
width: 250
}, {
x: 1600,
y: 1140,
width: 200
}, {
x: 400,
y: 1010,
width: 300
}, {
x: 900,
y: 880,
width: 200
}, {
x: 1300,
y: 750,
width: 250
}, {
x: 500,
y: 620,
width: 300
}, {
x: 1000,
y: 490,
width: 400
}];
for (var i = 0; i < platformData.length; i++) {
var pData = platformData[i];
var platform = game.addChild(new Platform(pData.width, 40));
platform.x = pData.x;
platform.y = pData.y;
platforms.push(platform);
}
;
// Start background music
LK.playMusic('bgmusic');
// Create enemies
var enemyData = [{
x: 600,
y: 2010,
startX: 600
}, {
x: 1000,
y: 1880,
startX: 1000
}, {
x: 1400,
y: 1750,
startX: 1400
}, {
x: 700,
y: 1360,
startX: 700
}, {
x: 1200,
y: 1230,
startX: 1200
}, {
x: 500,
y: 580,
startX: 500
}];
for (var i = 0; i < enemyData.length; i++) {
var eData = enemyData[i];
var enemy = game.addChild(new Enemy());
enemy.x = eData.x;
enemy.y = eData.y;
enemy.startX = eData.startX;
enemies.push(enemy);
}
// Create power-ups
var powerupData = [{
x: 1000,
y: 1880
}, {
x: 1800,
y: 1620
}, {
x: 300,
y: 1490
}, {
x: 1200,
y: 1230
}, {
x: 900,
y: 840
}, {
x: 1000,
y: 450
}];
for (var i = 0; i < powerupData.length; i++) {
var pData = powerupData[i];
var powerup = game.addChild(new PowerUp());
powerup.x = pData.x;
powerup.y = pData.y;
powerup.startY = pData.y;
powerups.push(powerup);
}
// Touch controls
var leftPressed = false;
var rightPressed = false;
// Control buttons with visual indicators
var leftButton = game.addChild(new Container());
var leftButtonBorder = leftButton.attachAsset('controlButtonBorder', {
anchorX: 0.5,
anchorY: 0.5
});
var leftButtonGraphics = leftButton.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5
});
leftButton.x = 150;
leftButton.y = 2550;
var rightButton = game.addChild(new Container());
var rightButtonBorder = rightButton.attachAsset('controlButtonBorder', {
anchorX: 0.5,
anchorY: 0.5
});
var rightButtonGraphics = rightButton.attachAsset('controlButton', {
anchorX: 0.5,
anchorY: 0.5
});
rightButton.x = 350;
rightButton.y = 2550;
var jumpButton = game.addChild(new Container());
var jumpButtonBorder = jumpButton.attachAsset('jumpButtonBorder', {
anchorX: 0.5,
anchorY: 0.5
});
var jumpButtonGraphics = jumpButton.attachAsset('jumpButton', {
anchorX: 0.5,
anchorY: 0.5
});
jumpButton.x = 1848;
jumpButton.y = 2550;
var shootButton = game.addChild(new Container());
var shootButtonBorder = shootButton.attachAsset('shootButtonBorder', {
anchorX: 0.5,
anchorY: 0.5
});
var shootButtonGraphics = shootButton.attachAsset('shootButton', {
anchorX: 0.5,
anchorY: 0.5
});
shootButton.x = 1524;
shootButton.y = 2550;
// Add button labels
var leftLabel = new Text2('<', {
size: 80,
fill: 0xFFFFFF
});
leftLabel.anchor.set(0.5, 0.5);
leftLabel.x = 0;
leftLabel.y = 0;
leftButton.addChild(leftLabel);
var rightLabel = new Text2('>', {
size: 80,
fill: 0xFFFFFF
});
rightLabel.anchor.set(0.5, 0.5);
rightLabel.x = 0;
rightLabel.y = 0;
rightButton.addChild(rightLabel);
var jumpLabel = new Text2('JUMP', {
size: 40,
fill: 0xFFFFFF
});
jumpLabel.anchor.set(0.5, 0.5);
jumpLabel.x = 0;
jumpLabel.y = 0;
jumpButton.addChild(jumpLabel);
var shootLabel = new Text2('SHOOT', {
size: 30,
fill: 0xFFFFFF
});
shootLabel.anchor.set(0.5, 0.5);
shootLabel.x = 0;
shootLabel.y = 0;
shootButton.addChild(shootLabel);
leftButton.down = function () {
leftPressed = true;
leftButtonGraphics.alpha = 0.5;
};
leftButton.up = function () {
leftPressed = false;
leftButtonGraphics.alpha = 1.0;
};
rightButton.down = function () {
rightPressed = true;
rightButtonGraphics.alpha = 0.5;
};
rightButton.up = function () {
rightPressed = false;
rightButtonGraphics.alpha = 1.0;
};
jumpButton.down = function () {
hero.jump();
jumpButtonGraphics.alpha = 0.5;
};
jumpButton.up = function () {
jumpButtonGraphics.alpha = 1.0;
};
shootButton.down = function () {
hero.shoot();
shootButtonGraphics.alpha = 0.5;
};
shootButton.up = function () {
shootButtonGraphics.alpha = 1.0;
};
game.update = function () {
// Handle continuous movement
if (leftPressed) {
hero.moveLeft();
}
if (rightPressed) {
hero.moveRight();
}
// Update lives display
livesText.setText('Lives: ' + lives);
// Update progress display
var progressText = 'Enemies: ' + enemies.length + ' | Coins: ' + powerups.length;
if (!game.progressDisplay) {
game.progressDisplay = new Text2(progressText, {
size: 50,
fill: 0xFFFFFF
});
game.progressDisplay.anchor.set(0.5, 0);
game.progressDisplay.x = 0;
game.progressDisplay.y = 50;
LK.gui.top.addChild(game.progressDisplay);
}
game.progressDisplay.setText(progressText);
// Check win condition - must kill all enemies and collect all powerups
if (enemies.length === 0 && powerups.length === 0) {
LK.showYouWin();
}
// Clean up destroyed projectiles
for (var i = projectiles.length - 1; i >= 0; i--) {
if (!projectiles[i].parent) {
projectiles.splice(i, 1);
}
}
// Clean up destroyed enemies
for (var i = enemies.length - 1; i >= 0; i--) {
if (!enemies[i].parent) {
enemies.splice(i, 1);
}
}
// Clean up destroyed powerups
for (var i = powerups.length - 1; i >= 0; i--) {
if (!powerups[i].parent) {
powerups.splice(i, 1);
}
}
};