User prompt
when game start, start music coffee
User prompt
make background more realistic
User prompt
Earn 25 dollars for every 25 targets
User prompt
every target is 25$
User prompt
when click shop button, open shop menu
User prompt
make a shop button
User prompt
make character movable
User prompt
continue
User prompt
continue
User prompt
continue
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'satisfactionTxt.style.fill = "#00ff00";' Line Number: 160
Code edit (1 edits merged)
Please save this source code
User prompt
Coffee Rush
Initial prompt
coffee
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var CoffeeBean = Container.expand(function (type) {
var self = Container.call(this);
var beanType = type || 'arabica';
var beanGraphics = self.attachAsset(beanType + 'Bean', {
anchorX: 0.5,
anchorY: 0.5
});
self.beanType = beanType;
self.speed = 3;
self.points = beanType === 'espresso' ? 10 : beanType === 'arabica' ? 5 : 3;
self.update = function () {
self.y += self.speed;
};
return self;
});
var CoffeeCup = Container.expand(function () {
var self = Container.call(this);
var cupGraphics = self.attachAsset('coffeeCup', {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = 8;
self.isDragging = false;
return self;
});
var Obstacle = Container.expand(function (type) {
var self = Container.call(this);
var obstacleType = type || 'spilledMilk';
var obstacleGraphics = self.attachAsset(obstacleType, {
anchorX: 0.5,
anchorY: 0.5
});
self.obstacleType = obstacleType;
self.speed = 4;
self.penalty = obstacleType === 'spilledMilk' ? 5 : 3;
self.update = function () {
self.y += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x3e2723
});
/****
* Game Code
****/
// Sounds
// Obstacles
// Coffee beans
// Coffee cups
// Game variables
var coffeeCup;
var beans = [];
var obstacles = [];
var dragNode = null;
var gameSpeed = 1;
var customerSatisfaction = 100;
var targetScore = 500;
var spawnTimer = 0;
var difficultyTimer = 0;
// UI Elements
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(scoreTxt);
var satisfactionTxt = new Text2('Satisfaction: 100%', {
size: 50,
fill: 0x00FF00
});
satisfactionTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(satisfactionTxt);
var targetTxt = new Text2('Target: ' + targetScore, {
size: 45,
fill: 0xFFFF00
});
targetTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(targetTxt);
// Initialize coffee cup
coffeeCup = game.addChild(new CoffeeCup());
coffeeCup.x = 1024; // Center of screen
coffeeCup.y = 2500; // Near bottom
// Spawn functions
function spawnBean() {
var beanTypes = ['espresso', 'arabica', 'robusta'];
var randomType = beanTypes[Math.floor(Math.random() * beanTypes.length)];
var newBean = new CoffeeBean(randomType);
newBean.x = Math.random() * (2048 - 100) + 50;
newBean.y = -50;
newBean.speed = 3 + gameSpeed;
beans.push(newBean);
game.addChild(newBean);
}
function spawnObstacle() {
var obstacleTypes = ['spilledMilk', 'sugarCube'];
var randomType = obstacleTypes[Math.floor(Math.random() * obstacleTypes.length)];
var newObstacle = new Obstacle(randomType);
newObstacle.x = Math.random() * (2048 - 100) + 50;
newObstacle.y = -50;
newObstacle.speed = 4 + gameSpeed;
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
// Event handlers
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = Math.max(60, Math.min(1988, x));
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
if (coffeeCup.intersects({
x: x,
y: y,
width: 1,
height: 1
})) {
dragNode = coffeeCup;
coffeeCup.isDragging = true;
handleMove(x, y, obj);
}
};
game.up = function (x, y, obj) {
if (dragNode) {
dragNode.isDragging = false;
dragNode = null;
}
};
// Update satisfaction display
function updateSatisfactionDisplay() {
satisfactionTxt.setText('Satisfaction: ' + Math.round(customerSatisfaction) + '%');
if (customerSatisfaction > 70) {
satisfactionTxt.style.fill = "#00ff00";
} else if (customerSatisfaction > 30) {
satisfactionTxt.style.fill = "#ffff00";
} else {
satisfactionTxt.style.fill = "#ff0000";
}
}
// Main game loop
game.update = function () {
spawnTimer++;
difficultyTimer++;
// Spawn beans and obstacles
if (spawnTimer % (90 - Math.floor(gameSpeed * 10)) === 0) {
spawnBean();
}
if (spawnTimer % 180 === 0) {
spawnObstacle();
}
// Increase difficulty over time
if (difficultyTimer % 1800 === 0) {
// Every 30 seconds
gameSpeed += 0.5;
}
// Update and check beans
for (var i = beans.length - 1; i >= 0; i--) {
var bean = beans[i];
if (bean.lastY === undefined) bean.lastY = bean.y;
// Check if bean is caught by cup
if (bean.intersects(coffeeCup)) {
LK.setScore(LK.getScore() + bean.points);
scoreTxt.setText('Score: ' + LK.getScore());
LK.getSound('catch').play();
// Flash cup green
LK.effects.flashObject(coffeeCup, 0x00ff00, 300);
bean.destroy();
beans.splice(i, 1);
continue;
}
// Check if bean fell off screen
if (bean.lastY < 2732 && bean.y >= 2732) {
customerSatisfaction -= 2;
updateSatisfactionDisplay();
bean.destroy();
beans.splice(i, 1);
continue;
}
bean.lastY = bean.y;
}
// Update and check obstacles
for (var j = obstacles.length - 1; j >= 0; j--) {
var obstacle = obstacles[j];
if (obstacle.lastY === undefined) obstacle.lastY = obstacle.y;
// Check if obstacle hits cup
if (obstacle.intersects(coffeeCup)) {
LK.setScore(Math.max(0, LK.getScore() - obstacle.penalty));
scoreTxt.setText('Score: ' + LK.getScore());
customerSatisfaction -= obstacle.penalty;
updateSatisfactionDisplay();
LK.getSound('obstacle').play();
// Flash cup red
LK.effects.flashObject(coffeeCup, 0xff0000, 500);
obstacle.destroy();
obstacles.splice(j, 1);
continue;
}
// Remove obstacle if it falls off screen
if (obstacle.lastY < 2732 && obstacle.y >= 2732) {
obstacle.destroy();
obstacles.splice(j, 1);
continue;
}
obstacle.lastY = obstacle.y;
}
// Check win condition
if (LK.getScore() >= targetScore) {
LK.showYouWin();
}
// Check lose condition
if (customerSatisfaction <= 0) {
LK.showGameOver();
}
// Gradually decrease satisfaction over time
if (LK.ticks % 300 === 0) {
// Every 5 seconds
customerSatisfaction = Math.max(0, customerSatisfaction - 1);
updateSatisfactionDisplay();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,234 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var CoffeeBean = Container.expand(function (type) {
+ var self = Container.call(this);
+ var beanType = type || 'arabica';
+ var beanGraphics = self.attachAsset(beanType + 'Bean', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.beanType = beanType;
+ self.speed = 3;
+ self.points = beanType === 'espresso' ? 10 : beanType === 'arabica' ? 5 : 3;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+var CoffeeCup = Container.expand(function () {
+ var self = Container.call(this);
+ var cupGraphics = self.attachAsset('coffeeCup', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ self.speed = 8;
+ self.isDragging = false;
+ return self;
+});
+var Obstacle = Container.expand(function (type) {
+ var self = Container.call(this);
+ var obstacleType = type || 'spilledMilk';
+ var obstacleGraphics = self.attachAsset(obstacleType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.obstacleType = obstacleType;
+ self.speed = 4;
+ self.penalty = obstacleType === 'spilledMilk' ? 5 : 3;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x3e2723
+});
+
+/****
+* Game Code
+****/
+// Sounds
+// Obstacles
+// Coffee beans
+// Coffee cups
+// Game variables
+var coffeeCup;
+var beans = [];
+var obstacles = [];
+var dragNode = null;
+var gameSpeed = 1;
+var customerSatisfaction = 100;
+var targetScore = 500;
+var spawnTimer = 0;
+var difficultyTimer = 0;
+// UI Elements
+var scoreTxt = new Text2('Score: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0, 0);
+LK.gui.topLeft.addChild(scoreTxt);
+var satisfactionTxt = new Text2('Satisfaction: 100%', {
+ size: 50,
+ fill: 0x00FF00
+});
+satisfactionTxt.anchor.set(1, 0);
+LK.gui.topRight.addChild(satisfactionTxt);
+var targetTxt = new Text2('Target: ' + targetScore, {
+ size: 45,
+ fill: 0xFFFF00
+});
+targetTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(targetTxt);
+// Initialize coffee cup
+coffeeCup = game.addChild(new CoffeeCup());
+coffeeCup.x = 1024; // Center of screen
+coffeeCup.y = 2500; // Near bottom
+// Spawn functions
+function spawnBean() {
+ var beanTypes = ['espresso', 'arabica', 'robusta'];
+ var randomType = beanTypes[Math.floor(Math.random() * beanTypes.length)];
+ var newBean = new CoffeeBean(randomType);
+ newBean.x = Math.random() * (2048 - 100) + 50;
+ newBean.y = -50;
+ newBean.speed = 3 + gameSpeed;
+ beans.push(newBean);
+ game.addChild(newBean);
+}
+function spawnObstacle() {
+ var obstacleTypes = ['spilledMilk', 'sugarCube'];
+ var randomType = obstacleTypes[Math.floor(Math.random() * obstacleTypes.length)];
+ var newObstacle = new Obstacle(randomType);
+ newObstacle.x = Math.random() * (2048 - 100) + 50;
+ newObstacle.y = -50;
+ newObstacle.speed = 4 + gameSpeed;
+ obstacles.push(newObstacle);
+ game.addChild(newObstacle);
+}
+// Event handlers
+function handleMove(x, y, obj) {
+ if (dragNode) {
+ dragNode.x = Math.max(60, Math.min(1988, x));
+ }
+}
+game.move = handleMove;
+game.down = function (x, y, obj) {
+ if (coffeeCup.intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ dragNode = coffeeCup;
+ coffeeCup.isDragging = true;
+ handleMove(x, y, obj);
+ }
+};
+game.up = function (x, y, obj) {
+ if (dragNode) {
+ dragNode.isDragging = false;
+ dragNode = null;
+ }
+};
+// Update satisfaction display
+function updateSatisfactionDisplay() {
+ satisfactionTxt.setText('Satisfaction: ' + Math.round(customerSatisfaction) + '%');
+ if (customerSatisfaction > 70) {
+ satisfactionTxt.style.fill = "#00ff00";
+ } else if (customerSatisfaction > 30) {
+ satisfactionTxt.style.fill = "#ffff00";
+ } else {
+ satisfactionTxt.style.fill = "#ff0000";
+ }
+}
+// Main game loop
+game.update = function () {
+ spawnTimer++;
+ difficultyTimer++;
+ // Spawn beans and obstacles
+ if (spawnTimer % (90 - Math.floor(gameSpeed * 10)) === 0) {
+ spawnBean();
+ }
+ if (spawnTimer % 180 === 0) {
+ spawnObstacle();
+ }
+ // Increase difficulty over time
+ if (difficultyTimer % 1800 === 0) {
+ // Every 30 seconds
+ gameSpeed += 0.5;
+ }
+ // Update and check beans
+ for (var i = beans.length - 1; i >= 0; i--) {
+ var bean = beans[i];
+ if (bean.lastY === undefined) bean.lastY = bean.y;
+ // Check if bean is caught by cup
+ if (bean.intersects(coffeeCup)) {
+ LK.setScore(LK.getScore() + bean.points);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ LK.getSound('catch').play();
+ // Flash cup green
+ LK.effects.flashObject(coffeeCup, 0x00ff00, 300);
+ bean.destroy();
+ beans.splice(i, 1);
+ continue;
+ }
+ // Check if bean fell off screen
+ if (bean.lastY < 2732 && bean.y >= 2732) {
+ customerSatisfaction -= 2;
+ updateSatisfactionDisplay();
+ bean.destroy();
+ beans.splice(i, 1);
+ continue;
+ }
+ bean.lastY = bean.y;
+ }
+ // Update and check obstacles
+ for (var j = obstacles.length - 1; j >= 0; j--) {
+ var obstacle = obstacles[j];
+ if (obstacle.lastY === undefined) obstacle.lastY = obstacle.y;
+ // Check if obstacle hits cup
+ if (obstacle.intersects(coffeeCup)) {
+ LK.setScore(Math.max(0, LK.getScore() - obstacle.penalty));
+ scoreTxt.setText('Score: ' + LK.getScore());
+ customerSatisfaction -= obstacle.penalty;
+ updateSatisfactionDisplay();
+ LK.getSound('obstacle').play();
+ // Flash cup red
+ LK.effects.flashObject(coffeeCup, 0xff0000, 500);
+ obstacle.destroy();
+ obstacles.splice(j, 1);
+ continue;
+ }
+ // Remove obstacle if it falls off screen
+ if (obstacle.lastY < 2732 && obstacle.y >= 2732) {
+ obstacle.destroy();
+ obstacles.splice(j, 1);
+ continue;
+ }
+ obstacle.lastY = obstacle.y;
+ }
+ // Check win condition
+ if (LK.getScore() >= targetScore) {
+ LK.showYouWin();
+ }
+ // Check lose condition
+ if (customerSatisfaction <= 0) {
+ LK.showGameOver();
+ }
+ // Gradually decrease satisfaction over time
+ if (LK.ticks % 300 === 0) {
+ // Every 5 seconds
+ customerSatisfaction = Math.max(0, customerSatisfaction - 1);
+ updateSatisfactionDisplay();
+ }
+};
\ No newline at end of file
arabica bean. In-Game asset. 2d. High contrast. No shadows
coffee cup. In-Game asset. 2d. High contrast. No shadows
espresso bean. In-Game asset. 2d. High contrast. No shadows
robusta bean. In-Game asset. 2d. High contrast. No shadows
shop button. In-Game asset. 2d. High contrast. No shadows
spilled milk. In-Game asset. 2d. High contrast. No shadows
steam effect. In-Game asset. 2d. High contrast. No shadows
sugar cube. In-Game asset. 2d. High contrast. No shadows
coffee machine. In-Game asset. 2d. High contrast. No shadows
shelf. In-Game asset. 2d. High contrast. No shadows
tile. In-Game asset. 2d. High contrast. No shadows
wood counter. In-Game asset. 2d. High contrast. No shadows