===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,330 @@
/****
* Classes
-****/
+****/
+// Replace basic particle graphics with enhanced ParticleGraphics
+// Ball class
+var Ball = Container.expand(function () {
+ var self = Container.call(this);
+ self.particlePool = new ParticlePool();
+ self.createParticle = function () {
+ var particle = this.particlePool.getParticle();
+ if (particle) {
+ particle.x = self.x;
+ particle.y = self.y;
+ particle.alpha = 1; // Reset particle alpha
+ if (!self.isDestroyed && game.children.includes(self)) {
+ game.addChildAt(particle, game.getChildIndex(self));
+ }
+ }
+ };
+ // Use BallGraphics for ball visuals
+ var ballGraphics = new BallGraphics();
+ var shadowGraphics = new ShadowGraphics();
+ shadowGraphics.y = ballGraphics.height * 0.1;
+ shadowGraphics.alpha = 0.5;
+ self.addChild(shadowGraphics);
+ self.addChild(ballGraphics);
+ self.speed = Math.random() * 3 + 2;
+ self.scoreValue = 1; // Default score value for each ball
+ self._move_migrated = function () {
+ var speedMultiplier = gameSettings.difficulty === 'hard' ? 4 : gameSettings.difficulty === 'insane' ? 10 : gameSettings.difficulty === 'easy' ? 1 : 2;
+ self.y += self.speed * speedMultiplier;
+ self.createParticle();
+ };
+ self.resetPosition = function () {
+ self.x = Math.random() * (2048 - ballGraphics.width) + ballGraphics.width / 2;
+ self.y = -ballGraphics.height;
+ };
+ self.isDestroyed = false;
+ self.resetPosition();
+});
+// BallGraphics class for enhanced ball visuals
+var BallGraphics = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('ball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Additional visual enhancements can be added here
+});
+// CoffeeBean class
+var CoffeeBean = Container.expand(function () {
+ var self = Container.call(this);
+ self.particlePool = new ParticlePool();
+ self.createParticle = function () {
+ var particle = this.particlePool.getParticle();
+ if (particle) {
+ particle.x = self.x;
+ particle.y = self.y;
+ particle.alpha = 1; // Reset particle alpha
+ if (!self.isDestroyed && game.children.includes(self)) {
+ game.addChildAt(particle, game.getChildIndex(self));
+ }
+ }
+ };
+ // Use CoffeeBeanGraphics for coffee bean visuals
+ var coffeeBeanGraphics = new CoffeeBeanGraphics();
+ var shadowGraphics = new ShadowGraphics();
+ shadowGraphics.y = coffeeBeanGraphics.height * 0.1;
+ shadowGraphics.alpha = 0.5;
+ self.addChild(shadowGraphics);
+ self.addChild(coffeeBeanGraphics);
+ self.speed = Math.random() * 3 + 2;
+ self.scoreValue = 5; // Default score value for each coffee bean
+ self._move_migrated = function () {
+ var speedMultiplier = gameSettings.difficulty === 'hard' ? 16 : gameSettings.difficulty === 'insane' ? 40 : gameSettings.difficulty === 'easy' ? 4 : 8;
+ self.y += self.speed * speedMultiplier;
+ self.createParticle();
+ if (self.y > 2732) {
+ self.isDestroyed = true;
+ }
+ };
+ self.resetPosition = function () {
+ self.x = Math.random() * (2048 - coffeeBeanGraphics.width) + coffeeBeanGraphics.width / 2;
+ self.y = -coffeeBeanGraphics.height;
+ };
+ self.isDestroyed = false;
+ self.resetPosition();
+});
+// CoffeeBeanGraphics class for enhanced coffee bean visuals
+var CoffeeBeanGraphics = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('coffeeBean', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Additional visual enhancements can be added here
+});
+// CoffeeCup class
+var CoffeeCup = Container.expand(function () {
+ var self = Container.call(this);
+ var cupGraphics = new CupGraphics();
+ self.addChild(cupGraphics);
+ self.x = 2048 / 2 - 100;
+ self.y = 2732 - cupGraphics.height / 2;
+ self.intersects = function (ball) {
+ var bounds = self.getBounds();
+ var ballBounds = ball.getBounds();
+ if (bounds.x < ballBounds.x + ballBounds.width && bounds.x + bounds.width > ballBounds.x && bounds.y < ballBounds.y + ballBounds.height && bounds.y + bounds.height > ballBounds.y) {
+ LK.setScore(LK.getScore() + ball.scoreValue);
+ if (!(ball instanceof TimerItem) && gameSettings.difficulty !== 'hard' && gameSettings.difficulty !== 'insane') {
+ countdownTimer.duration += 1;
+ } // Add time to the timer based on difficulty
+ updateScoreDisplay();
+ timerTxt.setText(countdownTimer.duration.toString()); // Update the timer display instantly
+ LK.effects.flashObject(ball, 0xffff00, 300); // Add a yellow glow effect to the ball for 300ms when caught
+ self.animate(); // Trigger cup animation when a ball is collected
+ return true;
+ }
+ return false;
+ };
+ self.animate = function () {
+ var originalScaleX = self.scale.x;
+ var originalScaleY = self.scale.y;
+ var scaleFactor = 1.1;
+ var animationFrames = 7.5;
+ var currentFrame = 0;
+ var grow = true;
+ function updateAnimation() {
+ if (currentFrame < animationFrames) {
+ if (grow) {
+ self.scale.x = originalScaleX * (1 + (scaleFactor - 1) * (currentFrame / animationFrames));
+ self.scale.y = originalScaleY * (1 + (scaleFactor - 1) * (currentFrame / animationFrames));
+ } else {
+ self.scale.x = originalScaleX * (1 + (scaleFactor - 1) * (1 - currentFrame / animationFrames));
+ self.scale.y = originalScaleY * (1 + (scaleFactor - 1) * (1 - currentFrame / animationFrames));
+ }
+ currentFrame++;
+ } else if (grow) {
+ grow = false;
+ currentFrame = 0;
+ } else {
+ self.scale.x = originalScaleX;
+ self.scale.y = originalScaleY;
+ LK.off('tick', updateAnimation);
+ }
+ }
+ if (!self.animationCooldown) {
+ self.animationCooldown = true;
+ LK.setTimeout(function () {
+ self.animationCooldown = false;
+ }, 500);
+ LK.on('tick', updateAnimation);
+ }
+ };
+});
+var Countdown = Container.expand(function () {
+ var self = Container.call(this);
+ Countdown.prototype.animateDownwards = function () {
+ var startY = self.y;
+ var endY = 2732 / 2 + 200; // Move 200 pixels downwards from the center
+ var frames = 20; // Animation duration of 1/3 second at 60FPS
+ var currentFrame = 0;
+ function updateAnimation() {
+ if (currentFrame < frames) {
+ var progress = currentFrame / frames;
+ self.y = startY + (endY - startY) * progress;
+ currentFrame++;
+ } else {
+ LK.off('tick', updateAnimation);
+ game.removeChild(self);
+ }
+ }
+ LK.on('tick', updateAnimation);
+ };
+ self.counter = 3;
+ var countdownText = new Text2(self.counter.toString(), {
+ size: 200,
+ fill: '#00ff00',
+ // Green color
+ stroke: '#000000',
+ // Black stroke
+ strokeThickness: 8,
+ // Stroke thickness
+ anchor: {
+ x: 0.5,
+ y: 0.5
+ }
+ });
+ self.addChild(countdownText);
+ countdownText.x = 2048 / 2;
+ countdownText.y = 2732 / 2;
+ self._update_migrated = function () {
+ if (self.counter > 0 && !self.countdownStarted) {
+ self.countdownStarted = true;
+ var countdownInterval = LK.setInterval(function () {
+ self.counter--;
+ countdownText.setText(self.counter.toString());
+ if (self.counter === 0) {
+ LK.clearInterval(countdownInterval);
+ self.animateDownwards();
+ isPaused = false; // Unpause the game after countdown
+ }
+ }, 1000);
+ }
+ };
+ LK.on('tick', self._update_migrated);
+});
+// CountdownTimer class to manage the 60-second countdown
+var CountdownTimer = Container.expand(function (duration, displayText, onComplete) {
+ var self = Container.call(this);
+ self.duration = duration;
+ self.displayText = displayText;
+ self.onComplete = onComplete;
+ self._update_migrated = function () {
+ if (!isPaused && LK.ticks % 60 == 0) {
+ if (self.duration > 0) {
+ self.duration--;
+ self.displayText.setText(self.duration.toString());
+ } else if (self.duration === 0) {
+ LK.showGameOver();
+ }
+ }
+ };
+});
+// CupGraphics class for enhanced cup visuals
+var CupGraphics = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('cup', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ // Additional visual enhancements can be added here
+});
+var DancingCup = Container.expand(function () {
+ var self = Container.call(this);
+ var cupGraphics = self.attachAsset('DancingCup', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(cupGraphics);
+ var animationSpeed = 0.1;
+ var animationDistance = 20;
+ var direction = 1;
+ cupGraphics.rotation = -35 * (Math.PI / 180);
+ self.updateDance = function () {
+ var rotationSpeed = 70 * (Math.PI / 180);
+ var stayDuration = 60; // 1 second at 60FPS
+ if (self.stayCounter > 0) {
+ self.stayCounter--;
+ return;
+ }
+ cupGraphics.rotation += (self.reverseAnimation ? -1 : 1) * direction * rotationSpeed;
+ if (Math.abs(cupGraphics.rotation) >= rotationSpeed) {
+ direction *= -1;
+ self.stayCounter = stayDuration;
+ }
+ };
+ self.stayCounter = 0;
+ LK.on('tick', self.updateDance);
+});
+var DancingCupAsset = Container.expand(function () {
+ var self = Container.call(this);
+ this.preload = function () {
+ var graphics = self.attachAsset('DancingCup', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ };
+ this.preload();
+});
+// Instantiate ExplosionAsset to preload the asset
+var Explosion = Container.expand(function () {
+ var self = Container.call(this);
+ var explosionGraphics = new ExplosionGraphics();
+ self.addChild(explosionGraphics);
+ self.lifeSpan = 30; // Frames until explosion fades out
+ self._update_migrated = function () {
+ self.alpha -= 1 / self.lifeSpan;
+ if (self.alpha <= 0) {
+ self.destroy();
+ } // Destroy explosion when faded out
+ };
+ LK.on('tick', self._update_migrated);
+});
+var ExplosionAsset = Container.expand(function () {
+ var self = Container.call(this);
+ this.preload = function () {
+ var graphics = self.attachAsset('explosion', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ };
+ this.preload();
+});
+var GUIAnimation = Container.expand(function (target, changeFactor, animationFrames, animationType, onComplete) {
+ var self = Container.call(this);
+ self.target = target;
+ self.changeFactor = changeFactor;
+ self.animationFrames = animationFrames;
+ self.currentFrame = 0;
+ self.animationType = animationType;
+ self.onComplete = onComplete;
+ self.updateAnimation = function () {
+ if (self.currentFrame < self.animationFrames) {
+ switch (self.animationType) {
+ case 'scale':
+ self.target.scale.x *= 1 - self.changeFactor * (self.currentFrame / self.animationFrames);
+ self.target.scale.y *= 1 - self.changeFactor * (self.currentFrame / self.animationFrames);
+ break;
+ case 'slide':
+ self.target.x += self.changeFactor * (self.currentFrame / self.animationFrames) * 2048; // Slide to the right
+ break;
+ // Other animation types can be added here
+ }
+ self.currentFrame++;
+ } else {
+ LK.off('tick', self.updateAnimation);
+ if (self.onComplete) {
+ self.onComplete();
+ }
+ }
+ };
+ self.start = function () {
+ LK.on('tick', self.updateAnimation);
+ };
+});
var GameModeGUI = Container.expand(function () {
var self = Container.call(this);
var gameModeGUIAsset = self.attachAsset('gameModeGUI', {
anchorX: 0.5,
@@ -69,37 +392,186 @@
insaneButton.scale.y /= 1.05;
}
});
});
-var ExplosionAsset = Container.expand(function () {
+var GameSettings = Container.expand(function () {
var self = Container.call(this);
- this.preload = function () {
- var graphics = self.attachAsset('explosion', {
- anchorX: 0.5,
- anchorY: 0.5
- });
+ self.soundEnabled = true;
+ self.difficulty = typeof LK.localStorage !== 'undefined' ? LK.localStorage.getItem('selectedDifficulty') || 'normal' : 'normal';
+ self.toggleSound = function () {
+ self.soundEnabled = !self.soundEnabled;
};
- this.preload();
+ self.setDifficulty = function (difficulty) {
+ self.difficulty = difficulty;
+ // Persist the selected difficulty
+ if (typeof LK.localStorage !== 'undefined') {
+ LK.localStorage.setItem('selectedDifficulty', difficulty);
+ }
+ };
+ self.setButtonTint = function (difficulty, tint) {
+ self.buttonTints[difficulty] = tint;
+ };
});
-var DancingCupAsset = Container.expand(function () {
+var HelpGUI = Container.expand(function () {
var self = Container.call(this);
- this.preload = function () {
- var graphics = self.attachAsset('DancingCup', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- };
- this.preload();
+ var helpAsset = self.attachAsset('helpAsset', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ helpAsset.tint = 0xD2B48C; // Light brown color
+ self.addChild(helpAsset);
+ helpAsset.x = 0;
+ helpAsset.y = 0;
+ // Add a home button to the help GUI
+ var homeButton = LK.getAsset('homeButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ homeButton.x = 850;
+ homeButton.y = -1250; // Position 1250 pixels above the center of the help GUI and 750 pixels to the right
+ self.addChild(homeButton);
+ homeButton.on('down', function () {
+ // Start the closing animation for the help GUI
+ var closingAnimationFrames = 30;
+ var currentClosingFrame = 0;
+ var startY = self.y;
+ var endY = 2732 + self.height / 2; // End position off-screen at the bottom
+ var startAlpha = self.alpha;
+ function animateClosing() {
+ if (currentClosingFrame < closingAnimationFrames) {
+ var progress = currentClosingFrame / closingAnimationFrames;
+ self.y = startY + (endY - startY) * progress;
+ self.alpha = startAlpha * (1 - progress);
+ currentClosingFrame++;
+ } else {
+ LK.off('tick', animateClosing);
+ game.removeChild(self);
+ }
+ }
+ LK.on('tick', animateClosing);
+ // Show the start GUI and settings GUI if they are not already visible
+ if (!game.children.includes(startScreen)) {
+ startScreen.x = 2048 / 2;
+ startScreen.y = 2732 / 2;
+ game.addChild(startScreen);
+ }
+ if (settingsGUI && !game.children.includes(settingsGUI)) {
+ game.addChild(settingsGUI);
+ settingsGUI.visible = true;
+ }
+ });
+ // Add information about the stagnant ball item
+ var ballInfoContainer = new Container();
+ var ballAsset = LK.getAsset('ball', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ ballAsset.rotation = 10 * (Math.PI / 180);
+ ballInfoContainer.addChild(ballAsset);
+ var ballInfoText = new Text2('Collect the coffee drop for +1 score. +1 on the \ncountdown for easy and normal gamemodes.', {
+ size: 50,
+ fill: '#ffffff',
+ anchor: {
+ x: 0,
+ y: 0.5
+ },
+ stroke: '#000000',
+ strokeThickness: 5
+ });
+ ballInfoText.x = ballAsset.width - 20;
+ ballInfoText.rotation = 5 * (Math.PI / 360);
+ ballInfoContainer.addChild(ballInfoText);
+ ballInfoContainer.x = -750;
+ ballInfoContainer.y = homeButton.y + homeButton.height + 50;
+ ballInfoText.y = ballAsset.height - 200;
+ self.addChild(ballInfoContainer);
+ // Add new coffee bean help below the ball help
+ var coffeeBeanInfoContainer = new Container();
+ var coffeeBeanAsset = LK.getAsset('coffeeBean', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ coffeeBeanAsset.rotation = 10 * (Math.PI / 180);
+ coffeeBeanInfoContainer.addChild(coffeeBeanAsset);
+ var coffeeBeanInfoText = new Text2('Collect the Coffee Bean for +5 score. +1 on the\ncountdown for easy and normal gamemodes.\n*WARNING! THIS ITEM FALLS DOWN FAST!*', {
+ size: 50,
+ fill: '#ffffff',
+ anchor: {
+ x: 0,
+ y: 0.5
+ },
+ stroke: '#000000',
+ strokeThickness: 5
+ });
+ coffeeBeanInfoText.x = coffeeBeanAsset.width - 20;
+ coffeeBeanInfoText.rotation = 5 * (Math.PI / 360);
+ coffeeBeanInfoContainer.addChild(coffeeBeanInfoText);
+ coffeeBeanInfoContainer.x = -750;
+ coffeeBeanInfoContainer.y = ballInfoContainer.y + ballInfoContainer.height + 50;
+ coffeeBeanInfoText.y = coffeeBeanAsset.height - 200;
+ self.addChild(coffeeBeanInfoContainer);
+ // Add new timer help below the coffee bean help
+ var timerInfoContainer = new Container();
+ var timerAsset = LK.getAsset('timerItem', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ timerAsset.rotation = 10 * (Math.PI / 180);
+ timerInfoContainer.addChild(timerAsset);
+ var timerInfoText = new Text2('Collect the Timer for +5 on the countdown.\n*WARNING! THIS ITEM FALLS DOWN FAST!*', {
+ size: 50,
+ fill: '#ffffff',
+ anchor: {
+ x: 0,
+ y: 0.5
+ },
+ stroke: '#000000',
+ strokeThickness: 5
+ });
+ timerInfoText.x = timerAsset.width - 20;
+ timerInfoText.rotation = 5 * (Math.PI / 360);
+ timerInfoContainer.addChild(timerInfoText);
+ timerInfoContainer.x = -750;
+ timerInfoContainer.y = coffeeBeanInfoContainer.y + coffeeBeanInfoContainer.height + 80; // Moved down by 50 pixels
+ timerInfoText.y = timerAsset.height - 200;
+ self.addChild(timerInfoContainer);
+ // Add new spinning spike help below the timer help
+ var spinningSpikeInfoContainer = new Container();
+ var spinningSpikeAsset = LK.getAsset('spinningSpike', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ spinningSpikeInfoContainer.addChild(spinningSpikeAsset);
+ var spinningSpikeInfoText = new Text2('*Avoid the spinning spike at all costs!*\nThis item will make you lose 10 score!', {
+ size: 50,
+ fill: '#ffffff',
+ anchor: {
+ x: 0,
+ y: 0.5
+ },
+ stroke: '#000000',
+ strokeThickness: 5
+ });
+ spinningSpikeInfoText.x = spinningSpikeAsset.width - 20;
+ spinningSpikeInfoText.rotation = 5 * (Math.PI / 360);
+ spinningSpikeInfoContainer.addChild(spinningSpikeInfoText);
+ spinningSpikeInfoContainer.x = -750;
+ spinningSpikeInfoContainer.y = timerInfoContainer.y + timerInfoContainer.height + 30;
+ self.addChild(spinningSpikeInfoContainer);
});
-var SplashAsset = Container.expand(function () {
+// Replace basic splash graphics with enhanced SplashGraphics
+// Function to create a splash effect
+var Particle = Container.expand(function () {
var self = Container.call(this);
- this.preload = function () {
- var graphics = self.attachAsset('splash', {
- anchorX: 0.5,
- anchorY: 0.5
- });
+ var particleGraphics = new ParticleGraphics();
+ self.addChild(particleGraphics);
+ self.lifeSpan = 60; // Frames until particle fades out
+ self._update_migrated = function () {
+ self.alpha -= 1 / self.lifeSpan;
+ if (self.alpha <= 0) {
+ self.destroy();
+ } // Destroy particle when faded out
};
- this.preload();
});
var ParticleAsset = Container.expand(function () {
var self = Container.call(this);
this.preload = function () {
@@ -109,92 +581,44 @@
});
};
this.preload();
});
-var TimerParticleAsset = Container.expand(function () {
+// Initialize the particle pool
+// ParticleGraphics class for enhanced particle visuals
+var ParticleGraphics = Container.expand(function () {
var self = Container.call(this);
- this.preload = function () {
- var graphics = self.attachAsset('timerParticle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- };
- this.preload();
-});
-// Instantiate ExplosionAsset to preload the asset
-var Explosion = Container.expand(function () {
- var self = Container.call(this);
- var explosionGraphics = new ExplosionGraphics();
- self.addChild(explosionGraphics);
- self.lifeSpan = 30; // Frames until explosion fades out
- self.update = function () {
- self.alpha -= 1 / self.lifeSpan;
- if (self.alpha <= 0) {
- self.destroy();
- } // Destroy explosion when faded out
- };
- LK.on('tick', self.update);
-});
-var DancingCup = Container.expand(function () {
- var self = Container.call(this);
- var cupGraphics = self.attachAsset('DancingCup', {
+ var graphics = LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
- self.addChild(cupGraphics);
- var animationSpeed = 0.1;
- var animationDistance = 20;
- var direction = 1;
- cupGraphics.rotation = -35 * (Math.PI / 180);
- self.updateDance = function () {
- var rotationSpeed = 70 * (Math.PI / 180);
- var stayDuration = 60; // 1 second at 60FPS
- if (self.stayCounter > 0) {
- self.stayCounter--;
- return;
- }
- cupGraphics.rotation += (self.reverseAnimation ? -1 : 1) * direction * rotationSpeed;
- if (Math.abs(cupGraphics.rotation) >= rotationSpeed) {
- direction *= -1;
- self.stayCounter = stayDuration;
- }
- };
- self.stayCounter = 0;
- LK.on('tick', self.updateDance);
+ self.addChild(graphics);
+ // Additional visual enhancements can be added here
});
-var StartButtonAnimation = Container.expand(function (startButton) {
+var ParticlePool = Container.expand(function () {
var self = Container.call(this);
- self.startButton = startButton;
- var minX = game.width / 2 - 10;
- var maxX = game.width / 2 + 10;
- var speed = 0.5; // Speed of the animation
- var direction = 1; // Start moving to the right
- self.updateAnimation = function () {
- if (!isPaused) {
- self.startButton.x += speed * direction;
- if (self.startButton.x > maxX || self.startButton.x < minX) {
- direction *= -1; // Reverse direction
+ self.pool = [];
+ self.maxParticles = 100;
+ self.getParticle = function () {
+ for (var i = 0; i < self.pool.length; i++) {
+ if (self.pool[i].alpha <= 0) {
+ return self.pool[i];
}
}
+ if (self.pool.length < self.maxParticles) {
+ var newParticle = new Particle();
+ self.pool.push(newParticle);
+ return newParticle;
+ }
+ return null;
};
- LK.on('tick', self.updateAnimation);
-});
-// CountdownTimer class to manage the 60-second countdown
-var CountdownTimer = Container.expand(function (duration, displayText, onComplete) {
- var self = Container.call(this);
- self.duration = duration;
- self.displayText = displayText;
- self.onComplete = onComplete;
- self.update = function () {
- if (!isPaused && LK.ticks % 60 == 0) {
- if (self.duration > 0) {
- self.duration--;
- self.displayText.setText(self.duration.toString());
- } else if (self.duration === 0) {
- LK.showGameOver();
+ self._update_migrated = function () {
+ self.pool.forEach(function (particle) {
+ if (particle.alpha > 0) {
+ particle._update_migrated();
}
- }
+ });
};
+ LK.on('tick', self._update_migrated);
});
var RotateAndZoomAnimation = Container.expand(function (target, zoomFactor, animationFrames, rotations) {
var self = Container.call(this);
self.target = target;
@@ -220,92 +644,8 @@
self.onComplete = onComplete;
LK.on('tick', self.updateAnimation);
};
});
-var Countdown = Container.expand(function () {
- var self = Container.call(this);
- Countdown.prototype.animateDownwards = function () {
- var startY = self.y;
- var endY = 2732 / 2 + 200; // Move 200 pixels downwards from the center
- var frames = 20; // Animation duration of 1/3 second at 60FPS
- var currentFrame = 0;
- function updateAnimation() {
- if (currentFrame < frames) {
- var progress = currentFrame / frames;
- self.y = startY + (endY - startY) * progress;
- currentFrame++;
- } else {
- LK.off('tick', updateAnimation);
- game.removeChild(self);
- }
- }
- LK.on('tick', updateAnimation);
- };
- self.counter = 3;
- var countdownText = new Text2(self.counter.toString(), {
- size: 200,
- fill: '#00ff00',
- // Green color
- stroke: '#000000',
- // Black stroke
- strokeThickness: 8,
- // Stroke thickness
- anchor: {
- x: 0.5,
- y: 0.5
- }
- });
- self.addChild(countdownText);
- countdownText.x = 2048 / 2;
- countdownText.y = 2732 / 2;
- self.update = function () {
- if (self.counter > 0 && !self.countdownStarted) {
- self.countdownStarted = true;
- var countdownInterval = LK.setInterval(function () {
- self.counter--;
- countdownText.setText(self.counter.toString());
- if (self.counter === 0) {
- LK.clearInterval(countdownInterval);
- self.animateDownwards();
- isPaused = false; // Unpause the game after countdown
- }
- }, 1000);
- }
- };
- LK.on('tick', self.update);
-});
-var GUIAnimation = Container.expand(function (target, changeFactor, animationFrames, animationType, onComplete) {
- var self = Container.call(this);
- self.target = target;
- self.changeFactor = changeFactor;
- self.animationFrames = animationFrames;
- self.currentFrame = 0;
- self.animationType = animationType;
- self.onComplete = onComplete;
- self.updateAnimation = function () {
- if (self.currentFrame < self.animationFrames) {
- switch (self.animationType) {
- case 'scale':
- self.target.scale.x *= 1 - self.changeFactor * (self.currentFrame / self.animationFrames);
- self.target.scale.y *= 1 - self.changeFactor * (self.currentFrame / self.animationFrames);
- break;
- case 'slide':
- self.target.x += self.changeFactor * (self.currentFrame / self.animationFrames) * 2048; // Slide to the right
- break;
- // Other animation types can be added here
- }
- self.currentFrame++;
- } else {
- LK.off('tick', self.updateAnimation);
- if (self.onComplete) {
- self.onComplete();
- }
- }
- };
- self.start = function () {
- LK.on('tick', self.updateAnimation);
- };
-});
var ScaleAnimation = Container.expand(function (target, scaleFactor, animationFrames) {
var self = Container.call(this);
self.target = target;
self.originalScaleX = target.scale.x;
@@ -329,25 +669,95 @@
self.onComplete = onComplete;
LK.on('tick', self.updateAnimation);
};
});
-var GameSettings = Container.expand(function () {
+// Initialize game settings
+var SettingsButton = Container.expand(function () {
var self = Container.call(this);
- self.soundEnabled = true;
- self.difficulty = typeof LK.localStorage !== 'undefined' ? LK.localStorage.getItem('selectedDifficulty') || 'normal' : 'normal';
- self.toggleSound = function () {
- self.soundEnabled = !self.soundEnabled;
- };
- self.setDifficulty = function (difficulty) {
- self.difficulty = difficulty;
- // Persist the selected difficulty
- if (typeof LK.localStorage !== 'undefined') {
- LK.localStorage.setItem('selectedDifficulty', difficulty);
+ var buttonGraphics = self.attachAsset('settingsButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(buttonGraphics);
+ self.x = 2048 - buttonGraphics.width / 2 - 60; // Position from the right edge and 50 pixels to the left
+ self.y = buttonGraphics.height / 2 + 60; // Position from the top edge and 50 pixels down
+ var settingsGUI = new SettingsGUI();
+ settingsGUI.x = 2048 / 2;
+ settingsGUI.y = 2732 / 2;
+ self.on('down', function (x, y, obj) {
+ if (game.children.includes(settingsGUI)) {
+ settingsGUI.animateClose();
+ } else if (!self.clickDisabled) {
+ self.pauseGame();
}
+ });
+ SettingsButton.prototype.pauseGame = function () {
+ timerTxt.visible = false;
+ scoreTxt.visible = false;
+ this.isDown = true;
+ var rotateAndZoomAnimation = new RotateAndZoomAnimation(this, 0.1, 5, 1);
+ rotateAndZoomAnimation.start(function () {
+ self.visible = false;
+ isPaused = true; // Pause the game when settings are opened
+ self.scale.x = 1;
+ self.scale.y = 1; // Reset scale after animation
+ if (startScreen.parent) {
+ LK.setTimeout(function () {
+ self.clickDisabled = false;
+ }, 1000); // Disable click for 1 second if start screen is up
+ } else {
+ LK.setTimeout(function () {
+ self.clickDisabled = false;
+ }, 4000); // Otherwise, disable click for 4 seconds
+ }
+ self.clickDisabled = true;
+ });
};
- self.setButtonTint = function (difficulty, tint) {
- self.buttonTints[difficulty] = tint;
- };
+ self.on('up', function (x, y, obj) {
+ if (self.isDown) {
+ self.isDown = false;
+ self.scale.x /= 1.05;
+ self.scale.y /= 1.05;
+ if (!settingsGUI || !game.children.includes(settingsGUI)) {
+ var animateFadeIn = function animateFadeIn() {
+ if (currentFrame < fadeInFrames) {
+ settingsGUI.alpha = currentFrame / fadeInFrames;
+ currentFrame++;
+ } else {
+ LK.off('tick', animateFadeIn);
+ }
+ };
+ settingsGUI = new SettingsGUI();
+ settingsGUI.x = 2048 / 2;
+ settingsGUI.y = 2732 / 2;
+ settingsGUI.alpha = 0; // Start with the GUI fully transparent
+ game.addChild(settingsGUI);
+ // Animate the GUI to fade in
+ var fadeInFrames = 30;
+ var currentFrame = 0;
+ LK.on('tick', animateFadeIn);
+ }
+ }
+ });
+ self.on('upoutside', function (obj) {
+ if (self.isDown) {
+ self.isDown = false;
+ self.scale.x /= 1.05;
+ self.scale.y /= 1.05;
+ }
+ });
+ self.on('over', function (obj) {
+ if (!self.isDown) {
+ self.scale.x *= 1.05;
+ self.scale.y *= 1.05;
+ }
+ });
+ self.on('out', function (obj) {
+ if (!self.isDown) {
+ self.scale.x /= 1.05;
+ self.scale.y /= 1.05;
+ }
+ });
});
var SettingsGUI = Container.expand(function () {
var self = Container.call(this);
function animateButtonZoom(button) {
@@ -429,9 +839,9 @@
}
if (!startScreen.parent) {
var countdown = new Countdown();
game.addChild(countdown);
- countdown.update();
+ countdown._update_migrated();
}
};
// Add difficulty selection buttons
var buttonPadding = 10;
@@ -608,96 +1018,8 @@
hardButton.tint = selectedDifficulty === 'hard' ? 0x66ff00 : 0xFF0000;
insaneButton.tint = selectedDifficulty === 'insane' ? 0x66ff00 : 0xFF0000;
}
});
-// Initialize game settings
-var SettingsButton = Container.expand(function () {
- var self = Container.call(this);
- var buttonGraphics = self.attachAsset('settingsButton', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.addChild(buttonGraphics);
- self.x = 2048 - buttonGraphics.width / 2 - 60; // Position from the right edge and 50 pixels to the left
- self.y = buttonGraphics.height / 2 + 60; // Position from the top edge and 50 pixels down
- var settingsGUI = new SettingsGUI();
- settingsGUI.x = 2048 / 2;
- settingsGUI.y = 2732 / 2;
- self.on('down', function (obj) {
- if (game.children.includes(settingsGUI)) {
- settingsGUI.animateClose();
- } else if (!self.clickDisabled) {
- self.pauseGame();
- }
- });
- SettingsButton.prototype.pauseGame = function () {
- timerTxt.visible = false;
- scoreTxt.visible = false;
- this.isDown = true;
- var rotateAndZoomAnimation = new RotateAndZoomAnimation(this, 0.1, 5, 1);
- rotateAndZoomAnimation.start(function () {
- self.visible = false;
- isPaused = true; // Pause the game when settings are opened
- self.scale.x = 1;
- self.scale.y = 1; // Reset scale after animation
- if (startScreen.parent) {
- LK.setTimeout(function () {
- self.clickDisabled = false;
- }, 1000); // Disable click for 1 second if start screen is up
- } else {
- LK.setTimeout(function () {
- self.clickDisabled = false;
- }, 4000); // Otherwise, disable click for 4 seconds
- }
- self.clickDisabled = true;
- });
- };
- self.on('up', function (obj) {
- if (self.isDown) {
- self.isDown = false;
- self.scale.x /= 1.05;
- self.scale.y /= 1.05;
- if (!settingsGUI || !game.children.includes(settingsGUI)) {
- var animateFadeIn = function animateFadeIn() {
- if (currentFrame < fadeInFrames) {
- settingsGUI.alpha = currentFrame / fadeInFrames;
- currentFrame++;
- } else {
- LK.off('tick', animateFadeIn);
- }
- };
- settingsGUI = new SettingsGUI();
- settingsGUI.x = 2048 / 2;
- settingsGUI.y = 2732 / 2;
- settingsGUI.alpha = 0; // Start with the GUI fully transparent
- game.addChild(settingsGUI);
- // Animate the GUI to fade in
- var fadeInFrames = 30;
- var currentFrame = 0;
- LK.on('tick', animateFadeIn);
- }
- }
- });
- self.on('upoutside', function (obj) {
- if (self.isDown) {
- self.isDown = false;
- self.scale.x /= 1.05;
- self.scale.y /= 1.05;
- }
- });
- self.on('over', function (obj) {
- if (!self.isDown) {
- self.scale.x *= 1.05;
- self.scale.y *= 1.05;
- }
- });
- self.on('out', function (obj) {
- if (!self.isDown) {
- self.scale.x /= 1.05;
- self.scale.y /= 1.05;
- }
- });
-});
// ShadowGraphics class for shadow visuals
var ShadowGraphics = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('shadow', {
@@ -705,174 +1027,8 @@
anchorY: 0.5
});
// Additional visual enhancements for shadow can be added here
});
-// Splash effect class
-var Splash = Container.expand(function () {
- var self = Container.call(this);
- // Replace basic splash graphics with enhanced SplashGraphics
- var splashGraphics = new SplashGraphics();
- self.addChild(splashGraphics);
- self.lifeSpan = 30; // Frames until splash fades out
- self.update = function () {
- self.alpha -= 1 / self.lifeSpan;
- if (self.alpha <= 0) {
- self.destroy();
- } // Destroy splash when faded out
- };
- LK.on('tick', self.update);
-});
-// SplashGraphics class for enhanced splash visuals
-var SplashGraphics = Container.expand(function () {
- var self = Container.call(this);
- var graphics = self.attachAsset('splash', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- // Additional visual enhancements can be added here
-});
-// Replace basic splash graphics with enhanced SplashGraphics
-// Function to create a splash effect
-var Particle = Container.expand(function () {
- var self = Container.call(this);
- var particleGraphics = new ParticleGraphics();
- self.addChild(particleGraphics);
- self.lifeSpan = 60; // Frames until particle fades out
- self.update = function () {
- self.alpha -= 1 / self.lifeSpan;
- if (self.alpha <= 0) {
- self.destroy();
- } // Destroy particle when faded out
- };
-});
-var ParticlePool = Container.expand(function () {
- var self = Container.call(this);
- self.pool = [];
- self.maxParticles = 100;
- self.getParticle = function () {
- for (var i = 0; i < self.pool.length; i++) {
- if (self.pool[i].alpha <= 0) {
- return self.pool[i];
- }
- }
- if (self.pool.length < self.maxParticles) {
- var newParticle = new Particle();
- self.pool.push(newParticle);
- return newParticle;
- }
- return null;
- };
- self.update = function () {
- self.pool.forEach(function (particle) {
- if (particle.alpha > 0) {
- particle.update();
- }
- });
- };
- LK.on('tick', self.update);
-});
-// TimerParticle class for unique TimerItem particle visuals
-var TimerParticle = Container.expand(function () {
- var self = Container.call(this);
- var graphics = self.attachAsset('timerParticle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.lifeSpan = 60; // Frames until particle fades out
- self.update = function () {
- self.alpha -= 1 / self.lifeSpan;
- if (self.alpha <= 0) {
- self.destroy();
- } // Destroy particle when faded out
- };
- LK.on('tick', self.update);
-});
-// TimerParticlePool class for pooling TimerItem's unique particles
-var TimerParticlePool = Container.expand(function () {
- var self = Container.call(this);
- self.pool = [];
- self.maxParticles = 100;
- self.getParticle = function () {
- for (var i = 0; i < self.pool.length; i++) {
- if (self.pool[i].alpha <= 0) {
- return self.pool[i];
- }
- }
- if (self.pool.length < self.maxParticles) {
- var newParticle = new TimerParticle();
- self.pool.push(newParticle);
- return newParticle;
- }
- return null;
- };
- self.update = function () {
- self.pool.forEach(function (particle) {
- if (particle.alpha > 0) {
- particle.update();
- }
- });
- };
- LK.on('tick', self.update);
-});
-// Initialize the particle pool
-// ParticleGraphics class for enhanced particle visuals
-var ParticleGraphics = Container.expand(function () {
- var self = Container.call(this);
- var graphics = LK.getAsset('particle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.addChild(graphics);
- // Additional visual enhancements can be added here
-});
-// CoffeeBean class
-var CoffeeBean = Container.expand(function () {
- var self = Container.call(this);
- self.particlePool = new ParticlePool();
- self.createParticle = function () {
- var particle = this.particlePool.getParticle();
- if (particle) {
- particle.x = self.x;
- particle.y = self.y;
- particle.alpha = 1; // Reset particle alpha
- if (!self.isDestroyed && game.children.includes(self)) {
- game.addChildAt(particle, game.getChildIndex(self));
- }
- }
- };
- // Use CoffeeBeanGraphics for coffee bean visuals
- var coffeeBeanGraphics = new CoffeeBeanGraphics();
- var shadowGraphics = new ShadowGraphics();
- shadowGraphics.y = coffeeBeanGraphics.height * 0.1;
- shadowGraphics.alpha = 0.5;
- self.addChild(shadowGraphics);
- self.addChild(coffeeBeanGraphics);
- self.speed = Math.random() * 3 + 2;
- self.scoreValue = 5; // Default score value for each coffee bean
- self.move = function () {
- var speedMultiplier = gameSettings.difficulty === 'hard' ? 16 : gameSettings.difficulty === 'insane' ? 40 : gameSettings.difficulty === 'easy' ? 4 : 8;
- self.y += self.speed * speedMultiplier;
- self.createParticle();
- if (self.y > 2732) {
- self.isDestroyed = true;
- }
- };
- self.resetPosition = function () {
- self.x = Math.random() * (2048 - coffeeBeanGraphics.width) + coffeeBeanGraphics.width / 2;
- self.y = -coffeeBeanGraphics.height;
- };
- self.isDestroyed = false;
- self.resetPosition();
-});
-// CoffeeBeanGraphics class for enhanced coffee bean visuals
-var CoffeeBeanGraphics = Container.expand(function () {
- var self = Container.call(this);
- var graphics = self.attachAsset('coffeeBean', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- // Additional visual enhancements can be added here
-});
// SpinningSpike class
var SpinningSpike = Container.expand(function () {
var self = Container.call(this);
var spikeGraphics = self.attachAsset('spinningSpike', {
@@ -882,9 +1038,9 @@
self.addChild(spikeGraphics);
self.speed = Math.random() * 3 + 2;
self.rotationSpeed = 4 * 2 * Math.PI; // 4 times per second
self.scoreValue = -10; // Deducts points when collected
- self.move = function () {
+ self._move_migrated = function () {
self.y += self.speed * 2; // Fall speed increased by 2 times
self.rotation += self.rotationSpeed / 60; // Game runs at 60FPS
if (self.y > 2732) {
self.isDestroyed = true;
@@ -895,161 +1051,59 @@
self.y = -spikeGraphics.height;
};
self.resetPosition();
});
-// Replace basic particle graphics with enhanced ParticleGraphics
-// Ball class
-var Ball = Container.expand(function () {
+// Splash effect class
+var Splash = Container.expand(function () {
var self = Container.call(this);
- self.particlePool = new ParticlePool();
- self.createParticle = function () {
- var particle = this.particlePool.getParticle();
- if (particle) {
- particle.x = self.x;
- particle.y = self.y;
- particle.alpha = 1; // Reset particle alpha
- if (!self.isDestroyed && game.children.includes(self)) {
- game.addChildAt(particle, game.getChildIndex(self));
- }
- }
+ // Replace basic splash graphics with enhanced SplashGraphics
+ var splashGraphics = new SplashGraphics();
+ self.addChild(splashGraphics);
+ self.lifeSpan = 30; // Frames until splash fades out
+ self._update_migrated = function () {
+ self.alpha -= 1 / self.lifeSpan;
+ if (self.alpha <= 0) {
+ self.destroy();
+ } // Destroy splash when faded out
};
- // Use BallGraphics for ball visuals
- var ballGraphics = new BallGraphics();
- var shadowGraphics = new ShadowGraphics();
- shadowGraphics.y = ballGraphics.height * 0.1;
- shadowGraphics.alpha = 0.5;
- self.addChild(shadowGraphics);
- self.addChild(ballGraphics);
- self.speed = Math.random() * 3 + 2;
- self.scoreValue = 1; // Default score value for each ball
- self.move = function () {
- var speedMultiplier = gameSettings.difficulty === 'hard' ? 4 : gameSettings.difficulty === 'insane' ? 10 : gameSettings.difficulty === 'easy' ? 1 : 2;
- self.y += self.speed * speedMultiplier;
- self.createParticle();
- };
- self.resetPosition = function () {
- self.x = Math.random() * (2048 - ballGraphics.width) + ballGraphics.width / 2;
- self.y = -ballGraphics.height;
- };
- self.isDestroyed = false;
- self.resetPosition();
+ LK.on('tick', self._update_migrated);
});
-// TimerItem class
-var TimerItem = Container.expand(function () {
+var SplashAsset = Container.expand(function () {
var self = Container.call(this);
- var timerItemGraphics = self.attachAsset('timerItem', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- var shadowGraphics = new ShadowGraphics();
- shadowGraphics.y = timerItemGraphics.height * 0.1;
- shadowGraphics.alpha = 0.5;
- self.addChild(shadowGraphics);
- self.addChild(timerItemGraphics);
- self.speed = Math.random() * 3 + 2;
- self.move = function () {
- var speedMultiplier = gameSettings.difficulty === 'hard' ? 12 : gameSettings.difficulty === 'insane' ? 30 : gameSettings.difficulty === 'easy' ? 3 : 6;
- self.y += self.speed * speedMultiplier;
- self.createParticle();
- if (self.y > 2732) {
- self.isDestroyed = true;
- }
+ this.preload = function () {
+ var graphics = self.attachAsset('splash', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
};
- self.resetPosition = function () {
- self.x = Math.random() * (2048 - timerItemGraphics.width) + timerItemGraphics.width / 2;
- self.y = -timerItemGraphics.height;
- };
- self.isDestroyed = false;
- self.resetPosition();
- self.particlePool = new TimerParticlePool();
- self.createParticle = function () {
- var particle = self.particlePool.getParticle();
- if (particle) {
- particle.x = self.x;
- particle.y = self.y;
- particle.alpha = 1; // Reset particle alpha
- if (!self.isDestroyed && game.children.includes(self)) {
- game.addChildAt(particle, game.getChildIndex(self));
- }
- }
- };
+ this.preload();
});
-// BallGraphics class for enhanced ball visuals
-var BallGraphics = Container.expand(function () {
+// SplashGraphics class for enhanced splash visuals
+var SplashGraphics = Container.expand(function () {
var self = Container.call(this);
- var graphics = self.attachAsset('ball', {
+ var graphics = self.attachAsset('splash', {
anchorX: 0.5,
anchorY: 0.5
});
// Additional visual enhancements can be added here
});
-// CoffeeCup class
-var CoffeeCup = Container.expand(function () {
+var StartButtonAnimation = Container.expand(function (startButton) {
var self = Container.call(this);
- var cupGraphics = new CupGraphics();
- self.addChild(cupGraphics);
- self.x = 2048 / 2 - 100;
- self.y = 2732 - cupGraphics.height / 2;
- self.intersects = function (ball) {
- var bounds = self.getBounds();
- var ballBounds = ball.getBounds();
- if (bounds.x < ballBounds.x + ballBounds.width && bounds.x + bounds.width > ballBounds.x && bounds.y < ballBounds.y + ballBounds.height && bounds.y + bounds.height > ballBounds.y) {
- LK.setScore(LK.getScore() + ball.scoreValue);
- if (!(ball instanceof TimerItem) && gameSettings.difficulty !== 'hard' && gameSettings.difficulty !== 'insane') {
- countdownTimer.duration += 1;
- } // Add time to the timer based on difficulty
- updateScoreDisplay();
- timerTxt.setText(countdownTimer.duration.toString()); // Update the timer display instantly
- LK.effects.flashObject(ball, 0xffff00, 300); // Add a yellow glow effect to the ball for 300ms when caught
- self.animate(); // Trigger cup animation when a ball is collected
- return true;
- }
- return false;
- };
- self.animate = function () {
- var originalScaleX = self.scale.x;
- var originalScaleY = self.scale.y;
- var scaleFactor = 1.1;
- var animationFrames = 7.5;
- var currentFrame = 0;
- var grow = true;
- function updateAnimation() {
- if (currentFrame < animationFrames) {
- if (grow) {
- self.scale.x = originalScaleX * (1 + (scaleFactor - 1) * (currentFrame / animationFrames));
- self.scale.y = originalScaleY * (1 + (scaleFactor - 1) * (currentFrame / animationFrames));
- } else {
- self.scale.x = originalScaleX * (1 + (scaleFactor - 1) * (1 - currentFrame / animationFrames));
- self.scale.y = originalScaleY * (1 + (scaleFactor - 1) * (1 - currentFrame / animationFrames));
- }
- currentFrame++;
- } else if (grow) {
- grow = false;
- currentFrame = 0;
- } else {
- self.scale.x = originalScaleX;
- self.scale.y = originalScaleY;
- LK.off('tick', updateAnimation);
+ self.startButton = startButton;
+ var minX = game.width / 2 - 10;
+ var maxX = game.width / 2 + 10;
+ var speed = 0.5; // Speed of the animation
+ var direction = 1; // Start moving to the right
+ self.updateAnimation = function () {
+ if (!isPaused) {
+ self.startButton.x += speed * direction;
+ if (self.startButton.x > maxX || self.startButton.x < minX) {
+ direction *= -1; // Reverse direction
}
}
- if (!self.animationCooldown) {
- self.animationCooldown = true;
- LK.setTimeout(function () {
- self.animationCooldown = false;
- }, 500);
- LK.on('tick', updateAnimation);
- }
};
+ LK.on('tick', self.updateAnimation);
});
-// CupGraphics class for enhanced cup visuals
-var CupGraphics = Container.expand(function () {
- var self = Container.call(this);
- var graphics = self.attachAsset('cup', {
- anchorX: 0.5,
- anchorY: 1
- });
- // Additional visual enhancements can be added here
-});
var StartScreen = Container.expand(function () {
var self = Container.call(this);
var startScreenBackground = self.attachAsset('startScreen', {
anchorX: 0.5,
@@ -1139,167 +1193,113 @@
});
closeAnimation.start();
});
});
-var HelpGUI = Container.expand(function () {
+// TimerItem class
+var TimerItem = Container.expand(function () {
var self = Container.call(this);
- var helpAsset = self.attachAsset('helpAsset', {
+ var timerItemGraphics = self.attachAsset('timerItem', {
anchorX: 0.5,
anchorY: 0.5
});
- helpAsset.tint = 0xD2B48C; // Light brown color
- self.addChild(helpAsset);
- helpAsset.x = 0;
- helpAsset.y = 0;
- // Add a home button to the help GUI
- var homeButton = LK.getAsset('homeButton', {
+ var shadowGraphics = new ShadowGraphics();
+ shadowGraphics.y = timerItemGraphics.height * 0.1;
+ shadowGraphics.alpha = 0.5;
+ self.addChild(shadowGraphics);
+ self.addChild(timerItemGraphics);
+ self.speed = Math.random() * 3 + 2;
+ self._move_migrated = function () {
+ var speedMultiplier = gameSettings.difficulty === 'hard' ? 12 : gameSettings.difficulty === 'insane' ? 30 : gameSettings.difficulty === 'easy' ? 3 : 6;
+ self.y += self.speed * speedMultiplier;
+ self.createParticle();
+ if (self.y > 2732) {
+ self.isDestroyed = true;
+ }
+ };
+ self.resetPosition = function () {
+ self.x = Math.random() * (2048 - timerItemGraphics.width) + timerItemGraphics.width / 2;
+ self.y = -timerItemGraphics.height;
+ };
+ self.isDestroyed = false;
+ self.resetPosition();
+ self.particlePool = new TimerParticlePool();
+ self.createParticle = function () {
+ var particle = self.particlePool.getParticle();
+ if (particle) {
+ particle.x = self.x;
+ particle.y = self.y;
+ particle.alpha = 1; // Reset particle alpha
+ if (!self.isDestroyed && game.children.includes(self)) {
+ game.addChildAt(particle, game.getChildIndex(self));
+ }
+ }
+ };
+});
+// TimerParticle class for unique TimerItem particle visuals
+var TimerParticle = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('timerParticle', {
anchorX: 0.5,
anchorY: 0.5
});
- homeButton.x = 850;
- homeButton.y = -1250; // Position 1250 pixels above the center of the help GUI and 750 pixels to the right
- self.addChild(homeButton);
- homeButton.on('down', function () {
- // Start the closing animation for the help GUI
- var closingAnimationFrames = 30;
- var currentClosingFrame = 0;
- var startY = self.y;
- var endY = 2732 + self.height / 2; // End position off-screen at the bottom
- var startAlpha = self.alpha;
- function animateClosing() {
- if (currentClosingFrame < closingAnimationFrames) {
- var progress = currentClosingFrame / closingAnimationFrames;
- self.y = startY + (endY - startY) * progress;
- self.alpha = startAlpha * (1 - progress);
- currentClosingFrame++;
- } else {
- LK.off('tick', animateClosing);
- game.removeChild(self);
+ self.lifeSpan = 60; // Frames until particle fades out
+ self._update_migrated = function () {
+ self.alpha -= 1 / self.lifeSpan;
+ if (self.alpha <= 0) {
+ self.destroy();
+ } // Destroy particle when faded out
+ };
+ LK.on('tick', self._update_migrated);
+});
+var TimerParticleAsset = Container.expand(function () {
+ var self = Container.call(this);
+ this.preload = function () {
+ var graphics = self.attachAsset('timerParticle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ };
+ this.preload();
+});
+// TimerParticlePool class for pooling TimerItem's unique particles
+var TimerParticlePool = Container.expand(function () {
+ var self = Container.call(this);
+ self.pool = [];
+ self.maxParticles = 100;
+ self.getParticle = function () {
+ for (var i = 0; i < self.pool.length; i++) {
+ if (self.pool[i].alpha <= 0) {
+ return self.pool[i];
}
}
- LK.on('tick', animateClosing);
- // Show the start GUI and settings GUI if they are not already visible
- if (!game.children.includes(startScreen)) {
- startScreen.x = 2048 / 2;
- startScreen.y = 2732 / 2;
- game.addChild(startScreen);
+ if (self.pool.length < self.maxParticles) {
+ var newParticle = new TimerParticle();
+ self.pool.push(newParticle);
+ return newParticle;
}
- if (settingsGUI && !game.children.includes(settingsGUI)) {
- game.addChild(settingsGUI);
- settingsGUI.visible = true;
- }
- });
- // Add information about the stagnant ball item
- var ballInfoContainer = new Container();
- var ballAsset = LK.getAsset('ball', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- ballAsset.rotation = 10 * (Math.PI / 180);
- ballInfoContainer.addChild(ballAsset);
- var ballInfoText = new Text2('Collect the coffee drop for +1 score. +1 on the \ncountdown for easy and normal gamemodes.', {
- size: 50,
- fill: '#ffffff',
- anchor: {
- x: 0,
- y: 0.5
- },
- stroke: '#000000',
- strokeThickness: 5
- });
- ballInfoText.x = ballAsset.width - 20;
- ballInfoText.rotation = 5 * (Math.PI / 360);
- ballInfoContainer.addChild(ballInfoText);
- ballInfoContainer.x = -750;
- ballInfoContainer.y = homeButton.y + homeButton.height + 50;
- ballInfoText.y = ballAsset.height - 200;
- self.addChild(ballInfoContainer);
- // Add new coffee bean help below the ball help
- var coffeeBeanInfoContainer = new Container();
- var coffeeBeanAsset = LK.getAsset('coffeeBean', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- coffeeBeanAsset.rotation = 10 * (Math.PI / 180);
- coffeeBeanInfoContainer.addChild(coffeeBeanAsset);
- var coffeeBeanInfoText = new Text2('Collect the Coffee Bean for +5 score. +1 on the\ncountdown for easy and normal gamemodes.\n*WARNING! THIS ITEM FALLS DOWN FAST!*', {
- size: 50,
- fill: '#ffffff',
- anchor: {
- x: 0,
- y: 0.5
- },
- stroke: '#000000',
- strokeThickness: 5
- });
- coffeeBeanInfoText.x = coffeeBeanAsset.width - 20;
- coffeeBeanInfoText.rotation = 5 * (Math.PI / 360);
- coffeeBeanInfoContainer.addChild(coffeeBeanInfoText);
- coffeeBeanInfoContainer.x = -750;
- coffeeBeanInfoContainer.y = ballInfoContainer.y + ballInfoContainer.height + 50;
- coffeeBeanInfoText.y = coffeeBeanAsset.height - 200;
- self.addChild(coffeeBeanInfoContainer);
- // Add new timer help below the coffee bean help
- var timerInfoContainer = new Container();
- var timerAsset = LK.getAsset('timerItem', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- timerAsset.rotation = 10 * (Math.PI / 180);
- timerInfoContainer.addChild(timerAsset);
- var timerInfoText = new Text2('Collect the Timer for +5 on the countdown.\n*WARNING! THIS ITEM FALLS DOWN FAST!*', {
- size: 50,
- fill: '#ffffff',
- anchor: {
- x: 0,
- y: 0.5
- },
- stroke: '#000000',
- strokeThickness: 5
- });
- timerInfoText.x = timerAsset.width - 20;
- timerInfoText.rotation = 5 * (Math.PI / 360);
- timerInfoContainer.addChild(timerInfoText);
- timerInfoContainer.x = -750;
- timerInfoContainer.y = coffeeBeanInfoContainer.y + coffeeBeanInfoContainer.height + 80; // Moved down by 50 pixels
- timerInfoText.y = timerAsset.height - 200;
- self.addChild(timerInfoContainer);
- // Add new spinning spike help below the timer help
- var spinningSpikeInfoContainer = new Container();
- var spinningSpikeAsset = LK.getAsset('spinningSpike', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- spinningSpikeInfoContainer.addChild(spinningSpikeAsset);
- var spinningSpikeInfoText = new Text2('*Avoid the spinning spike at all costs!*\nThis item will make you lose 10 score!', {
- size: 50,
- fill: '#ffffff',
- anchor: {
- x: 0,
- y: 0.5
- },
- stroke: '#000000',
- strokeThickness: 5
- });
- spinningSpikeInfoText.x = spinningSpikeAsset.width - 20;
- spinningSpikeInfoText.rotation = 5 * (Math.PI / 360);
- spinningSpikeInfoContainer.addChild(spinningSpikeInfoText);
- spinningSpikeInfoContainer.x = -750;
- spinningSpikeInfoContainer.y = timerInfoContainer.y + timerInfoContainer.height + 30;
- self.addChild(spinningSpikeInfoContainer);
+ return null;
+ };
+ self._update_migrated = function () {
+ self.pool.forEach(function (particle) {
+ if (particle.alpha > 0) {
+ particle._update_migrated();
+ }
+ });
+ };
+ LK.on('tick', self._update_migrated);
});
/****
* Initialize Game
-****/
+****/
// Replace basic cup graphics with enhanced CupGraphics
var game = new LK.Game({
backgroundColor: 0x00000000 //Set game background to invisible
});
/****
* Game Code
-****/
+****/
// Instantiate ExplosionAsset to preload the asset
// Function to create a splash effect
// Replace basic splash graphics with enhanced SplashGraphics
// Function to create a splash effect
@@ -1316,9 +1316,9 @@
}
function updateFallingObjects() {
// Move existing falling objects
balls.forEach(function (ball) {
- ball.move();
+ ball._move_migrated();
});
// Handle off-screen falling objects
for (var i = balls.length - 1; i >= 0; i--) {
if (balls[i].y > game.height || balls[i].isDestroyed) {
@@ -1466,18 +1466,18 @@
}
// Create a function to handle dragging the cup
function handleDrag(obj) {
var event = obj.event;
- var pos = event.getLocalPosition(game);
+ var pos = game.toLocal(event.global);
cup.x = pos.x;
}
// Add event listeners for dragging the cup
-game.on('down', function (obj) {
+game.on('down', function (x, y, obj) {
if (!isPaused) {
handleDrag(obj);
}
});
-game.on('move', function (obj) {
+game.on('move', function (x, y, obj) {
if (!isPaused) {
handleDrag(obj);
}
});
@@ -1505,9 +1505,9 @@
LK.showGameOver();
});
LK.on('tick', function () {
// Update the countdown timer
- countdownTimer.update();
+ countdownTimer._update_migrated();
// Handle collisions
handleCollisions();
// Update falling objects
if (!isPaused) {
Coffee splashing effect. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No Shadows.
Clock, Nothing else in the image.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A white particle trail, vertical. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Remove the plus from this image
White rectangle, curved corners. Small black border. Simple, modern. Aspect ratio 1550 * 2500.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Include only the spike.
Remove the bottom part that is not coming from the center explosion
scatola vuota, ma colorata con scritta candy. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
caramella. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
vietate caramelle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
scatola caramelle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
scritta caramelle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
scritta game mode con sfondo caramelle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
punto di domanda a modi caramelle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
casa di caramelle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
caramella con scritta start. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
goccia caramella. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.