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 Animal = Container.expand(function () {
var self = Container.call(this);
var animalGraphics = self.attachAsset('animal', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = (Math.random() - 0.5) * 4;
self.speedY = (Math.random() - 0.5) * 4;
self.lifeTime = 300; // 5 seconds at 60fps
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
self.lifeTime--;
if (self.lifeTime <= 0) {
self.destroy();
}
};
return self;
});
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
****/
// Add forest background
var forestBackground = game.attachAsset('forest', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// 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;
var animals = [];
var maxFires = 1; // Start with 1 fire, increase with level
// 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);
// Spawn escaping animal near fire
var animal = new Animal();
animal.x = pos.x + (Math.random() - 0.5) * 120;
animal.y = pos.y + (Math.random() - 0.5) * 120;
animals.push(animal);
game.addChild(animal);
}
// 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 if needed
if (fires.length < maxFires) {
spawnFire();
}
// Flash effect
LK.effects.flashObject(head, 0x00FF00, 300);
} else {
// Snake burns when touching fire without enough water
LK.effects.flashObject(head, 0xFF0000, 500);
gameOver();
return;
}
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();
}
// Increase difficulty - add more fires at higher scores
var currentLevel = Math.floor(LK.getScore() / 300) + 1;
maxFires = Math.min(currentLevel, 5); // Maximum 5 fires
if (fires.length < maxFires && LK.ticks % 900 === 0) {
spawnFire();
}
// Clean up dead animals
for (var i = animals.length - 1; i >= 0; i--) {
if (animals[i].lifeTime <= 0) {
animals.splice(i, 1);
}
}
// 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
@@ -5,8 +5,27 @@
/****
* Classes
****/
+var Animal = Container.expand(function () {
+ var self = Container.call(this);
+ var animalGraphics = self.attachAsset('animal', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speedX = (Math.random() - 0.5) * 4;
+ self.speedY = (Math.random() - 0.5) * 4;
+ self.lifeTime = 300; // 5 seconds at 60fps
+ self.update = function () {
+ self.x += self.speedX;
+ self.y += self.speedY;
+ self.lifeTime--;
+ if (self.lifeTime <= 0) {
+ self.destroy();
+ }
+ };
+ return self;
+});
var Fire = Container.expand(function (size) {
var self = Container.call(this);
self.size = size || 1;
self.waterNeeded = self.size;
@@ -55,8 +74,15 @@
/****
* Game Code
****/
+// Add forest background
+var forestBackground = game.attachAsset('forest', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: 0
+});
// Game variables
var snake = [];
var snakeDirection = {
x: 1,
@@ -76,8 +102,10 @@
var waterCollected = 0;
var moveTimer = 0;
var moveInterval = 15; // Snake moves every 15 ticks
var gameRunning = true;
+var animals = [];
+var maxFires = 1; // Start with 1 fire, increase with level
// UI Elements
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
@@ -178,8 +206,14 @@
fire.x = pos.x;
fire.y = pos.y;
fires.push(fire);
game.addChild(fire);
+ // Spawn escaping animal near fire
+ var animal = new Animal();
+ animal.x = pos.x + (Math.random() - 0.5) * 120;
+ animal.y = pos.y + (Math.random() - 0.5) * 120;
+ animals.push(animal);
+ game.addChild(animal);
}
// Move snake
function moveSnake() {
if (!gameRunning) return;
@@ -257,12 +291,19 @@
fire.destroy();
fires.splice(i, 1);
// Play sound
LK.getSound('extinguish').play();
- // Spawn new fire
- spawnFire();
+ // Spawn new fire if needed
+ if (fires.length < maxFires) {
+ spawnFire();
+ }
// Flash effect
LK.effects.flashObject(head, 0x00FF00, 300);
+ } else {
+ // Snake burns when touching fire without enough water
+ LK.effects.flashObject(head, 0xFF0000, 500);
+ gameOver();
+ return;
}
break;
}
}
@@ -332,8 +373,20 @@
// Spawn additional water periodically
if (LK.ticks % 600 === 0 && waterDroplets.length < 4) {
spawnWater();
}
+ // Increase difficulty - add more fires at higher scores
+ var currentLevel = Math.floor(LK.getScore() / 300) + 1;
+ maxFires = Math.min(currentLevel, 5); // Maximum 5 fires
+ if (fires.length < maxFires && LK.ticks % 900 === 0) {
+ spawnFire();
+ }
+ // Clean up dead animals
+ for (var i = animals.length - 1; i >= 0; i--) {
+ if (animals[i].lifeTime <= 0) {
+ animals.splice(i, 1);
+ }
+ }
// Make game slightly faster as score increases
if (LK.getScore() > 0 && LK.getScore() % 200 === 0) {
moveInterval = Math.max(8, moveInterval - 1);
}