Code edit (1 edits merged)
Please save this source code
User prompt
In the top right corner of the screen it should say little orange “Glaud”. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
oyun skoru olarak survival time deki sayı değeri alınacak
User prompt
sürekli patlama 1 çalıyor
User prompt
ses hatası oluyor
User prompt
mermiler ekrandan çıktığı gibi yok olsun.
User prompt
Please fix the bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'x')' in or related to this line: 'enemy.x = ground[randomGroundIndex].x;' Line Number: 231
User prompt
fon music ekle sürekli çalsın
User prompt
düşman oyuncuya çarparsa deth çalsın
User prompt
olmadı zemin ile düşman çarptığında patlama1 çıkacalk
User prompt
bomba zemine değince patlama1 olsun
User prompt
her bomba yok olduğunda patlama sesi çıksın.
User prompt
0,5 yap
User prompt
şimdide 0,80
User prompt
0,30 olsun şimdide
User prompt
mermi atma süresini 0,05 samiye yap
User prompt
yok sadece ama misal attı 2 saniye sonra tekrar atış gibi bu şekilde sürekli
User prompt
olmadı çok kısa bir süre beklse yeter
User prompt
mermi atmak için her atıştan sonra 2 saniye geçmesi gerek
User prompt
her mermi atışında sdece ilk atışta çıksın ses
User prompt
mermi sesini mermiye ekle
User prompt
zamanla düşen düşman sayısı 2 olsun ve öye devam etsin
User prompt
Please fix the bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'x')' in or related to this line: 'enemy.x = ground[randomGroundIndex].x;' Line Number: 212
User prompt
x ekseni en yüksek olan zemin bloklarını yok et
User prompt
aynı şekilde düşsünler ama oluşma noktasını yani x eksenleri zemini dikkate alsın düşmanların
/****
* Classes
****/
// Define a class for bullets
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -15;
self.update = function () {
if (self.y < 0 || self.x < 0 || self.x > 2048) {
self.destroy();
return; // Exit early if bullet is destroyed
}
self.y += self.speed;
if (self.speedX) {
self.x += self.speedX; // Update x position if horizontal speed is set
}
// Play bullet sound only on the first bullet shot
if (!this.soundPlayed) {
LK.getSound('mermi').play();
this.soundPlayed = true;
}
};
});
// Define a class for enemies
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
if (self.y > 2732) {
self.y = 0;
self.x = Math.random() * 2048; // Always reset x position
return; // Exit early if enemy is reset
}
self.speed += 0.1; // Increase speed to simulate acceleration
self.y += self.speed;
};
});
// Define a class for the entity
// Define a class for the ground
var Ground = Container.expand(function () {
var self = Container.call(this);
var groundGraphics = self.attachAsset('ground', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Check for intersection with falling entities
for (var i = 0; i < enemies.length; i++) {
if (self.intersects(enemies[i])) {
enemies[i].destroy(); // Destroy the enemy
self.destroy(); // Destroy the ground piece
ground.splice(ground.indexOf(self), 1); // Remove the destroyed ground piece from the array
enemyKillCounterText.setText('Ground Blocks: ' + ground.length); // Update ground block counter
break; // Exit loop after handling collision
}
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define a class for the MainCharacter
var MainCharacter = Container.expand(function () {
var self = Container.call(this);
var mainCharacterGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// MainCharacter update logic with gravity, jumping, and horizontal movement
if (self.y > 2732 - self.height / 2) {
// Check if on the ground
self.y = 2732 - self.height / 2 - 300; // Further decrease the y-axis position of the player by 100
self.speedY = 0;
self.canJump = true;
} else {
self.y += self.speedY; // Apply gravity
self.speedY += 1; // Gravity effect
}
if (game.isMouseDown && self.canJump) {
self.speedY = -20; // Jump strength
self.canJump = false;
}
// Horizontal movement
if (game.keys['ArrowLeft']) {
self.x -= self.speed; // Move left
}
if (game.keys['ArrowRight']) {
self.x += self.speed; // Move right
}
for (var i = 0; i < ground.length; i++) {
if (self.intersects(ground[i])) {
if (self.y + self.height / 2 >= ground[i].y) {
self.y = ground[i].y - self.height / 2 - 1; // Ensure player is slightly above the ground
}
self.speedY = 0; // Stop falling
self.canJump = true; // Allow jumping
break;
}
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var newEntity = LK.getAsset('entity', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0,
scaleX: 2.048,
scaleY: 2.732
});
if (!game.children.includes(newEntity)) {
game.addChild(newEntity);
}
// Display 'Protect the Cave' message before the game starts
var protectMessage = new Text2('Protect the Ground', {
size: 100,
fill: 0x000000
});
protectMessage.anchor.set(0.5, 0.5);
protectMessage.x = 0;
protectMessage.y = 0;
LK.gui.center.addChild(protectMessage);
// Remove the message after 3 seconds
LK.setTimeout(function () {
LK.gui.center.removeChild(protectMessage);
}, 3000);
// Initialize ground with a flat surface for the character
var ground = [];
var groundPositions = [];
var xPositions = [];
var groundWidth = 200; // Width of each ground block
var totalGroundWidth = 0;
var maxGroundWidth = 2048; // Maximum width of the game area
while (totalGroundWidth < maxGroundWidth) {
var xPos;
do {
xPos = Math.floor(Math.random() * (maxGroundWidth / groundWidth)) * groundWidth + groundWidth / 2;
} while (xPositions.includes(xPos));
xPositions.push(xPos);
groundPositions.push({
x: xPos,
y: 2650 // Slightly more increased y position for all ground blocks
});
totalGroundWidth += groundWidth;
}
for (var i = 0; i < groundPositions.length; i++) {
var groundPiece = new Ground();
groundPiece.x = groundPositions[i].x;
groundPiece.y = groundPositions[i].y;
ground.push(groundPiece);
game.addChild(groundPiece);
}
// Create a new layer of ground blocks slightly above the current ground
var upperGroundPositions = groundPositions.map(function (pos) {
return {
x: pos.x,
y: pos.y - 200 // Position the new layer 200 pixels above the current ground
};
});
for (var i = 0; i < upperGroundPositions.length; i++) {
var upperGroundPiece = new Ground();
upperGroundPiece.x = upperGroundPositions[i].x;
upperGroundPiece.y = upperGroundPositions[i].y;
ground.push(upperGroundPiece);
game.addChild(upperGroundPiece);
}
// Initialize main character with gravity and jumping mechanics
var mainCharacter = game.addChild(new MainCharacter());
mainCharacter.x = 2048 / 2;
mainCharacter.y = 0; // Set the player's y position to 0
mainCharacter.speedY = 0; // Initial vertical speed
mainCharacter.canJump = false; // Initial jump state
// Initialize bullets
var bullets = [];
// Initialize key states for movement
game.keys = {};
// Initialize click counter and timing for shooting
var clickCounter = 0;
var lastClickTime = 0;
// Initialize collectibles
var collectibles = [];
// Initialize enemies with spawning logic
var enemies = [];
function spawnEnemy() {
if (enemies.length < 3) {
// Limit to 3 enemies at a time
var enemy = new Enemy();
var randomGroundIndex = Math.floor(Math.random() * ground.length);
enemy.x = ground[randomGroundIndex].x;
enemy.y = -enemy.height; // Set initial y position above the screen
enemies.push(enemy);
game.addChild(enemy);
}
}
// Display countdown timer for enemy spawn delay
var countdownText = new Text2('Enemies in: 5', {
size: 100,
fill: 0xFFFFFF
});
countdownText.anchor.set(0.5, 0.5);
countdownText.x = 2048 / 2;
countdownText.y = 2732 / 2 + 150; // Position below the 'Protect the Cave' message
LK.gui.center.addChild(countdownText);
var countdown = 5;
var countdownInterval = LK.setInterval(function () {
countdown--;
countdownText.setText('Enemies in: ' + countdown);
if (countdown <= 0) {
LK.clearInterval(countdownInterval);
LK.gui.center.removeChild(countdownText);
}
}, 1000);
// Delay enemy spawning to give player time to build a shelter
LK.setTimeout(function () {
// Initialize enemy spawn interval
var enemySpawnInterval = 2000; // Set to 2 seconds
// Spawn an enemy at the current interval
LK.setInterval(function () {
spawnEnemy();
}, enemySpawnInterval);
}, 5000); // 5-second delay before enemies start spawning
// Handle player movement
game.down = function (x, y, obj) {
mainCharacter.x = x; // Set the main character's x position to the mouse x position
};
// Handle shooting
game.up = function (x, y, obj) {
// Check if the time between clicks is greater than or equal to 300ms (0.30 seconds)
var currentTime = Date.now();
// Check if the time between clicks is greater than or equal to 800ms (0.80 seconds)
if (currentTime - lastClickTime >= 800) {
// Shoot bullet to the left
var leftBullet = new Bullet();
leftBullet.x = mainCharacter.x - mainCharacter.width / 2;
leftBullet.y = mainCharacter.y;
leftBullet.speedX = -10; // Set horizontal speed for left bullet
bullets.push(leftBullet);
game.addChild(leftBullet);
// Shoot bullet to the right
var rightBullet = new Bullet();
rightBullet.x = mainCharacter.x + mainCharacter.width / 2;
rightBullet.y = mainCharacter.y;
rightBullet.speedX = 10; // Set horizontal speed for right bullet
bullets.push(rightBullet);
game.addChild(rightBullet);
// Shoot bullet forward
var forwardBullet = new Bullet();
forwardBullet.x = mainCharacter.x;
forwardBullet.y = mainCharacter.y - mainCharacter.height;
bullets.push(forwardBullet);
game.addChild(forwardBullet);
}
// Update last click time
lastClickTime = currentTime;
};
// Initialize enemy kill counter display
var enemyKillCounterText = new Text2('Ground Blocks: ' + ground.length, {
size: 50,
fill: 0xFFFFFF
});
enemyKillCounterText.anchor.set(0, 0);
enemyKillCounterText.x = 0;
enemyKillCounterText.y = 150;
LK.gui.topLeft.addChild(enemyKillCounterText);
// Initialize survival time display
var survivalTimeText = new Text2('Survival Time: 0s', {
size: 100,
fill: 0xFFFFFF
});
survivalTimeText.anchor.set(0.5, 0);
survivalTimeText.x = 2048 / 2 - 1000;
survivalTimeText.y = 30; // Decrease y position to move text slightly higher
LK.gui.top.addChild(survivalTimeText);
// Initialize survival time counter
var survivalTime = 0;
LK.setInterval(function () {
survivalTime++;
survivalTimeText.setText('Survival Time: ' + survivalTime + 's');
}, 1000);
// Game update loop
game.update = function () {
// Update main character
mainCharacter.update();
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
if (mainCharacter.intersects(enemies[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
break; // Exit loop early if game over is triggered
}
enemies[i].update();
if (enemies[i].y > 2732) {
enemies[i].destroy();
enemies.splice(i, 1);
}
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
if (bullets[j].y < 0) {
bullets[j].destroy();
bullets.splice(j, 1);
continue;
}
for (var k = enemies.length - 1; k >= 0; k--) {
if (bullets[j].intersects(enemies[k])) {
bullets[j].destroy();
bullets.splice(j, 1);
enemies[k].destroy();
enemies.splice(k, 1);
// Update ground block counter
enemyKillCounterText.setText('Ground Blocks: ' + ground.length);
break;
}
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -245,10 +245,10 @@
// Handle shooting
game.up = function (x, y, obj) {
// Check if the time between clicks is greater than or equal to 300ms (0.30 seconds)
var currentTime = Date.now();
- // Check if the time between clicks is greater than or equal to 50ms (0.05 seconds)
- if (currentTime - lastClickTime >= 50) {
+ // Check if the time between clicks is greater than or equal to 800ms (0.80 seconds)
+ if (currentTime - lastClickTime >= 800) {
// Shoot bullet to the left
var leftBullet = new Bullet();
leftBullet.x = mainCharacter.x - mainCharacter.width / 2;
leftBullet.y = mainCharacter.y;
bomb pikcel. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
güzel minecraft arka plan gün batımı. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
minecraft steve pikcel. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
ışın yuvarlak lazer skrol. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.