User prompt
уменьши размер текста счетчиков и выведи их оба в верхней части экрана с левой стороны, на экраны anvil и ForgeOfMatter
Code edit (1 edits merged)
Please save this source code
User prompt
счетчик Growth rate обнуляется при выходе с окна magicNursery, сделай так что бы прогресс счетчика сохранялся
User prompt
счетчик Growth rate обнуляется при переходе на окно anvil и обратно, сделай так что бы прогресс сохранялся при возвращении
User prompt
сделай что бы прогресс в счетчике Growth rate не обнулялся при переходах между окнами
User prompt
теперь при переходах через door2 пиiется undefined в счетчике growth rate, нужно что бы счетчик сохранял прогресс при любых пререходах
User prompt
посмотри как реализован счетчик forging skill и сделай так же в счетчике growth rate при переходах через door2
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'visible')' in or related to this line: 'game.magicNursery.forgeOfMatter.visible = false;' Line Number: 127
User prompt
при переходе в door2 счетчик начинает отсчитывать заново поверх прошлого прогресса, нужно что бы прогресс счетчика продолжился, исправь ошибки
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'visible')' in or related to this line: 'forgeOfMatter.visible = false;' Line Number: 127
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'visible')' in or related to this line: 'game.magicNursery.forgeOfMatter.visible = false;' Line Number: 127
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'visible')' in or related to this line: 'forgeOfMatter.visible = false;' Line Number: 127
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'visible')' in or related to this line: 'game.magicNursery.forgeOfMatter.visible = false;' Line Number: 127
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'visible')' in or related to this line: 'forgeOfMatter.visible = false;' Line Number: 127
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of null (setting 'visible')' in or related to this line: 'forgeOfMatter.visible = false;' Line Number: 127
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'visible')' in or related to this line: 'forgeOfMatter.visible = false;' Line Number: 127
User prompt
Please fix the bug: 'Uncaught ReferenceError: forgeOfMatter is not defined' in or related to this line: 'forgeOfMatter.visible = false;' Line Number: 127
User prompt
проблемы с обьектом ForgeOfMatter, при переходе в door2 обьект удаляется и прогресс счетчика пропадает, нужно что бы он не удалялся а скрывался
User prompt
Please fix the bug: 'Uncaught ReferenceError: magicNursery is not defined' in or related to this line: 'magicNursery.x = 2048 / 4;' Line Number: 198
User prompt
пропала кликабельность обьекта magicAnvin
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'visible')' in or related to this line: 'game.magicNursery.growthRateText.visible = true;' Line Number: 129
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'visible')' in or related to this line: 'game.magicNursery.growthRateText.visible = true;' Line Number: 129
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'visible')' in or related to this line: 'game.magicNursery.growthRateText.visible = true;' Line Number: 128
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'growthRateText.y = counterText.height;' Line Number: 150
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'height')' in or related to this line: 'growthRateText.y = counterText.height;' Line Number: 150
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Create a new class for the anvil object var Anvil = Container.expand(function () { var self = Container.call(this); // Attach 'anvil' asset to the 'Anvil' object var anvilGraphics = self.attachAsset('anvil', { anchorX: 0.5, anchorY: 0.5 }); // Initialize the click counter self.clickCounter = 0; // Make the 'Anvil' object interactive self.interactive = true; // Define the 'down' event handler self.down = function (x, y, obj) { // Increment the click counter self.clickCounter++; // Update the text object with the click counter and label counterText.setText('Forging skill: ' + self.clickCounter); // Change the color of the counter text based on the click counter if (self.clickCounter >= 100 && self.clickCounter < 200) { counterText.tint = 0x00FF00; // Green } else if (self.clickCounter >= 200 && self.clickCounter < 300) { counterText.tint = 0x0000FF; // Blue } else if (self.clickCounter >= 300) { counterText.tint = 0x800080; // Purple } }; }); // Create a new class for the Door object var Door = Container.expand(function () { var self = Container.call(this); // Attach 'Door' asset to the 'Door' object var doorGraphics = self.attachAsset('Door', { anchorX: 0.5, anchorY: 0.5 }); // Make the 'Door' object interactive self.interactive = true; // Define the 'down' event handler self.down = function (x, y, obj) { // Remove the existing hammer hammer.destroy(); // Create a new screen game.magicNursery = game.addChild(new Container()); // Attach 'magicNurseryBackground' asset to the 'magicNursery' object var magicNurseryBackground = game.magicNursery.attachAsset('magicNurseryBackground', { anchorX: 0.5, anchorY: 0.5, interactive: false, // Disable interactivity to prevent blurring on click scaleX: 2, // Double the size horizontally scaleY: 2 // Double the size vertically }); // Recreate the hammer asset magicNurseryBackground.x = 2048 / 2; magicNurseryBackground.y = 2732 / 2; // Attach 'ForgeOfMatter' asset to the 'magicNursery' object var forgeOfMatter = game.magicNursery.attachAsset('ForgeOfMatter', { anchorX: 0.5, anchorY: 0.5, interactive: true, scaleX: 1, scaleY: 1 }); // Initialize the click counter for ForgeOfMatter forgeOfMatter.clickCounter = 0; // Define the 'down' event handler for ForgeOfMatter forgeOfMatter.down = function (x, y, obj) { // Increment the click counter forgeOfMatter.clickCounter++; // Update the text object with the click counter and label growthRateText.setText('Growth rate: ' + forgeOfMatter.clickCounter); }; forgeOfMatter.x = 2048 / 2; forgeOfMatter.y = 2732 / 1.35; // Add a new counter to the ForgeOfMatter object growthRateText = new Text2('Growth rate: 0', { size: 150, fill: 0xFFFFFF }); growthRateText.anchor.set(0.5, 0); LK.gui.top.addChild(growthRateText); growthRateText.y = counterText.height; // Hide the game screen gameScreen.visible = false; // Hide the counter display counterText.visible = false; // Add a new object 'Door2' var door2 = game.magicNursery.addChild(new Door2()); // Position 'Door2' to the right, between the center and the edge of the screen door2.x = 2048 * 0.75; door2.y = 2732 * 0.9; hammer = game.addChild(LK.getAsset('hammer', { anchorX: 0.5, anchorY: 0.5, scaleX: -1 })); }; }); // Create a new class for the Door2 object var Door2 = Container.expand(function () { var self = Container.call(this); // Attach 'Door' asset to the 'Door2' object var doorGraphics = self.attachAsset('Door', { anchorX: 0.5, anchorY: 0.5 }); // Make the 'Door2' object interactive self.interactive = true; // Define the 'down' event handler self.down = function (x, y, obj) { // Remove the existing hammer hammer.destroy(); // Show the Anvil screen gameScreen.visible = true; // Show the counter display counterText.visible = true; // Hide the Magic Nursery screen game.magicNursery.visible = false; // Hide the Growth rate counter growthRateText.visible = false; // Recreate the hammer asset hammer = game.addChild(LK.getAsset('hammer', { anchorX: 0.5, anchorY: 0.5, scaleX: -1 })); }; }); /**** * Initialize Game ****/ // Create a new text object to display the click counter var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Create a new class for the Door object var growthRateText; var background = game.addChild(new Container()); background.width = 2048; background.height = 2732; background.x = 2048 / 2; background.y = 2732 / 2; var backgroundGraphics = background.attachAsset('background', { anchorX: 0.5, anchorY: 0.5 }); var gameScreen; var newGame = game.addChild(new Container()); newGame.x = 2048 / 2; newGame.y = 2732 * 3 / 4; // Attach 'newGameText' asset to the 'New Game' object var newGameText = newGame.attachAsset('newGameText', { anchorX: 0.5, anchorY: 0.5, stroke: 0xFFFFFF, // White color strokeThickness: 5 // 5px thickness }); // Make the 'New Game' object clickable newGame.interactive = true; newGame.down = function (x, y, obj) { hammer.destroy(); // Create a new game screen gameScreen = game.addChild(new Container()); gameScreen.x = 2048 / 2; gameScreen.y = 2732 / 2; // Attach 'gameScreenBackground' asset to the 'gameScreen' object var gameScreenBackground = gameScreen.attachAsset('gameScreenBackground', { anchorX: 0.5, anchorY: 0.5 }); // Hide the main menu newGame.visible = false; // Disable the background background.visible = false; // Create a new instance of the Anvil class var anvil = gameScreen.addChild(new Anvil()); // Position 'The anvil' closer to the left center of the game screen anvil.x = 2048 / 10; anvil.y = 2732 / 9; // Add a new object 'Magic Nursery' var magicNursery = gameScreen.addChild(new Door()); // Position 'Magic Nursery' to the left and up magicNursery.x = 2048 / 4; magicNursery.y = 2732 / 2.5; hammer = game.addChild(LK.getAsset('hammer', { anchorX: 0.5, anchorY: 0.5, scaleX: -1 })); }; // Create a new text object to display the click counter var counterText = new Text2('Forging skill: 0', { size: 150, fill: 0xFFFFFF }); // Position the text object at the top right corner of the screen counterText.anchor.set(1, 0); LK.gui.topRight.addChild(counterText); counterText.y = 0; // Initialize hammer asset var hammer; hammer = game.addChild(LK.getAsset('hammer', { anchorX: 0.5, anchorY: 0.5, scaleX: -1 })); // Function to make the hammer follow the mouse/touch position function updateHammerPosition(x, y) { if (hammer) { hammer.x = x; hammer.y = y; } } // Make the cursor follow the mouse/touch position game.move = function (x, y, obj) { updateHammerPosition(x, y); }; // Animate cursor rotation on click game.down = function (x, y, obj) { LK.getSound('hammer').play(); tween(hammer, { rotation: -Math.PI / 2 }, { duration: 125, easing: tween.easeInOut, onFinish: function onFinish() { // Create stars around the hammer for 0.25 seconds for (var i = 0; i < 5; i++) { var star = game.addChild(LK.getAsset('star', { anchorX: 0.5, anchorY: 0.5 })); star.x = hammer.x - hammer.width / 2 + Math.random() * 100 - 25; star.y = hammer.y + hammer.height / 2 + Math.random() * 100 - 25; (function (star) { // Make the star move upwards star.update = function () { star.y -= 5; // Move the star upwards by 5 pixels per frame if (star.x < hammer.x) { star.x += 2; // Move the star slightly to the right if on the left side of the hammer } else { star.x -= 2; // Move the star slightly to the left if on the right side of the hammer } }; LK.setTimeout(function () { star.destroy(); }, 250); })(star); } tween(hammer, { rotation: 0 }, { duration: 125, easing: tween.easeInOut }); } }); };
===================================================================
--- original.js
+++ change.js
@@ -1,5 +1,10 @@
/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
* Classes
****/
// Create a new class for the anvil object
var Anvil = Container.expand(function () {
@@ -40,8 +45,10 @@
// Make the 'Door' object interactive
self.interactive = true;
// Define the 'down' event handler
self.down = function (x, y, obj) {
+ // Remove the existing hammer
+ hammer.destroy();
// Create a new screen
game.magicNursery = game.addChild(new Container());
// Attach 'magicNurseryBackground' asset to the 'magicNursery' object
var magicNurseryBackground = game.magicNursery.attachAsset('magicNurseryBackground', {
@@ -52,8 +59,9 @@
scaleX: 2,
// Double the size horizontally
scaleY: 2 // Double the size vertically
});
+ // Recreate the hammer asset
magicNurseryBackground.x = 2048 / 2;
magicNurseryBackground.y = 2732 / 2;
// Attach 'ForgeOfMatter' asset to the 'magicNursery' object
var forgeOfMatter = game.magicNursery.attachAsset('ForgeOfMatter', {
@@ -68,31 +76,35 @@
// Define the 'down' event handler for ForgeOfMatter
forgeOfMatter.down = function (x, y, obj) {
// Increment the click counter
forgeOfMatter.clickCounter++;
- growthRateValue = forgeOfMatter.clickCounter; // Update the global growthRateValue
// Update the text object with the click counter and label
growthRateText.setText('Growth rate: ' + forgeOfMatter.clickCounter);
};
forgeOfMatter.x = 2048 / 2;
forgeOfMatter.y = 2732 / 1.35;
// Add a new counter to the ForgeOfMatter object
- growthRateText = new Text2('Growth rate: ' + growthRateValue, {
- size: 100,
+ growthRateText = new Text2('Growth rate: 0', {
+ size: 150,
fill: 0xFFFFFF
});
- growthRateText.anchor.set(0, 0);
- LK.gui.topLeft.addChild(growthRateText);
+ growthRateText.anchor.set(0.5, 0);
+ LK.gui.top.addChild(growthRateText);
growthRateText.y = counterText.height;
// Hide the game screen
gameScreen.visible = false;
- // Show the counter display
- counterText.visible = true;
+ // Hide the counter display
+ counterText.visible = false;
// Add a new object 'Door2'
var door2 = game.magicNursery.addChild(new Door2());
// Position 'Door2' to the right, between the center and the edge of the screen
door2.x = 2048 * 0.75;
door2.y = 2732 * 0.9;
+ hammer = game.addChild(LK.getAsset('hammer', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: -1
+ }));
};
});
// Create a new class for the Door2 object
var Door2 = Container.expand(function () {
@@ -105,16 +117,24 @@
// Make the 'Door2' object interactive
self.interactive = true;
// Define the 'down' event handler
self.down = function (x, y, obj) {
+ // Remove the existing hammer
+ hammer.destroy();
// Show the Anvil screen
gameScreen.visible = true;
// Show the counter display
counterText.visible = true;
// Hide the Magic Nursery screen
game.magicNursery.visible = false;
- // Show the Growth rate counter
- growthRateText.visible = true;
+ // Hide the Growth rate counter
+ growthRateText.visible = false;
+ // Recreate the hammer asset
+ hammer = game.addChild(LK.getAsset('hammer', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: -1
+ }));
};
});
/****
@@ -129,9 +149,8 @@
* Game Code
****/
// Create a new class for the Door object
var growthRateText;
-var growthRateValue = 0; // Initialize a global variable to store the growth rate value
var background = game.addChild(new Container());
background.width = 2048;
background.height = 2732;
background.x = 2048 / 2;
@@ -146,13 +165,17 @@
newGame.y = 2732 * 3 / 4;
// Attach 'newGameText' asset to the 'New Game' object
var newGameText = newGame.attachAsset('newGameText', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0.5,
+ stroke: 0xFFFFFF,
+ // White color
+ strokeThickness: 5 // 5px thickness
});
// Make the 'New Game' object clickable
newGame.interactive = true;
newGame.down = function (x, y, obj) {
+ hammer.destroy();
// Create a new game screen
gameScreen = game.addChild(new Container());
gameScreen.x = 2048 / 2;
gameScreen.y = 2732 / 2;
@@ -174,14 +197,78 @@
var magicNursery = gameScreen.addChild(new Door());
// Position 'Magic Nursery' to the left and up
magicNursery.x = 2048 / 4;
magicNursery.y = 2732 / 2.5;
+ hammer = game.addChild(LK.getAsset('hammer', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: -1
+ }));
};
// Create a new text object to display the click counter
var counterText = new Text2('Forging skill: 0', {
- size: 100,
+ size: 150,
fill: 0xFFFFFF
});
-// Position the text object at the top left corner of the screen
-counterText.anchor.set(0, 0);
-LK.gui.topLeft.addChild(counterText);
-counterText.y = 0;
\ No newline at end of file
+// Position the text object at the top right corner of the screen
+counterText.anchor.set(1, 0);
+LK.gui.topRight.addChild(counterText);
+counterText.y = 0;
+// Initialize hammer asset
+var hammer;
+hammer = game.addChild(LK.getAsset('hammer', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: -1
+}));
+// Function to make the hammer follow the mouse/touch position
+function updateHammerPosition(x, y) {
+ if (hammer) {
+ hammer.x = x;
+ hammer.y = y;
+ }
+}
+// Make the cursor follow the mouse/touch position
+game.move = function (x, y, obj) {
+ updateHammerPosition(x, y);
+};
+// Animate cursor rotation on click
+game.down = function (x, y, obj) {
+ LK.getSound('hammer').play();
+ tween(hammer, {
+ rotation: -Math.PI / 2
+ }, {
+ duration: 125,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ // Create stars around the hammer for 0.25 seconds
+ for (var i = 0; i < 5; i++) {
+ var star = game.addChild(LK.getAsset('star', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ star.x = hammer.x - hammer.width / 2 + Math.random() * 100 - 25;
+ star.y = hammer.y + hammer.height / 2 + Math.random() * 100 - 25;
+ (function (star) {
+ // Make the star move upwards
+ star.update = function () {
+ star.y -= 5; // Move the star upwards by 5 pixels per frame
+ if (star.x < hammer.x) {
+ star.x += 2; // Move the star slightly to the right if on the left side of the hammer
+ } else {
+ star.x -= 2; // Move the star slightly to the left if on the right side of the hammer
+ }
+ };
+ LK.setTimeout(function () {
+ star.destroy();
+ }, 250);
+ })(star);
+ }
+ tween(hammer, {
+ rotation: 0
+ }, {
+ duration: 125,
+ easing: tween.easeInOut
+ });
+ }
+ });
+};
\ No newline at end of file