User prompt
Yılanın dayanılılık seviyesi sıfıra yaklaştıkça yılanın boyutunda azalma gerçekleşsin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Oyuna zehirli elma ekle bu yılan bu elmalardan birini yerse dayanıklılık sayısindaki azalma 10 saniyeliğine 2 katına çıkıyor ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Snake Survival Arena
Initial prompt
Bir yılan etrafta dolaşan fareleri yiyerek hayatta kalmaya çalışıyor fakat eğer dayanıklılıği sıfıra düşerse ölüyor her fare 2 dayanıklılık demek yılan ise 30 dayanıklılığa sahip ve her saniye 1 dayanıklılık puanı kaybediyor
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Mouse = Container.expand(function () {
var self = Container.call(this);
var mouseGraphics = self.attachAsset('mouse', {
anchorX: 0.5,
anchorY: 0.5
});
self.spawn = function () {
// Spawn within arena bounds
self.x = 124 + 50 + Math.random() * (1800 - 100);
self.y = 166 + 50 + Math.random() * (2400 - 100);
};
return self;
});
var Snake = Container.expand(function () {
var self = Container.call(this);
self.segments = [];
self.direction = {
x: 1,
y: 0
};
self.speed = 4;
self.segmentSize = 60;
// Create initial snake with 3 segments
for (var i = 0; i < 3; i++) {
var segment;
if (i === 0) {
segment = self.attachAsset('snakeHead', {
anchorX: 0.5,
anchorY: 0.5
});
} else {
segment = self.attachAsset('snakeSegment', {
anchorX: 0.5,
anchorY: 0.5
});
}
segment.x = 1024 - i * self.segmentSize;
segment.y = 1366;
self.segments.push(segment);
}
self.update = function () {
// Move head
var head = self.segments[0];
head.x += self.direction.x * self.speed;
head.y += self.direction.y * self.speed;
// Keep snake within arena bounds
if (head.x < 124 + 30) head.x = 124 + 30;
if (head.x > 1924 - 30) head.x = 1924 - 30;
if (head.y < 166 + 30) head.y = 166 + 30;
if (head.y > 2566 - 30) head.y = 2566 - 30;
// Move body segments
for (var i = 1; i < self.segments.length; i++) {
var segment = self.segments[i];
var prevSegment = self.segments[i - 1];
var dx = prevSegment.x - segment.x;
var dy = prevSegment.y - segment.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > self.segmentSize) {
segment.x += dx / distance * self.speed;
segment.y += dy / distance * self.speed;
}
}
};
self.getHead = function () {
return self.segments[0];
};
self.grow = function () {
var lastSegment = self.segments[self.segments.length - 1];
var newSegment = self.attachAsset('snakeSegment', {
anchorX: 0.5,
anchorY: 0.5
});
newSegment.x = lastSegment.x;
newSegment.y = lastSegment.y;
self.segments.push(newSegment);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2E7D32
});
/****
* Game Code
****/
// Game arena
var arena = game.attachAsset('arena', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
// Game variables
var snake = game.addChild(new Snake());
var mice = [];
var maxMice = 8;
var stamina = 30;
var maxStamina = 30;
var staminaDrainTimer = 0;
var mouseSpawnTimer = 0;
var gameRunning = true;
// UI Elements
var staminaBarBg = LK.getAsset('arena', {
anchorX: 0,
anchorY: 0,
scaleX: 0.28,
scaleY: 0.04,
x: 0,
y: 0
});
staminaBarBg.tint = 0x333333;
LK.gui.topLeft.addChild(staminaBarBg);
var staminaBarFill = LK.getAsset('arena', {
anchorX: 0,
anchorY: 0,
scaleX: 0.28,
scaleY: 0.04,
x: 0,
y: 0
});
staminaBarFill.tint = 0xFF4444;
LK.gui.topLeft.addChild(staminaBarFill);
var staminaText = new Text2('Stamina: 30', {
size: 60,
fill: 0xFFFFFF
});
staminaText.anchor.set(0, 0);
staminaText.x = 0;
staminaText.y = 120;
LK.gui.topLeft.addChild(staminaText);
var scoreText = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Initialize mice
function spawnMouse() {
if (mice.length < maxMice) {
var mouse = new Mouse();
mouse.spawn();
mice.push(mouse);
game.addChild(mouse);
}
}
// Initial mouse spawning
for (var i = 0; i < maxMice; i++) {
spawnMouse();
}
// Touch controls
var touchStartX = 0;
var touchStartY = 0;
var isTouch = false;
game.down = function (x, y, obj) {
touchStartX = x;
touchStartY = y;
isTouch = true;
};
game.up = function (x, y, obj) {
if (!gameRunning || !isTouch) return;
var deltaX = x - touchStartX;
var deltaY = y - touchStartY;
var minSwipeDistance = 50;
if (Math.abs(deltaX) > Math.abs(deltaY) && Math.abs(deltaX) > minSwipeDistance) {
// Horizontal swipe
if (deltaX > 0 && snake.direction.x !== -1) {
snake.direction = {
x: 1,
y: 0
}; // Right
} else if (deltaX < 0 && snake.direction.x !== 1) {
snake.direction = {
x: -1,
y: 0
}; // Left
}
} else if (Math.abs(deltaY) > minSwipeDistance) {
// Vertical swipe
if (deltaY > 0 && snake.direction.y !== -1) {
snake.direction = {
x: 0,
y: 1
}; // Down
} else if (deltaY < 0 && snake.direction.y !== 1) {
snake.direction = {
x: 0,
y: -1
}; // Up
}
}
isTouch = false;
};
function updateStaminaBar() {
var staminaPercentage = stamina / maxStamina;
staminaBarFill.scaleX = 0.28 * staminaPercentage;
// Change color based on stamina level
if (staminaPercentage > 0.6) {
staminaBarFill.tint = 0x4CAF50; // Green
} else if (staminaPercentage > 0.3) {
staminaBarFill.tint = 0xFFC107; // Yellow
} else {
staminaBarFill.tint = 0xFF4444; // Red
}
}
function checkMouseCollisions() {
var head = snake.getHead();
for (var i = mice.length - 1; i >= 0; i--) {
var mouse = mice[i];
if (head.intersects(mouse)) {
// Eat mouse
stamina = Math.min(maxStamina, stamina + 2);
LK.setScore(LK.getScore() + 10);
scoreText.setText('Score: ' + LK.getScore());
staminaText.setText('Stamina: ' + Math.ceil(stamina));
// Visual feedback
LK.effects.flashObject(mouse, 0xFFFFFF, 200);
// Play eat sound
LK.getSound('eat').play();
// Remove mouse and spawn new one
mouse.destroy();
mice.splice(i, 1);
// Grow snake slightly
snake.grow();
break;
}
}
}
game.update = function () {
if (!gameRunning) return;
// Update stamina drain timer
staminaDrainTimer++;
if (staminaDrainTimer >= 60) {
// 1 second at 60 FPS
stamina -= 1;
staminaDrainTimer = 0;
staminaText.setText('Stamina: ' + Math.ceil(stamina));
if (stamina <= 0) {
gameRunning = false;
LK.getSound('gameOver').play();
LK.showGameOver();
return;
}
}
// Update stamina bar
updateStaminaBar();
// Check mouse collisions
checkMouseCollisions();
// Spawn new mice periodically
mouseSpawnTimer++;
if (mouseSpawnTimer >= 180 && mice.length < maxMice) {
// Every 3 seconds
spawnMouse();
mouseSpawnTimer = 0;
}
// Update score based on survival time
if (LK.ticks % 60 === 0) {
// Every second
LK.setScore(LK.getScore() + 1);
scoreText.setText('Score: ' + LK.getScore());
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,273 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Mouse = Container.expand(function () {
+ var self = Container.call(this);
+ var mouseGraphics = self.attachAsset('mouse', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.spawn = function () {
+ // Spawn within arena bounds
+ self.x = 124 + 50 + Math.random() * (1800 - 100);
+ self.y = 166 + 50 + Math.random() * (2400 - 100);
+ };
+ return self;
+});
+var Snake = Container.expand(function () {
+ var self = Container.call(this);
+ self.segments = [];
+ self.direction = {
+ x: 1,
+ y: 0
+ };
+ self.speed = 4;
+ self.segmentSize = 60;
+ // Create initial snake with 3 segments
+ for (var i = 0; i < 3; i++) {
+ var segment;
+ if (i === 0) {
+ segment = self.attachAsset('snakeHead', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ } else {
+ segment = self.attachAsset('snakeSegment', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ }
+ segment.x = 1024 - i * self.segmentSize;
+ segment.y = 1366;
+ self.segments.push(segment);
+ }
+ self.update = function () {
+ // Move head
+ var head = self.segments[0];
+ head.x += self.direction.x * self.speed;
+ head.y += self.direction.y * self.speed;
+ // Keep snake within arena bounds
+ if (head.x < 124 + 30) head.x = 124 + 30;
+ if (head.x > 1924 - 30) head.x = 1924 - 30;
+ if (head.y < 166 + 30) head.y = 166 + 30;
+ if (head.y > 2566 - 30) head.y = 2566 - 30;
+ // Move body segments
+ for (var i = 1; i < self.segments.length; i++) {
+ var segment = self.segments[i];
+ var prevSegment = self.segments[i - 1];
+ var dx = prevSegment.x - segment.x;
+ var dy = prevSegment.y - segment.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > self.segmentSize) {
+ segment.x += dx / distance * self.speed;
+ segment.y += dy / distance * self.speed;
+ }
+ }
+ };
+ self.getHead = function () {
+ return self.segments[0];
+ };
+ self.grow = function () {
+ var lastSegment = self.segments[self.segments.length - 1];
+ var newSegment = self.attachAsset('snakeSegment', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ newSegment.x = lastSegment.x;
+ newSegment.y = lastSegment.y;
+ self.segments.push(newSegment);
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2E7D32
+});
+
+/****
+* Game Code
+****/
+// Game arena
+var arena = game.attachAsset('arena', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1024,
+ y: 1366
+});
+// Game variables
+var snake = game.addChild(new Snake());
+var mice = [];
+var maxMice = 8;
+var stamina = 30;
+var maxStamina = 30;
+var staminaDrainTimer = 0;
+var mouseSpawnTimer = 0;
+var gameRunning = true;
+// UI Elements
+var staminaBarBg = LK.getAsset('arena', {
+ anchorX: 0,
+ anchorY: 0,
+ scaleX: 0.28,
+ scaleY: 0.04,
+ x: 0,
+ y: 0
+});
+staminaBarBg.tint = 0x333333;
+LK.gui.topLeft.addChild(staminaBarBg);
+var staminaBarFill = LK.getAsset('arena', {
+ anchorX: 0,
+ anchorY: 0,
+ scaleX: 0.28,
+ scaleY: 0.04,
+ x: 0,
+ y: 0
+});
+staminaBarFill.tint = 0xFF4444;
+LK.gui.topLeft.addChild(staminaBarFill);
+var staminaText = new Text2('Stamina: 30', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+staminaText.anchor.set(0, 0);
+staminaText.x = 0;
+staminaText.y = 120;
+LK.gui.topLeft.addChild(staminaText);
+var scoreText = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreText.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreText);
+// Initialize mice
+function spawnMouse() {
+ if (mice.length < maxMice) {
+ var mouse = new Mouse();
+ mouse.spawn();
+ mice.push(mouse);
+ game.addChild(mouse);
+ }
+}
+// Initial mouse spawning
+for (var i = 0; i < maxMice; i++) {
+ spawnMouse();
+}
+// Touch controls
+var touchStartX = 0;
+var touchStartY = 0;
+var isTouch = false;
+game.down = function (x, y, obj) {
+ touchStartX = x;
+ touchStartY = y;
+ isTouch = true;
+};
+game.up = function (x, y, obj) {
+ if (!gameRunning || !isTouch) return;
+ var deltaX = x - touchStartX;
+ var deltaY = y - touchStartY;
+ var minSwipeDistance = 50;
+ if (Math.abs(deltaX) > Math.abs(deltaY) && Math.abs(deltaX) > minSwipeDistance) {
+ // Horizontal swipe
+ if (deltaX > 0 && snake.direction.x !== -1) {
+ snake.direction = {
+ x: 1,
+ y: 0
+ }; // Right
+ } else if (deltaX < 0 && snake.direction.x !== 1) {
+ snake.direction = {
+ x: -1,
+ y: 0
+ }; // Left
+ }
+ } else if (Math.abs(deltaY) > minSwipeDistance) {
+ // Vertical swipe
+ if (deltaY > 0 && snake.direction.y !== -1) {
+ snake.direction = {
+ x: 0,
+ y: 1
+ }; // Down
+ } else if (deltaY < 0 && snake.direction.y !== 1) {
+ snake.direction = {
+ x: 0,
+ y: -1
+ }; // Up
+ }
+ }
+ isTouch = false;
+};
+function updateStaminaBar() {
+ var staminaPercentage = stamina / maxStamina;
+ staminaBarFill.scaleX = 0.28 * staminaPercentage;
+ // Change color based on stamina level
+ if (staminaPercentage > 0.6) {
+ staminaBarFill.tint = 0x4CAF50; // Green
+ } else if (staminaPercentage > 0.3) {
+ staminaBarFill.tint = 0xFFC107; // Yellow
+ } else {
+ staminaBarFill.tint = 0xFF4444; // Red
+ }
+}
+function checkMouseCollisions() {
+ var head = snake.getHead();
+ for (var i = mice.length - 1; i >= 0; i--) {
+ var mouse = mice[i];
+ if (head.intersects(mouse)) {
+ // Eat mouse
+ stamina = Math.min(maxStamina, stamina + 2);
+ LK.setScore(LK.getScore() + 10);
+ scoreText.setText('Score: ' + LK.getScore());
+ staminaText.setText('Stamina: ' + Math.ceil(stamina));
+ // Visual feedback
+ LK.effects.flashObject(mouse, 0xFFFFFF, 200);
+ // Play eat sound
+ LK.getSound('eat').play();
+ // Remove mouse and spawn new one
+ mouse.destroy();
+ mice.splice(i, 1);
+ // Grow snake slightly
+ snake.grow();
+ break;
+ }
+ }
+}
+game.update = function () {
+ if (!gameRunning) return;
+ // Update stamina drain timer
+ staminaDrainTimer++;
+ if (staminaDrainTimer >= 60) {
+ // 1 second at 60 FPS
+ stamina -= 1;
+ staminaDrainTimer = 0;
+ staminaText.setText('Stamina: ' + Math.ceil(stamina));
+ if (stamina <= 0) {
+ gameRunning = false;
+ LK.getSound('gameOver').play();
+ LK.showGameOver();
+ return;
+ }
+ }
+ // Update stamina bar
+ updateStaminaBar();
+ // Check mouse collisions
+ checkMouseCollisions();
+ // Spawn new mice periodically
+ mouseSpawnTimer++;
+ if (mouseSpawnTimer >= 180 && mice.length < maxMice) {
+ // Every 3 seconds
+ spawnMouse();
+ mouseSpawnTimer = 0;
+ }
+ // Update score based on survival time
+ if (LK.ticks % 60 === 0) {
+ // Every second
+ LK.setScore(LK.getScore() + 1);
+ scoreText.setText('Score: ' + LK.getScore());
+ }
+};
\ No newline at end of file