Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: isAnimating is not defined' in or related to this line: 'if (!isAnimating && dragNode === rightBoard) {' Line Number: 530
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: requestAnimationFrame is not a function' in or related to this line: 'requestAnimationFrame(self.applyMomentum);' Line Number: 726
User prompt
Please fix the bug: 'Uncaught TypeError: requestAnimationFrame is not a function' in or related to this line: 'requestAnimationFrame(self.applyMomentum);' Line Number: 726
Code edit (2 edits merged)
Please save this source code
User prompt
the dragNode update should be hangled globally because currently it is not updated when up event occurs out of rightBoard or buttons
User prompt
buttons drag/swipe isn't coherent when user touches only the rightBoard and when he touches buttons. repair that to make the movement coherent
User prompt
Please fix the bug: 'Uncaught ReferenceError: dragNode is not defined' in or related to this line: 'if (dragNode) {' Line Number: 671
User prompt
currently buttons always move with the cursor. they should move with the cursor only during the mouse down state
User prompt
currently buttons always move with the cursor. they should only move when user taps the screen
User prompt
Please fix the bug: 'Uncaught ReferenceError: y is not defined' in or related to this line: 'globalStartY = y; // Update globalStartY for continuous movement' Line Number: 666
User prompt
Please fix the bug: 'Uncaught TypeError: self.handleSwipe is not a function' in or related to this line: 'self.handleSwipe(y - globalStartY);' Line Number: 645
User prompt
in rightBoard introduce the use of move() event handler to make swipe more fluid (remove tween if necessary). then update handleSwipe eevery where it was used
User prompt
you removed handleSwipe() but it's still used in GeneratorButton. update
User prompt
in rightBoard introduce the use of move() event handler to make swipe more fluid (remove tween if necessary)
User prompt
in rightBoard introduce the use of move event to make swipe more fluid (remove tween if necessary)
Code edit (1 edits merged)
Please save this source code
User prompt
move the button swipe logic in RightBoard instead of Generatot buttons
Code edit (7 edits merged)
Please save this source code
User prompt
in GeneratorButton down and up events, don't use a local startY per instance but a unique global one
Code edit (4 edits merged)
Please save this source code
User prompt
now in RightBoard.swipe, don't prevent movement if firstButtonNewY < 1366 / 2 or lastButtonNewY > 1366 but limit detlaY to reach the boundary
User prompt
in RightBoard.swipe, use tween to make buttons movement smooth ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -309,8 +309,9 @@
anchorY: 0.5
});
// Ensure rightBoard is initialized before accessing its properties
self.index = Math.min(Math.max(0, index), maxGenerators);
+ self.isAnimating = false; // Add isAnimating flag at instance level
var generatorAsset = self.attachAsset('generator_' + self.index, {
anchorX: 0.5,
anchorY: 0.5
});
@@ -354,14 +355,22 @@
// self.x = 2048 / 2;
// self.y = 2732 / 2;
// Event handler called when a press happens on the button
self.down = function (x, y, obj) {
+ if (self.isAnimating) {
+ return;
+ } // Prevent interaction during animation
log("Generator button pressed", y);
globalStartY = y;
+ dragNode = rightBoard;
self.startTime = Date.now();
self.startX = x;
};
self.up = function (x, y, obj) {
+ if (self.isAnimating) {
+ dragNode = null;
+ return; // Prevent interaction during animation
+ }
var endTime = Date.now();
var timeDiff = endTime - self.startTime;
var distance = Math.sqrt(Math.pow(x - self.startX, 2) + Math.pow(y - globalStartY, 2));
if (timeDiff < 200 && distance < 10) {
@@ -370,33 +379,41 @@
// Check if tapCount is less than the cost of the generator
if (tapCount < self.config.cost) {
log("No enough love");
LK.getSound('cantBuyGenerator').play(); // Play sound when player can't buy
+ // Store original position
+ var originalX = self.x;
+ var originalY = self.y;
+ self.isAnimating = true;
tween(self, {
- x: 10,
- y: 10
+ x: originalX + 10,
+ y: originalY + 10
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
- x: -10,
- y: -10
+ x: originalX - 10,
+ y: originalY - 10
}, {
duration: 100,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
- x: 0,
- y: 0
+ x: originalX,
+ y: originalY
}, {
duration: 100,
- easing: tween.easeInOut
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ }
});
}
});
}
});
+ dragNode = null; // Reset dragNode immediately when starting animation
return; // Exit if not enough taps
}
// Buy the corresponding generator using progressManager
if (progressManager.buyGenerator(self.index)) {
@@ -424,11 +441,11 @@
} else {
log("Failed to purchase generator");
}
} else {
- // Detected as a swipe
- log("Detected swipe on Generator button");
- if (dragNode === self) {
+ // Only handle swipe if not animating
+ if (!isAnimating && dragNode === rightBoard) {
+ log("Detected swipe on Generator button");
rightBoard.handleSwipe(y - globalStartY);
}
dragNode = null; // Reset dragNode when mouse is up
}
@@ -535,21 +552,22 @@
self.lastY = 0;
self.velocity = 0;
self.isAnimating = false;
self.lastTime = Date.now();
- self.lastDeltaY = 0;
- self.moveCount = 0;
// Add momentum animation
self.applyMomentum = function () {
- if (Math.abs(self.velocity) < 1) {
+ if (Math.abs(self.velocity) < 0.1) {
self.velocity = 0;
self.isAnimating = false;
return;
}
+ var currentTime = Date.now();
+ var deltaTime = (currentTime - self.lastTime) / 16; // Normalize to ~60fps
+ self.lastTime = currentTime;
// Apply friction
- self.velocity *= 0.95;
+ self.velocity *= Math.pow(0.95, deltaTime);
// Calculate movement with velocity
- var deltaY = self.velocity;
+ var deltaY = self.velocity * deltaTime;
// Check boundaries
var firstButtonNewY = self.y + self.generatorButtons[0].y + deltaY;
var lastButtonNewY = self.y + self.generatorButtons[self.generatorButtons.length - 1].y + deltaY;
// Bounce effect at boundaries
@@ -571,13 +589,17 @@
};
// Position the rightBoard at the right side of the screen
self.x = 1848;
self.y = 1366;
- self.generatorButtons = [];
- for (var i = 0; i < maxGenerators; i++) {
+ self.buttonsOffsetX = 50;
+ self.buttonsOffsetY = -300;
+ self.generatorButtons = []; // Initialize an array to hold generator buttons
+ // Create and position generator buttons
+ for (var i = 0; i <= 9; i++) {
+ // Todo : use maxGenerators
var generatorButton = new GeneratorButton(i);
- generatorButton.x = 0;
- generatorButton.y = i * 300;
+ generatorButton.x = self.buttonsOffsetX; //0 * self.x + i * 100 - 100; // Position buttons with some spacing
+ generatorButton.y = self.buttonsOffsetY + i * 300 + i * 300 * 0.1; //self.y;
self.generatorButtons.push(generatorButton);
self.addChild(generatorButton);
}
self.down = function (x, y, obj) {
@@ -588,40 +610,29 @@
self.isAnimating = false;
dragNode = self;
self.startTime = Date.now();
self.lastTime = Date.now();
- self.moveCount = 0;
- self.lastDeltaY = 0;
};
self.move = function (x, y, obj) {
+ // Check if any generator button is animating
+ var isAnyButtonAnimating = self.generatorButtons.some(function (button) {
+ return button.isAnimating;
+ });
+ if (isAnyButtonAnimating) {
+ return; // Prevent movement if any button is animating
+ }
if (dragNode === self || dragNode instanceof GeneratorButton) {
var deltaY = y - globalStartY;
- var currentTime = Date.now();
- // Track movement for momentum
- self.moveCount++;
- var moveDeltaY = y - self.lastY;
- self.lastDeltaY = moveDeltaY;
- // Calculate velocity based on recent movement
- // We'll use this for initial momentum when letting go
- self.velocity = moveDeltaY * 1.2; // Amplify the velocity a bit
- // Update tracking variables
- self.lastY = y;
- self.lastTime = currentTime;
// Calculate new positions for boundaries
var firstButtonNewY = self.y + self.generatorButtons[0].y + deltaY;
var lastButtonNewY = self.y + self.generatorButtons[self.generatorButtons.length - 1].y + deltaY;
+ log("firstButtonNewY:", firstButtonNewY, "lastButtonNewY:", lastButtonNewY);
// Adjust deltaY to prevent moving beyond boundaries
if (deltaY > 0) {
deltaY = Math.min(deltaY, 1000 - (self.y + self.generatorButtons[0].y));
- if (firstButtonNewY > 1000) {
- self.velocity *= 0.5;
- }
}
if (deltaY < 0) {
deltaY = Math.max(deltaY, 1366 - (self.y + self.generatorButtons[self.generatorButtons.length - 1].y));
- if (lastButtonNewY < 1366) {
- self.velocity *= 0.5;
- }
}
// Move all generator buttons vertically based on swipe direction
self.generatorButtons.forEach(function (button) {
button.y += deltaY;
@@ -635,12 +646,10 @@
var distance = Math.sqrt(Math.pow(x - self.startX, 2) + Math.pow(y - globalStartY, 2));
if (timeDiff < 200 && distance < 10) {
// Detected as a tap
log("Detected tap on RightBoard");
- } else if (self.moveCount > 2) {
- // Only apply momentum if there was actual movement
- // Use the last movement delta for initial momentum
- self.velocity = self.lastDeltaY * 1.2; // Amplify the final velocity a bit
+ } else {
+ // Start momentum animation
self.isAnimating = true;
LK.setTimeout(self.applyMomentum, 16);
}
dragNode = null;
@@ -703,8 +712,10 @@
// Declare a global variable to store the startY position for GeneratorButton events
var globalStartY = 0;
// Declare a global variable to track the node being dragged
var dragNode = null;
+// Declare a global variable to track animation state
+var isAnimating = false;
// Global event listener for mouse or touch up
game.up = function (x, y, obj) {
dragNode = null; // Reset dragNode when mouse is up
};
@@ -927,40 +938,8 @@
9: 1000
};
}
self.lastUpdateTime = self.currentTime;
- self.updateGeneratorsUi = function () {
- // Update generator button visibility based on money
- //log("Updating Generators UI");
- rightBoard.generatorButtons.forEach(function (button, index) {
- var generatorConfig = rightBoard.generatorButtons[index].config;
- rightBoard.generatorButtons[index].costText.setText(generatorConfig.cost.toString()); // Update the cost text to reflect the new exponential cost
- if (generatorConfig) {
- // Store a flag 'wasShown' in generatorButton when displayed
- if (self.money >= generatorConfig.cost * 0.75) {
- if (!button.wasShown) {
- button.x = 2048 + button.width; // Start from the right border
- tween(button, {
- x: 0
- }, {
- duration: 500,
- easing: tween.easeOut
- }); // Animate entrance
- }
- // Show generator if player has at least 75% of its cost
- button.wasShown = true;
- button.visible = true;
- // Set alpha to 0.75 if player can't buy the generator
- button.alpha = self.money >= generatorConfig.cost ? 1 : 0.6;
- } else {
- button.visible = button.wasShown;
- button.alpha = 0.6;
- }
- } else {
- button.visible = false;
- }
- });
- };
self.updateGame = function () {
//log("ProgressManager updateGame...");
var now = Date.now();
var deltaTime = now - self.lastUpdateTime;
@@ -1085,8 +1064,40 @@
upgrade.apply(targetGenerator);
self.upgrades[upgradeId] = upgrade;
return true;
};
+ self.updateGeneratorsUi = function () {
+ // Update generator button visibility based on money
+ //log("Updating Generators UI");
+ rightBoard.generatorButtons.forEach(function (button, index) {
+ var generatorConfig = rightBoard.generatorButtons[index].config;
+ rightBoard.generatorButtons[index].costText.setText(generatorConfig.cost.toString()); // Update the cost text to reflect the new exponential cost
+ if (generatorConfig) {
+ // Store a flag 'wasShown' in generatorButton when displayed
+ if (self.money >= generatorConfig.cost * 0.75) {
+ if (!button.wasShown) {
+ button.x = 2048 + button.width; // Start from the right border
+ tween(button, {
+ x: 0
+ }, {
+ duration: 500,
+ easing: tween.easeOut
+ }); // Animate entrance
+ }
+ // Show generator if player has at least 75% of its cost
+ button.wasShown = true;
+ button.visible = true;
+ // Set alpha to 0.75 if player can't buy the generator
+ button.alpha = self.money >= generatorConfig.cost ? 1 : 0.6;
+ } else {
+ button.visible = button.wasShown;
+ button.alpha = 0.6;
+ }
+ } else {
+ button.visible = false;
+ }
+ });
+ };
}
function Generator(config) {
var self = this;
self.id = config.id;
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