/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Brick = Container.expand(function () {
var self = Container.call(this);
var brickGraphics = self.attachAsset('pauseButton', {
anchorX: 0.5,
anchorY: 0.5,
width: 80,
height: 40,
color: 0x8B4513
});
self.velocityY = 0;
self.gravity = 0.8;
self.hit = false;
self.update = function () {
self.velocityY += self.gravity;
self.y += self.velocityY;
};
return self;
});
var Cactus = Container.expand(function (type) {
var self = Container.call(this);
var assetName = type === 'tall' ? 'tallCactus' : 'smallCactus';
var cactusGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 1.0
});
self.type = type;
self.speed = gameSpeed;
self.passed = false;
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Chicken = Container.expand(function () {
var self = Container.call(this);
var chickenGraphics = self.attachAsset('chicken', {
anchorX: 0.5,
anchorY: 1.0
});
self.groundY = 2732 - 200;
self.jumpStartY = self.groundY;
self.isJumping = false;
self.jumpVelocity = 0;
self.gravity = 1.2;
self.maxJumpVelocity = -45;
self.jumpChargeTime = 0;
self.isCharging = false;
self.canDoubleJump = false;
self.hasDoubleJumped = false;
self.isDashing = false;
self.dashSpeed = 25;
self.dashDuration = 300; // milliseconds
self.update = function () {
if (self.isJumping && !self.isDashing) {
self.y += self.jumpVelocity;
self.jumpVelocity += self.gravity;
if (self.y >= self.groundY) {
self.y = self.groundY;
self.isJumping = false;
self.jumpVelocity = 0;
self.canDoubleJump = false;
self.hasDoubleJumped = false;
}
}
if (self.isCharging && self.jumpChargeTime < 30) {
self.jumpChargeTime++;
}
};
self.startJump = function () {
if (!self.isJumping) {
self.isCharging = true;
self.jumpChargeTime = 0;
}
};
self.executeJump = function () {
if (!self.isJumping && self.isCharging) {
var jumpPower = Math.min(self.jumpChargeTime / 30, 1);
self.jumpVelocity = self.maxJumpVelocity * (0.4 + jumpPower * 0.6);
self.isJumping = true;
self.isCharging = false;
self.jumpChargeTime = 0;
self.canDoubleJump = true;
LK.getSound('jump').play();
} else if (self.isJumping && self.canDoubleJump && !self.hasDoubleJumped) {
// Double jump
self.jumpVelocity = self.maxJumpVelocity * 0.8;
self.hasDoubleJumped = true;
self.canDoubleJump = false;
LK.getSound('jump').play();
// Create particles below chicken's feet
for (var i = 0; i < 8; i++) {
var particle = new Particle();
particle.x = self.x + (Math.random() - 0.5) * 40;
particle.y = self.y + 30; // Below chicken's feet
particles.push(particle);
game.addChild(particle);
}
}
};
self.startDash = function () {
// Dash functionality disabled
};
return self;
});
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
cloudGraphics.alpha = 0.7;
self.speed = 1;
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Particle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = (Math.random() - 0.5) * 8;
self.velocityY = Math.random() * -4 - 2;
self.life = 30;
self.maxLife = 30;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += 0.2; // gravity
self.life--;
// Fade out over time
var alpha = self.life / self.maxLife;
particleGraphics.alpha = alpha;
if (self.life <= 0) {
self.markForDestroy = true;
}
};
return self;
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = gameSpeed;
self.floatOffset = 0;
self.collected = false;
self.update = function () {
self.x -= self.speed;
// Floating animation
self.floatOffset += 0.2;
self.y += Math.sin(self.floatOffset) * 2;
};
return self;
});
var TrailParticle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.attachAsset('trailParticle', {
anchorX: 0.5,
anchorY: 0.5
});
// Random color for trail particles
var colors = [0xff4500, 0xff6347, 0xffd700, 0xff1493, 0x00ff00, 0x00bfff];
particleGraphics.tint = colors[Math.floor(Math.random() * colors.length)];
self.velocityX = (Math.random() - 0.5) * 6;
self.velocityY = Math.random() * -3 - 1;
self.life = 40;
self.maxLife = 40;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += 0.15; // gravity
self.life--;
// Fade out over time
var alpha = self.life / self.maxLife;
particleGraphics.alpha = alpha;
if (self.life <= 0) {
self.markForDestroy = true;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var gameSpeed = 8;
var maxGameSpeed = 20;
var speedIncrement = 0.02;
var cactusSpawnTimer = 0;
var cactusSpawnInterval = 90;
var minSpawnInterval = 45;
var cloudSpawnTimer = 0;
var distanceTraveled = 0;
var lastScoreSound = 0;
var jumpScore = 0;
var chicken;
var chickenLives = 3;
var lifeDisplays = [];
var cacti = [];
var clouds = [];
var powerUps = [];
var particles = [];
var trailParticles = [];
var bricks = [];
var brickSpawnTimer = 0;
var brickSpawnInterval = 3000; // 50 seconds at 60fps
var ground;
var isGameRunning = true;
var isJumpPressed = false;
var tapCount = 0;
var lastTapTime = 0;
var doubleTapThreshold = 300; // milliseconds for double tap detection
var dashCooldown = 0; // Timer for dash cooldown
var dashCooldownDuration = 600; // 10 seconds at 60fps (10 * 60 = 600 frames)
// Power-up system
var powerUpSpawnTimer = 0;
var powerUpSpawnInterval = 1200 + Math.random() * 1200; // Random 20-40 seconds at 60fps
var isInvincible = false;
var invincibilityTimer = 0;
var invincibilityDuration = 1500; // 25 seconds at 60fps
var baseGameSpeed = 8;
// Pause system
var isPaused = false;
var pauseButton;
// Create ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 1.0
}));
ground.x = 0;
ground.y = 2732 - 140;
// Create chicken
chicken = game.addChild(new Chicken());
chicken.x = 300;
chicken.y = chicken.groundY;
// Create life display hearts beside pause button
for (var i = 0; i < chickenLives; i++) {
var heart = LK.getAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
heart.x = 250 + i * 50; // Position next to pause button
heart.y = 70; // Align with pause button
lifeDisplays.push(heart);
LK.gui.topLeft.addChild(heart);
}
// Score display for cactus jumps
var jumpScoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
jumpScoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(jumpScoreText);
jumpScoreText.y = 20;
// Tap counter display
var tapCountText = new Text2('CP: 0', {
size: 60,
fill: 0xFFFFFF
});
tapCountText.anchor.set(0.5, 0);
LK.gui.top.addChild(tapCountText);
tapCountText.y = 90;
// Distance display
var scoreText = new Text2('Distance: 0m', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreText);
scoreText.x = -20;
scoreText.y = 20;
// Instructions
var instructionText = new Text2('TAP & HOLD TO JUMP HIGHER', {
size: 45,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionText);
instructionText.y = 100;
// Power-up timer display
var powerUpTimerText = new Text2('', {
size: 80,
fill: 0xFFFF00 // Yellow color
});
powerUpTimerText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(powerUpTimerText);
powerUpTimerText.visible = false;
// Create pause button in top left (avoiding the 100x100 platform menu area)
pauseButton = LK.getAsset('pauseButton', {
anchorX: 0,
anchorY: 0
});
LK.gui.topLeft.addChild(pauseButton);
pauseButton.x = 120; // Offset from very top left to avoid platform menu
pauseButton.y = 20;
// Add pause symbol (two vertical lines)
var pauseLine1 = LK.getAsset('pauseButton', {
anchorX: 0.5,
anchorY: 0.5,
width: 8,
height: 40,
color: 0xffffff
});
var pauseLine2 = LK.getAsset('pauseButton', {
anchorX: 0.5,
anchorY: 0.5,
width: 8,
height: 40,
color: 0xffffff
});
pauseButton.addChild(pauseLine1);
pauseButton.addChild(pauseLine2);
pauseLine1.x = 25;
pauseLine1.y = 40;
pauseLine2.x = 55;
pauseLine2.y = 40;
// Variable to store play triangle reference
var playTriangle = null;
// Pause button functionality
pauseButton.down = function (x, y, obj) {
isPaused = !isPaused;
if (isPaused) {
// Show paused state - make lines into play triangle
pauseLine1.visible = false;
pauseLine2.visible = false;
// Create play triangle
playTriangle = LK.getAsset('pauseButton', {
anchorX: 0.5,
anchorY: 0.5,
width: 0,
height: 0,
color: 0xffffff
});
pauseButton.addChild(playTriangle);
playTriangle.x = 45;
playTriangle.y = 40;
// Create triangle using three lines (simple approach)
var tri1 = LK.getAsset('pauseButton', {
width: 30,
height: 4,
color: 0xffffff,
anchorX: 0,
anchorY: 0.5
});
var tri2 = LK.getAsset('pauseButton', {
width: 30,
height: 4,
color: 0xffffff,
anchorX: 0,
anchorY: 0.5
});
var tri3 = LK.getAsset('pauseButton', {
width: 30,
height: 4,
color: 0xffffff,
anchorX: 0,
anchorY: 0.5
});
playTriangle.addChild(tri1);
playTriangle.addChild(tri2);
playTriangle.addChild(tri3);
tri1.x = -15;
tri1.y = -15;
tri1.rotation = 0.5;
tri2.x = -15;
tri2.y = 15;
tri2.rotation = -0.5;
tri3.x = -15;
tri3.y = 0;
tri3.rotation = 0;
} else {
// Show pause state - remove play triangle and show pause lines
if (playTriangle) {
pauseButton.removeChild(playTriangle);
playTriangle = null;
}
pauseLine1.visible = true;
pauseLine2.visible = true;
}
};
// Game controls
game.down = function (x, y, obj) {
if (isGameRunning) {
// Single tap - start jump
isJumpPressed = true;
chicken.startJump();
tapCount++;
tapCountText.setText('CP: ' + tapCount);
}
};
game.up = function (x, y, obj) {
if (isGameRunning && isJumpPressed) {
isJumpPressed = false;
chicken.executeJump();
}
};
function spawnCactus() {
var cactusType = Math.random() < 0.6 ? 'small' : 'tall';
var newCactus = new Cactus(cactusType);
newCactus.x = 2048 + 100;
newCactus.y = 2732 - 200;
newCactus.speed = gameSpeed;
cacti.push(newCactus);
game.addChild(newCactus);
}
function spawnCloud() {
var newCloud = new Cloud();
newCloud.x = 2048 + 200;
newCloud.y = 200 + Math.random() * 400;
clouds.push(newCloud);
game.addChild(newCloud);
}
function spawnPowerUp() {
var newPowerUp = new PowerUp();
newPowerUp.x = 2048 + 100;
newPowerUp.y = 2732 - 400 - Math.random() * 200; // Spawn in air
newPowerUp.speed = gameSpeed;
powerUps.push(newPowerUp);
game.addChild(newPowerUp);
}
function spawnBrick() {
var newBrick = new Brick();
newBrick.x = 200 + Math.random() * 1648; // Random x position across screen
newBrick.y = -100; // Start above screen
bricks.push(newBrick);
game.addChild(newBrick);
}
function checkCollisions() {
for (var i = cacti.length - 1; i >= 0; i--) {
var cactus = cacti[i];
if (chicken.intersects(cactus)) {
if (isInvincible) {
// Destroy cactus with visual effect
tween(cactus, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 200,
onFinish: function onFinish() {
cactus.destroy();
}
});
cacti.splice(i, 1);
} else {
// Lose a life
chickenLives--;
// Hide one heart
if (lifeDisplays.length > 0) {
var heartToRemove = lifeDisplays.pop();
tween(heartToRemove, {
alpha: 0,
scaleX: 0,
scaleY: 0
}, {
duration: 300,
onFinish: function onFinish() {
heartToRemove.destroy();
}
});
}
// Push chicken backwards
tween(chicken, {
x: chicken.x - 150
}, {
duration: 500,
easing: tween.easeOut
});
// Flash chicken red briefly
tween(chicken, {
tint: 0xff0000
}, {
duration: 200,
onFinish: function onFinish() {
tween(chicken, {
tint: 0xffffff
}, {
duration: 200
});
}
});
// Destroy the cactus that hit the chicken with animation
tween(cactus, {
alpha: 0,
scaleX: 2,
scaleY: 2,
rotation: Math.PI
}, {
duration: 400,
easing: tween.easeOut,
onFinish: function onFinish() {
cactus.destroy();
}
});
cacti.splice(i, 1);
// Check if all lives are lost
if (chickenLives <= 0) {
isGameRunning = false;
LK.effects.flashScreen(0xFF0000, 800);
LK.setTimeout(function () {
LK.showGameOver();
}, 400);
return;
}
}
}
}
}
function updateScore() {
distanceTraveled = Math.floor(LK.ticks / 6);
scoreText.setText('Distance: ' + distanceTraveled + 'm');
// Play score sound every 100 meters
if (distanceTraveled > 0 && distanceTraveled % 100 === 0 && distanceTraveled !== lastScoreSound) {
LK.getSound('score').play();
lastScoreSound = distanceTraveled;
}
}
function checkCactusJumps() {
for (var i = 0; i < cacti.length; i++) {
var cactus = cacti[i];
// Check if chicken has passed the cactus (chicken is to the right of cactus)
if (!cactus.passed && chicken.x > cactus.x + 30) {
cactus.passed = true;
jumpScore++;
LK.setScore(jumpScore);
jumpScoreText.setText('Score: ' + jumpScore);
LK.getSound('score').play();
increaseDifficulty();
}
}
}
function checkPowerUpCollisions() {
for (var i = powerUps.length - 1; i >= 0; i--) {
var powerUp = powerUps[i];
if (chicken.intersects(powerUp) && !powerUp.collected) {
powerUp.collected = true;
// Activate invincibility
isInvincible = true;
invincibilityTimer = 0;
// Increase chicken speed by 70%
chicken.speed = baseGameSpeed * 1.7;
LK.getSound('powerup').play();
// Create colorful trail particles behind chicken
for (var j = 0; j < 12; j++) {
var trailParticle = new TrailParticle();
trailParticle.x = chicken.x - 50 - Math.random() * 30; // Behind chicken
trailParticle.y = chicken.y - Math.random() * 40;
trailParticles.push(trailParticle);
game.addChild(trailParticle);
}
// Visual feedback - make chicken glow
tween(chicken, {
tint: 0xffff00
}, {
duration: 300
});
// Remove power-up with effect
tween(powerUp, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 300,
onFinish: function onFinish() {
powerUp.destroy();
}
});
powerUps.splice(i, 1);
}
}
}
function checkBrickCollisions() {
for (var i = bricks.length - 1; i >= 0; i--) {
var brick = bricks[i];
if (chicken.intersects(brick) && !brick.hit) {
brick.hit = true;
if (!isInvincible) {
// Lose 2 lives
chickenLives -= 2;
// Hide two hearts
for (var h = 0; h < 2 && lifeDisplays.length > 0; h++) {
var heartToRemove = lifeDisplays.pop();
tween(heartToRemove, {
alpha: 0,
scaleX: 0,
scaleY: 0
}, {
duration: 300,
onFinish: function onFinish() {
heartToRemove.destroy();
}
});
}
// Push chicken backwards
tween(chicken, {
x: chicken.x - 150
}, {
duration: 500,
easing: tween.easeOut
});
// Flash chicken red briefly
tween(chicken, {
tint: 0xff0000
}, {
duration: 200,
onFinish: function onFinish() {
tween(chicken, {
tint: 0xffffff
}, {
duration: 200
});
}
});
// Check if all lives are lost
if (chickenLives <= 0) {
isGameRunning = false;
LK.effects.flashScreen(0xFF0000, 800);
LK.setTimeout(function () {
LK.showGameOver();
}, 400);
return;
}
}
// Destroy the brick with animation
tween(brick, {
alpha: 0,
scaleX: 2,
scaleY: 2,
rotation: Math.PI
}, {
duration: 400,
easing: tween.easeOut,
onFinish: function onFinish() {
brick.destroy();
}
});
bricks.splice(i, 1);
}
}
}
function increaseDifficulty() {
// Increase speed every 50 points
var targetSpeed = 8 + Math.floor(jumpScore / 50) * 2;
if (targetSpeed > maxGameSpeed) {
targetSpeed = maxGameSpeed;
}
gameSpeed = targetSpeed;
// Decrease spawn interval based on score
var targetInterval = 90 - Math.floor(jumpScore / 50) * 10;
if (targetInterval < minSpawnInterval) {
targetInterval = minSpawnInterval;
}
cactusSpawnInterval = targetInterval;
}
function updateInvincibility() {
if (isInvincible) {
invincibilityTimer++;
// Update power-up timer display
var remainingSeconds = Math.ceil((invincibilityDuration - invincibilityTimer) / 60);
powerUpTimerText.setText(remainingSeconds + 's');
powerUpTimerText.visible = true;
// Make chicken flash during invincibility
if (invincibilityTimer % 10 === 0) {
var currentTint = chicken.tint === 0xffff00 ? 0xffffff : 0xffff00;
chicken.tint = currentTint;
}
// End invincibility after duration
if (invincibilityTimer >= invincibilityDuration) {
isInvincible = false;
invincibilityTimer = 0;
powerUpTimerText.visible = false;
// Reset chicken speed
chicken.speed = baseGameSpeed;
// Reset chicken appearance
tween(chicken, {
tint: 0xffffff
}, {
duration: 500
});
}
} else {
powerUpTimerText.visible = false;
}
}
game.update = function () {
if (!isGameRunning || isPaused) return;
updateScore();
// Spawn cacti
cactusSpawnTimer++;
if (cactusSpawnTimer >= cactusSpawnInterval) {
spawnCactus();
cactusSpawnTimer = 0;
}
// Spawn clouds
cloudSpawnTimer++;
if (cloudSpawnTimer >= 180) {
spawnCloud();
cloudSpawnTimer = 0;
}
// Spawn power-ups
powerUpSpawnTimer++;
if (powerUpSpawnTimer >= powerUpSpawnInterval) {
spawnPowerUp();
powerUpSpawnTimer = 0;
// Set new random interval for next power-up (20-40 seconds)
powerUpSpawnInterval = 1200 + Math.random() * 1200;
}
// Spawn bricks every 50 seconds
brickSpawnTimer++;
if (brickSpawnTimer >= brickSpawnInterval) {
spawnBrick();
brickSpawnTimer = 0;
}
// Update and clean up cacti
for (var i = cacti.length - 1; i >= 0; i--) {
var cactus = cacti[i];
cactus.speed = gameSpeed;
if (cactus.x < -100) {
cactus.destroy();
cacti.splice(i, 1);
}
}
// Update and clean up clouds
for (var i = clouds.length - 1; i >= 0; i--) {
var cloud = clouds[i];
if (cloud.x < -200) {
cloud.destroy();
clouds.splice(i, 1);
}
}
// Update and clean up power-ups
for (var i = powerUps.length - 1; i >= 0; i--) {
var powerUp = powerUps[i];
powerUp.speed = gameSpeed;
if (powerUp.x < -100) {
powerUp.destroy();
powerUps.splice(i, 1);
}
}
// Update and clean up particles
for (var i = particles.length - 1; i >= 0; i--) {
var particle = particles[i];
if (particle.markForDestroy) {
particle.destroy();
particles.splice(i, 1);
}
}
// Update and clean up trail particles
for (var i = trailParticles.length - 1; i >= 0; i--) {
var trailParticle = trailParticles[i];
if (trailParticle.markForDestroy) {
trailParticle.destroy();
trailParticles.splice(i, 1);
}
}
// Update and clean up bricks
for (var i = bricks.length - 1; i >= 0; i--) {
var brick = bricks[i];
if (brick.y > 2732 + 100) {
// Off-screen cleanup
brick.destroy();
bricks.splice(i, 1);
}
}
updateInvincibility();
// Update dash cooldown
if (dashCooldown > 0) {
dashCooldown--;
}
checkCollisions();
checkCactusJumps();
checkPowerUpCollisions();
checkBrickCollisions();
// Hide instructions after first jump
if (chicken.isJumping && instructionText.alpha > 0) {
tween(instructionText, {
alpha: 0
}, {
duration: 1000
});
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Brick = Container.expand(function () {
var self = Container.call(this);
var brickGraphics = self.attachAsset('pauseButton', {
anchorX: 0.5,
anchorY: 0.5,
width: 80,
height: 40,
color: 0x8B4513
});
self.velocityY = 0;
self.gravity = 0.8;
self.hit = false;
self.update = function () {
self.velocityY += self.gravity;
self.y += self.velocityY;
};
return self;
});
var Cactus = Container.expand(function (type) {
var self = Container.call(this);
var assetName = type === 'tall' ? 'tallCactus' : 'smallCactus';
var cactusGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 1.0
});
self.type = type;
self.speed = gameSpeed;
self.passed = false;
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Chicken = Container.expand(function () {
var self = Container.call(this);
var chickenGraphics = self.attachAsset('chicken', {
anchorX: 0.5,
anchorY: 1.0
});
self.groundY = 2732 - 200;
self.jumpStartY = self.groundY;
self.isJumping = false;
self.jumpVelocity = 0;
self.gravity = 1.2;
self.maxJumpVelocity = -45;
self.jumpChargeTime = 0;
self.isCharging = false;
self.canDoubleJump = false;
self.hasDoubleJumped = false;
self.isDashing = false;
self.dashSpeed = 25;
self.dashDuration = 300; // milliseconds
self.update = function () {
if (self.isJumping && !self.isDashing) {
self.y += self.jumpVelocity;
self.jumpVelocity += self.gravity;
if (self.y >= self.groundY) {
self.y = self.groundY;
self.isJumping = false;
self.jumpVelocity = 0;
self.canDoubleJump = false;
self.hasDoubleJumped = false;
}
}
if (self.isCharging && self.jumpChargeTime < 30) {
self.jumpChargeTime++;
}
};
self.startJump = function () {
if (!self.isJumping) {
self.isCharging = true;
self.jumpChargeTime = 0;
}
};
self.executeJump = function () {
if (!self.isJumping && self.isCharging) {
var jumpPower = Math.min(self.jumpChargeTime / 30, 1);
self.jumpVelocity = self.maxJumpVelocity * (0.4 + jumpPower * 0.6);
self.isJumping = true;
self.isCharging = false;
self.jumpChargeTime = 0;
self.canDoubleJump = true;
LK.getSound('jump').play();
} else if (self.isJumping && self.canDoubleJump && !self.hasDoubleJumped) {
// Double jump
self.jumpVelocity = self.maxJumpVelocity * 0.8;
self.hasDoubleJumped = true;
self.canDoubleJump = false;
LK.getSound('jump').play();
// Create particles below chicken's feet
for (var i = 0; i < 8; i++) {
var particle = new Particle();
particle.x = self.x + (Math.random() - 0.5) * 40;
particle.y = self.y + 30; // Below chicken's feet
particles.push(particle);
game.addChild(particle);
}
}
};
self.startDash = function () {
// Dash functionality disabled
};
return self;
});
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
cloudGraphics.alpha = 0.7;
self.speed = 1;
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Particle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = (Math.random() - 0.5) * 8;
self.velocityY = Math.random() * -4 - 2;
self.life = 30;
self.maxLife = 30;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += 0.2; // gravity
self.life--;
// Fade out over time
var alpha = self.life / self.maxLife;
particleGraphics.alpha = alpha;
if (self.life <= 0) {
self.markForDestroy = true;
}
};
return self;
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = gameSpeed;
self.floatOffset = 0;
self.collected = false;
self.update = function () {
self.x -= self.speed;
// Floating animation
self.floatOffset += 0.2;
self.y += Math.sin(self.floatOffset) * 2;
};
return self;
});
var TrailParticle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.attachAsset('trailParticle', {
anchorX: 0.5,
anchorY: 0.5
});
// Random color for trail particles
var colors = [0xff4500, 0xff6347, 0xffd700, 0xff1493, 0x00ff00, 0x00bfff];
particleGraphics.tint = colors[Math.floor(Math.random() * colors.length)];
self.velocityX = (Math.random() - 0.5) * 6;
self.velocityY = Math.random() * -3 - 1;
self.life = 40;
self.maxLife = 40;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += 0.15; // gravity
self.life--;
// Fade out over time
var alpha = self.life / self.maxLife;
particleGraphics.alpha = alpha;
if (self.life <= 0) {
self.markForDestroy = true;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var gameSpeed = 8;
var maxGameSpeed = 20;
var speedIncrement = 0.02;
var cactusSpawnTimer = 0;
var cactusSpawnInterval = 90;
var minSpawnInterval = 45;
var cloudSpawnTimer = 0;
var distanceTraveled = 0;
var lastScoreSound = 0;
var jumpScore = 0;
var chicken;
var chickenLives = 3;
var lifeDisplays = [];
var cacti = [];
var clouds = [];
var powerUps = [];
var particles = [];
var trailParticles = [];
var bricks = [];
var brickSpawnTimer = 0;
var brickSpawnInterval = 3000; // 50 seconds at 60fps
var ground;
var isGameRunning = true;
var isJumpPressed = false;
var tapCount = 0;
var lastTapTime = 0;
var doubleTapThreshold = 300; // milliseconds for double tap detection
var dashCooldown = 0; // Timer for dash cooldown
var dashCooldownDuration = 600; // 10 seconds at 60fps (10 * 60 = 600 frames)
// Power-up system
var powerUpSpawnTimer = 0;
var powerUpSpawnInterval = 1200 + Math.random() * 1200; // Random 20-40 seconds at 60fps
var isInvincible = false;
var invincibilityTimer = 0;
var invincibilityDuration = 1500; // 25 seconds at 60fps
var baseGameSpeed = 8;
// Pause system
var isPaused = false;
var pauseButton;
// Create ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 1.0
}));
ground.x = 0;
ground.y = 2732 - 140;
// Create chicken
chicken = game.addChild(new Chicken());
chicken.x = 300;
chicken.y = chicken.groundY;
// Create life display hearts beside pause button
for (var i = 0; i < chickenLives; i++) {
var heart = LK.getAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
heart.x = 250 + i * 50; // Position next to pause button
heart.y = 70; // Align with pause button
lifeDisplays.push(heart);
LK.gui.topLeft.addChild(heart);
}
// Score display for cactus jumps
var jumpScoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
jumpScoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(jumpScoreText);
jumpScoreText.y = 20;
// Tap counter display
var tapCountText = new Text2('CP: 0', {
size: 60,
fill: 0xFFFFFF
});
tapCountText.anchor.set(0.5, 0);
LK.gui.top.addChild(tapCountText);
tapCountText.y = 90;
// Distance display
var scoreText = new Text2('Distance: 0m', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreText);
scoreText.x = -20;
scoreText.y = 20;
// Instructions
var instructionText = new Text2('TAP & HOLD TO JUMP HIGHER', {
size: 45,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionText);
instructionText.y = 100;
// Power-up timer display
var powerUpTimerText = new Text2('', {
size: 80,
fill: 0xFFFF00 // Yellow color
});
powerUpTimerText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(powerUpTimerText);
powerUpTimerText.visible = false;
// Create pause button in top left (avoiding the 100x100 platform menu area)
pauseButton = LK.getAsset('pauseButton', {
anchorX: 0,
anchorY: 0
});
LK.gui.topLeft.addChild(pauseButton);
pauseButton.x = 120; // Offset from very top left to avoid platform menu
pauseButton.y = 20;
// Add pause symbol (two vertical lines)
var pauseLine1 = LK.getAsset('pauseButton', {
anchorX: 0.5,
anchorY: 0.5,
width: 8,
height: 40,
color: 0xffffff
});
var pauseLine2 = LK.getAsset('pauseButton', {
anchorX: 0.5,
anchorY: 0.5,
width: 8,
height: 40,
color: 0xffffff
});
pauseButton.addChild(pauseLine1);
pauseButton.addChild(pauseLine2);
pauseLine1.x = 25;
pauseLine1.y = 40;
pauseLine2.x = 55;
pauseLine2.y = 40;
// Variable to store play triangle reference
var playTriangle = null;
// Pause button functionality
pauseButton.down = function (x, y, obj) {
isPaused = !isPaused;
if (isPaused) {
// Show paused state - make lines into play triangle
pauseLine1.visible = false;
pauseLine2.visible = false;
// Create play triangle
playTriangle = LK.getAsset('pauseButton', {
anchorX: 0.5,
anchorY: 0.5,
width: 0,
height: 0,
color: 0xffffff
});
pauseButton.addChild(playTriangle);
playTriangle.x = 45;
playTriangle.y = 40;
// Create triangle using three lines (simple approach)
var tri1 = LK.getAsset('pauseButton', {
width: 30,
height: 4,
color: 0xffffff,
anchorX: 0,
anchorY: 0.5
});
var tri2 = LK.getAsset('pauseButton', {
width: 30,
height: 4,
color: 0xffffff,
anchorX: 0,
anchorY: 0.5
});
var tri3 = LK.getAsset('pauseButton', {
width: 30,
height: 4,
color: 0xffffff,
anchorX: 0,
anchorY: 0.5
});
playTriangle.addChild(tri1);
playTriangle.addChild(tri2);
playTriangle.addChild(tri3);
tri1.x = -15;
tri1.y = -15;
tri1.rotation = 0.5;
tri2.x = -15;
tri2.y = 15;
tri2.rotation = -0.5;
tri3.x = -15;
tri3.y = 0;
tri3.rotation = 0;
} else {
// Show pause state - remove play triangle and show pause lines
if (playTriangle) {
pauseButton.removeChild(playTriangle);
playTriangle = null;
}
pauseLine1.visible = true;
pauseLine2.visible = true;
}
};
// Game controls
game.down = function (x, y, obj) {
if (isGameRunning) {
// Single tap - start jump
isJumpPressed = true;
chicken.startJump();
tapCount++;
tapCountText.setText('CP: ' + tapCount);
}
};
game.up = function (x, y, obj) {
if (isGameRunning && isJumpPressed) {
isJumpPressed = false;
chicken.executeJump();
}
};
function spawnCactus() {
var cactusType = Math.random() < 0.6 ? 'small' : 'tall';
var newCactus = new Cactus(cactusType);
newCactus.x = 2048 + 100;
newCactus.y = 2732 - 200;
newCactus.speed = gameSpeed;
cacti.push(newCactus);
game.addChild(newCactus);
}
function spawnCloud() {
var newCloud = new Cloud();
newCloud.x = 2048 + 200;
newCloud.y = 200 + Math.random() * 400;
clouds.push(newCloud);
game.addChild(newCloud);
}
function spawnPowerUp() {
var newPowerUp = new PowerUp();
newPowerUp.x = 2048 + 100;
newPowerUp.y = 2732 - 400 - Math.random() * 200; // Spawn in air
newPowerUp.speed = gameSpeed;
powerUps.push(newPowerUp);
game.addChild(newPowerUp);
}
function spawnBrick() {
var newBrick = new Brick();
newBrick.x = 200 + Math.random() * 1648; // Random x position across screen
newBrick.y = -100; // Start above screen
bricks.push(newBrick);
game.addChild(newBrick);
}
function checkCollisions() {
for (var i = cacti.length - 1; i >= 0; i--) {
var cactus = cacti[i];
if (chicken.intersects(cactus)) {
if (isInvincible) {
// Destroy cactus with visual effect
tween(cactus, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 200,
onFinish: function onFinish() {
cactus.destroy();
}
});
cacti.splice(i, 1);
} else {
// Lose a life
chickenLives--;
// Hide one heart
if (lifeDisplays.length > 0) {
var heartToRemove = lifeDisplays.pop();
tween(heartToRemove, {
alpha: 0,
scaleX: 0,
scaleY: 0
}, {
duration: 300,
onFinish: function onFinish() {
heartToRemove.destroy();
}
});
}
// Push chicken backwards
tween(chicken, {
x: chicken.x - 150
}, {
duration: 500,
easing: tween.easeOut
});
// Flash chicken red briefly
tween(chicken, {
tint: 0xff0000
}, {
duration: 200,
onFinish: function onFinish() {
tween(chicken, {
tint: 0xffffff
}, {
duration: 200
});
}
});
// Destroy the cactus that hit the chicken with animation
tween(cactus, {
alpha: 0,
scaleX: 2,
scaleY: 2,
rotation: Math.PI
}, {
duration: 400,
easing: tween.easeOut,
onFinish: function onFinish() {
cactus.destroy();
}
});
cacti.splice(i, 1);
// Check if all lives are lost
if (chickenLives <= 0) {
isGameRunning = false;
LK.effects.flashScreen(0xFF0000, 800);
LK.setTimeout(function () {
LK.showGameOver();
}, 400);
return;
}
}
}
}
}
function updateScore() {
distanceTraveled = Math.floor(LK.ticks / 6);
scoreText.setText('Distance: ' + distanceTraveled + 'm');
// Play score sound every 100 meters
if (distanceTraveled > 0 && distanceTraveled % 100 === 0 && distanceTraveled !== lastScoreSound) {
LK.getSound('score').play();
lastScoreSound = distanceTraveled;
}
}
function checkCactusJumps() {
for (var i = 0; i < cacti.length; i++) {
var cactus = cacti[i];
// Check if chicken has passed the cactus (chicken is to the right of cactus)
if (!cactus.passed && chicken.x > cactus.x + 30) {
cactus.passed = true;
jumpScore++;
LK.setScore(jumpScore);
jumpScoreText.setText('Score: ' + jumpScore);
LK.getSound('score').play();
increaseDifficulty();
}
}
}
function checkPowerUpCollisions() {
for (var i = powerUps.length - 1; i >= 0; i--) {
var powerUp = powerUps[i];
if (chicken.intersects(powerUp) && !powerUp.collected) {
powerUp.collected = true;
// Activate invincibility
isInvincible = true;
invincibilityTimer = 0;
// Increase chicken speed by 70%
chicken.speed = baseGameSpeed * 1.7;
LK.getSound('powerup').play();
// Create colorful trail particles behind chicken
for (var j = 0; j < 12; j++) {
var trailParticle = new TrailParticle();
trailParticle.x = chicken.x - 50 - Math.random() * 30; // Behind chicken
trailParticle.y = chicken.y - Math.random() * 40;
trailParticles.push(trailParticle);
game.addChild(trailParticle);
}
// Visual feedback - make chicken glow
tween(chicken, {
tint: 0xffff00
}, {
duration: 300
});
// Remove power-up with effect
tween(powerUp, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 300,
onFinish: function onFinish() {
powerUp.destroy();
}
});
powerUps.splice(i, 1);
}
}
}
function checkBrickCollisions() {
for (var i = bricks.length - 1; i >= 0; i--) {
var brick = bricks[i];
if (chicken.intersects(brick) && !brick.hit) {
brick.hit = true;
if (!isInvincible) {
// Lose 2 lives
chickenLives -= 2;
// Hide two hearts
for (var h = 0; h < 2 && lifeDisplays.length > 0; h++) {
var heartToRemove = lifeDisplays.pop();
tween(heartToRemove, {
alpha: 0,
scaleX: 0,
scaleY: 0
}, {
duration: 300,
onFinish: function onFinish() {
heartToRemove.destroy();
}
});
}
// Push chicken backwards
tween(chicken, {
x: chicken.x - 150
}, {
duration: 500,
easing: tween.easeOut
});
// Flash chicken red briefly
tween(chicken, {
tint: 0xff0000
}, {
duration: 200,
onFinish: function onFinish() {
tween(chicken, {
tint: 0xffffff
}, {
duration: 200
});
}
});
// Check if all lives are lost
if (chickenLives <= 0) {
isGameRunning = false;
LK.effects.flashScreen(0xFF0000, 800);
LK.setTimeout(function () {
LK.showGameOver();
}, 400);
return;
}
}
// Destroy the brick with animation
tween(brick, {
alpha: 0,
scaleX: 2,
scaleY: 2,
rotation: Math.PI
}, {
duration: 400,
easing: tween.easeOut,
onFinish: function onFinish() {
brick.destroy();
}
});
bricks.splice(i, 1);
}
}
}
function increaseDifficulty() {
// Increase speed every 50 points
var targetSpeed = 8 + Math.floor(jumpScore / 50) * 2;
if (targetSpeed > maxGameSpeed) {
targetSpeed = maxGameSpeed;
}
gameSpeed = targetSpeed;
// Decrease spawn interval based on score
var targetInterval = 90 - Math.floor(jumpScore / 50) * 10;
if (targetInterval < minSpawnInterval) {
targetInterval = minSpawnInterval;
}
cactusSpawnInterval = targetInterval;
}
function updateInvincibility() {
if (isInvincible) {
invincibilityTimer++;
// Update power-up timer display
var remainingSeconds = Math.ceil((invincibilityDuration - invincibilityTimer) / 60);
powerUpTimerText.setText(remainingSeconds + 's');
powerUpTimerText.visible = true;
// Make chicken flash during invincibility
if (invincibilityTimer % 10 === 0) {
var currentTint = chicken.tint === 0xffff00 ? 0xffffff : 0xffff00;
chicken.tint = currentTint;
}
// End invincibility after duration
if (invincibilityTimer >= invincibilityDuration) {
isInvincible = false;
invincibilityTimer = 0;
powerUpTimerText.visible = false;
// Reset chicken speed
chicken.speed = baseGameSpeed;
// Reset chicken appearance
tween(chicken, {
tint: 0xffffff
}, {
duration: 500
});
}
} else {
powerUpTimerText.visible = false;
}
}
game.update = function () {
if (!isGameRunning || isPaused) return;
updateScore();
// Spawn cacti
cactusSpawnTimer++;
if (cactusSpawnTimer >= cactusSpawnInterval) {
spawnCactus();
cactusSpawnTimer = 0;
}
// Spawn clouds
cloudSpawnTimer++;
if (cloudSpawnTimer >= 180) {
spawnCloud();
cloudSpawnTimer = 0;
}
// Spawn power-ups
powerUpSpawnTimer++;
if (powerUpSpawnTimer >= powerUpSpawnInterval) {
spawnPowerUp();
powerUpSpawnTimer = 0;
// Set new random interval for next power-up (20-40 seconds)
powerUpSpawnInterval = 1200 + Math.random() * 1200;
}
// Spawn bricks every 50 seconds
brickSpawnTimer++;
if (brickSpawnTimer >= brickSpawnInterval) {
spawnBrick();
brickSpawnTimer = 0;
}
// Update and clean up cacti
for (var i = cacti.length - 1; i >= 0; i--) {
var cactus = cacti[i];
cactus.speed = gameSpeed;
if (cactus.x < -100) {
cactus.destroy();
cacti.splice(i, 1);
}
}
// Update and clean up clouds
for (var i = clouds.length - 1; i >= 0; i--) {
var cloud = clouds[i];
if (cloud.x < -200) {
cloud.destroy();
clouds.splice(i, 1);
}
}
// Update and clean up power-ups
for (var i = powerUps.length - 1; i >= 0; i--) {
var powerUp = powerUps[i];
powerUp.speed = gameSpeed;
if (powerUp.x < -100) {
powerUp.destroy();
powerUps.splice(i, 1);
}
}
// Update and clean up particles
for (var i = particles.length - 1; i >= 0; i--) {
var particle = particles[i];
if (particle.markForDestroy) {
particle.destroy();
particles.splice(i, 1);
}
}
// Update and clean up trail particles
for (var i = trailParticles.length - 1; i >= 0; i--) {
var trailParticle = trailParticles[i];
if (trailParticle.markForDestroy) {
trailParticle.destroy();
trailParticles.splice(i, 1);
}
}
// Update and clean up bricks
for (var i = bricks.length - 1; i >= 0; i--) {
var brick = bricks[i];
if (brick.y > 2732 + 100) {
// Off-screen cleanup
brick.destroy();
bricks.splice(i, 1);
}
}
updateInvincibility();
// Update dash cooldown
if (dashCooldown > 0) {
dashCooldown--;
}
checkCollisions();
checkCactusJumps();
checkPowerUpCollisions();
checkBrickCollisions();
// Hide instructions after first jump
if (chicken.isJumping && instructionText.alpha > 0) {
tween(instructionText, {
alpha: 0
}, {
duration: 1000
});
}
};
Generame un cactus. In-Game asset. 2d. Estilo cartoon. Cartoon
Que el personaje tenga un casco de militar de la guerra con unos lentes de mira redonda
Un cañón verde estilo cartón plano y con un aura naranja resplandeciente como borde. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat