User prompt
if an object is above y=0, start the gameovertimer (3 seconds) flash the screen red every second, if the timer is over check again if an object is above y=0 then go game over, if there is none then continiue the game like normal
User prompt
remove the ball spawning cooldown
User prompt
add score when balls merge
User prompt
also add points for every new merged ball not only the new spawned balls
User prompt
if an object is above y=0 instead of going game over instantly, start the game over timer (3 seconds) flash the screen red every second, if the timer is over check again if an object is above y=0 then go game over, if there is none then continiue the game like normal
User prompt
when an object gets above y=0 go game over
User prompt
Migrate to the latest version of LK
User prompt
Replace getBallColor with a custom function
User prompt
replace newBall.getAssetColor by a custom function
User prompt
make the background color a darker version of the last spawned ball
User prompt
make the background a darker version of the last dropped ball
User prompt
make a multiplier when balls merge
User prompt
make a multiplier
User prompt
showmultiplier in the top right
User prompt
make a multiplier
User prompt
add a ball merging multiplier
User prompt
modefy the code so that merging balls gives +1 score
User prompt
modefy the code so that merging balls gives +1 score
User prompt
if balls merge add one to the score, keep the normal score
User prompt
change the score so each merge should be the normal score +1
User prompt
halve the size of each ball
User prompt
make it impossible for balls to clip into eachother
User prompt
what you changed is good, but make the bounce on collissiong with other balls less
User prompt
make the balls bounce less
User prompt
what you changed is good, but make the bounce on collide less
===================================================================
--- original.js
+++ change.js
@@ -1,51 +1,7 @@
/****
* Classes
-****/
-// Class to display the next ball type in the top left corner
-var NextBallDisplay = Container.expand(function (type) {
- var self = Container.call(this);
- self.nextBallGraphic = self.attachAsset('ball' + type, {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 100,
- // Position x-coordinate
- y: 100,
- // Position y-coordinate
- width: 100,
- // Set width to 100
- height: 100 // Set height to 100
- });
- self.updateNextBallType = function (type) {
- self.removeChild(self.nextBallGraphic);
- self.nextBallGraphic = self.attachAsset('ball' + type, {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 100,
- // Position x-coordinate
- y: 100,
- // Position y-coordinate
- width: 100,
- // Set width to 100
- height: 100 // Set height to 100
- });
- };
-});
-var Score = Container.expand(function () {
- var self = Container.call(this);
- var scoreText = new Text2('0', {
- size: 150,
- fill: "#ffffff"
- });
- self.addChild(scoreText);
- self.value = 0;
- self.updateScore = function () {
- self.value = balls.reduce(function (score, ball) {
- return score + Math.pow(2, parseBallType(ball.type) - 1);
- }, 0);
- scoreText.setText(self.value.toString());
- };
-});
+****/
// Ball class to represent the game balls
var Ball = Container.expand(function (type) {
var self = Container.call(this);
var assetId = 'ball' + type;
@@ -101,45 +57,65 @@
// Increase the score when balls merge
LK.setScore(LK.getScore() + 1);
};
});
+// Class to display the next ball type in the top left corner
+var NextBallDisplay = Container.expand(function (type) {
+ var self = Container.call(this);
+ self.nextBallGraphic = self.attachAsset('ball' + type, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 100,
+ // Position x-coordinate
+ y: 100,
+ // Position y-coordinate
+ width: 100,
+ // Set width to 100
+ height: 100 // Set height to 100
+ });
+ self.updateNextBallType = function (type) {
+ self.removeChild(self.nextBallGraphic);
+ self.nextBallGraphic = self.attachAsset('ball' + type, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 100,
+ // Position x-coordinate
+ y: 100,
+ // Position y-coordinate
+ width: 100,
+ // Set width to 100
+ height: 100 // Set height to 100
+ });
+ };
+});
+var Score = Container.expand(function () {
+ var self = Container.call(this);
+ var scoreText = new Text2('0', {
+ size: 150,
+ fill: "#ffffff"
+ });
+ self.addChild(scoreText);
+ self.value = 0;
+ self.updateScore = function () {
+ self.value = balls.reduce(function (score, ball) {
+ return score + Math.pow(2, parseBallType(ball.type) - 1);
+ }, 0);
+ scoreText.setText(self.value.toString());
+ };
+});
/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
-****/
+****/
// Initialize an array to keep track of all balls
// Define ball assets with increasing sizes and colors for each upgrade level
-function customGetBallColor(type) {
- switch (type) {
- case '1':
- return 0xff0000;
- case '2':
- return 0xff0095;
- case '3':
- return 0x430094;
- case '4':
- return 0x0400ff;
- case '5':
- return 0x4a86e8;
- case '6':
- return 0x00ff88;
- case '7':
- return 0x00ff04;
- case '8':
- return 0x006607;
- case '9':
- return 0xd4ff00;
- default:
- return 0xff0000;
- }
-}
function calculateNextBallType(ballCount) {
var ballType = '1';
if (ballCount > 50) {
var rand = Math.random();
@@ -189,10 +165,9 @@
// Event listener for spawning balls on touch
var ballCount = 0;
var canThrowBall = true;
var nextBallType = '1'; // Pre-calculate the next ball type
-var lastBallColor = 0x000000; // Store the color of the last spawned ball
-game.on('down', function (obj) {
+game.on('down', function (x, y, obj) {
if (canThrowBall) {
var ballTypesToString = function ballTypesToString(ballsArray) {
var counts = {};
ballsArray.forEach(function (ball) {
@@ -202,17 +177,14 @@
return 'Type ' + type + ': ' + counts[type];
}).join(', ');
};
canThrowBall = false;
- var event = obj.event;
- var pos = event.getLocalPosition(game);
+ var event = obj;
+ var pos = game.toLocal(event.global);
var ballType = nextBallType; // Use the precalculated ball type
var newBall = new Ball(ballType);
newBall.x = pos.x + (Math.random() * 20 - 10);
newBall.y = 300 + (Math.random() * 20 - 10);
- // Update the background color to a darker version of the last spawned ball
- lastBallColor = darkenColor(customGetBallColor(newBall.type), 0.5);
- game.setBackgroundColor(lastBallColor);
// Update the next ball type display
nextBallDisplay.updateNextBallType(ballType);
balls.push(newBall);
game.addChild(newBall);
@@ -225,18 +197,8 @@
nextBallDisplay.updateNextBallType(nextBallType); // Update the display with the new next ball type
}, 1000);
}
});
-// Utility function to darken a color
-function darkenColor(color, factor) {
- var r = color >> 16 & 0xFF;
- var g = color >> 8 & 0xFF;
- var b = color & 0xFF;
- r = Math.floor(r * factor);
- g = Math.floor(g * factor);
- b = Math.floor(b * factor);
- return r << 16 | g << 8 | b;
-}
// Main game update loop
LK.on('tick', function () {
score.updateScore();
// Apply gravity to each ball