Code edit (1 edits merged)
Please save this source code
User prompt
also add a screen flash on explosion
Code edit (8 edits merged)
Please save this source code
User prompt
add a new function shakeMiddleground that shakes only middlegroundContainer ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (8 edits merged)
Please save this source code
User prompt
use a Background instance for the background
User prompt
create a background class; use background_1 asset
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
augment power of projections in up direction
Code edit (1 edits merged)
Please save this source code
User prompt
in updateHeartType, switch visibility of heart assets in the heartpool objects depending on their heartType
User prompt
ok change Projections algorithm : in Projections constructor add all heat types assets in the heart Container and only make visible current heatType ones
User prompt
ok change Projections algorithm : add all heat types assets in the heart Container and only make visible current heatType ones
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: newHeartAsset is not defined' in or related to this line: 'heart.addChild(newHeartAsset);' Line Number: 240
User prompt
add a flag to avoid using hearts in popHearts while updateHeartType is running
Code edit (1 edits merged)
Please save this source code
User prompt
in updateHeartType remember to update the heartPool using preloadedAssets. don't use `clone` which do not exists and don't use attachAsset neither LK.getasset() inside updateHeartType to avoid performence issues
User prompt
in updateHeartType remember to update the heartPool using preloadedAssets. don't use `clone` which do not exists and don't use attachAsset/getasset to avoid performence issues
User prompt
in updateHeartType remember to update the heartPool using preloadedAssets. don't use `clone` which do not exists and don't use attachAsset to avoid performence issues
User prompt
in updateHeartType remember to update the heartPool using preloadedAssets. don't use `clone` which do not exists and don't use attachAsset to avoid performence issues
User prompt
Please fix the bug: 'TypeError: heartAsset.clone is not a function' in or related to this line: 'heart.addChild(heartAsset.clone());' Line Number: 236
User prompt
in updateHeartType remember to update the heartPool using preloadedAssets
User prompt
in updateHeartType remember to update the heartPool
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Create a class for bigHeart var BigHeart = Container.expand(function () { var self = Container.call(this); self.currentGraphic = null; self.nextGraphic = null; self.tapLimit = 20; // 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 // 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, { anchorX: 0.5, anchorY: 0.5, scaleX: 0.9, scaleY: 0.9, heartType: type, index: 5 - i }); } } self.currentGraphic = self.heartFrames[self.heartType][5]; self.nextGraphic = self.heartFrames[self.heartType][4]; self.currentGraphic.scaleX = 1.1; self.currentGraphic.scaleY = 1.1; self.nextGraphic.scaleX = 1.1; self.nextGraphic.scaleY = 1.1; //self.currentGraphic = heartFrames[5]; //self.nextGraphic = heartFrames[4]; // Position the bigHeart at the center of the screen self.x = 2048 / 2; self.y = 2732 / 2 - 300; // Define baseWidth and baseHeight 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) { // Play beat sound LK.getSound('bump').play(); // Animate the size of the bigHeart to 1.5 times its original size over 0.5 seconds 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 / 5); if (!self.explosionTriggered && tapCount < self.tapLimit * (self.heartType + 1) && frameIndex > 0) { self.currentGraphic = self.heartFrames[self.heartType][frameIndex]; self.nextGraphic = self.heartFrames[self.heartType][frameIndex - 1]; } else if (tapCount >= self.tapLimit * (self.heartType + 1)) { log("Tap count: ", tapCount); // Log the tap count // Explosion triggerExplosion(self); } log("Tap count: ", tapCount); // Log the tap count self.currentGraphic.alpha = Math.max(0, Math.min(1, 1 - ((self.heartType + 1) * self.tapLimit - tapCount) / 10)); /* for (var i = 5; i >= 0; i--) { // Calculate the alpha value for each heart frame based on tapCount // 1 - (tapCount - (5 - i) * 5) / 10: // - (5 - i) * 5: Determines the threshold for each frame based on its index // - tapCount - (5 - i) * 5: Calculates how far the tapCount is beyond the threshold // - (tapCount - (5 - i) * 5) / 10: Normalizes the value to a range of 0 to 1 // - 1 - ...: Inverts the value so that higher tapCounts result in lower alpha self.heartFrames[self.heartType][i].alpha = Math.max(0, Math.min(1, 1 - (tapCount - (5 - i) * self.nbTapsPerFrame * (self.heartType + 1)) / (10 * (self.heartType + 1)))); } */ // Log the down event log("Down event triggered on BigHeart"); shakeScreen(); }; }); // Create a class for Projections var Projections = Container.expand(function () { var self = Container.call(this); var nbProjections = 5; var heartSpeed = 20; var gravity = 0.5; var initialScale = 0.25; var scaleVariation = 0.5; var alphaDecay = 0.002; self.heartPool = []; self.preloadedAssets = {}; // Preload assets for each heart type for (var type = 0; type <= 9; type++) { self.preloadedAssets[type] = LK.getAsset('heart_' + type + '_frame_0', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.5, scaleY: 0.5 }); } // Initialize heart pool for (var i = 0; i < nbProjections * 5; i++) { var heart = new Container(); heart.vx = 0; heart.vy = 0; heart.alpha = 0; heart.update = function () { this.x += this.vx; this.y += this.vy; this.vy += gravity; // Add gravity effect this.alpha -= alphaDecay; if (this.alpha <= 0 || this.y > 2900) { this.alpha = 0; self.heartPool.push(this); } }; // Add all heart type assets to the heart Container for (var type = 0; type <= 9; type++) { var heartAsset = heart.attachAsset('heart_' + type + '_frame_0', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.5, scaleY: 0.5, heartType: type, visible: type === 0 // Only make the current heartType visible }); } self.heartPool.push(heart); } self.x = 2048 / 2; self.y = 2732 / 2 - 400; // Function to pop hearts self.popHearts = function (heartType) { if (self.isUpdatingHeartType) { return; } // Exit if updateHeartType is running for (var i = 0; i < nbProjections; i++) { if (self.heartPool.length > 0) { var heart = self.heartPool.pop(); if (heart.alpha <= 0) { // Ensure heart has finished its previous animation heart.x = 0; heart.y = 0; heart.vx = (Math.random() - 0.5) * heartSpeed; heart.vy = (Math.random() - 1.5) * heartSpeed; heart.alpha = 0.8; heart.scaleX = initialScale + Math.random() * scaleVariation; // Randomize scale between initialScale and initialScale + scaleVariation heart.scaleY = heart.scaleX; // Keep aspect ratio consistent heart.rotation = Math.random() * Math.PI * 2; // Randomize rotation between 0 and 2π self.addChild(heart); } else { self.heartPool.push(heart); // Return heart to pool if it hasn't finished animation } } } }; self.updateHeartType = function (heartType) { // 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 }); }); self.isUpdatingHeartType = false; // Reset flag after updateHeartType completes }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xa16e9f //Init game with black background }); /**** * Game Code ****/ function shakeScreen() { tween(game, { x: 10, y: 10 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(game, { x: -10, y: -10 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(game, { x: 0, y: 0 }, { duration: 100, easing: tween.easeInOut }); } }); } }); } function triggerExplosion(self) { if (!self.explosionTriggered) { LK.getSound('boom').play(); LK.setTimeout(function () { // Make all frames of the current heartType invisible self.heartFrames[self.heartType].forEach(function (frame) { if (frame.index == self.nextGraphic.index) { return; } frame.visible = false; }); tween(self.nextGraphic, { scaleX: 45, scaleY: 45, alpha: 0 }, { duration: 3000, easing: tween.easeOut, onFinish: function onFinish() { // Make all frames of the current heartType invisible self.heartFrames[self.heartType].forEach(function (frame) { frame.visible = false; }); // Switch to the next heart type self.heartType = (self.heartType + 1) % 10; self.currentGraphic = self.heartFrames[self.heartType][5]; self.nextGraphic = self.heartFrames[self.heartType][4]; projectionsManager.updateHeartType(self.heartType); self.explosionTriggered = false; // Reset explosion flag } }); // Make next frame bigger tween(self.heartFrames[(self.heartType + 1) % 10][5], { scaleX: 1.1, scaleY: 1.1 }, { duration: 300, easing: tween.easeOut }); // Make next frame bigger tween(self.heartFrames[(self.heartType + 1) % 10][4], { scaleX: 1.1, scaleY: 1.1 }, { duration: 300, easing: tween.easeOut }); }, 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); game.addChild(middlegroundContainer); game.addChild(foregroundContainer); var isDebug = true; var projectionsManager = backgroundContainer.addChild(new Projections()); // Place projectionsManager in backgroundContainer function log() { if (isDebug) { console.log.apply(console, arguments); } } // Declare tapCount as a global variable var tapCount = 0; // Create a text object to display tapCount var tapCountText = new Text2('Love: 0', { size: 100, fill: 0xFFFFFF }); // Center the text horizontally, anchor point set at the middle of its top edge. tapCountText.anchor.set(0.5, 0); // Position the text at the top-center of the screen. LK.gui.top.addChild(tapCountText); // Add a big heart at the center of the screen var bigHeart = new BigHeart(); middlegroundContainer.addChild(bigHeart); // Update the tapCountText whenever tapCount changes function updateTapCountText() { tapCountText.setText('Love: ' + tapCount); } // Global ProgressManager function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) { return t; } var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) { return i; } throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var progressManager; // Constants for Generators and Upgrades var GENERATORS = { ME: { id: 1, name: "Me", description: "It's you! The player whose heart beats love", autoClick: false, clickRate: 0, cost: 0, upgradeLevel: 0 }, FAIRY: { id: 2, name: "Fairy", description: "A magical fairy that generates love beats", autoClick: true, clickRate: 0.1, // 1 click per 10 seconds cost: 100, upgradeLevel: 0 } }; var UPGRADES = { ROSE: { id: 1, name: "Rose", description: "A rose that enhances love generation", targetGenerator: 1, // Targets Generator #1 (Me) multipliers: [2, 4, 8], // Levels of multiplier cost: 10 } }; // Progress Management function ProgressManager() { var self = this; self.money = 0; self.generators = {}; self.upgrades = {}; self.currentTime = Date.now(); self.lastUpdateTime = self.currentTime; self.updateGame = function () { var now = Date.now(); var deltaTime = now - self.lastUpdateTime; // Update generators Object.values(self.generators).forEach(function (generator) { var generated = generator.generate(deltaTime); self.money += generated; }); self.lastUpdateTime = now; }; self.buyGenerator = function (generatorId) { var generatorConfig = Object.values(GENERATORS).find(function (g) { return g.id === generatorId; }); if (!generatorConfig) { throw new Error("Generator with id ".concat(generatorId, " not found")); } if (self.money < generatorConfig.cost) { return false; } self.money -= generatorConfig.cost; self.generators[generatorId] = new Generator(generatorConfig); return true; }; self.buyUpgrade = function (upgradeId, generatorId) { var upgradeConfig = Object.values(UPGRADES).find(function (u) { return u.id === upgradeId; }); var targetGenerator = self.generators[generatorId]; if (!upgradeConfig || !targetGenerator) { throw new Error("Upgrade or Generator not found"); } if (self.money < upgradeConfig.cost) { return false; } self.money -= upgradeConfig.cost; var upgrade = new Upgrade(upgradeConfig); upgrade.apply(targetGenerator); self.upgrades[upgradeId] = upgrade; return true; }; } function Generator(config) { var self = this; self.id = config.id; self.name = config.name; self.description = config.description; self.autoClick = config.autoClick; self.clickRate = config.clickRate; self.cost = config.cost; self.upgradeLevel = config.upgradeLevel; self.generate = function (deltaTime) { if (!self.autoClick) { return 0; } var clickAmount = self.clickRate * deltaTime / 1000; return clickAmount * Math.pow(2, self.upgradeLevel); }; self.currentMultiplier = Math.pow(2, self.upgradeLevel); self.manualGenerate = function () { return 1 * self.currentMultiplier; }; self.upgrade = function (upgradeMultiplier) { self.upgradeLevel++; }; } function Upgrade(config) { var self = this; self.id = config.id; self.name = config.name; self.description = config.description; self.targetGenerator = config.targetGenerator; self.multipliers = config.multipliers; self.cost = config.cost; self.currentLevel = 0; self.apply = function (generator) { if (self.currentLevel < self.multipliers.length) { generator.upgrade(self.multipliers[self.currentLevel]); self.currentLevel++; } }; } function initializeGame() { progressManager = new ProgressManager(); // Initialize starting generator (Me) progressManager.generators[GENERATORS.ME.id] = new Generator(GENERATORS.ME); } initializeGame();
===================================================================
--- original.js
+++ change.js
@@ -154,9 +154,9 @@
// Ensure heart has finished its previous animation
heart.x = 0;
heart.y = 0;
heart.vx = (Math.random() - 0.5) * heartSpeed;
- heart.vy = (Math.random() - 1.2) * heartSpeed;
+ heart.vy = (Math.random() - 1.5) * heartSpeed;
heart.alpha = 0.8;
heart.scaleX = initialScale + Math.random() * scaleVariation; // Randomize scale between initialScale and initialScale + scaleVariation
heart.scaleY = heart.scaleX; // Keep aspect ratio consistent
heart.rotation = Math.random() * Math.PI * 2; // Randomize rotation between 0 and 2π
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
beautifull red gift box.
black plastic 3d triangle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
basic red horizontal rectangle button with white text "RESET".