Code edit (1 edits merged)
Please save this source code
User prompt
when spawning a gift, set a random rotation winthin a range of -PI/4 +PI/4
Code edit (18 edits merged)
Please save this source code
User prompt
in GiftRain, when a gift moves out of bounds move it back to gift.x = Math.random() * (1948 - 100) + 100; gift.y = -300; // Start above the screen in order to make a countious anim
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
I don't see gifts falling; I thing activesGifts are not atteched to the GiftRain instance in the GiftRain class
Code edit (1 edits merged)
Please save this source code
User prompt
I don't see gifts falling; I thing it misses and "attachement" to GiftRain
Code edit (1 edits merged)
Please save this source code
User prompt
add logs in GifRain and RainDrop
Code edit (6 edits merged)
Please save this source code
User prompt
for GiftRain, use RainDrop instances in the giftPool. and call upsateAsset() with the generator index
User prompt
create a class RainDrop with a list of non visible assets generator_N (with N from 0 to maxGenerators) . in This class add a update asset function that takes an index as argument and make the index asset visible.
User prompt
GiftRain should not use 'generatorButton' asset but 'generator_X' asset depending on the bought generators
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'addChild')' in or related to this line: 'middlegroundContainer.addChild(giftRain);' Line Number: 863
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'addChild')' in or related to this line: 'middlegroundContainer.addChild(giftRain);' Line Number: 863
User prompt
create a new class GiftRain. It will be responsible of making a continuous animation of falling gifts. The gifts will start to fall when player buys a generator. The gifts will use the same asset as the generators buttons. The more generators bought the more gifts will spawn. Gifts spawn at random x between 100 and 1948. Gifts spawn at random y between -100 and -300. The class will use a pool of objects and re-use gifts with y > 3000
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -459,8 +459,53 @@
dragNode = null; // Reset dragNode when mouse is up
}
};
});
+var GiftRain = Container.expand(function () {
+ var self = Container.call(this);
+ self.giftPool = [];
+ self.activeGifts = [];
+ self.generatorCount = 0;
+ // Initialize gift pool
+ for (var i = 0; i < 50; i++) {
+ var gift = self.attachAsset('generatorButton', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ visible: false
+ });
+ gift.speed = Math.random() * 2 + 1; // Random speed for each gift
+ self.giftPool.push(gift);
+ }
+ // Function to spawn a gift
+ self.spawnGift = function () {
+ if (self.giftPool.length > 0) {
+ var gift = self.giftPool.pop();
+ gift.x = Math.random() * (1948 - 100) + 100;
+ gift.y = Math.random() * (-300 + 100) - 300;
+ gift.visible = true;
+ self.activeGifts.push(gift);
+ }
+ };
+ // Update function to move gifts
+ self.update = function () {
+ for (var i = self.activeGifts.length - 1; i >= 0; i--) {
+ var gift = self.activeGifts[i];
+ gift.y += gift.speed;
+ if (gift.y > 3000) {
+ gift.visible = false;
+ self.giftPool.push(gift);
+ self.activeGifts.splice(i, 1);
+ }
+ }
+ };
+ // Function to increase gift spawn rate
+ self.increaseSpawnRate = function () {
+ self.generatorCount++;
+ for (var i = 0; i < self.generatorCount; i++) {
+ self.spawnGift();
+ }
+ };
+});
// Create a class for Projections
var Projections = Container.expand(function () {
var self = Container.call(this);
var nbProjections = 5;
@@ -554,15 +599,15 @@
anchorX: 0.5,
anchorY: 0.5,
width: 400,
height: 3000,
- alpha: 0.2,
- visible: true // For Debugging
+ alpha: 0
});
self.lastY = 0;
self.velocity = 0;
self.isAnimating = false;
self.lastTime = Date.now();
+ self.swipeOffset = 0;
// Add momentum animation
self.applyMomentum = function () {
if (Math.abs(self.velocity) < 0.1) {
self.velocity = 0;
@@ -611,11 +656,11 @@
self.generatorButtons.push(generatorButton);
self.addChild(generatorButton);
}
self.cleanUp = function () {
- // Re-calculate positions for all buttons
+ // Re-calculate positions for all buttons while maintaining the swipe offset
self.generatorButtons.forEach(function (button, index) {
- button.y = self.buttonsOffsetY + index * 300 + index * 300 * 0.1;
+ button.y = self.buttonsOffsetY + index * 300 + index * 300 * 0.1 + self.swipeOffset;
});
};
self.down = function (x, y, obj) {
log("RightBoard pressed", y);
@@ -642,19 +687,18 @@
// Calculate new positions for the first and last buttons
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);
+ // Check if the first button stays above the screen center and the last button stays below the screen center
// Adjust deltaY to prevent moving beyond boundaries
if (deltaY > 0) {
deltaY = Math.min(deltaY, 1000 - (self.y + self.generatorButtons[0].y));
}
- if (deltaY < 0) {
- deltaY = Math.max(deltaY, 1366 - (self.y + self.generatorButtons[self.generatorButtons.length - 1].y));
- }
// Move all generator buttons vertically based on swipe direction
self.generatorButtons.forEach(function (button) {
button.y += deltaY;
});
+ self.swipeOffset += deltaY; // Update the total swipe offset
globalStartY = y; // Update globalStartY for continuous movement
}
};
self.up = function (x, y, obj) {
@@ -691,8 +735,9 @@
// Move all generator buttons vertically based on swipe direction
self.generatorButtons.forEach(function (button) {
button.y += deltaY;
});
+ self.swipeOffset += deltaY; // Update the total swipe offset
globalStartY = y; // Update globalStartY for continuous movement
};
self.move = function (x, y, obj) {
if (dragNode === self || dragNode instanceof GeneratorButton) {
@@ -713,8 +758,9 @@
// Move all generator buttons vertically based on swipe direction
self.generatorButtons.forEach(function (button) {
button.y += deltaY;
});
+ self.swipeOffset += deltaY; // Update the total swipe offset
globalStartY = y; // Update globalStartY for continuous movement
}
};
});
@@ -728,8 +774,14 @@
/****
* Game Code
****/
+var giftRain = new GiftRain();
+middlegroundContainer.addChild(giftRain);
+// Update function to include giftRain update
+game.update = function () {
+ giftRain.update();
+};
// 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;
@@ -856,9 +908,9 @@
// Declare tapCount as a global variable
var tapCount = 0;
// Create a text object to display tapCount
var tapCountText = new Text2('LOVE\r\n ', {
- size: 100,
+ size: 140,
fill: 0xFFFFFF,
dropShadow: true,
align: 'center'
});
@@ -1064,8 +1116,9 @@
self.generatorCounts[generatorId]++; // Increment the count for the generator
rightBoard.generatorButtons[generatorId].countText.setText(self.generatorCounts[generatorId].toString());
log("Generator", generatorId, "Count:", self.generatorCounts[generatorId], "New Cost:", newCost);
LK.getSound('buyGenerator').play();
+ giftRain.increaseSpawnRate();
return true;
};
self.buyUpgrade = function (upgradeId, generatorId) {
var upgradeConfig = Object.values(UPGRADES).find(function (u) {
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