Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: Tree is not defined' in or related to this line: 'var newTree = new Tree();' Line Number: 129
User prompt
change shooting rock with shooting trees
User prompt
1-If the dragon shot the rocks he get random points from 0-40 2-If the dragon get points than increase the score by the amount of point he get.
Code edit (12 edits merged)
Please save this source code
User prompt
Make the dragon get less damage from rock01 object
User prompt
Make the rock the first object in this game
User prompt
Dragon take damage if touched by rock01
User prompt
Let rock01 explode by firballs of the dragon
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Move the health bar to right little bit
User prompt
Don't let space between health bar and th score text
User prompt
Move it to middle of the bottom side
User prompt
Move the health bar to the middle
User prompt
Move the health bar to the bottom middle of the screen
User prompt
Make the health bar down the scor text and make text up little bit to let space for the health bar
User prompt
Make the health bar down the level text
User prompt
Move the score to the left bottom of the screen, let small distance from the bottom of the screen line
User prompt
arange the text scor and health bar
User prompt
Lower the health bar little bit
User prompt
Please fix the bug: 'level is not defined' in or related to this line: 'if (level === 1) {' Line Number: 102
User prompt
Make the health bar down little bit separated from score text
User prompt
Make the game very smooth for better performace
User prompt
Make less objects of rock01
/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Dragon class to represent the player character var Dragon = Container.expand(function () { var self = Container.call(this); var dragonGraphics = self.attachAsset('dragon', { anchorX: 0.5, anchorY: 0.5, scaleX: 2.0, scaleY: 2.0, smooth: true, filterQuality: 2 }); self.speed = 10; // Speed of the dragon self.update = function () { // Update logic for the dragon can be added here if needed }; }); // Fireball class to represent the fireballs that the dragon shoots var Fireball = Container.expand(function () { var self = Container.call(this); var fireballGraphics = self.attachAsset('Shout', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5, smooth: true, filterQuality: 2 }); self.speed = 20; // Increase the speed of the fireball self.update = function () { // Move the fireball straight down self.y += self.speed; }; }); // HealthBar class to represent the player's health var HealthBar = Container.expand(function () { var self = Container.call(this); var healthBarGraphics = self.attachAsset('healthBar', { anchorX: 0.0, anchorY: 0.0, scaleX: 2048 / 1000, // Scale to fit the game width scaleY: 0.1 }); self.maxHealth = 1000; self.currentHealth = self.maxHealth; self.update = function () { healthBarGraphics.scaleX = self.currentHealth / self.maxHealth; healthBarGraphics.scaleY = 0.05; // Resize the health bar to fit the top of the screen }; }); // Rock class to represent the second object var Rock = Container.expand(function () { var self = Container.call(this); var rockGraphics = self.attachAsset('Rock01', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.0, scaleY: 1.0, smooth: true, filterQuality: 1 }); self.speed = 5; // Speed of the rock self.update = function () { // Move the rock straight up self.y -= self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000, //Init game with black background height: 3000 // Increase the game screen height }); /**** * Game Code ****/ // Initialize level variable var level = 1; // Set the initial level to 1 // Initialize game variables var dragon; var spheres = []; var fireballs = []; // Initialize fireballs array var score = 0; // Initialize score to 0 var scoreTxt; // Add background image to the game for level 1 only if (level === 1) { var background = LK.getAsset('Background', { anchorX: 0.0, anchorY: 0.0 }); background = game.addChild(background); background.width = game.width; background.height = game.height; background.smooth = true; // Enable smoothing to remove pixelation background.filterQuality = 5; // Reduce the filter quality to improve performance background.scale.set(game.width / background.width, game.height / background.height); // Scale the background to fit the screen // Refresh the background to be clearer & fit to screen every 60 ticks game.update = function () { if (LK.ticks % 60 == 0) { background.texture.update(); } }; } // Function to handle game updates game.update = function () { // Update dragon position based on touch input if (!LK.gameOver && dragNode && dragNode.global) { dragNode.x = game.toLocal(dragNode.global).x; } // Spawn new rocks only for level 1 if (level === 1 && !LK.gameOver && LK.ticks % 120 == 0) { var newRock = new Rock(); newRock.x = Math.random() * 2048; newRock.y = 2732; spheres.push(newRock); game.addChild(newRock); } // Regenerate player's health to max when score reaches 1000 if (score >= 1000) { healthBar.currentHealth = healthBar.maxHealth; } // Check for collision between rocks and dragon for (var i = spheres.length - 1; i >= 0; i--) { if (spheres[i].intersects(dragon)) { // Generate random damage between 0 and 20 var damage = Math.floor(Math.random() * 21); // Reduce health by damage healthBar.currentHealth = Math.max(0, healthBar.currentHealth - damage); // Destroy the rock after collision spheres[i].destroy(); spheres.splice(i, 1); } } // Check for collision between fireballs and rocks for (var i = spheres.length - 1; i >= 0; i--) { for (var j = fireballs.length - 1; j >= 0; j--) { if (spheres[i] && fireballs[j] && spheres[i].intersects(fireballs[j])) { // Generate random score between 0 and 40 var scoreIncrease = Math.floor(Math.random() * 41); // Increase score score += scoreIncrease; // Update score display scoreTxt.setText('Score: ' + score); // Destroy the rock and fireball after collision spheres[i].destroy(); fireballs[j].destroy(); spheres.splice(i, 1); fireballs.splice(j, 1); } } } // Add a delay to the game update function to reduce lag LK.setTimeout(game.update, 1000 / 60); }; // Initialize dragon dragon = game.addChild(new Dragon()); dragon.x = 2048 / 2; dragon.y = 200; // Initialize level display var levelTxt = new Text2('Level: 1', { size: 100, fill: 0x800080, // Purple color font: "'Time new roman',Impact,'Arial Black',Tahoma" }); levelTxt.anchor.set(1, 1); LK.gui.bottomRight.addChild(levelTxt); levelTxt.x = -50; // Move the level text to the right side of the screen levelTxt.y = -100; // Position the level text at the bottom of the screen // Initialize score display scoreTxt = new Text2('Score: 0', { size: 100, fill: 0x800080, // Purple color font: "'Time new roman',Impact,'Arial Black',Tahoma" }); LK.gui.top.addChild(scoreTxt); scoreTxt.anchor.set(0, 0); // Sets anchor to the left of the top edge of the text. scoreTxt.x = 50; // Position the score text a little bit to the right scoreTxt.y = levelTxt.y - scoreTxt.height - 50; // Position the score text 50 pixels above the level text // Initialize health bar var healthBar = game.addChild(new HealthBar()); healthBar.x = 50; healthBar.y = 2732 - healthBar.height - 150; // Move health bar a little bit down scoreTxt.anchor.set(0, 0); LK.gui.bottomLeft.addChild(scoreTxt); // Handle touch input for dragging the dragon var dragNode = null; game.down = function (x, y, obj) { dragNode = dragon; }; game.up = function (x, y, obj) { dragNode = null; }; game.move = function (x, y, obj) { if (dragNode) { // Limit the dragon's movement to the game area var newX = Math.max(dragon.width / 2, Math.min(2048 - dragon.width / 2, x)); var newY = Math.max(dragon.height / 2, Math.min(2732 - dragon.height / 2, y)); dragNode.x = newX; dragNode.y = newY; // Shoot a fireball at regular intervals if (LK.ticks % 10 == 0) { for (var i = 0; i < 1; i++) { var fireball = new Fireball(); fireball.x = dragon.x; fireball.y = dragon.y; fireballs.push(fireball); game.addChild(fireball); } } } };
===================================================================
--- original.js
+++ change.js
@@ -189,9 +189,9 @@
scoreTxt.y = levelTxt.y - scoreTxt.height - 50; // Position the score text 50 pixels above the level text
// Initialize health bar
var healthBar = game.addChild(new HealthBar());
healthBar.x = 50;
-healthBar.y = 2732 - healthBar.height - 100; // Move health bar a little bit down
+healthBar.y = 2732 - healthBar.height - 150; // Move health bar a little bit down
scoreTxt.anchor.set(0, 0);
LK.gui.bottomLeft.addChild(scoreTxt);
// Handle touch input for dragging the dragon
var dragNode = null;