/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Boss = Container.expand(function () {
var self = Container.call(this);
var bossGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 1.5,
tint: 0x8B0000
});
self.health = 5;
self.x = 1800;
self.y = 500;
self.moveDirection = 1;
self.speed = 3;
self.lastSpawnTime = 0;
self.update = function () {
self.y += self.moveDirection * self.speed;
if (self.y <= 300) {
self.y = 300;
self.moveDirection = 1;
}
if (self.y >= 2400) {
self.y = 2400;
self.moveDirection = -1;
}
// Spawn falling objects every 60 frames
if (LK.ticks - self.lastSpawnTime > 60) {
spawnFallingObject();
self.lastSpawnTime = LK.ticks;
}
};
return self;
});
var CoffeeCup = Container.expand(function () {
var self = Container.call(this);
var cupGraphics = self.attachAsset('coffeeCup', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 0;
self.gravity = 0.8;
self.jumpForce = -12;
self.isRising = false;
self.isInvincible = false;
self.invincibleTimer = 0;
self.wasRisingLastFrame = false;
self.update = function () {
var wasRising = self.isRising;
if (self.isRising) {
self.velocityY += self.jumpForce * 0.3;
// Add flying animation when starting to rise
if (!self.wasRisingLastFrame) {
tween(cupGraphics, {
rotation: -0.3,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut
});
}
} else {
self.velocityY += self.gravity;
// Return to normal when not rising
if (self.wasRisingLastFrame) {
tween(cupGraphics, {
rotation: 0,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeOut
});
}
}
self.wasRisingLastFrame = wasRising;
self.velocityY = Math.max(-15, Math.min(15, self.velocityY));
self.y += self.velocityY;
if (self.y < 100) {
self.y = 100;
self.velocityY = 0;
}
if (self.y > 2632) {
self.y = 2632;
self.velocityY = 0;
}
if (self.isInvincible) {
self.invincibleTimer--;
cupGraphics.alpha = self.invincibleTimer % 10 < 5 ? 0.5 : 1.0;
if (self.invincibleTimer <= 0) {
self.isInvincible = false;
cupGraphics.alpha = 1.0;
}
}
};
self.makeInvincible = function () {
self.isInvincible = true;
self.invincibleTimer = 300;
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemigo', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -6;
self.health = 1;
self.update = function () {
self.x += self.speed;
enemyGraphics.rotation += 0.1;
};
return self;
});
var FallingObject = Container.expand(function () {
var self = Container.call(this);
var objectGraphics = self.attachAsset('regularBean', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5,
tint: 0xFF4500
});
self.velocityX = -6;
self.velocityY = 2;
self.gravity = 0.5;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += self.gravity;
objectGraphics.rotation += 0.2;
};
return self;
});
var GoldenBean = Container.expand(function () {
var self = Container.call(this);
var beanGraphics = self.attachAsset('goldenBean', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -8;
self.collected = false;
self.pulseTimer = 0;
self.update = function () {
self.x += self.speed;
beanGraphics.rotation += 0.15;
self.pulseTimer += 0.2;
var scale = 1 + Math.sin(self.pulseTimer) * 0.2;
beanGraphics.scaleX = scale;
beanGraphics.scaleY = scale;
};
return self;
});
var Heart = Container.expand(function () {
var self = Container.call(this);
var heartGraphics = self.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -8;
self.collected = false;
self.pulseTimer = 0;
self.update = function () {
self.x += self.speed;
self.pulseTimer += 0.15;
var scale = 1 + Math.sin(self.pulseTimer) * 0.3;
heartGraphics.scaleX = scale;
heartGraphics.scaleY = scale;
heartGraphics.rotation += 0.1;
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -8;
self.update = function () {
self.x += self.speed;
};
return self;
});
var Projectile = Container.expand(function () {
var self = Container.call(this);
var projectileGraphics = self.attachAsset('bread', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.0,
scaleY: 1.0
});
self.velocityX = 12;
self.velocityY = 0;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
projectileGraphics.rotation += 0.3;
};
return self;
});
var RegularBean = Container.expand(function () {
var self = Container.call(this);
var beanGraphics = self.attachAsset('regularBean', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -8;
self.collected = false;
self.update = function () {
self.x += self.speed;
beanGraphics.rotation += 0.1;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
game.setBackgroundColor(0x000000);
// Add rectangle background
var backgroundRect = LK.getAsset('backgroundRect', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
game.addChild(backgroundRect);
// Game variables
var coffeeCup;
var regularBeans = [];
var goldenBeans = [];
var obstacles = [];
var gameSpeed = 1;
var spawnTimer = 0;
var goldenBeanTimer = 0;
var highScore = storage.highScore || 0;
var bossActive = false;
var boss = null;
var bossHealth = 5;
var fallingObjects = [];
var bossSpawnTimer = 0;
var lives = 3;
var energy = 100;
var maxEnergy = 100;
var energyDecayRate = 0.2;
var projectiles = [];
var canFire = true;
var fireButtonPressed = false;
var enemies = [];
var hearts = [];
var heartTimer = 0;
// UI elements
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var highScoreTxt = new Text2('Best: ' + highScore, {
size: 60,
fill: 0xFFFF00
});
highScoreTxt.anchor.set(1, 0);
highScoreTxt.x = -50;
highScoreTxt.y = 100;
LK.gui.topRight.addChild(highScoreTxt);
var livesTxt = new Text2('Lives: ' + lives, {
size: 60,
fill: 0xFF69B4
});
livesTxt.anchor.set(0, 0);
livesTxt.x = 50;
livesTxt.y = 100;
LK.gui.topLeft.addChild(livesTxt);
var bossHealthTxt = new Text2('Boss Health: 5', {
size: 60,
fill: 0xFF0000
});
bossHealthTxt.anchor.set(0.5, 0);
bossHealthTxt.x = 0;
bossHealthTxt.y = 200;
bossHealthTxt.visible = false;
LK.gui.top.addChild(bossHealthTxt);
var energyTxt = new Text2('Energy: 100', {
size: 60,
fill: 0x00FF00
});
energyTxt.anchor.set(0, 0);
energyTxt.x = 50;
energyTxt.y = 180;
LK.gui.topLeft.addChild(energyTxt);
var fireButton = LK.getAsset('rocket', {
anchorX: 0.5,
anchorY: 0.5
});
fireButton.x = -100;
fireButton.y = -100;
LK.gui.bottomRight.addChild(fireButton);
// Initialize coffee cup
coffeeCup = game.addChild(new CoffeeCup());
coffeeCup.x = 400;
coffeeCup.y = 1366;
// Input handling
game.down = function (x, y, obj) {
// Check if fire button was pressed
if (x > 1800 && x < 2048 && y > 2500 && y < 2732) {
fireButtonPressed = true;
if (canFire) {
var projectile = new Projectile();
projectile.x = coffeeCup.x + 50;
projectile.y = coffeeCup.y;
projectiles.push(projectile);
game.addChild(projectile);
canFire = false;
LK.setTimeout(function () {
canFire = true;
}, 200);
}
} else {
coffeeCup.isRising = true;
}
};
game.up = function (x, y, obj) {
fireButtonPressed = false;
coffeeCup.isRising = false;
};
// Spawn functions
function spawnRegularBean() {
var bean = new RegularBean();
bean.x = 2200;
bean.y = Math.random() * 2400 + 200;
regularBeans.push(bean);
game.addChild(bean);
}
function spawnGoldenBean() {
var bean = new GoldenBean();
bean.x = 2200;
bean.y = Math.random() * 2400 + 200;
goldenBeans.push(bean);
game.addChild(bean);
}
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = 2200;
obstacle.y = Math.random() * 2000 + 400;
obstacles.push(obstacle);
game.addChild(obstacle);
}
function spawnBoss() {
var boss = new Boss();
game.addChild(boss);
return boss;
}
function spawnFallingObject() {
var obj = new FallingObject();
obj.x = 1800 + Math.random() * 200 - 100;
obj.y = 200;
fallingObjects.push(obj);
game.addChild(obj);
}
function spawnEnemy() {
var enemy = new Enemy();
enemy.x = 2200;
enemy.y = Math.random() * 2400 + 200;
enemies.push(enemy);
game.addChild(enemy);
}
function spawnHeart() {
var heart = new Heart();
heart.x = 2200;
heart.y = Math.random() * 2400 + 200;
hearts.push(heart);
game.addChild(heart);
}
// Main game loop
game.update = function () {
// Check for boss activation at score 1000
if (LK.getScore() >= 1000 && !bossActive) {
bossActive = true;
boss = spawnBoss();
bossHealth = boss.health;
// Clear existing elements when boss appears
for (var clear = obstacles.length - 1; clear >= 0; clear--) {
obstacles[clear].destroy();
obstacles.splice(clear, 1);
}
for (var clearBeans = regularBeans.length - 1; clearBeans >= 0; clearBeans--) {
regularBeans[clearBeans].destroy();
regularBeans.splice(clearBeans, 1);
}
for (var clearEnemies = enemies.length - 1; clearEnemies >= 0; clearEnemies--) {
enemies[clearEnemies].destroy();
enemies.splice(clearEnemies, 1);
}
for (var clearHearts = hearts.length - 1; clearHearts >= 0; clearHearts--) {
hearts[clearHearts].destroy();
hearts.splice(clearHearts, 1);
}
LK.effects.flashScreen(0x8B0000, 1000);
}
if (!bossActive) {
// Update game speed
gameSpeed = 1 + LK.getScore() / 100 * 0.5;
// Update spawn timers
spawnTimer++;
goldenBeanTimer++;
heartTimer++;
// Spawn regular beans
if (spawnTimer % Math.max(30, 60 - Math.floor(LK.getScore() / 10)) === 0) {
spawnRegularBean();
}
// Spawn obstacles
if (spawnTimer % Math.max(80, 120 - Math.floor(LK.getScore() / 5)) === 0) {
spawnObstacle();
}
// Spawn golden bean (rare)
if (goldenBeanTimer > 600 && Math.random() < 0.01) {
spawnGoldenBean();
goldenBeanTimer = 0;
}
// Spawn enemies every 50 points
if (LK.getScore() > 0 && LK.getScore() % 50 === 0 && spawnTimer % 120 === 0) {
spawnEnemy();
}
// Spawn hearts every 15 seconds (900 ticks at 60fps)
if (heartTimer > 900 && Math.random() < 0.02) {
spawnHeart();
heartTimer = 0;
}
bossHealthTxt.visible = false;
} else {
// Show boss health during boss battle
bossHealthTxt.visible = true;
bossHealthTxt.setText('Boss Health: ' + bossHealth);
}
// Update and check regular beans
for (var i = regularBeans.length - 1; i >= 0; i--) {
var bean = regularBeans[i];
if (bean.x < -100) {
bean.destroy();
regularBeans.splice(i, 1);
continue;
}
if (!bean.collected && bean.intersects(coffeeCup)) {
bean.collected = true;
LK.setScore(LK.getScore() + 10);
scoreTxt.setText('Score: ' + LK.getScore());
// Restore energy when collecting beans
energy = Math.min(maxEnergy, energy + 20);
energyTxt.setText('Energy: ' + Math.floor(energy));
// Update energy color based on level
if (energy > 60) {
energyTxt.fill = "#00FF00"; // Green
} else if (energy > 30) {
energyTxt.fill = "#FFFF00"; // Yellow
} else {
energyTxt.fill = "#FF0000"; // Red
}
LK.getSound('collectBean').play();
LK.effects.flashObject(bean, 0xFFFFFF, 200);
tween(bean, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 200,
onFinish: function onFinish() {
bean.destroy();
}
});
regularBeans.splice(i, 1);
}
}
// Update and check golden beans
for (var j = goldenBeans.length - 1; j >= 0; j--) {
var goldenBean = goldenBeans[j];
if (goldenBean.x < -100) {
goldenBean.destroy();
goldenBeans.splice(j, 1);
continue;
}
if (!goldenBean.collected && goldenBean.intersects(coffeeCup)) {
goldenBean.collected = true;
LK.setScore(LK.getScore() + 100);
scoreTxt.setText('Score: ' + LK.getScore());
// Restore significant energy when collecting golden beans
energy = maxEnergy;
energyTxt.setText('Energy: ' + Math.floor(energy));
energyTxt.fill = "#00FF00"; // Green
LK.getSound('collectGolden').play();
LK.effects.flashScreen(0xFFD700, 500);
coffeeCup.makeInvincible();
tween(goldenBean, {
alpha: 0,
scaleX: 3,
scaleY: 3
}, {
duration: 500,
onFinish: function onFinish() {
goldenBean.destroy();
}
});
goldenBeans.splice(j, 1);
}
}
// Update and check obstacles
for (var k = obstacles.length - 1; k >= 0; k--) {
var obstacle = obstacles[k];
if (obstacle.x < -100) {
obstacle.destroy();
obstacles.splice(k, 1);
continue;
}
// Check projectile collision with obstacles
for (var proj = projectiles.length - 1; proj >= 0; proj--) {
var projectile = projectiles[proj];
if (projectile.intersects(obstacle)) {
LK.setScore(LK.getScore() + 50);
scoreTxt.setText('Score: ' + LK.getScore());
LK.effects.flashObject(obstacle, 0xFFFFFF, 200);
projectile.destroy();
projectiles.splice(proj, 1);
obstacle.destroy();
obstacles.splice(k, 1);
break;
}
}
if (!coffeeCup.isInvincible && obstacle.intersects(coffeeCup)) {
lives--;
livesTxt.setText('Lives: ' + lives);
coffeeCup.makeInvincible();
LK.effects.flashScreen(0xFF0000, 500);
obstacle.destroy();
obstacles.splice(k, 1);
if (lives <= 0) {
// Update high score
if (LK.getScore() > highScore) {
highScore = LK.getScore();
storage.highScore = highScore;
}
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
break;
}
}
// Update and clean up projectiles
for (var p = projectiles.length - 1; p >= 0; p--) {
var projectile = projectiles[p];
if (projectile.x > 2200 || projectile.y < -100 || projectile.y > 2800) {
projectile.destroy();
projectiles.splice(p, 1);
continue;
}
}
// Update and check hearts
for (var h = hearts.length - 1; h >= 0; h--) {
var heart = hearts[h];
if (heart.x < -100) {
heart.destroy();
hearts.splice(h, 1);
continue;
}
if (!heart.collected && heart.intersects(coffeeCup)) {
heart.collected = true;
lives = Math.min(5, lives + 1); // Max 5 lives
livesTxt.setText('Lives: ' + lives);
LK.getSound('collectGolden').play();
LK.effects.flashObject(heart, 0xFF69B4, 300);
tween(heart, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 300,
onFinish: function onFinish() {
heart.destroy();
}
});
hearts.splice(h, 1);
}
}
// Update and check enemies
for (var e = enemies.length - 1; e >= 0; e--) {
var enemy = enemies[e];
if (enemy.x < -100) {
enemy.destroy();
enemies.splice(e, 1);
continue;
}
// Check projectile collision with enemies
for (var projEnemy = projectiles.length - 1; projEnemy >= 0; projEnemy--) {
var projectileEnemy = projectiles[projEnemy];
if (projectileEnemy.intersects(enemy)) {
LK.setScore(LK.getScore() + 25);
scoreTxt.setText('Score: ' + LK.getScore());
LK.effects.flashObject(enemy, 0xFFFFFF, 200);
projectileEnemy.destroy();
projectiles.splice(projEnemy, 1);
enemy.destroy();
enemies.splice(e, 1);
break;
}
}
// Check collision with coffee cup
if (!coffeeCup.isInvincible && enemy.intersects(coffeeCup)) {
lives--;
livesTxt.setText('Lives: ' + lives);
coffeeCup.makeInvincible();
LK.effects.flashScreen(0xFF0000, 500);
enemy.destroy();
enemies.splice(e, 1);
if (lives <= 0) {
// Update high score
if (LK.getScore() > highScore) {
highScore = LK.getScore();
storage.highScore = highScore;
}
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
break;
}
}
// Update speed for all moving objects
for (var l = 0; l < regularBeans.length; l++) {
regularBeans[l].speed = -8 * gameSpeed;
}
for (var m = 0; m < goldenBeans.length; m++) {
goldenBeans[m].speed = -8 * gameSpeed;
}
for (var n = 0; n < obstacles.length; n++) {
obstacles[n].speed = -8 * gameSpeed;
}
for (var enemySpeed = 0; enemySpeed < enemies.length; enemySpeed++) {
enemies[enemySpeed].speed = -6 * gameSpeed;
}
for (var heartSpeed = 0; heartSpeed < hearts.length; heartSpeed++) {
hearts[heartSpeed].speed = -8 * gameSpeed;
}
// Handle falling objects during boss battle
if (bossActive) {
for (var f = fallingObjects.length - 1; f >= 0; f--) {
var fallingObj = fallingObjects[f];
if (fallingObj.y > 2800 || fallingObj.x < -100) {
fallingObj.destroy();
fallingObjects.splice(f, 1);
continue;
}
// Check collision with coffee cup
if (fallingObj.intersects(coffeeCup) && !coffeeCup.isInvincible) {
lives--;
livesTxt.setText('Lives: ' + lives);
coffeeCup.makeInvincible();
LK.effects.flashScreen(0xFF0000, 500);
fallingObj.destroy();
fallingObjects.splice(f, 1);
if (lives <= 0) {
// Update high score
if (LK.getScore() > highScore) {
highScore = LK.getScore();
storage.highScore = highScore;
}
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
break;
}
// Check projectile collision with boss
for (var projBoss = projectiles.length - 1; projBoss >= 0; projBoss--) {
var projectileBoss = projectiles[projBoss];
if (projectileBoss.intersects(boss)) {
boss.health--;
bossHealth = boss.health;
LK.effects.flashObject(boss, 0xFF0000, 300);
// Add screen shake effect when boss is hit
tween(game, {
x: Math.random() * 20 - 10,
y: Math.random() * 20 - 10
}, {
duration: 100,
onFinish: function onFinish() {
tween(game, {
x: 0,
y: 0
}, {
duration: 100
});
}
});
projectileBoss.destroy();
projectiles.splice(projBoss, 1);
if (bossHealth <= 0) {
// Boss defeated
LK.setScore(LK.getScore() + 500);
scoreTxt.setText('Score: ' + LK.getScore());
boss.destroy();
bossActive = false;
boss = null;
LK.effects.flashScreen(0x00FF00, 1000);
LK.showYouWin();
}
break;
}
}
// Check if falling object hits boss (coffee cup can throw objects at boss)
if (fallingObj.intersects(boss) && fallingObj.velocityX < 0) {
boss.health--;
bossHealth = boss.health;
LK.effects.flashObject(boss, 0xFF0000, 300);
// Add screen shake effect when boss is hit
tween(game, {
x: Math.random() * 20 - 10,
y: Math.random() * 20 - 10
}, {
duration: 100,
onFinish: function onFinish() {
tween(game, {
x: 0,
y: 0
}, {
duration: 100
});
}
});
fallingObj.destroy();
fallingObjects.splice(f, 1);
if (bossHealth <= 0) {
// Boss defeated
LK.setScore(LK.getScore() + 500);
scoreTxt.setText('Score: ' + LK.getScore());
boss.destroy();
bossActive = false;
boss = null;
LK.effects.flashScreen(0x00FF00, 1000);
LK.showYouWin();
}
}
}
}
// Energy decay system
if (!bossActive) {
energy -= energyDecayRate;
energy = Math.max(0, energy);
energyTxt.setText('Energy: ' + Math.floor(energy));
// Update energy color based on level
if (energy > 60) {
energyTxt.fill = "#00FF00"; // Green
} else if (energy > 30) {
energyTxt.fill = "#FFFF00"; // Yellow
} else {
energyTxt.fill = "#FF0000"; // Red
}
// Game over when energy reaches zero
if (energy <= 0) {
// Update high score
if (LK.getScore() > highScore) {
highScore = LK.getScore();
storage.highScore = highScore;
}
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
}
};
// Start background music
LK.playMusic('bgmusic'); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Boss = Container.expand(function () {
var self = Container.call(this);
var bossGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 1.5,
tint: 0x8B0000
});
self.health = 5;
self.x = 1800;
self.y = 500;
self.moveDirection = 1;
self.speed = 3;
self.lastSpawnTime = 0;
self.update = function () {
self.y += self.moveDirection * self.speed;
if (self.y <= 300) {
self.y = 300;
self.moveDirection = 1;
}
if (self.y >= 2400) {
self.y = 2400;
self.moveDirection = -1;
}
// Spawn falling objects every 60 frames
if (LK.ticks - self.lastSpawnTime > 60) {
spawnFallingObject();
self.lastSpawnTime = LK.ticks;
}
};
return self;
});
var CoffeeCup = Container.expand(function () {
var self = Container.call(this);
var cupGraphics = self.attachAsset('coffeeCup', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityY = 0;
self.gravity = 0.8;
self.jumpForce = -12;
self.isRising = false;
self.isInvincible = false;
self.invincibleTimer = 0;
self.wasRisingLastFrame = false;
self.update = function () {
var wasRising = self.isRising;
if (self.isRising) {
self.velocityY += self.jumpForce * 0.3;
// Add flying animation when starting to rise
if (!self.wasRisingLastFrame) {
tween(cupGraphics, {
rotation: -0.3,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut
});
}
} else {
self.velocityY += self.gravity;
// Return to normal when not rising
if (self.wasRisingLastFrame) {
tween(cupGraphics, {
rotation: 0,
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 300,
easing: tween.easeOut
});
}
}
self.wasRisingLastFrame = wasRising;
self.velocityY = Math.max(-15, Math.min(15, self.velocityY));
self.y += self.velocityY;
if (self.y < 100) {
self.y = 100;
self.velocityY = 0;
}
if (self.y > 2632) {
self.y = 2632;
self.velocityY = 0;
}
if (self.isInvincible) {
self.invincibleTimer--;
cupGraphics.alpha = self.invincibleTimer % 10 < 5 ? 0.5 : 1.0;
if (self.invincibleTimer <= 0) {
self.isInvincible = false;
cupGraphics.alpha = 1.0;
}
}
};
self.makeInvincible = function () {
self.isInvincible = true;
self.invincibleTimer = 300;
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemigo', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -6;
self.health = 1;
self.update = function () {
self.x += self.speed;
enemyGraphics.rotation += 0.1;
};
return self;
});
var FallingObject = Container.expand(function () {
var self = Container.call(this);
var objectGraphics = self.attachAsset('regularBean', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5,
tint: 0xFF4500
});
self.velocityX = -6;
self.velocityY = 2;
self.gravity = 0.5;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += self.gravity;
objectGraphics.rotation += 0.2;
};
return self;
});
var GoldenBean = Container.expand(function () {
var self = Container.call(this);
var beanGraphics = self.attachAsset('goldenBean', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -8;
self.collected = false;
self.pulseTimer = 0;
self.update = function () {
self.x += self.speed;
beanGraphics.rotation += 0.15;
self.pulseTimer += 0.2;
var scale = 1 + Math.sin(self.pulseTimer) * 0.2;
beanGraphics.scaleX = scale;
beanGraphics.scaleY = scale;
};
return self;
});
var Heart = Container.expand(function () {
var self = Container.call(this);
var heartGraphics = self.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -8;
self.collected = false;
self.pulseTimer = 0;
self.update = function () {
self.x += self.speed;
self.pulseTimer += 0.15;
var scale = 1 + Math.sin(self.pulseTimer) * 0.3;
heartGraphics.scaleX = scale;
heartGraphics.scaleY = scale;
heartGraphics.rotation += 0.1;
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -8;
self.update = function () {
self.x += self.speed;
};
return self;
});
var Projectile = Container.expand(function () {
var self = Container.call(this);
var projectileGraphics = self.attachAsset('bread', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.0,
scaleY: 1.0
});
self.velocityX = 12;
self.velocityY = 0;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
projectileGraphics.rotation += 0.3;
};
return self;
});
var RegularBean = Container.expand(function () {
var self = Container.call(this);
var beanGraphics = self.attachAsset('regularBean', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -8;
self.collected = false;
self.update = function () {
self.x += self.speed;
beanGraphics.rotation += 0.1;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
game.setBackgroundColor(0x000000);
// Add rectangle background
var backgroundRect = LK.getAsset('backgroundRect', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
game.addChild(backgroundRect);
// Game variables
var coffeeCup;
var regularBeans = [];
var goldenBeans = [];
var obstacles = [];
var gameSpeed = 1;
var spawnTimer = 0;
var goldenBeanTimer = 0;
var highScore = storage.highScore || 0;
var bossActive = false;
var boss = null;
var bossHealth = 5;
var fallingObjects = [];
var bossSpawnTimer = 0;
var lives = 3;
var energy = 100;
var maxEnergy = 100;
var energyDecayRate = 0.2;
var projectiles = [];
var canFire = true;
var fireButtonPressed = false;
var enemies = [];
var hearts = [];
var heartTimer = 0;
// UI elements
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var highScoreTxt = new Text2('Best: ' + highScore, {
size: 60,
fill: 0xFFFF00
});
highScoreTxt.anchor.set(1, 0);
highScoreTxt.x = -50;
highScoreTxt.y = 100;
LK.gui.topRight.addChild(highScoreTxt);
var livesTxt = new Text2('Lives: ' + lives, {
size: 60,
fill: 0xFF69B4
});
livesTxt.anchor.set(0, 0);
livesTxt.x = 50;
livesTxt.y = 100;
LK.gui.topLeft.addChild(livesTxt);
var bossHealthTxt = new Text2('Boss Health: 5', {
size: 60,
fill: 0xFF0000
});
bossHealthTxt.anchor.set(0.5, 0);
bossHealthTxt.x = 0;
bossHealthTxt.y = 200;
bossHealthTxt.visible = false;
LK.gui.top.addChild(bossHealthTxt);
var energyTxt = new Text2('Energy: 100', {
size: 60,
fill: 0x00FF00
});
energyTxt.anchor.set(0, 0);
energyTxt.x = 50;
energyTxt.y = 180;
LK.gui.topLeft.addChild(energyTxt);
var fireButton = LK.getAsset('rocket', {
anchorX: 0.5,
anchorY: 0.5
});
fireButton.x = -100;
fireButton.y = -100;
LK.gui.bottomRight.addChild(fireButton);
// Initialize coffee cup
coffeeCup = game.addChild(new CoffeeCup());
coffeeCup.x = 400;
coffeeCup.y = 1366;
// Input handling
game.down = function (x, y, obj) {
// Check if fire button was pressed
if (x > 1800 && x < 2048 && y > 2500 && y < 2732) {
fireButtonPressed = true;
if (canFire) {
var projectile = new Projectile();
projectile.x = coffeeCup.x + 50;
projectile.y = coffeeCup.y;
projectiles.push(projectile);
game.addChild(projectile);
canFire = false;
LK.setTimeout(function () {
canFire = true;
}, 200);
}
} else {
coffeeCup.isRising = true;
}
};
game.up = function (x, y, obj) {
fireButtonPressed = false;
coffeeCup.isRising = false;
};
// Spawn functions
function spawnRegularBean() {
var bean = new RegularBean();
bean.x = 2200;
bean.y = Math.random() * 2400 + 200;
regularBeans.push(bean);
game.addChild(bean);
}
function spawnGoldenBean() {
var bean = new GoldenBean();
bean.x = 2200;
bean.y = Math.random() * 2400 + 200;
goldenBeans.push(bean);
game.addChild(bean);
}
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = 2200;
obstacle.y = Math.random() * 2000 + 400;
obstacles.push(obstacle);
game.addChild(obstacle);
}
function spawnBoss() {
var boss = new Boss();
game.addChild(boss);
return boss;
}
function spawnFallingObject() {
var obj = new FallingObject();
obj.x = 1800 + Math.random() * 200 - 100;
obj.y = 200;
fallingObjects.push(obj);
game.addChild(obj);
}
function spawnEnemy() {
var enemy = new Enemy();
enemy.x = 2200;
enemy.y = Math.random() * 2400 + 200;
enemies.push(enemy);
game.addChild(enemy);
}
function spawnHeart() {
var heart = new Heart();
heart.x = 2200;
heart.y = Math.random() * 2400 + 200;
hearts.push(heart);
game.addChild(heart);
}
// Main game loop
game.update = function () {
// Check for boss activation at score 1000
if (LK.getScore() >= 1000 && !bossActive) {
bossActive = true;
boss = spawnBoss();
bossHealth = boss.health;
// Clear existing elements when boss appears
for (var clear = obstacles.length - 1; clear >= 0; clear--) {
obstacles[clear].destroy();
obstacles.splice(clear, 1);
}
for (var clearBeans = regularBeans.length - 1; clearBeans >= 0; clearBeans--) {
regularBeans[clearBeans].destroy();
regularBeans.splice(clearBeans, 1);
}
for (var clearEnemies = enemies.length - 1; clearEnemies >= 0; clearEnemies--) {
enemies[clearEnemies].destroy();
enemies.splice(clearEnemies, 1);
}
for (var clearHearts = hearts.length - 1; clearHearts >= 0; clearHearts--) {
hearts[clearHearts].destroy();
hearts.splice(clearHearts, 1);
}
LK.effects.flashScreen(0x8B0000, 1000);
}
if (!bossActive) {
// Update game speed
gameSpeed = 1 + LK.getScore() / 100 * 0.5;
// Update spawn timers
spawnTimer++;
goldenBeanTimer++;
heartTimer++;
// Spawn regular beans
if (spawnTimer % Math.max(30, 60 - Math.floor(LK.getScore() / 10)) === 0) {
spawnRegularBean();
}
// Spawn obstacles
if (spawnTimer % Math.max(80, 120 - Math.floor(LK.getScore() / 5)) === 0) {
spawnObstacle();
}
// Spawn golden bean (rare)
if (goldenBeanTimer > 600 && Math.random() < 0.01) {
spawnGoldenBean();
goldenBeanTimer = 0;
}
// Spawn enemies every 50 points
if (LK.getScore() > 0 && LK.getScore() % 50 === 0 && spawnTimer % 120 === 0) {
spawnEnemy();
}
// Spawn hearts every 15 seconds (900 ticks at 60fps)
if (heartTimer > 900 && Math.random() < 0.02) {
spawnHeart();
heartTimer = 0;
}
bossHealthTxt.visible = false;
} else {
// Show boss health during boss battle
bossHealthTxt.visible = true;
bossHealthTxt.setText('Boss Health: ' + bossHealth);
}
// Update and check regular beans
for (var i = regularBeans.length - 1; i >= 0; i--) {
var bean = regularBeans[i];
if (bean.x < -100) {
bean.destroy();
regularBeans.splice(i, 1);
continue;
}
if (!bean.collected && bean.intersects(coffeeCup)) {
bean.collected = true;
LK.setScore(LK.getScore() + 10);
scoreTxt.setText('Score: ' + LK.getScore());
// Restore energy when collecting beans
energy = Math.min(maxEnergy, energy + 20);
energyTxt.setText('Energy: ' + Math.floor(energy));
// Update energy color based on level
if (energy > 60) {
energyTxt.fill = "#00FF00"; // Green
} else if (energy > 30) {
energyTxt.fill = "#FFFF00"; // Yellow
} else {
energyTxt.fill = "#FF0000"; // Red
}
LK.getSound('collectBean').play();
LK.effects.flashObject(bean, 0xFFFFFF, 200);
tween(bean, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 200,
onFinish: function onFinish() {
bean.destroy();
}
});
regularBeans.splice(i, 1);
}
}
// Update and check golden beans
for (var j = goldenBeans.length - 1; j >= 0; j--) {
var goldenBean = goldenBeans[j];
if (goldenBean.x < -100) {
goldenBean.destroy();
goldenBeans.splice(j, 1);
continue;
}
if (!goldenBean.collected && goldenBean.intersects(coffeeCup)) {
goldenBean.collected = true;
LK.setScore(LK.getScore() + 100);
scoreTxt.setText('Score: ' + LK.getScore());
// Restore significant energy when collecting golden beans
energy = maxEnergy;
energyTxt.setText('Energy: ' + Math.floor(energy));
energyTxt.fill = "#00FF00"; // Green
LK.getSound('collectGolden').play();
LK.effects.flashScreen(0xFFD700, 500);
coffeeCup.makeInvincible();
tween(goldenBean, {
alpha: 0,
scaleX: 3,
scaleY: 3
}, {
duration: 500,
onFinish: function onFinish() {
goldenBean.destroy();
}
});
goldenBeans.splice(j, 1);
}
}
// Update and check obstacles
for (var k = obstacles.length - 1; k >= 0; k--) {
var obstacle = obstacles[k];
if (obstacle.x < -100) {
obstacle.destroy();
obstacles.splice(k, 1);
continue;
}
// Check projectile collision with obstacles
for (var proj = projectiles.length - 1; proj >= 0; proj--) {
var projectile = projectiles[proj];
if (projectile.intersects(obstacle)) {
LK.setScore(LK.getScore() + 50);
scoreTxt.setText('Score: ' + LK.getScore());
LK.effects.flashObject(obstacle, 0xFFFFFF, 200);
projectile.destroy();
projectiles.splice(proj, 1);
obstacle.destroy();
obstacles.splice(k, 1);
break;
}
}
if (!coffeeCup.isInvincible && obstacle.intersects(coffeeCup)) {
lives--;
livesTxt.setText('Lives: ' + lives);
coffeeCup.makeInvincible();
LK.effects.flashScreen(0xFF0000, 500);
obstacle.destroy();
obstacles.splice(k, 1);
if (lives <= 0) {
// Update high score
if (LK.getScore() > highScore) {
highScore = LK.getScore();
storage.highScore = highScore;
}
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
break;
}
}
// Update and clean up projectiles
for (var p = projectiles.length - 1; p >= 0; p--) {
var projectile = projectiles[p];
if (projectile.x > 2200 || projectile.y < -100 || projectile.y > 2800) {
projectile.destroy();
projectiles.splice(p, 1);
continue;
}
}
// Update and check hearts
for (var h = hearts.length - 1; h >= 0; h--) {
var heart = hearts[h];
if (heart.x < -100) {
heart.destroy();
hearts.splice(h, 1);
continue;
}
if (!heart.collected && heart.intersects(coffeeCup)) {
heart.collected = true;
lives = Math.min(5, lives + 1); // Max 5 lives
livesTxt.setText('Lives: ' + lives);
LK.getSound('collectGolden').play();
LK.effects.flashObject(heart, 0xFF69B4, 300);
tween(heart, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 300,
onFinish: function onFinish() {
heart.destroy();
}
});
hearts.splice(h, 1);
}
}
// Update and check enemies
for (var e = enemies.length - 1; e >= 0; e--) {
var enemy = enemies[e];
if (enemy.x < -100) {
enemy.destroy();
enemies.splice(e, 1);
continue;
}
// Check projectile collision with enemies
for (var projEnemy = projectiles.length - 1; projEnemy >= 0; projEnemy--) {
var projectileEnemy = projectiles[projEnemy];
if (projectileEnemy.intersects(enemy)) {
LK.setScore(LK.getScore() + 25);
scoreTxt.setText('Score: ' + LK.getScore());
LK.effects.flashObject(enemy, 0xFFFFFF, 200);
projectileEnemy.destroy();
projectiles.splice(projEnemy, 1);
enemy.destroy();
enemies.splice(e, 1);
break;
}
}
// Check collision with coffee cup
if (!coffeeCup.isInvincible && enemy.intersects(coffeeCup)) {
lives--;
livesTxt.setText('Lives: ' + lives);
coffeeCup.makeInvincible();
LK.effects.flashScreen(0xFF0000, 500);
enemy.destroy();
enemies.splice(e, 1);
if (lives <= 0) {
// Update high score
if (LK.getScore() > highScore) {
highScore = LK.getScore();
storage.highScore = highScore;
}
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
break;
}
}
// Update speed for all moving objects
for (var l = 0; l < regularBeans.length; l++) {
regularBeans[l].speed = -8 * gameSpeed;
}
for (var m = 0; m < goldenBeans.length; m++) {
goldenBeans[m].speed = -8 * gameSpeed;
}
for (var n = 0; n < obstacles.length; n++) {
obstacles[n].speed = -8 * gameSpeed;
}
for (var enemySpeed = 0; enemySpeed < enemies.length; enemySpeed++) {
enemies[enemySpeed].speed = -6 * gameSpeed;
}
for (var heartSpeed = 0; heartSpeed < hearts.length; heartSpeed++) {
hearts[heartSpeed].speed = -8 * gameSpeed;
}
// Handle falling objects during boss battle
if (bossActive) {
for (var f = fallingObjects.length - 1; f >= 0; f--) {
var fallingObj = fallingObjects[f];
if (fallingObj.y > 2800 || fallingObj.x < -100) {
fallingObj.destroy();
fallingObjects.splice(f, 1);
continue;
}
// Check collision with coffee cup
if (fallingObj.intersects(coffeeCup) && !coffeeCup.isInvincible) {
lives--;
livesTxt.setText('Lives: ' + lives);
coffeeCup.makeInvincible();
LK.effects.flashScreen(0xFF0000, 500);
fallingObj.destroy();
fallingObjects.splice(f, 1);
if (lives <= 0) {
// Update high score
if (LK.getScore() > highScore) {
highScore = LK.getScore();
storage.highScore = highScore;
}
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
break;
}
// Check projectile collision with boss
for (var projBoss = projectiles.length - 1; projBoss >= 0; projBoss--) {
var projectileBoss = projectiles[projBoss];
if (projectileBoss.intersects(boss)) {
boss.health--;
bossHealth = boss.health;
LK.effects.flashObject(boss, 0xFF0000, 300);
// Add screen shake effect when boss is hit
tween(game, {
x: Math.random() * 20 - 10,
y: Math.random() * 20 - 10
}, {
duration: 100,
onFinish: function onFinish() {
tween(game, {
x: 0,
y: 0
}, {
duration: 100
});
}
});
projectileBoss.destroy();
projectiles.splice(projBoss, 1);
if (bossHealth <= 0) {
// Boss defeated
LK.setScore(LK.getScore() + 500);
scoreTxt.setText('Score: ' + LK.getScore());
boss.destroy();
bossActive = false;
boss = null;
LK.effects.flashScreen(0x00FF00, 1000);
LK.showYouWin();
}
break;
}
}
// Check if falling object hits boss (coffee cup can throw objects at boss)
if (fallingObj.intersects(boss) && fallingObj.velocityX < 0) {
boss.health--;
bossHealth = boss.health;
LK.effects.flashObject(boss, 0xFF0000, 300);
// Add screen shake effect when boss is hit
tween(game, {
x: Math.random() * 20 - 10,
y: Math.random() * 20 - 10
}, {
duration: 100,
onFinish: function onFinish() {
tween(game, {
x: 0,
y: 0
}, {
duration: 100
});
}
});
fallingObj.destroy();
fallingObjects.splice(f, 1);
if (bossHealth <= 0) {
// Boss defeated
LK.setScore(LK.getScore() + 500);
scoreTxt.setText('Score: ' + LK.getScore());
boss.destroy();
bossActive = false;
boss = null;
LK.effects.flashScreen(0x00FF00, 1000);
LK.showYouWin();
}
}
}
}
// Energy decay system
if (!bossActive) {
energy -= energyDecayRate;
energy = Math.max(0, energy);
energyTxt.setText('Energy: ' + Math.floor(energy));
// Update energy color based on level
if (energy > 60) {
energyTxt.fill = "#00FF00"; // Green
} else if (energy > 30) {
energyTxt.fill = "#FFFF00"; // Yellow
} else {
energyTxt.fill = "#FF0000"; // Red
}
// Game over when energy reaches zero
if (energy <= 0) {
// Update high score
if (LK.getScore() > highScore) {
highScore = LK.getScore();
storage.highScore = highScore;
}
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
}
};
// Start background music
LK.playMusic('bgmusic');
una tasa de cafe caricaturesca de pixeles con un jet pak. In-Game asset. 2d. High contrast. No shadows
grano de cafe dorado de pixeles. In-Game asset. 2d. High contrast. No shadows
grano de caffe de pixeles. In-Game asset. 2d. High contrast. No shadows
martillo mounstroso de pixeles. In-Game asset. 2d. High contrast. No shadows
corazon de pixeles. In-Game asset. 2d. High contrast. No shadows
pan de pixeles. In-Game asset. 2d. High contrast. No shadows
coete de pixeles. In-Game asset. 2d. High contrast. No shadows
paisage con cascadas de cafe de pixeles. In-Game asset. 2d. High contrast. No shadows