User prompt
Now so if a red tree touches a normal tree the tree will be destroyed
User prompt
Make birds not always appear on normal trees like 50/50 Of probability
User prompt
Add birds which will be like red trees but will appear from above to disturb the jump but they can only appear if there are no red trees below
User prompt
Now so the excavator can't jump more than twice in a row
User prompt
Ace the longest jump
User prompt
So the excavator jumps for longer to make it easier to avoid the red trees
User prompt
So the excavator jumps higher to make it easier to avoid the red trees
Initial prompt
Excavator festructor
/**** * Classes ****/ // Class for Birds var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.x -= self.speed; }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Class for the Excavator var Excavator = Container.expand(function () { var self = Container.call(this); var excavatorGraphics = self.attachAsset('excavator', { anchorX: 0.5, anchorY: 0.5 }); self.jumpHeight = 500; self.isJumping = false; self.jumpSpeed = 20; self.originalY = 0; self.jumpCount = 0; // Initialize jump counter self.jump = function () { if (!self.isJumping && self.jumpCount < 2) { // Check if the excavator is not jumping and has jumped less than twice self.isJumping = true; self.originalY = self.y; self.jumpCount++; // Increment jump counter } }; self.update = function () { if (self.isJumping) { self.y -= self.jumpSpeed; if (self.y <= self.originalY - self.jumpHeight * 3) { self.isJumping = false; self.jumpCount = 0; // Reset jump counter when the excavator lands } } else if (self.y < self.originalY) { self.y += self.jumpSpeed; } }; }); // Class for Trees var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = self.attachAsset('tree', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.isRed = false; self.update = function () { self.x -= self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ var excavator = game.addChild(new Excavator()); excavator.x = 200; excavator.y = 2000; var trees = []; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); game.down = function (x, y, obj) { excavator.jump(); }; game.update = function () { excavator.update(); if (LK.ticks % 60 == 0) { var newTree = new Tree(); newTree.x = 2048; newTree.y = 2000; if (Math.random() < 0.2) { newTree.isRed = true; newTree.attachAsset('redTree', { anchorX: 0.5, anchorY: 0.5 }); } trees.push(newTree); game.addChild(newTree); // Add birds only if there are no red trees below and with a 50% probability if (!newTree.isRed && Math.random() < 0.5) { var newBird = new Bird(); newBird.x = 2048; newBird.y = 1000; trees.push(newBird); game.addChild(newBird); } } for (var i = trees.length - 1; i >= 0; i--) { var tree = trees[i]; tree.update(); if (tree.x < -100) { tree.destroy(); trees.splice(i, 1); continue; } if (excavator.intersects(tree)) { if (tree instanceof Bird) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } else if (tree.isRed && !excavator.isJumping) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } else if (!tree.isRed) { score++; scoreTxt.setText(score); tree.destroy(); trees.splice(i, 1); if (score >= 50) { LK.showYouWin(); } } } else if (tree.isRed) { for (var j = trees.length - 1; j >= 0; j--) { var normalTree = trees[j]; if (!normalTree.isRed && tree.intersects(normalTree)) { normalTree.destroy(); trees.splice(j, 1); } } } } };
===================================================================
--- original.js
+++ change.js
@@ -134,7 +134,15 @@
if (score >= 50) {
LK.showYouWin();
}
}
+ } else if (tree.isRed) {
+ for (var j = trees.length - 1; j >= 0; j--) {
+ var normalTree = trees[j];
+ if (!normalTree.isRed && tree.intersects(normalTree)) {
+ normalTree.destroy();
+ trees.splice(j, 1);
+ }
+ }
}
}
};
\ No newline at end of file
Excavator with 2d tender rockets. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Tree. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Red tree. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Nube. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Mud ground. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows