User prompt
Öldürülen her düşman için puan verilsin. Oyun bitince o puanlarla karakterin geliştirilebileceği bir panel açılsın ↪💡 Consider importing and using the following plugins: @upit/storage.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Zombie Blaster Arena
Initial prompt
Zombotron tarzı bir oyun yap
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var AmmoPickup = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('ammoPickup', { anchorX: 0.5, anchorY: 0.5 }); self.ammoAmount = 10; self.lifetime = 600; self.lastPlayerCollision = false; self.update = function () { self.lifetime--; graphics.rotation += 0.05; if (self.lifetime <= 0) { self.remove(); return; } var currentCollision = self.intersects(player); if (!self.lastPlayerCollision && currentCollision) { player.addAmmo(self.ammoAmount); LK.getSound('pickup').play(); self.remove(); return; } self.lastPlayerCollision = currentCollision; }; self.remove = function () { var index = ammoPickups.indexOf(self); if (index > -1) { ammoPickups.splice(index, 1); } self.destroy(); }; return self; }); var Bullet = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('bullet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.dx = 0; self.dy = 0; self.lifetime = 120; self.update = function () { self.x += self.dx * self.speed; self.y += self.dy * self.speed; self.lifetime--; if (self.lifetime <= 0 || self.isOutOfBounds()) { self.remove(); return; } for (var i = 0; i < zombies.length; i++) { var zombie = zombies[i]; if (self.intersects(zombie)) { zombie.takeDamage(1); self.remove(); return; } } }; self.isOutOfBounds = function () { return self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732; }; self.remove = function () { var index = bullets.indexOf(self); if (index > -1) { bullets.splice(index, 1); } self.destroy(); }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); // Load upgrades from storage var healthUpgrade = (storage.maxHealthLevel || 0) * 20; var ammoUpgrade = (storage.maxAmmoLevel || 0) * 10; self.health = 100 + healthUpgrade; self.maxHealth = 100 + healthUpgrade; self.ammo = 30 + ammoUpgrade; self.maxAmmo = 30 + ammoUpgrade; self.shootCooldown = 0; self.update = function () { if (self.shootCooldown > 0) { self.shootCooldown--; } }; self.takeDamage = function (damage) { self.health -= damage; if (self.health <= 0) { self.health = 0; LK.effects.flashScreen(0xff0000, 1000); // Show upgrade panel instead of immediate game over var upgradePanel = new UpgradePanel(); upgradePanel.x = 2048 / 2; upgradePanel.y = 2732 / 2; game.addChild(upgradePanel); } else { LK.effects.flashObject(self, 0xff0000, 200); } }; self.addAmmo = function (amount) { self.ammo = Math.min(self.ammo + amount, self.maxAmmo); }; self.canShoot = function () { return self.ammo > 0 && self.shootCooldown <= 0; }; self.shoot = function () { if (self.canShoot()) { self.ammo--; self.shootCooldown = 10; return true; } return false; }; return self; }); var UpgradePanel = Container.expand(function () { var self = Container.call(this); // Panel background var panelBg = LK.getAsset('upgradePanel', { width: 1600, height: 1200, color: 0x222222, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); self.addChild(panelBg); // Title var title = new Text2('UPGRADE YOUR CHARACTER', { size: 80, fill: 0xFFFFFF }); title.anchor.set(0.5, 0.5); title.x = 0; title.y = -450; self.addChild(title); // Score display var scoreText = new Text2('Final Score: ' + LK.getScore(), { size: 60, fill: 0xFFFF00 }); scoreText.anchor.set(0.5, 0.5); scoreText.x = 0; scoreText.y = -350; self.addChild(scoreText); // Upgrade buttons var upgradeButtons = []; var upgrades = [{ name: 'Health', cost: 100, property: 'maxHealth', increase: 20 }, { name: 'Ammo', cost: 80, property: 'maxAmmo', increase: 10 }, { name: 'Damage', cost: 150, property: 'damage', increase: 1 }]; for (var i = 0; i < upgrades.length; i++) { var upgrade = upgrades[i]; var currentLevel = storage[upgrade.property + 'Level'] || 0; var cost = upgrade.cost + currentLevel * 50; // Button background var buttonBg = LK.getAsset('upgradeButton', { width: 400, height: 150, color: LK.getScore() >= cost ? 0x00AA00 : 0xAA0000, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); buttonBg.x = (i - 1) * 500; buttonBg.y = -100; self.addChild(buttonBg); // Button text var buttonText = new Text2(upgrade.name + ' +' + upgrade.increase + '\nCost: ' + cost + '\nLevel: ' + currentLevel, { size: 40, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); buttonText.x = buttonBg.x; buttonText.y = buttonBg.y; self.addChild(buttonText); // Store button data upgradeButtons.push({ bg: buttonBg, text: buttonText, upgrade: upgrade, cost: cost, currentLevel: currentLevel }); } // Continue button var continueButton = LK.getAsset('continueButton', { width: 300, height: 100, color: 0x0080FF, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); continueButton.x = 0; continueButton.y = 300; self.addChild(continueButton); var continueText = new Text2('CONTINUE', { size: 50, fill: 0xFFFFFF }); continueText.anchor.set(0.5, 0.5); continueText.x = 0; continueText.y = 300; self.addChild(continueText); // Handle button clicks self.down = function (x, y, obj) { // Check upgrade buttons for (var i = 0; i < upgradeButtons.length; i++) { var button = upgradeButtons[i]; var localPos = self.toLocal(obj.parent.toGlobal(obj.position)); if (Math.abs(localPos.x - button.bg.x) < 200 && Math.abs(localPos.y - button.bg.y) < 75 && LK.getScore() >= button.cost) { // Purchase upgrade LK.setScore(LK.getScore() - button.cost); var newLevel = button.currentLevel + 1; storage[button.upgrade.property + 'Level'] = newLevel; // Update display var newCost = button.upgrade.cost + newLevel * 50; button.text.setText(button.upgrade.name + ' +' + button.upgrade.increase + '\nCost: ' + newCost + '\nLevel: ' + newLevel); button.bg.tint = LK.getScore() >= newCost ? 0x00AA00 : 0xAA0000; scoreText.setText('Final Score: ' + LK.getScore()); return; } } // Check continue button var localPos = self.toLocal(obj.parent.toGlobal(obj.position)); if (Math.abs(localPos.x - continueButton.x) < 150 && Math.abs(localPos.y - continueButton.y) < 50) { self.close(); } }; self.close = function () { self.destroy(); // Restart game with upgrades LK.showGameOver(); }; return self; }); var Zombie = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('zombie', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 1 + Math.random() * 0.5; self.health = 1; self.damage = 10; self.lastPlayerCollision = false; self.update = function () { 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; } var currentCollision = self.intersects(player); if (!self.lastPlayerCollision && currentCollision) { player.takeDamage(self.damage); self.takeDamage(1); } self.lastPlayerCollision = currentCollision; }; self.takeDamage = function (damage) { self.health -= damage; if (self.health <= 0) { LK.effects.flashObject(self, 0xffffff, 100); LK.setScore(LK.getScore() + 10); LK.getSound('zombieHit').play(); var index = zombies.indexOf(self); if (index > -1) { zombies.splice(index, 1); } self.destroy(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2d2d2d }); /**** * Game Code ****/ var arena = game.attachAsset('arena', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; var zombies = []; var bullets = []; var ammoPickups = []; var waveNumber = 1; var zombiesInWave = 5; var zombiesSpawned = 0; var spawnTimer = 0; var pickupTimer = 0; var healthBar = new Text2('Health: 100', { size: 60, fill: 0xFF0000 }); healthBar.anchor.set(0, 0); LK.gui.topLeft.addChild(healthBar); var ammoDisplay = new Text2('Ammo: 30', { size: 60, fill: 0x00FF00 }); ammoDisplay.anchor.set(0, 0); ammoDisplay.y = 70; LK.gui.topLeft.addChild(ammoDisplay); var scoreDisplay = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreDisplay.anchor.set(0.5, 0); LK.gui.top.addChild(scoreDisplay); var waveDisplay = new Text2('Wave: 1', { size: 60, fill: 0xFFFF00 }); waveDisplay.anchor.set(1, 0); LK.gui.topRight.addChild(waveDisplay); function spawnZombie() { var zombie = new Zombie(); var angle = Math.random() * Math.PI * 2; var spawnRadius = 1000; zombie.x = player.x + Math.cos(angle) * spawnRadius; zombie.y = player.y + Math.sin(angle) * spawnRadius; zombies.push(zombie); game.addChild(zombie); } function spawnAmmoPickup() { var pickup = new AmmoPickup(); var angle = Math.random() * Math.PI * 2; var radius = 200 + Math.random() * 400; pickup.x = player.x + Math.cos(angle) * radius; pickup.y = player.y + Math.sin(angle) * radius; ammoPickups.push(pickup); game.addChild(pickup); } function shootBullet(targetX, targetY) { if (player.shoot()) { var bullet = new Bullet(); bullet.x = player.x; bullet.y = player.y; var dx = targetX - player.x; var dy = targetY - player.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > 0) { bullet.dx = dx / distance; bullet.dy = dy / distance; } bullets.push(bullet); game.addChild(bullet); LK.getSound('shoot').play(); } } game.down = function (x, y, obj) { shootBullet(x, y); }; game.update = function () { spawnTimer++; pickupTimer++; if (zombiesSpawned < zombiesInWave && spawnTimer >= 60) { spawnZombie(); zombiesSpawned++; spawnTimer = 0; } if (zombiesSpawned >= zombiesInWave && zombies.length === 0) { waveNumber++; zombiesInWave = Math.min(5 + waveNumber * 2, 20); zombiesSpawned = 0; waveDisplay.setText('Wave: ' + waveNumber); for (var i = 0; i < zombies.length; i++) { zombies[i].speed += 0.1; } } if (pickupTimer >= 900) { spawnAmmoPickup(); pickupTimer = 0; } healthBar.setText('Health: ' + player.health); ammoDisplay.setText('Ammo: ' + player.ammo); scoreDisplay.setText('Score: ' + LK.getScore()); for (var i = bullets.length - 1; i >= 0; i--) { bullets[i].update(); } for (var i = zombies.length - 1; i >= 0; i--) { zombies[i].update(); } for (var i = ammoPickups.length - 1; i >= 0; i--) { ammoPickups[i].update(); } }; LK.playMusic('bgmusic');
===================================================================
--- original.js
+++ change.js
@@ -1,8 +1,9 @@
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
@@ -84,12 +85,15 @@
var graphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
- self.health = 100;
- self.maxHealth = 100;
- self.ammo = 30;
- self.maxAmmo = 30;
+ // Load upgrades from storage
+ var healthUpgrade = (storage.maxHealthLevel || 0) * 20;
+ var ammoUpgrade = (storage.maxAmmoLevel || 0) * 10;
+ self.health = 100 + healthUpgrade;
+ self.maxHealth = 100 + healthUpgrade;
+ self.ammo = 30 + ammoUpgrade;
+ self.maxAmmo = 30 + ammoUpgrade;
self.shootCooldown = 0;
self.update = function () {
if (self.shootCooldown > 0) {
self.shootCooldown--;
@@ -99,9 +103,13 @@
self.health -= damage;
if (self.health <= 0) {
self.health = 0;
LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
+ // Show upgrade panel instead of immediate game over
+ var upgradePanel = new UpgradePanel();
+ upgradePanel.x = 2048 / 2;
+ upgradePanel.y = 2732 / 2;
+ game.addChild(upgradePanel);
} else {
LK.effects.flashObject(self, 0xff0000, 200);
}
};
@@ -120,8 +128,142 @@
return false;
};
return self;
});
+var UpgradePanel = Container.expand(function () {
+ var self = Container.call(this);
+ // Panel background
+ var panelBg = LK.getAsset('upgradePanel', {
+ width: 1600,
+ height: 1200,
+ color: 0x222222,
+ shape: 'box',
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.addChild(panelBg);
+ // Title
+ var title = new Text2('UPGRADE YOUR CHARACTER', {
+ size: 80,
+ fill: 0xFFFFFF
+ });
+ title.anchor.set(0.5, 0.5);
+ title.x = 0;
+ title.y = -450;
+ self.addChild(title);
+ // Score display
+ var scoreText = new Text2('Final Score: ' + LK.getScore(), {
+ size: 60,
+ fill: 0xFFFF00
+ });
+ scoreText.anchor.set(0.5, 0.5);
+ scoreText.x = 0;
+ scoreText.y = -350;
+ self.addChild(scoreText);
+ // Upgrade buttons
+ var upgradeButtons = [];
+ var upgrades = [{
+ name: 'Health',
+ cost: 100,
+ property: 'maxHealth',
+ increase: 20
+ }, {
+ name: 'Ammo',
+ cost: 80,
+ property: 'maxAmmo',
+ increase: 10
+ }, {
+ name: 'Damage',
+ cost: 150,
+ property: 'damage',
+ increase: 1
+ }];
+ for (var i = 0; i < upgrades.length; i++) {
+ var upgrade = upgrades[i];
+ var currentLevel = storage[upgrade.property + 'Level'] || 0;
+ var cost = upgrade.cost + currentLevel * 50;
+ // Button background
+ var buttonBg = LK.getAsset('upgradeButton', {
+ width: 400,
+ height: 150,
+ color: LK.getScore() >= cost ? 0x00AA00 : 0xAA0000,
+ shape: 'box',
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ buttonBg.x = (i - 1) * 500;
+ buttonBg.y = -100;
+ self.addChild(buttonBg);
+ // Button text
+ var buttonText = new Text2(upgrade.name + ' +' + upgrade.increase + '\nCost: ' + cost + '\nLevel: ' + currentLevel, {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ buttonText.x = buttonBg.x;
+ buttonText.y = buttonBg.y;
+ self.addChild(buttonText);
+ // Store button data
+ upgradeButtons.push({
+ bg: buttonBg,
+ text: buttonText,
+ upgrade: upgrade,
+ cost: cost,
+ currentLevel: currentLevel
+ });
+ }
+ // Continue button
+ var continueButton = LK.getAsset('continueButton', {
+ width: 300,
+ height: 100,
+ color: 0x0080FF,
+ shape: 'box',
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ continueButton.x = 0;
+ continueButton.y = 300;
+ self.addChild(continueButton);
+ var continueText = new Text2('CONTINUE', {
+ size: 50,
+ fill: 0xFFFFFF
+ });
+ continueText.anchor.set(0.5, 0.5);
+ continueText.x = 0;
+ continueText.y = 300;
+ self.addChild(continueText);
+ // Handle button clicks
+ self.down = function (x, y, obj) {
+ // Check upgrade buttons
+ for (var i = 0; i < upgradeButtons.length; i++) {
+ var button = upgradeButtons[i];
+ var localPos = self.toLocal(obj.parent.toGlobal(obj.position));
+ if (Math.abs(localPos.x - button.bg.x) < 200 && Math.abs(localPos.y - button.bg.y) < 75 && LK.getScore() >= button.cost) {
+ // Purchase upgrade
+ LK.setScore(LK.getScore() - button.cost);
+ var newLevel = button.currentLevel + 1;
+ storage[button.upgrade.property + 'Level'] = newLevel;
+ // Update display
+ var newCost = button.upgrade.cost + newLevel * 50;
+ button.text.setText(button.upgrade.name + ' +' + button.upgrade.increase + '\nCost: ' + newCost + '\nLevel: ' + newLevel);
+ button.bg.tint = LK.getScore() >= newCost ? 0x00AA00 : 0xAA0000;
+ scoreText.setText('Final Score: ' + LK.getScore());
+ return;
+ }
+ }
+ // Check continue button
+ var localPos = self.toLocal(obj.parent.toGlobal(obj.position));
+ if (Math.abs(localPos.x - continueButton.x) < 150 && Math.abs(localPos.y - continueButton.y) < 50) {
+ self.close();
+ }
+ };
+ self.close = function () {
+ self.destroy();
+ // Restart game with upgrades
+ LK.showGameOver();
+ };
+ return self;
+});
var Zombie = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('zombie', {
anchorX: 0.5,
Üstten görünümlü zombi. In-Game asset. 2d. High contrast. No shadows
Ortasında elips şeklinde bir boşluk hariç her yeri sık ağaçlık olan bir orman. In-Game asset. 2d. High contrast. No shadows
Ahşap tema. In-Game asset. 2d. High contrast. No shadows
pompalı tüfek mermisi. In-Game asset. 2d. High contrast. No shadows
hafif makineli tüfek mermisi. In-Game asset. 2d. High contrast. No shadows
Uzi çiz. In-Game asset. 2d. High contrast. No shadows
Pompalı Tüfek. In-Game asset. 2d. High contrast. No shadows
Bunun arkaplanını sil
Arkaplanını sil
boss zombie. In-Game asset. 2d. High contrast. No shadows
dümdüz sadece buzullardan oluşsun aralarında yarıklar olmasın