User prompt
manual drop water bomb with tap
User prompt
drone auto move βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
User prompt
fix music
User prompt
slowly drone moving βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
User prompt
fix touch control βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
User prompt
make touch pad to control drone βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
User prompt
smooth drone control βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
User prompt
drone easy swipe control βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
User prompt
fix swipe quick response
User prompt
add distance bush asset and tree asset
User prompt
add more bushes
User prompt
add more trees
User prompt
make green bush asset
User prompt
add much more tree
User prompt
add light green background
User prompt
make easy swipe control βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
User prompt
fix swipe control, make easy swipe βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
User prompt
make swipe control are smooth βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
User prompt
change logic. drone can move left or right by swipe
User prompt
fix drone moving automaticly to left or right
User prompt
drone automatic move left dan right βͺπ‘ Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Forest Fire Fighter
Initial prompt
game title : drone throwing water bombs. fires in forest groups βgame mechanics : flying drones throwing water bombs at fire points βbackground : scattered forest areas.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Base = Container.expand(function () { var self = Container.call(this); var baseGraphics = self.attachAsset('base', { anchorX: 0.5, anchorY: 0.5 }); return self; }); var Drone = Container.expand(function () { var self = Container.call(this); var droneGraphics = self.attachAsset('drone', { anchorX: 0.5, anchorY: 0.5 }); self.waterBombs = 10; self.maxWaterBombs = 10; self.refillWater = function () { if (self.waterBombs < self.maxWaterBombs) { self.waterBombs = self.maxWaterBombs; LK.getSound('refill').play(); waterBombsText.setText('Water: ' + self.waterBombs); } }; self.dropWaterBomb = function () { if (self.waterBombs > 0) { self.waterBombs--; waterBombsText.setText('Water: ' + self.waterBombs); var waterBomb = new WaterBomb(); waterBomb.x = self.x; waterBomb.y = self.y + 30; waterBombs.push(waterBomb); game.addChild(waterBomb); LK.getSound('drop').play(); } }; return self; }); var Fire = Container.expand(function () { var self = Container.call(this); var fireGraphics = self.attachAsset('fire', { anchorX: 0.5, anchorY: 0.5 }); self.extinguished = false; self.update = function () { if (!self.extinguished) { fireGraphics.alpha = 0.7 + Math.sin(LK.ticks * 0.2) * 0.3; } }; self.extinguish = function () { if (!self.extinguished) { self.extinguished = true; LK.getSound('extinguish').play(); tween(fireGraphics, { alpha: 0, scaleX: 0.1, scaleY: 0.1 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); LK.setScore(LK.getScore() + 100); scoreText.setText('Score: ' + LK.getScore()); firesExtinguished++; } }; return self; }); var Tree = Container.expand(function () { var self = Container.call(this); var treeGraphics = self.attachAsset('tree', { anchorX: 0.5, anchorY: 1.0 }); return self; }); var WaterBomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = self.attachAsset('waterBomb', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.update = function () { self.y += self.speed; if (self.y > 2732 + 50) { self.destroy(); for (var i = waterBombs.length - 1; i >= 0; i--) { if (waterBombs[i] === self) { waterBombs.splice(i, 1); break; } } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var drone = game.addChild(new Drone()); drone.x = 1024; drone.y = 200; var base = game.addChild(new Base()); base.x = 1024; base.y = 100; var fires = []; var waterBombs = []; var trees = []; var dragNode = null; var firesExtinguished = 0; var totalFires = 8; // Create forest background with trees for (var i = 0; i < 15; i++) { var tree = game.addChild(new Tree()); tree.x = Math.random() * 1800 + 124; tree.y = Math.random() * 2000 + 400; trees.push(tree); } // Create fires scattered throughout the forest for (var i = 0; i < totalFires; i++) { var fire = game.addChild(new Fire()); fire.x = Math.random() * 1600 + 224; fire.y = Math.random() * 1800 + 600; fires.push(fire); } // UI Elements var scoreText = new Text2('Score: 0', { size: 60, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); var waterBombsText = new Text2('Water: 10', { size: 50, fill: 0xFFFFFF }); waterBombsText.anchor.set(0, 0); waterBombsText.x = 150; waterBombsText.y = 50; LK.gui.topLeft.addChild(waterBombsText); var instructionText = new Text2('Drag drone to move, Tap to drop water bombs', { size: 40, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 0); instructionText.y = 100; LK.gui.top.addChild(instructionText); // Game event handlers game.down = function (x, y, obj) { var droneDistance = Math.sqrt(Math.pow(x - drone.x, 2) + Math.pow(y - drone.y, 2)); if (droneDistance < 100) { dragNode = drone; } else { drone.dropWaterBomb(); } }; game.move = function (x, y, obj) { if (dragNode) { dragNode.x = Math.max(40, Math.min(2008, x)); dragNode.y = Math.max(40, Math.min(2692, y)); } }; game.up = function (x, y, obj) { dragNode = null; }; game.update = function () { // Check for water bomb collisions with fires for (var i = waterBombs.length - 1; i >= 0; i--) { var waterBomb = waterBombs[i]; for (var j = fires.length - 1; j >= 0; j--) { var fire = fires[j]; if (!fire.extinguished && waterBomb.intersects(fire)) { fire.extinguish(); waterBomb.destroy(); waterBombs.splice(i, 1); fires.splice(j, 1); break; } } } // Check if drone is at base for refill if (drone.intersects(base) && drone.waterBombs < drone.maxWaterBombs) { drone.refillWater(); } // Check win condition if (firesExtinguished >= totalFires) { LK.showYouWin(); } // Check lose condition (no water and fires remaining) if (drone.waterBombs === 0 && waterBombs.length === 0 && fires.length > 0) { var timeoutLose = LK.setTimeout(function () { LK.showGameOver(); }, 2000); } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,215 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Base = Container.expand(function () {
+ var self = Container.call(this);
+ var baseGraphics = self.attachAsset('base', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ return self;
+});
+var Drone = Container.expand(function () {
+ var self = Container.call(this);
+ var droneGraphics = self.attachAsset('drone', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.waterBombs = 10;
+ self.maxWaterBombs = 10;
+ self.refillWater = function () {
+ if (self.waterBombs < self.maxWaterBombs) {
+ self.waterBombs = self.maxWaterBombs;
+ LK.getSound('refill').play();
+ waterBombsText.setText('Water: ' + self.waterBombs);
+ }
+ };
+ self.dropWaterBomb = function () {
+ if (self.waterBombs > 0) {
+ self.waterBombs--;
+ waterBombsText.setText('Water: ' + self.waterBombs);
+ var waterBomb = new WaterBomb();
+ waterBomb.x = self.x;
+ waterBomb.y = self.y + 30;
+ waterBombs.push(waterBomb);
+ game.addChild(waterBomb);
+ LK.getSound('drop').play();
+ }
+ };
+ return self;
+});
+var Fire = Container.expand(function () {
+ var self = Container.call(this);
+ var fireGraphics = self.attachAsset('fire', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.extinguished = false;
+ self.update = function () {
+ if (!self.extinguished) {
+ fireGraphics.alpha = 0.7 + Math.sin(LK.ticks * 0.2) * 0.3;
+ }
+ };
+ self.extinguish = function () {
+ if (!self.extinguished) {
+ self.extinguished = true;
+ LK.getSound('extinguish').play();
+ tween(fireGraphics, {
+ alpha: 0,
+ scaleX: 0.1,
+ scaleY: 0.1
+ }, {
+ duration: 500,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ self.destroy();
+ }
+ });
+ LK.setScore(LK.getScore() + 100);
+ scoreText.setText('Score: ' + LK.getScore());
+ firesExtinguished++;
+ }
+ };
+ return self;
+});
+var Tree = Container.expand(function () {
+ var self = Container.call(this);
+ var treeGraphics = self.attachAsset('tree', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ return self;
+});
+var WaterBomb = Container.expand(function () {
+ var self = Container.call(this);
+ var bombGraphics = self.attachAsset('waterBomb', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 8;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732 + 50) {
+ self.destroy();
+ for (var i = waterBombs.length - 1; i >= 0; i--) {
+ if (waterBombs[i] === self) {
+ waterBombs.splice(i, 1);
+ break;
+ }
+ }
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+var drone = game.addChild(new Drone());
+drone.x = 1024;
+drone.y = 200;
+var base = game.addChild(new Base());
+base.x = 1024;
+base.y = 100;
+var fires = [];
+var waterBombs = [];
+var trees = [];
+var dragNode = null;
+var firesExtinguished = 0;
+var totalFires = 8;
+// Create forest background with trees
+for (var i = 0; i < 15; i++) {
+ var tree = game.addChild(new Tree());
+ tree.x = Math.random() * 1800 + 124;
+ tree.y = Math.random() * 2000 + 400;
+ trees.push(tree);
+}
+// Create fires scattered throughout the forest
+for (var i = 0; i < totalFires; i++) {
+ var fire = game.addChild(new Fire());
+ fire.x = Math.random() * 1600 + 224;
+ fire.y = Math.random() * 1800 + 600;
+ fires.push(fire);
+}
+// UI Elements
+var scoreText = new Text2('Score: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+var waterBombsText = new Text2('Water: 10', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+waterBombsText.anchor.set(0, 0);
+waterBombsText.x = 150;
+waterBombsText.y = 50;
+LK.gui.topLeft.addChild(waterBombsText);
+var instructionText = new Text2('Drag drone to move, Tap to drop water bombs', {
+ size: 40,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 0);
+instructionText.y = 100;
+LK.gui.top.addChild(instructionText);
+// Game event handlers
+game.down = function (x, y, obj) {
+ var droneDistance = Math.sqrt(Math.pow(x - drone.x, 2) + Math.pow(y - drone.y, 2));
+ if (droneDistance < 100) {
+ dragNode = drone;
+ } else {
+ drone.dropWaterBomb();
+ }
+};
+game.move = function (x, y, obj) {
+ if (dragNode) {
+ dragNode.x = Math.max(40, Math.min(2008, x));
+ dragNode.y = Math.max(40, Math.min(2692, y));
+ }
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+};
+game.update = function () {
+ // Check for water bomb collisions with fires
+ for (var i = waterBombs.length - 1; i >= 0; i--) {
+ var waterBomb = waterBombs[i];
+ for (var j = fires.length - 1; j >= 0; j--) {
+ var fire = fires[j];
+ if (!fire.extinguished && waterBomb.intersects(fire)) {
+ fire.extinguish();
+ waterBomb.destroy();
+ waterBombs.splice(i, 1);
+ fires.splice(j, 1);
+ break;
+ }
+ }
+ }
+ // Check if drone is at base for refill
+ if (drone.intersects(base) && drone.waterBombs < drone.maxWaterBombs) {
+ drone.refillWater();
+ }
+ // Check win condition
+ if (firesExtinguished >= totalFires) {
+ LK.showYouWin();
+ }
+ // Check lose condition (no water and fires remaining)
+ if (drone.waterBombs === 0 && waterBombs.length === 0 && fires.length > 0) {
+ var timeoutLose = LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 2000);
+ }
+};
\ No newline at end of file