User prompt
ateş 10 kademe olarak büyüsün. Söndürülmedikçe ateş büyüsün ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
yılanın başı yöne göre dönsün
Code edit (1 edits merged)
Please save this source code
User prompt
Let there be a fire in several places at advanced levels. If the snake does not have enough water, it will burn when it touches the fire. Let's put a forest image in the background and let it pass through the roads between. Let animals occasionally escape from the place where the fire is
Code edit (1 edits merged)
Please save this source code
User prompt
Snake Fire Brigade
Initial prompt
snake style game. In the game, the snake collects water to extinguish the fire. There will be fires in some places. If the fire is small, the number of waters it collects will change according to the size of 1 water. When the fire is extinguished, a fire will start in a different place.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Fire = Container.expand(function (size) {
var self = Container.call(this);
self.size = size || 1;
self.waterNeeded = self.size;
var fireGraphics = self.attachAsset(self.size === 1 ? 'smallFire' : 'largeFire', {
anchorX: 0.5,
anchorY: 0.5
});
// Add flickering animation
self.animOffset = Math.random() * Math.PI * 2;
self.update = function () {
var flicker = 0.8 + Math.sin(LK.ticks * 0.1 + self.animOffset) * 0.2;
fireGraphics.alpha = flicker;
fireGraphics.scaleX = 1 + Math.sin(LK.ticks * 0.08 + self.animOffset) * 0.1;
fireGraphics.scaleY = 1 + Math.sin(LK.ticks * 0.08 + self.animOffset) * 0.1;
};
return self;
});
var SnakeSegment = Container.expand(function (isHead) {
var self = Container.call(this);
var segmentGraphics = self.attachAsset(isHead ? 'snakeHead' : 'snakeBody', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var WaterDroplet = Container.expand(function () {
var self = Container.call(this);
var waterGraphics = self.attachAsset('water', {
anchorX: 0.5,
anchorY: 0.5
});
// Add floating animation
self.animOffset = Math.random() * Math.PI * 2;
self.update = function () {
waterGraphics.y = Math.sin(LK.ticks * 0.05 + self.animOffset) * 5;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2F4F2F
});
/****
* Game Code
****/
// Game variables
var snake = [];
var snakeDirection = {
x: 1,
y: 0
};
var nextDirection = {
x: 1,
y: 0
};
var gridSize = 60;
var gameWidth = 2048;
var gameHeight = 2732;
var cols = Math.floor(gameWidth / gridSize);
var rows = Math.floor(gameHeight / gridSize);
var waterDroplets = [];
var fires = [];
var waterCollected = 0;
var moveTimer = 0;
var moveInterval = 15; // Snake moves every 15 ticks
var gameRunning = true;
// UI Elements
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var waterTxt = new Text2('Water: 0', {
size: 50,
fill: 0x1E90FF
});
waterTxt.anchor.set(1, 0);
waterTxt.x = -20;
waterTxt.y = 80;
LK.gui.topRight.addChild(waterTxt);
// Initialize snake
function initSnake() {
// Create initial snake with 3 segments
for (var i = 0; i < 3; i++) {
var segment = new SnakeSegment(i === 0);
segment.x = (5 - i) * gridSize + gridSize / 2;
segment.y = 5 * gridSize + gridSize / 2;
snake.push(segment);
game.addChild(segment);
}
}
// Convert grid coordinates to world coordinates
function gridToWorld(gridX, gridY) {
return {
x: gridX * gridSize + gridSize / 2,
y: gridY * gridSize + gridSize / 2
};
}
// Convert world coordinates to grid coordinates
function worldToGrid(worldX, worldY) {
return {
x: Math.floor(worldX / gridSize),
y: Math.floor(worldY / gridSize)
};
}
// Get random empty grid position
function getRandomEmptyPosition() {
var attempts = 0;
while (attempts < 100) {
var gridX = Math.floor(Math.random() * cols);
var gridY = Math.floor(Math.random() * rows);
var worldPos = gridToWorld(gridX, gridY);
var occupied = false;
// Check if position is occupied by snake
for (var i = 0; i < snake.length; i++) {
var snakeGrid = worldToGrid(snake[i].x, snake[i].y);
if (snakeGrid.x === gridX && snakeGrid.y === gridY) {
occupied = true;
break;
}
}
// Check if position is occupied by water
if (!occupied) {
for (var i = 0; i < waterDroplets.length; i++) {
var waterGrid = worldToGrid(waterDroplets[i].x, waterDroplets[i].y);
if (waterGrid.x === gridX && waterGrid.y === gridY) {
occupied = true;
break;
}
}
}
// Check if position is occupied by fire
if (!occupied) {
for (var i = 0; i < fires.length; i++) {
var fireGrid = worldToGrid(fires[i].x, fires[i].y);
if (fireGrid.x === gridX && fireGrid.y === gridY) {
occupied = true;
break;
}
}
}
if (!occupied) {
return worldPos;
}
attempts++;
}
// Fallback to center if no empty position found
return gridToWorld(Math.floor(cols / 2), Math.floor(rows / 2));
}
// Spawn water droplet
function spawnWater() {
var pos = getRandomEmptyPosition();
var water = new WaterDroplet();
water.x = pos.x;
water.y = pos.y;
waterDroplets.push(water);
game.addChild(water);
}
// Spawn fire
function spawnFire() {
var pos = getRandomEmptyPosition();
var fireSize = Math.random() < 0.7 ? 1 : 2; // 70% chance for small fire
var fire = new Fire(fireSize);
fire.x = pos.x;
fire.y = pos.y;
fires.push(fire);
game.addChild(fire);
}
// Move snake
function moveSnake() {
if (!gameRunning) return;
// Update direction
snakeDirection.x = nextDirection.x;
snakeDirection.y = nextDirection.y;
// Calculate new head position
var head = snake[0];
var headGrid = worldToGrid(head.x, head.y);
var newHeadGrid = {
x: headGrid.x + snakeDirection.x,
y: headGrid.y + snakeDirection.y
};
// Check boundaries
if (newHeadGrid.x < 0 || newHeadGrid.x >= cols || newHeadGrid.y < 0 || newHeadGrid.y >= rows) {
gameOver();
return;
}
// Check self collision
for (var i = 0; i < snake.length; i++) {
var segmentGrid = worldToGrid(snake[i].x, snake[i].y);
if (segmentGrid.x === newHeadGrid.x && segmentGrid.y === newHeadGrid.y) {
gameOver();
return;
}
}
// Move snake body
for (var i = snake.length - 1; i > 0; i--) {
snake[i].x = snake[i - 1].x;
snake[i].y = snake[i - 1].y;
}
// Move head
var newHeadPos = gridToWorld(newHeadGrid.x, newHeadGrid.y);
head.x = newHeadPos.x;
head.y = newHeadPos.y;
// Check water collection
for (var i = waterDroplets.length - 1; i >= 0; i--) {
var water = waterDroplets[i];
var waterGrid = worldToGrid(water.x, water.y);
if (waterGrid.x === newHeadGrid.x && waterGrid.y === newHeadGrid.y) {
// Collect water
waterCollected++;
waterTxt.setText('Water: ' + waterCollected);
LK.setScore(LK.getScore() + 10);
scoreTxt.setText('Score: ' + LK.getScore());
// Grow snake
var lastSegment = snake[snake.length - 1];
var newSegment = new SnakeSegment(false);
newSegment.x = lastSegment.x;
newSegment.y = lastSegment.y;
snake.push(newSegment);
game.addChild(newSegment);
// Remove water
water.destroy();
waterDroplets.splice(i, 1);
// Play sound
LK.getSound('collect').play();
// Spawn new water
spawnWater();
break;
}
}
// Check fire extinguishing
for (var i = fires.length - 1; i >= 0; i--) {
var fire = fires[i];
var fireGrid = worldToGrid(fire.x, fire.y);
if (fireGrid.x === newHeadGrid.x && fireGrid.y === newHeadGrid.y) {
if (waterCollected >= fire.waterNeeded) {
// Extinguish fire
waterCollected -= fire.waterNeeded;
waterTxt.setText('Water: ' + waterCollected);
LK.setScore(LK.getScore() + (fire.size === 1 ? 50 : 100));
scoreTxt.setText('Score: ' + LK.getScore());
// Remove fire
fire.destroy();
fires.splice(i, 1);
// Play sound
LK.getSound('extinguish').play();
// Spawn new fire
spawnFire();
// Flash effect
LK.effects.flashObject(head, 0x00FF00, 300);
}
break;
}
}
}
// Game over
function gameOver() {
gameRunning = false;
LK.showGameOver();
}
// Touch controls
var touchStartX = 0;
var touchStartY = 0;
var minSwipeDistance = 100;
game.down = function (x, y, obj) {
touchStartX = x;
touchStartY = y;
};
game.up = function (x, y, obj) {
if (!gameRunning) return;
var deltaX = x - touchStartX;
var deltaY = y - touchStartY;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
if (distance < minSwipeDistance) return;
var absX = Math.abs(deltaX);
var absY = Math.abs(deltaY);
if (absX > absY) {
// Horizontal swipe
if (deltaX > 0 && snakeDirection.x !== -1) {
nextDirection = {
x: 1,
y: 0
}; // Right
} else if (deltaX < 0 && snakeDirection.x !== 1) {
nextDirection = {
x: -1,
y: 0
}; // Left
}
} else {
// Vertical swipe
if (deltaY > 0 && snakeDirection.y !== -1) {
nextDirection = {
x: 0,
y: 1
}; // Down
} else if (deltaY < 0 && snakeDirection.y !== 1) {
nextDirection = {
x: 0,
y: -1
}; // Up
}
}
};
// Initialize game
initSnake();
spawnWater();
spawnWater();
spawnFire();
// Game update loop
game.update = function () {
if (!gameRunning) return;
moveTimer++;
if (moveTimer >= moveInterval) {
moveTimer = 0;
moveSnake();
}
// Spawn additional water periodically
if (LK.ticks % 600 === 0 && waterDroplets.length < 4) {
spawnWater();
}
// Make game slightly faster as score increases
if (LK.getScore() > 0 && LK.getScore() % 200 === 0) {
moveInterval = Math.max(8, moveInterval - 1);
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,340 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Fire = Container.expand(function (size) {
+ var self = Container.call(this);
+ self.size = size || 1;
+ self.waterNeeded = self.size;
+ var fireGraphics = self.attachAsset(self.size === 1 ? 'smallFire' : 'largeFire', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Add flickering animation
+ self.animOffset = Math.random() * Math.PI * 2;
+ self.update = function () {
+ var flicker = 0.8 + Math.sin(LK.ticks * 0.1 + self.animOffset) * 0.2;
+ fireGraphics.alpha = flicker;
+ fireGraphics.scaleX = 1 + Math.sin(LK.ticks * 0.08 + self.animOffset) * 0.1;
+ fireGraphics.scaleY = 1 + Math.sin(LK.ticks * 0.08 + self.animOffset) * 0.1;
+ };
+ return self;
+});
+var SnakeSegment = Container.expand(function (isHead) {
+ var self = Container.call(this);
+ var segmentGraphics = self.attachAsset(isHead ? 'snakeHead' : 'snakeBody', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ return self;
+});
+var WaterDroplet = Container.expand(function () {
+ var self = Container.call(this);
+ var waterGraphics = self.attachAsset('water', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Add floating animation
+ self.animOffset = Math.random() * Math.PI * 2;
+ self.update = function () {
+ waterGraphics.y = Math.sin(LK.ticks * 0.05 + self.animOffset) * 5;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2F4F2F
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var snake = [];
+var snakeDirection = {
+ x: 1,
+ y: 0
+};
+var nextDirection = {
+ x: 1,
+ y: 0
+};
+var gridSize = 60;
+var gameWidth = 2048;
+var gameHeight = 2732;
+var cols = Math.floor(gameWidth / gridSize);
+var rows = Math.floor(gameHeight / gridSize);
+var waterDroplets = [];
+var fires = [];
+var waterCollected = 0;
+var moveTimer = 0;
+var moveInterval = 15; // Snake moves every 15 ticks
+var gameRunning = true;
+// UI Elements
+var scoreTxt = new Text2('Score: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var waterTxt = new Text2('Water: 0', {
+ size: 50,
+ fill: 0x1E90FF
+});
+waterTxt.anchor.set(1, 0);
+waterTxt.x = -20;
+waterTxt.y = 80;
+LK.gui.topRight.addChild(waterTxt);
+// Initialize snake
+function initSnake() {
+ // Create initial snake with 3 segments
+ for (var i = 0; i < 3; i++) {
+ var segment = new SnakeSegment(i === 0);
+ segment.x = (5 - i) * gridSize + gridSize / 2;
+ segment.y = 5 * gridSize + gridSize / 2;
+ snake.push(segment);
+ game.addChild(segment);
+ }
+}
+// Convert grid coordinates to world coordinates
+function gridToWorld(gridX, gridY) {
+ return {
+ x: gridX * gridSize + gridSize / 2,
+ y: gridY * gridSize + gridSize / 2
+ };
+}
+// Convert world coordinates to grid coordinates
+function worldToGrid(worldX, worldY) {
+ return {
+ x: Math.floor(worldX / gridSize),
+ y: Math.floor(worldY / gridSize)
+ };
+}
+// Get random empty grid position
+function getRandomEmptyPosition() {
+ var attempts = 0;
+ while (attempts < 100) {
+ var gridX = Math.floor(Math.random() * cols);
+ var gridY = Math.floor(Math.random() * rows);
+ var worldPos = gridToWorld(gridX, gridY);
+ var occupied = false;
+ // Check if position is occupied by snake
+ for (var i = 0; i < snake.length; i++) {
+ var snakeGrid = worldToGrid(snake[i].x, snake[i].y);
+ if (snakeGrid.x === gridX && snakeGrid.y === gridY) {
+ occupied = true;
+ break;
+ }
+ }
+ // Check if position is occupied by water
+ if (!occupied) {
+ for (var i = 0; i < waterDroplets.length; i++) {
+ var waterGrid = worldToGrid(waterDroplets[i].x, waterDroplets[i].y);
+ if (waterGrid.x === gridX && waterGrid.y === gridY) {
+ occupied = true;
+ break;
+ }
+ }
+ }
+ // Check if position is occupied by fire
+ if (!occupied) {
+ for (var i = 0; i < fires.length; i++) {
+ var fireGrid = worldToGrid(fires[i].x, fires[i].y);
+ if (fireGrid.x === gridX && fireGrid.y === gridY) {
+ occupied = true;
+ break;
+ }
+ }
+ }
+ if (!occupied) {
+ return worldPos;
+ }
+ attempts++;
+ }
+ // Fallback to center if no empty position found
+ return gridToWorld(Math.floor(cols / 2), Math.floor(rows / 2));
+}
+// Spawn water droplet
+function spawnWater() {
+ var pos = getRandomEmptyPosition();
+ var water = new WaterDroplet();
+ water.x = pos.x;
+ water.y = pos.y;
+ waterDroplets.push(water);
+ game.addChild(water);
+}
+// Spawn fire
+function spawnFire() {
+ var pos = getRandomEmptyPosition();
+ var fireSize = Math.random() < 0.7 ? 1 : 2; // 70% chance for small fire
+ var fire = new Fire(fireSize);
+ fire.x = pos.x;
+ fire.y = pos.y;
+ fires.push(fire);
+ game.addChild(fire);
+}
+// Move snake
+function moveSnake() {
+ if (!gameRunning) return;
+ // Update direction
+ snakeDirection.x = nextDirection.x;
+ snakeDirection.y = nextDirection.y;
+ // Calculate new head position
+ var head = snake[0];
+ var headGrid = worldToGrid(head.x, head.y);
+ var newHeadGrid = {
+ x: headGrid.x + snakeDirection.x,
+ y: headGrid.y + snakeDirection.y
+ };
+ // Check boundaries
+ if (newHeadGrid.x < 0 || newHeadGrid.x >= cols || newHeadGrid.y < 0 || newHeadGrid.y >= rows) {
+ gameOver();
+ return;
+ }
+ // Check self collision
+ for (var i = 0; i < snake.length; i++) {
+ var segmentGrid = worldToGrid(snake[i].x, snake[i].y);
+ if (segmentGrid.x === newHeadGrid.x && segmentGrid.y === newHeadGrid.y) {
+ gameOver();
+ return;
+ }
+ }
+ // Move snake body
+ for (var i = snake.length - 1; i > 0; i--) {
+ snake[i].x = snake[i - 1].x;
+ snake[i].y = snake[i - 1].y;
+ }
+ // Move head
+ var newHeadPos = gridToWorld(newHeadGrid.x, newHeadGrid.y);
+ head.x = newHeadPos.x;
+ head.y = newHeadPos.y;
+ // Check water collection
+ for (var i = waterDroplets.length - 1; i >= 0; i--) {
+ var water = waterDroplets[i];
+ var waterGrid = worldToGrid(water.x, water.y);
+ if (waterGrid.x === newHeadGrid.x && waterGrid.y === newHeadGrid.y) {
+ // Collect water
+ waterCollected++;
+ waterTxt.setText('Water: ' + waterCollected);
+ LK.setScore(LK.getScore() + 10);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ // Grow snake
+ var lastSegment = snake[snake.length - 1];
+ var newSegment = new SnakeSegment(false);
+ newSegment.x = lastSegment.x;
+ newSegment.y = lastSegment.y;
+ snake.push(newSegment);
+ game.addChild(newSegment);
+ // Remove water
+ water.destroy();
+ waterDroplets.splice(i, 1);
+ // Play sound
+ LK.getSound('collect').play();
+ // Spawn new water
+ spawnWater();
+ break;
+ }
+ }
+ // Check fire extinguishing
+ for (var i = fires.length - 1; i >= 0; i--) {
+ var fire = fires[i];
+ var fireGrid = worldToGrid(fire.x, fire.y);
+ if (fireGrid.x === newHeadGrid.x && fireGrid.y === newHeadGrid.y) {
+ if (waterCollected >= fire.waterNeeded) {
+ // Extinguish fire
+ waterCollected -= fire.waterNeeded;
+ waterTxt.setText('Water: ' + waterCollected);
+ LK.setScore(LK.getScore() + (fire.size === 1 ? 50 : 100));
+ scoreTxt.setText('Score: ' + LK.getScore());
+ // Remove fire
+ fire.destroy();
+ fires.splice(i, 1);
+ // Play sound
+ LK.getSound('extinguish').play();
+ // Spawn new fire
+ spawnFire();
+ // Flash effect
+ LK.effects.flashObject(head, 0x00FF00, 300);
+ }
+ break;
+ }
+ }
+}
+// Game over
+function gameOver() {
+ gameRunning = false;
+ LK.showGameOver();
+}
+// Touch controls
+var touchStartX = 0;
+var touchStartY = 0;
+var minSwipeDistance = 100;
+game.down = function (x, y, obj) {
+ touchStartX = x;
+ touchStartY = y;
+};
+game.up = function (x, y, obj) {
+ if (!gameRunning) return;
+ var deltaX = x - touchStartX;
+ var deltaY = y - touchStartY;
+ var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+ if (distance < minSwipeDistance) return;
+ var absX = Math.abs(deltaX);
+ var absY = Math.abs(deltaY);
+ if (absX > absY) {
+ // Horizontal swipe
+ if (deltaX > 0 && snakeDirection.x !== -1) {
+ nextDirection = {
+ x: 1,
+ y: 0
+ }; // Right
+ } else if (deltaX < 0 && snakeDirection.x !== 1) {
+ nextDirection = {
+ x: -1,
+ y: 0
+ }; // Left
+ }
+ } else {
+ // Vertical swipe
+ if (deltaY > 0 && snakeDirection.y !== -1) {
+ nextDirection = {
+ x: 0,
+ y: 1
+ }; // Down
+ } else if (deltaY < 0 && snakeDirection.y !== 1) {
+ nextDirection = {
+ x: 0,
+ y: -1
+ }; // Up
+ }
+ }
+};
+// Initialize game
+initSnake();
+spawnWater();
+spawnWater();
+spawnFire();
+// Game update loop
+game.update = function () {
+ if (!gameRunning) return;
+ moveTimer++;
+ if (moveTimer >= moveInterval) {
+ moveTimer = 0;
+ moveSnake();
+ }
+ // Spawn additional water periodically
+ if (LK.ticks % 600 === 0 && waterDroplets.length < 4) {
+ spawnWater();
+ }
+ // Make game slightly faster as score increases
+ if (LK.getScore() > 0 && LK.getScore() % 200 === 0) {
+ moveInterval = Math.max(8, moveInterval - 1);
+ }
+};
\ No newline at end of file