User prompt
o zaman buna benzer bu işlevi gören alternatif bir sistem yapalım
User prompt
rapid fire düşme ihtimalini %5 yapalım ve healt pack düşme ihtimali de %10 olsun
User prompt
Canavarlardan %50 olasılıkla ammo düşsün ve canavarlardan %15 ihtimalle rapid fire düşsün.
Code edit (1 edits merged)
Please save this source code
User prompt
Zombie Shooter
Initial prompt
zombilerle silah ile savaştığımız bir oyun yapar mısın?
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
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.damage = 25;
self.targetX = 0;
self.targetY = 0;
self.directionX = 0;
self.directionY = 0;
self.setTarget = function (targetX, targetY) {
var dx = targetX - self.x;
var dy = targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.directionX = dx / distance;
self.directionY = dy / distance;
}
};
self.update = function () {
self.x += self.directionX * self.speed;
self.y += self.directionY * self.speed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.maxHealth = 100;
self.ammo = 50;
self.maxAmmo = 100;
self.shootCooldown = 0;
self.shootRate = 15; // shoots every 15 ticks
self.rapidFireBonus = 0;
self.takeDamage = function (damage) {
self.health -= damage;
if (self.health <= 0) {
self.health = 0;
return true; // player died
}
return false;
};
self.addHealth = function (amount) {
self.health = Math.min(self.health + amount, self.maxHealth);
};
self.addAmmo = function (amount) {
self.ammo = Math.min(self.ammo + amount, self.maxAmmo);
};
self.update = function () {
if (self.shootCooldown > 0) {
self.shootCooldown--;
}
if (self.rapidFireBonus > 0) {
self.rapidFireBonus--;
}
};
return self;
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
self.type = 'health';
self.lifetime = 600; // 10 seconds at 60fps
self.update = function () {
self.lifetime--;
if (self.lifetime <= 0) {
return true; // should be removed
}
return false;
};
return self;
});
var RapidFire = PowerUp.expand(function () {
var self = PowerUp.call(this);
var packGraphics = self.attachAsset('rapidFire', {
anchorX: 0.5,
anchorY: 0.5
});
self.type = 'rapidfire';
self.value = 300; // 5 seconds of rapid fire
return self;
});
var HealthPack = PowerUp.expand(function () {
var self = PowerUp.call(this);
var packGraphics = self.attachAsset('healthPack', {
anchorX: 0.5,
anchorY: 0.5
});
self.type = 'health';
self.value = 30;
return self;
});
var AmmoPack = PowerUp.expand(function () {
var self = PowerUp.call(this);
var packGraphics = self.attachAsset('ammoPack', {
anchorX: 0.5,
anchorY: 0.5
});
self.type = 'ammo';
self.value = 25;
return self;
});
var Zombie = Container.expand(function () {
var self = Container.call(this);
self.health = 50;
self.maxHealth = 50;
self.speed = 2;
self.damage = 20;
self.scoreValue = 10;
self.type = 'walker';
self.takeDamage = function (damage) {
self.health -= damage;
return self.health <= 0;
};
self.update = function () {
// Move toward player
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
};
return self;
});
var ZombieWalker = Zombie.expand(function () {
var self = Zombie.call(this);
var zombieGraphics = self.attachAsset('zombieWalker', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 50;
self.maxHealth = 50;
self.speed = 2;
self.damage = 20;
self.scoreValue = 10;
self.type = 'walker';
return self;
});
var ZombieRunner = Zombie.expand(function () {
var self = Zombie.call(this);
var zombieGraphics = self.attachAsset('zombieRunner', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 30;
self.maxHealth = 30;
self.speed = 4;
self.damage = 15;
self.scoreValue = 15;
self.type = 'runner';
return self;
});
var ZombieBrute = Zombie.expand(function () {
var self = Zombie.call(this);
var zombieGraphics = self.attachAsset('zombieBrute', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.maxHealth = 100;
self.speed = 1;
self.damage = 35;
self.scoreValue = 25;
self.type = 'brute';
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2d2d2d
});
/****
* Game Code
****/
// Game variables
var player;
var bullets = [];
var zombies = [];
var powerUps = [];
var waveNumber = 1;
var zombiesKilled = 0;
var gameTime = 0;
var spawnTimer = 0;
var powerUpTimer = 0;
var dragNode = null;
// UI Elements
var scoreText = new Text2('Score: 0', {
size: 40,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
scoreText.x = 120;
scoreText.y = 20;
LK.gui.topLeft.addChild(scoreText);
var healthText = new Text2('Health: 100', {
size: 40,
fill: 0xFF0000
});
healthText.anchor.set(0.5, 0);
LK.gui.top.addChild(healthText);
var ammoText = new Text2('Ammo: 50', {
size: 40,
fill: 0xFFFF00
});
ammoText.anchor.set(1, 0);
ammoText.x = -20;
ammoText.y = 20;
LK.gui.topRight.addChild(ammoText);
var waveText = new Text2('Wave: 1', {
size: 40,
fill: 0x00FF00
});
waveText.anchor.set(0.5, 0);
waveText.y = 80;
LK.gui.top.addChild(waveText);
// Initialize player
player = game.addChild(new Player());
player.x = 1024;
player.y = 1366;
// Helper functions
function updateUI() {
scoreText.setText('Score: ' + LK.getScore());
healthText.setText('Health: ' + player.health);
ammoText.setText('Ammo: ' + player.ammo);
waveText.setText('Wave: ' + waveNumber);
}
function getRandomSpawnPosition() {
var side = Math.floor(Math.random() * 4);
var x, y;
switch (side) {
case 0:
// top
x = Math.random() * 2048;
y = -50;
break;
case 1:
// right
x = 2098;
y = Math.random() * 2732;
break;
case 2:
// bottom
x = Math.random() * 2048;
y = 2782;
break;
case 3:
// left
x = -50;
y = Math.random() * 2732;
break;
}
return {
x: x,
y: y
};
}
function spawnZombie() {
var pos = getRandomSpawnPosition();
var zombie;
var rand = Math.random();
if (rand < 0.6) {
zombie = new ZombieWalker();
} else if (rand < 0.85) {
zombie = new ZombieRunner();
} else {
zombie = new ZombieBrute();
}
zombie.x = pos.x;
zombie.y = pos.y;
zombies.push(zombie);
game.addChild(zombie);
}
function spawnPowerUp() {
var x = Math.random() * 1800 + 124; // Keep away from edges
var y = Math.random() * 2400 + 166;
var powerUp;
var rand = Math.random();
if (rand < 0.4) {
powerUp = new HealthPack();
} else if (rand < 0.7) {
powerUp = new AmmoPack();
} else {
powerUp = new RapidFire();
}
powerUp.x = x;
powerUp.y = y;
powerUps.push(powerUp);
game.addChild(powerUp);
}
function findNearestZombie() {
var nearestZombie = null;
var minDistance = Infinity;
for (var i = 0; i < zombies.length; i++) {
var zombie = zombies[i];
var dx = zombie.x - player.x;
var dy = zombie.y - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < minDistance) {
minDistance = distance;
nearestZombie = zombie;
}
}
return nearestZombie;
}
function shootAtZombie() {
if (player.ammo <= 0 || player.shootCooldown > 0) {
return;
}
var target = findNearestZombie();
if (!target) {
return;
}
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
bullet.setTarget(target.x, target.y);
bullets.push(bullet);
game.addChild(bullet);
player.ammo--;
player.shootCooldown = player.rapidFireBonus > 0 ? 5 : player.shootRate;
LK.getSound('shoot').play();
}
// Event handlers
game.down = function (x, y, obj) {
dragNode = player;
player.x = x;
player.y = y;
};
game.move = function (x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
}
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Main game loop
game.update = function () {
gameTime++;
// Update spawn rate based on wave
var baseSpawnRate = Math.max(120 - waveNumber * 10, 30);
if (gameTime % baseSpawnRate === 0) {
spawnZombie();
}
// Spawn power-ups occasionally
powerUpTimer++;
if (powerUpTimer >= 1800) {
// Every 30 seconds
spawnPowerUp();
powerUpTimer = 0;
}
// Try to shoot
shootAtZombie();
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Check if bullet is off screen
if (bullet.x < -50 || bullet.x > 2098 || bullet.y < -50 || bullet.y > 2782) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check bullet-zombie collisions
var hitZombie = false;
for (var j = zombies.length - 1; j >= 0; j--) {
var zombie = zombies[j];
if (bullet.intersects(zombie)) {
if (zombie.takeDamage(bullet.damage)) {
// Zombie is dead
LK.setScore(LK.getScore() + zombie.scoreValue);
zombiesKilled++;
// Drop power-ups with specified chances
var dropChance = Math.random();
if (dropChance < 0.05) {
// 5% chance for rapid fire
var rapidFireDrop = new RapidFire();
rapidFireDrop.x = zombie.x;
rapidFireDrop.y = zombie.y;
powerUps.push(rapidFireDrop);
game.addChild(rapidFireDrop);
} else if (dropChance < 0.15) {
// 10% chance for health pack (5% + 10% = 15% total)
var healthDrop = new HealthPack();
healthDrop.x = zombie.x;
healthDrop.y = zombie.y;
powerUps.push(healthDrop);
game.addChild(healthDrop);
} else if (dropChance < 0.65) {
// 50% chance for ammo (15% + 50% = 65% total)
var ammoDrop = new AmmoPack();
ammoDrop.x = zombie.x;
ammoDrop.y = zombie.y;
powerUps.push(ammoDrop);
game.addChild(ammoDrop);
}
zombie.destroy();
zombies.splice(j, 1);
LK.getSound('zombieHit').play();
// Check for wave progression
if (zombiesKilled >= waveNumber * 10) {
waveNumber++;
zombiesKilled = 0;
}
}
bullet.destroy();
bullets.splice(i, 1);
hitZombie = true;
break;
}
}
if (hitZombie) continue;
}
// Update zombies and check player collision
for (var i = zombies.length - 1; i >= 0; i--) {
var zombie = zombies[i];
if (zombie.intersects(player)) {
if (player.takeDamage(zombie.damage)) {
// Player died
LK.showGameOver();
return;
}
LK.getSound('damage').play();
LK.effects.flashScreen(0xff0000, 500);
zombie.destroy();
zombies.splice(i, 1);
}
}
// Update power-ups and check collection
for (var i = powerUps.length - 1; i >= 0; i--) {
var powerUp = powerUps[i];
if (powerUp.update()) {
// Power-up expired
powerUp.destroy();
powerUps.splice(i, 1);
continue;
}
if (powerUp.intersects(player)) {
LK.getSound('powerup').play();
switch (powerUp.type) {
case 'health':
player.addHealth(powerUp.value);
break;
case 'ammo':
player.addAmmo(powerUp.value);
break;
case 'rapidfire':
player.rapidFireBonus = powerUp.value;
break;
}
powerUp.destroy();
powerUps.splice(i, 1);
}
}
// Update UI
updateUI();
// Check win condition (survive for 10 minutes)
if (gameTime >= 36000) {
// 10 minutes at 60fps
LK.showYouWin();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -389,15 +389,22 @@
LK.setScore(LK.getScore() + zombie.scoreValue);
zombiesKilled++;
// Drop power-ups with specified chances
var dropChance = Math.random();
- if (dropChance < 0.15) {
- // 15% chance for rapid fire
+ if (dropChance < 0.05) {
+ // 5% chance for rapid fire
var rapidFireDrop = new RapidFire();
rapidFireDrop.x = zombie.x;
rapidFireDrop.y = zombie.y;
powerUps.push(rapidFireDrop);
game.addChild(rapidFireDrop);
+ } else if (dropChance < 0.15) {
+ // 10% chance for health pack (5% + 10% = 15% total)
+ var healthDrop = new HealthPack();
+ healthDrop.x = zombie.x;
+ healthDrop.y = zombie.y;
+ powerUps.push(healthDrop);
+ game.addChild(healthDrop);
} else if (dropChance < 0.65) {
// 50% chance for ammo (15% + 50% = 65% total)
var ammoDrop = new AmmoPack();
ammoDrop.x = zombie.x;
Ammo pack. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Bullet. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Healt pack. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
üstten görünümlü yuvarlak asker. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
rapid fire. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
üsttem görünümlü yuvarlak zombi. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
üsttem görünümlü yuvarlak zombi. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
üsttem görünümlü yuvarlak zombi büyük kolları var tek gözünde göz maskesi var ve elinde bir sopa var. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat