User prompt
Please fix the bug: 'Cannot read properties of undefined (reading '0')' in or related to this line: 'self.tapLimit = TAPS_PER_LEVEL[0]; // Initialize tap limit' Line Number: 141
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading '0')' in or related to this line: 'self.tapLimit = TAPS_PER_LEVEL[0]; // Initialize tap limit' Line Number: 141
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading '0')' in or related to this line: 'self.tapLimit = TAPS_PER_LEVEL[0]; // Initialize tap limit' Line Number: 141
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading '0')' in or related to this line: 'self.tapLimit = TAPS_PER_LEVEL[0]; // Initialize tap limit' Line Number: 141
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading '0')' in or related to this line: 'self.tapLimit = TAPS_PER_LEVEL[0]; // Initialize tap limit' Line Number: 141
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'TAPS_PER_LEVEL')' in or related to this line: 'self.tapLimit = progressManager.TAPS_PER_LEVEL[0]; // Initialize tap limit' Line Number: 141
Code edit (4 edits merged)
Please save this source code
User prompt
extract the tapsPerLevel from progressManager class to a global constant
User prompt
is idDebug, Set debug cost for Generators to respectivly 10, 11 and 12
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'tapsPerLevel')' in or related to this line: 'bigHeart.nbTapsPerFrame = progressManager.tapsPerLevel[0] / 6; // Initialize number of taps per frame based on level 0' Line Number: 1050
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'tapsPerLevel')' in or related to this line: 'self.nbTapsPerFrame = progressManager.tapsPerLevel[0] / 6; // Initialize number of taps per frame based on level 0' Line Number: 141
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'tapsPerLevel')' in or related to this line: 'self.nbTapsPerFrame = progressManager.tapsPerLevel[0] / 6; // Initialize number of taps per frame based on level 0' Line Number: 141
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'tapsPerLevel')' in or related to this line: 'self.nbTapsPerFrame = progressManager.tapsPerLevel[0] / 6; // Initialize number of taps per frame based on level 0' Line Number: 141
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '1')' in or related to this line: 'self.currentGraphic = self.heartFrames[self.heartType][5];' Line Number: 746
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '1')' in or related to this line: 'self.currentGraphic = self.heartFrames[self.heartType][5];' Line Number: 754
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '1')' in or related to this line: 'self.currentGraphic = self.heartFrames[self.heartType][5];' Line Number: 788
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '1')' in or related to this line: 'self.currentGraphic = self.heartFrames[self.heartType][5];' Line Number: 772
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '1')' in or related to this line: 'self.currentGraphic = self.heartFrames[self.heartType][5];' Line Number: 772
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '1')' in or related to this line: 'self.currentGraphic = self.heartFrames[self.heartType][5];' Line Number: 760
===================================================================
--- original.js
+++ change.js
@@ -57,14 +57,15 @@
self.tapLimit = 12; // Initialize tap limit
self.nbTapsPerFrame = self.tapLimit / 6; // Initialize number of taps per frame
self.heartType = 0; // Initialize tap counter
self.explosionTriggered = false; // Initialize explosion flag
- self.heartFrames = Array.from({
- length: 10
- }, function () {
- return Array(6).fill(null);
- }); // Initialize heartFrames as a 2D array
- // Initialize all heart frames first
+ // Attach the bigHeart asset to the class
+ var bigHeartGraphics = self.attachAsset('bigHeart', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.1
+ });
+ self.heartFrames = {}; // Initialize heartFrames as a property of BigHeart class
for (var type = 9; type >= 0; type--) {
self.heartFrames[type] = [];
for (var i = 5; i >= 0; i--) {
self.heartFrames[type][5 - i] = self.attachAsset('heart_' + type + '_frame_' + i, {
@@ -77,47 +78,57 @@
visible: !i
});
}
}
- // Ensure frames are initialized before setting graphics
- if (self.heartFrames[self.heartType] && self.heartFrames[self.heartType][5]) {
- self.currentGraphic = self.heartFrames[self.heartType][5];
- self.nextGraphic = self.heartFrames[self.heartType][4];
- if (self.currentGraphic) {
+ log("Setting frames in constructor...");
+ self.currentGraphic = self.heartFrames[self.heartType][5];
+ self.nextGraphic = self.heartFrames[self.heartType][4];
+ if (self.currentGraphic) {
+ if (self.currentGraphic && self.currentGraphic.scaleX !== undefined) {
self.currentGraphic.scaleX = 1.1;
+ }
+ if (self.currentGraphic && self.currentGraphic.scaleY !== undefined) {
self.currentGraphic.scaleY = 1.1;
- self.currentGraphic.visible = true;
}
- if (self.nextGraphic) {
+ self.currentGraphic.visible = true;
+ }
+ if (self.nextGraphic) {
+ if (self.nextGraphic.scaleX !== undefined) {
self.nextGraphic.scaleX = 1.1;
+ }
+ if (self.nextGraphic.scaleY !== undefined) {
self.nextGraphic.scaleY = 1.1;
- self.nextGraphic.visible = false;
}
- } else {
- log("Warning: Heart frames not properly initialized!");
+ self.nextGraphic.visible = true;
}
// Position the bigHeart at the center of the screen
self.x = 2048 / 2;
self.y = 2732 / 2 - 300;
// Define baseWidth and baseHeight
- var baseWidth = 600;
- var baseHeight = 600;
+ var baseWidth = bigHeartGraphics.width;
+ var baseHeight = bigHeartGraphics.height;
// Event handler called when a press happens on element. This is automatically called on press if bigHeart is attached.
self.down = function (x, y, obj) {
// Log the down event
log("Down event triggered on BigHeart");
- // First animate the beat to ensure graphics are initialized
- self.animateBeat();
- // Then increment tap counter
+ if (self.currentGraphic && self.nextGraphic) {
+ log("Current indexes:: ", self.currentGraphic.index, ',', self.nextGraphic.index); // Log the tap count
+ } else {
+ log("CurrentGraphic or NextGraphic is not initialized.");
+ }
+ // Increment tap counter
progressManager.manualGeneration();
+ self.animateBeat();
+ self.animateFrames();
// Create a new heart projection using the current frame index
if (self.currentGraphic) {
projectionsManager.popHearts(self.currentGraphic.heartType);
} else {
log("CurrentGraphic is not initialized.");
}
shakeMiddleground();
};
+ // Beat Animation
self.animateBeat = function () {
// Play beat sound
LK.getSound('bump').play();
if (self.currentGraphic) {
@@ -172,84 +183,42 @@
}
});
}
};
- self.updateFramesByProgress = function (progress) {
- log("=== updateFramesByProgress ===");
- log("Raw progress:", progress);
- // Safety check for heart frames
- if (!self.heartFrames[self.heartType]) {
- log("Error: Heart frames not initialized for type", self.heartType);
+ // Frames Animation
+ self.animateFrames = function () {
+ if (self.explosionTriggered || tapCount >= self.tapLimit * (self.heartType + 1)) {
return;
}
- // Progress is already tap count / tapsPerLevel, so we need to scale it to frames
- // Each frame gets 20% of progress (0.2 per frame)
- var frameProgress = progress * 5; // Convert progress to frame scale (0-5)
- log("Progress calculations:");
- log("- frameProgress:", frameProgress);
- // Hide all frames of current type
- self.heartFrames[self.heartType].forEach(function (frame) {
- if (frame && frame._activeTween) {
- frame._activeTween.stop();
- }
- if (frame) {
- frame.visible = false;
- }
- });
- // Handle the final frame (0) separately - only shown after explosion
- if (progress >= 1) {
- log("Progress >= 1, showing frame 0");
- if (self.heartFrames[self.heartType][0]) {
- self.currentGraphic = self.heartFrames[self.heartType][0];
- self.currentGraphic.visible = true;
- self.currentGraphic.scaleX = self.currentGraphic.scaleY = 1.1;
- self.currentGraphic.alpha = 1;
- log("Frame 0 set to visible with alpha:", self.currentGraphic.alpha);
- }
- self.nextGraphic = null;
- return;
+ // Calculate progress in current level (0 to 1)
+ var progress = (tapCount - self.heartType * self.tapLimit) / self.tapLimit;
+ // Map progress to frame indices (frames go from 5 to 0)
+ var frameProgress = progress * 5;
+ var currentFrame = 5 - Math.floor(frameProgress);
+ var nextFrame = Math.max(0, currentFrame - 1);
+ var alpha = frameProgress - Math.floor(frameProgress);
+ // Update frame visibility only if current frame changed
+ if (self.currentGraphic !== self.heartFrames[self.heartType][currentFrame]) {
+ // Hide all frames
+ self.heartFrames[self.heartType].forEach(function (frame) {
+ return frame.visible = false;
+ });
+ // Setup current and next frames
+ self.currentGraphic = self.heartFrames[self.heartType][currentFrame];
+ self.nextGraphic = self.heartFrames[self.heartType][nextFrame];
+ [self.currentGraphic, self.nextGraphic].forEach(function (frame) {
+ if (frame) {
+ frame.visible = true;
+ frame.scaleX = frame.scaleY = 1.1;
+ }
+ });
}
- // Calculate frame indices based on progress
- var currentFrameIndex = 5 - Math.floor(frameProgress);
- var alpha = 1 - (frameProgress - Math.floor(frameProgress));
- log("Frame calculations:");
- log("- heartType:", self.heartType);
- log("- currentFrameIndex:", currentFrameIndex);
- log("- alpha:", alpha);
- // Show next frame first (it will be behind current frame)
- if (currentFrameIndex > 1 && self.heartFrames[self.heartType][currentFrameIndex - 1]) {
- // Only show next frame if we're not on frame 1
- self.nextGraphic = self.heartFrames[self.heartType][currentFrameIndex - 1];
- if (self.nextGraphic) {
- self.nextGraphic.visible = true;
- self.nextGraphic.alpha = 1; // Keep next frame fully visible
- self.nextGraphic.scaleX = self.nextGraphic.scaleY = 1.1;
- log("Next frame setup:");
- log("- heartType:", self.nextGraphic.heartType);
- log("- index:", currentFrameIndex - 1);
- log("- visible:", self.nextGraphic.visible);
- log("- alpha:", self.nextGraphic.alpha);
- log("- scale:", self.nextGraphic.scaleX);
- }
- } else {
- log("No next frame (currentFrameIndex <= 1)");
- self.nextGraphic = null;
+ // Update alpha for smooth transition
+ if (self.currentGraphic) {
+ self.currentGraphic.alpha = 1 - alpha;
}
- // Show current frame on top
- if (self.heartFrames[self.heartType][currentFrameIndex]) {
- self.currentGraphic = self.heartFrames[self.heartType][currentFrameIndex];
- self.currentGraphic.visible = true;
- self.currentGraphic.alpha = alpha; // Only fade out current frame
- self.currentGraphic.scaleX = self.currentGraphic.scaleY = 1.1;
- log("Current frame setup:");
- log("- heartType:", self.currentGraphic.heartType);
- log("- index:", currentFrameIndex);
- log("- visible:", self.currentGraphic.visible);
- log("- alpha:", self.currentGraphic.alpha);
- log("- scale:", self.currentGraphic.scaleX);
- }
- log("=== End updateFramesByProgress ===\n");
};
+ // Explosion Animation
self.animateExplosion = function (callback) {
if (!self.explosionTriggered) {
self.explosionTriggered = true;
if (true || !isDebug) {
@@ -265,35 +234,10 @@
alpha: 1
});
self.addChild(cloneGraphic);
}
- // Update heart type immediately so new frames are ready
- if (self.heartType < 9) {
- var nextHeartType = self.heartType + 1;
- // Pre-scale both frames of the next heart type
- tween(self.heartFrames[nextHeartType][5], {
- scaleX: 1.1,
- scaleY: 1.1
- }, {
- duration: 300,
- easing: tween.easeOut
- });
- tween(self.heartFrames[nextHeartType][4], {
- scaleX: 1.1,
- scaleY: 1.1
- }, {
- duration: 300,
- easing: tween.easeOut
- });
- // Initialize graphics for new heart type
- self.currentGraphic = self.heartFrames[nextHeartType][5];
- self.nextGraphic = self.heartFrames[nextHeartType][4];
- // Update heart type and notify projections
- self.heartType = nextHeartType;
- projectionsManager.updateHeartType(nextHeartType);
- }
LK.setTimeout(function () {
- LK.effects.flashScreen(0xffffff, 2000); // Flash the screen white
+ LK.effects.flashScreen(0xffffff, 2000); // Flash the screen white for 500ms
background.changeBackground(progressManager.currentLevel + 1); // Change background when level changes
if (cloneGraphic) {
log("nextGraphic for explosion!", cloneGraphic);
tween(cloneGraphic, {
@@ -303,56 +247,58 @@
}, {
duration: 3000,
easing: tween.easeOut,
onFinish: function onFinish() {
- // Make all frames of the previous heart type invisible
- self.heartFrames[self.heartType - 1].forEach(function (frame) {
+ // Make all frames of the current heartType invisible
+ self.heartFrames[self.heartType].forEach(function (frame) {
frame.visible = false;
});
- // Make current heart type frames visible
- if (self.currentGraphic) {
- self.currentGraphic.visible = true;
- }
- if (self.nextGraphic) {
- self.nextGraphic.visible = true;
- }
self.explosionTriggered = false; // Reset explosion flag
cloneGraphic.destroy(); // Remove the clone after animation
if (callback) {
callback();
}
}
});
+ // Pre scale next heart
+ tween(self.heartFrames[self.heartType + 1][5], {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ tween(self.heartFrames[self.heartType + 1][4], {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
} else {
log("No nextGraphic for explosion!");
}
}, 205);
}
};
self.resetGraphics = function () {
- log("=== resetGraphics ===");
+ log("resetGraphics...");
// Stop current graphic tweens
if (self.currentGraphic && self.currentGraphic._activeTween) {
self.currentGraphic._activeTween.stop();
- log("Stopped currentGraphic tween");
}
if (self.nextGraphic && self.nextGraphic._activeTween) {
self.nextGraphic._activeTween.stop();
- log("Stopped nextGraphic tween");
}
// Hide only active frames
if (self.currentGraphic) {
self.currentGraphic.visible = false;
- log("Set currentGraphic visible to false");
}
if (self.nextGraphic) {
self.nextGraphic.visible = false;
- log("Set nextGraphic visible to false");
}
self.currentGraphic = null;
self.nextGraphic = null;
- log("Reset currentGraphic and nextGraphic to null");
- log("=== End resetGraphics ===\n");
};
});
// Create a class for bigHeart
var GeneratorButton = Container.expand(function (index) {
@@ -642,71 +588,18 @@
}
}
};
self.updateHeartType = function (heartType) {
- log("=== updateHeartType ===");
- log("Previous heartType:", self.heartType);
- log("New heartType:", heartType);
- // Make all frames of the current heartType invisible
- if (self.heartType !== undefined && self.heartFrames[self.heartType]) {
- log("Hiding frames for heartType:", self.heartType);
- self.heartFrames[self.heartType].forEach(function (frame, index) {
- if (frame) {
- frame.visible = false;
- log("- Frame", index, "visibility set to false");
- }
+ // Update the heart type for all hearts in the pool
+ self.isUpdatingHeartType = true; // Set flag to indicate updateHeartType is running
+ self.heartPool.forEach(function (heart) {
+ heart.children.forEach(function (child) {
+ // Iterate over all children
+ child.visible = child.heartType === heartType; // Set visibility based on heartType
});
- }
- // Update heart type
- self.heartType = heartType;
- log("Heart type updated to:", self.heartType);
- // Reset graphics for new heart type
- self.resetGraphics();
- log("Graphics reset for new heart type");
- // Initialize graphics for new heart type
- self.currentGraphic = self.heartFrames[self.heartType][5];
- self.nextGraphic = self.heartFrames[self.heartType][4];
- if (self.currentGraphic) {
- self.currentGraphic.visible = true;
- self.currentGraphic.scaleX = self.currentGraphic.scaleY = 1.1;
- }
- if (self.nextGraphic) {
- self.nextGraphic.visible = true;
- self.nextGraphic.scaleX = self.nextGraphic.scaleY = 1;
- }
- log("Initialized graphics for new heart type");
- // Update projections
- if (projectionsManager) {
- log("Updating projections manager with heartType:", heartType);
- projectionsManager.updateHeartType(heartType);
- }
- log("=== End updateHeartType ===\n");
+ });
+ self.isUpdatingHeartType = false; // Reset flag after updateHeartType completes
};
- self.resetGraphics = function () {
- log("=== resetGraphics ===");
- // Stop current graphic tweens
- if (self.currentGraphic && self.currentGraphic._activeTween) {
- self.currentGraphic._activeTween.stop();
- log("Stopped currentGraphic tween");
- }
- if (self.nextGraphic && self.nextGraphic._activeTween) {
- self.nextGraphic._activeTween.stop();
- log("Stopped nextGraphic tween");
- }
- // Hide only active frames
- if (self.currentGraphic) {
- self.currentGraphic.visible = false;
- log("Set currentGraphic visible to false");
- }
- if (self.nextGraphic) {
- self.nextGraphic.visible = false;
- log("Set nextGraphic visible to false");
- }
- self.currentGraphic = null;
- self.nextGraphic = null;
- log("Reset currentGraphic and nextGraphic to null");
- log("=== End resetGraphics ===\n");
- };
});
var RainDrop = Container.expand(function () {
var self = Container.call(this);
self.assets = [];
@@ -951,18 +844,18 @@
name: "Choclate",
description: "A sweet choclate that generates love faster",
autoClick: true,
clickRate: 2,
- cost: 100,
+ cost: 11,
upgradeLevel: 0
},
CHAIN_BRACELET: {
id: 2,
name: "Chain Bracelet",
description: "A beautiful chain bracelet that generates love even faster",
autoClick: true,
clickRate: 3,
- cost: 300,
+ cost: 12,
upgradeLevel: 0
}
};
var UPGRADES = {
@@ -1187,9 +1080,8 @@
var self = this;
self.maxHeartBeatsPerSecond = 8; // Add maxHeartBeatsPerSecond property
self.priceIncreaseRate = 1.33; // Extracted price increase rate
self.money = tapCount;
- self.highestScore = tapCount; // Track highest score reached
self.generators = {};
self.generatorCounts = {}; // Add a counter for each generator
self.upgrades = {};
self.currentTime = Date.now();
@@ -1225,58 +1117,44 @@
//log("ProgressManager updateGame...");
var now = Date.now();
var deltaTime = now - self.lastUpdateTime;
var tempGenerated = 0;
+ // Update generators
Object.values(self.generators).forEach(function (generator) {
var generated = generator.generate(deltaTime) * self.generatorCounts[generator.id];
log("generator => +" + generated);
tempGenerated += Math.ceil(generated);
});
- var beatsToGenerate = Math.floor(tempGenerated / 2);
- beatsToGenerate = Math.min(beatsToGenerate, self.maxHeartBeatsPerSecond);
+ // Calculate beats based on generation rate
+ var beatsToGenerate = Math.floor(tempGenerated / 2); // One beat every 10 taps generated
+ beatsToGenerate = Math.min(beatsToGenerate, self.maxHeartBeatsPerSecond); // Cap at 5 beats per update to avoid overwhelming
if (tempGenerated > 0) {
self.money = addLargeNumbers(self.money, tempGenerated.toString());
tapCount = self.money;
- // Update highest score if current money is higher
- if (parseInt(self.money) > parseInt(self.highestScore)) {
- self.highestScore = self.money;
- self.updateHeartProgress();
- self.checkProgress();
- }
}
self.updateGeneratorsUi();
+ // Trigger multiple beats based on generation rate
if (tempGenerated > 0) {
for (var i = 0; i < beatsToGenerate; i++) {
LK.setTimeout(function () {
bigHeart.animateBeat();
}, i * 300);
}
}
- updateTapCountText();
+ updateTapCountText(); // Update the text display
+ self.checkProgress(); // Check the progress
self.lastUpdateTime = now;
};
self.manualGeneration = function () {
tapCount = addLargeNumbers(tapCount, "1");
self.money = addLargeNumbers(self.money, "1");
- // Update highest score if current money is higher
- if (parseInt(self.money) > parseInt(self.highestScore)) {
- self.highestScore = self.money;
- self.updateHeartProgress();
- self.checkProgress();
- }
- log("manualGeneration Tap count: ", tapCount);
- updateTapCountText();
+ log("manualGeneration Tap count: ", tapCount); // Log the tap count
+ updateTapCountText(); // Update the text display
self.updateGeneratorsUi();
+ self.checkProgress(); // Check for level up immediately
};
- self.updateHeartProgress = function () {
- var currentLevelTarget = self.tapsPerLevel[self.currentLevel];
- var score = parseInt(self.highestScore);
- var progress = Math.min(score / currentLevelTarget, 1);
- bigHeart.updateFramesByProgress(progress);
- };
self.checkProgress = function () {
- // Use highestScore instead of tapCount for level progression
- if (self.highestScore >= self.tapsPerLevel[self.currentLevel]) {
+ if (tapCount >= self.tapsPerLevel[self.currentLevel]) {
if (self.currentLevel < 9) {
// Ensure we don't exceed level 9
var previousLevel = self.currentLevel;
var previousFrames = bigHeart.heartFrames[previousLevel] || [];
@@ -1287,9 +1165,28 @@
frame.visible = false;
});
bigHeart.animateExplosion(function () {
self.currentLevel++;
- self.updateHeartProgress(); // Start new level with correct frame
+ bigHeart.heartType = self.currentLevel;
+ bigHeart.currentGraphic = bigHeart.heartFrames[bigHeart.heartType][5];
+ bigHeart.nextGraphic = bigHeart.heartFrames[bigHeart.heartType][4];
+ bigHeart.currentGraphic.visible = true;
+ projectionsManager.updateHeartType(bigHeart.heartType);
+ bigHeart.nextGraphic.visible = true;
+ tween(bigHeart.currentGraphic, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ tween(bigHeart.nextGraphic, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
});
}
}
};
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