Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'updateHeartType')' in or related to this line: 'self.updateHeartType = function (heartType) {' Line Number: 501
User prompt
add a function updateHeartType(heartType) in Projections
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: heartFrames is not defined' in or related to this line: 'heartFrames[self.heartType][i].alpha = Math.max(0, Math.min(1, 1 - (tapCount - (5 - i) * 5) / 10));' Line Number: 155
User prompt
Please fix the bug: 'Uncaught ReferenceError: heartFrames is not defined' in or related to this line: 'heartFrames[self.heartType][i].alpha = Math.max(0, Math.min(1, 1 - (tapCount - (5 - i) * 5) / 10));' Line Number: 154
User prompt
Please fix the bug: 'Uncaught ReferenceError: heartFrames is not defined' in or related to this line: 'self.currentGraphic = heartFrames[self.heartType][frameIndex];' Line Number: 146
User prompt
Please fix the bug: 'Uncaught ReferenceError: heartFrames is not defined' in or related to this line: 'self.currentGraphic = heartFrames[self.heartType][frameIndex];' Line Number: 146
User prompt
Please fix the bug: 'Uncaught ReferenceError: heartFrames is not defined' in or related to this line: 'self.currentGraphic = heartFrames[self.heartType][frameIndex];' Line Number: 133
User prompt
Please fix the bug: 'Uncaught ReferenceError: heartFrames is not defined' in or related to this line: 'self.currentGraphic = heartFrames[self.heartType][frameIndex];' Line Number: 133
User prompt
Please fix the bug: 'ReferenceError: heartFrames is not defined' in or related to this line: 'self.currentGraphic = heartFrames[self.heartType][5];' Line Number: 259
User prompt
after the explosion, switch to next heart type
Code edit (1 edits merged)
Please save this source code
User prompt
Analyze BigHeart deeply then make the hardcoded 50 limit of taps a property
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'explosionTriggered')' in or related to this line: 'if (!self.explosionTriggered) {' Line Number: 245
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'explosionTriggered')' in or related to this line: 'if (!self.explosionTriggered) {' Line Number: 245
Code edit (1 edits merged)
Please save this source code
User prompt
now add the 10 types of hearts in the heartFrames
Code edit (21 edits merged)
Please save this source code
User prompt
also extract the shake anim in a separate function
User prompt
Make BigHeart code more readable by extracting code in sepate functions
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
in Projections, for create variables for important values like scale, gravity, etc.. like it was done for speed and nbProjections. it's easier to tweak
===================================================================
--- original.js
+++ change.js
@@ -56,68 +56,26 @@
self.down = function (x, y, obj) {
// Play beat sound
LK.getSound('bump').play();
// Animate the size of the bigHeart to 1.5 times its original size over 0.5 seconds
- tween(self.currentGraphic, {
- scaleX: 1.2,
- scaleY: 1.2,
- x: 0
- }, {
- duration: 100,
- onFinish: function onFinish() {
- tween(self.currentGraphic, {
- scaleX: 1.1,
- scaleY: 1.1,
- x: 0
- }, {
- duration: 100
- });
- }
- });
- tween(self.nextGraphic, {
- scaleX: 1.2,
- scaleY: 1.2,
- x: 0
- }, {
- duration: 100,
- onFinish: function onFinish() {
- tween(self.nextGraphic, {
- scaleX: 1.1,
- scaleY: 1.1
- }, {
- duration: 100
- });
- }
- });
+ animateHeart(self.currentGraphic, 1.2, 1.1, 100);
+ if (!self.explosionTriggered) {
+ animateHeart(self.nextGraphic, 1.2, 1.1, 100);
+ }
log("Current indexes:: ", self.currentGraphic.index, ',', self.nextGraphic.index); // Log the tap count
// Increment tap counter
tapCount++; // Increment global tap counter
// Create a new heart projection using the current frame index
projectionsManager.popHearts(self.currentGraphic.heartType);
updateTapCountText(); // Update the text display
// Switch graphics based on tapCount
var frameIndex = 5 - Math.floor(tapCount / 10);
- if (tapCount < 50 && frameIndex > 0) {
+ if (!self.explosionTriggered && tapCount < 50 && frameIndex > 0) {
self.currentGraphic = heartFrames[frameIndex];
self.nextGraphic = heartFrames[frameIndex - 1];
} else if (tapCount >= 50) {
// Explosion
- if (!self.explosionTriggered) {
- LK.getSound('boom').play();
- // Animate explosion of nextGraphic when tapCount reaches 50
- LK.setTimeout(function () {
- tween(self.nextGraphic, {
- scaleX: 40,
- scaleY: 40,
- alpha: 0
- }, {
- duration: 3000,
- easing: tween.easeOut,
- onFinish: function onFinish() {}
- });
- }, 400);
- self.explosionTriggered = true; // Set flag to true after explosion
- }
+ triggerExplosion();
}
log("Tap count: ", self.tapCount); // Log the tap count
for (var i = 5; i >= 0; i--) {
heartFrames[i].alpha = Math.max(0, Math.min(1, 1 - (tapCount - (5 - i) * 10) / 10));
@@ -159,9 +117,9 @@
var heartSpeed = 20;
var gravity = 0.5;
var initialScale = 0.25;
var scaleVariation = 0.5;
- var alphaDecay = 0.005;
+ var alphaDecay = 0.002;
self.heartPool = [];
// Initialize heart pool
for (var i = 0; i < nbProjections * 5; i++) {
var heart = new Container();
@@ -178,9 +136,9 @@
this.x += this.vx;
this.y += this.vy;
this.vy += gravity; // Add gravity effect
this.alpha -= alphaDecay;
- if (this.alpha <= 0) {
+ if (this.alpha <= 0 || this.y > 2900) {
this.alpha = 0;
self.heartPool.push(this);
}
};
@@ -221,8 +179,44 @@
/****
* Game Code
****/
+function triggerExplosion() {
+ if (!self.explosionTriggered) {
+ LK.getSound('boom').play();
+ LK.setTimeout(function () {
+ tween(self.nextGraphic, {
+ scaleX: 45,
+ scaleY: 45,
+ alpha: 0
+ }, {
+ duration: 3000,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {}
+ });
+ }, 205);
+ self.explosionTriggered = true;
+ }
+}
+function animateHeart(graphic, scaleUp, scaleDown, duration) {
+ tween(graphic, {
+ scaleX: scaleUp,
+ scaleY: scaleUp,
+ x: 0
+ }, {
+ duration: duration,
+ onFinish: function onFinish() {
+ tween(graphic, {
+ scaleX: scaleDown,
+ scaleY: scaleDown,
+ x: 0
+ }, {
+ duration: duration
+ });
+ }
+ });
+}
+var nbHearts = 10;
var backgroundContainer = new Container();
var middlegroundContainer = new Container();
var foregroundContainer = new Container();
game.addChild(backgroundContainer);
a big lovely heart
a big stone heart
a big used copper heart
face view of a big bronze heart
face view of a big silver heart
Big shining gold heart verly slightly ornate. face view.
Big precious shiny porcelain heart slightly ornate. face view.
Large precious heart in mother-of-pearl, lightly ornate. Front view.
Large heart in precious ruby, very lightly decorated. Front view.
The most precious large heart in diamond, Front view.
clean pink enamel board witha very thin border