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; var swipeStartX = 0; var swipeStartY = 0; var isSwipeActive = false; // 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) { swipeStartX = x; swipeStartY = y; isSwipeActive = true; var droneDistance = Math.sqrt(Math.pow(x - drone.x, 2) + Math.pow(y - drone.y, 2)); if (droneDistance < 100) { dragNode = drone; } }; 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) { if (isSwipeActive && !dragNode) { var swipeDistanceX = x - swipeStartX; var swipeDistanceY = y - swipeStartY; var swipeDistance = Math.sqrt(swipeDistanceX * swipeDistanceX + swipeDistanceY * swipeDistanceY); if (swipeDistance > 50) { // It's a swipe if (Math.abs(swipeDistanceX) > Math.abs(swipeDistanceY)) { // Horizontal swipe tween.stop(drone, { x: true }); if (swipeDistanceX > 0) { // Swipe right tween(drone, { x: Math.min(1848, drone.x + 300) }, { duration: 500, easing: tween.easeOut }); } else { // Swipe left tween(drone, { x: Math.max(200, drone.x - 300) }, { duration: 500, easing: tween.easeOut }); } } } else { // It's a tap drone.dropWaterBomb(); } } dragNode = null; isSwipeActive = false; }; 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
@@ -128,8 +128,11 @@
var trees = [];
var dragNode = null;
var firesExtinguished = 0;
var totalFires = 8;
+var swipeStartX = 0;
+var swipeStartY = 0;
+var isSwipeActive = false;
// Create forest background with trees
for (var i = 0; i < 15; i++) {
var tree = game.addChild(new Tree());
tree.x = Math.random() * 1800 + 124;
@@ -166,13 +169,14 @@
instructionText.y = 100;
LK.gui.top.addChild(instructionText);
// Game event handlers
game.down = function (x, y, obj) {
+ swipeStartX = x;
+ swipeStartY = y;
+ isSwipeActive = true;
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) {
@@ -180,58 +184,46 @@
dragNode.y = Math.max(40, Math.min(2692, y));
}
};
game.up = function (x, y, obj) {
- dragNode = null;
-};
-game.update = function () {
- // Automatic drone movement left and right
- if (!dragNode) {
- // Only auto-move when not being dragged
- if (drone.lastX === undefined) drone.lastX = drone.x;
- if (drone.movingRight === undefined) drone.movingRight = true;
- if (drone.isMoving === undefined) drone.isMoving = false;
- // Check if drone reached boundaries and needs to change direction
- if (drone.lastX <= 200 && drone.x > 200 && drone.movingRight) {
- // Hit left boundary, start moving right
- drone.movingRight = true;
- drone.isMoving = false;
- }
- if (drone.lastX >= 1848 && drone.x < 1848 && !drone.movingRight) {
- // Hit right boundary, start moving left
- drone.movingRight = false;
- drone.isMoving = false;
- }
- // Start new movement if not currently tweening
- if (!drone.isMoving) {
- drone.isMoving = true;
- tween.stop(drone, {
- x: true
- }); // Stop any existing x movement
- if (drone.movingRight) {
- tween(drone, {
- x: 1848
- }, {
- duration: 3000,
- easing: tween.linear,
- onFinish: function onFinish() {
- drone.isMoving = false;
- }
+ if (isSwipeActive && !dragNode) {
+ var swipeDistanceX = x - swipeStartX;
+ var swipeDistanceY = y - swipeStartY;
+ var swipeDistance = Math.sqrt(swipeDistanceX * swipeDistanceX + swipeDistanceY * swipeDistanceY);
+ if (swipeDistance > 50) {
+ // It's a swipe
+ if (Math.abs(swipeDistanceX) > Math.abs(swipeDistanceY)) {
+ // Horizontal swipe
+ tween.stop(drone, {
+ x: true
});
- } else {
- tween(drone, {
- x: 200
- }, {
- duration: 3000,
- easing: tween.linear,
- onFinish: function onFinish() {
- drone.isMoving = false;
- }
- });
+ if (swipeDistanceX > 0) {
+ // Swipe right
+ tween(drone, {
+ x: Math.min(1848, drone.x + 300)
+ }, {
+ duration: 500,
+ easing: tween.easeOut
+ });
+ } else {
+ // Swipe left
+ tween(drone, {
+ x: Math.max(200, drone.x - 300)
+ }, {
+ duration: 500,
+ easing: tween.easeOut
+ });
+ }
}
+ } else {
+ // It's a tap
+ drone.dropWaterBomb();
}
- drone.lastX = drone.x;
}
+ dragNode = null;
+ isSwipeActive = false;
+};
+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--) {