User prompt
Make the bullet shoot higher than the player
User prompt
Make the player 3 times bigger
User prompt
Make the zombies take 2 hits before. They die
User prompt
Make the bullets point towards the touch location
User prompt
Make the bullets point in the direction of the player
User prompt
Make the bullet point towards the touch location
User prompt
Make the bullet size bigger
User prompt
Make the bullets shoot where the screen is touched
Code edit (1 edits merged)
Please save this source code
User prompt
Zombie Siege: Last Stand
Initial prompt
A zombie attack game with the player in the center
/**** * 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 = 10; self.direction = 0; self.update = function () { self.x += Math.cos(self.direction) * self.speed; self.y += Math.sin(self.direction) * 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.rotation = 0; self.shoot = function () { var bullet = new Bullet(); bullet.x = self.x; bullet.y = self.y; bullet.direction = self.rotation; bullets.push(bullet); game.addChild(bullet); LK.getSound('shoot').play(); }; return self; }); var Zombie = Container.expand(function () { var self = Container.call(this); var zombieGraphics = self.attachAsset('zombie', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.update = function () { var angle = Math.atan2(player.y - self.y, player.x - self.x); self.x += Math.cos(angle) * self.speed; self.y += Math.sin(angle) * self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Initialize assets used in this game. Scale them according to what is needed for the game. game.setBackgroundColor(0x000000); var player = new Player(); player.x = 2048 / 2; player.y = 2732 / 2; game.addChild(player); var bullets = []; var zombies = []; var score = 0; function spawnZombie() { var zombie = new Zombie(); var edge = Math.floor(Math.random() * 4); switch (edge) { case 0: // Top zombie.x = Math.random() * 2048; zombie.y = -50; break; case 1: // Right zombie.x = 2048 + 50; zombie.y = Math.random() * 2732; break; case 2: // Bottom zombie.x = Math.random() * 2048; zombie.y = 2732 + 50; break; case 3: // Left zombie.x = -50; zombie.y = Math.random() * 2732; break; } zombies.push(zombie); game.addChild(zombie); } game.down = function (x, y, obj) { var angle = Math.atan2(y - player.y, x - player.x); player.rotation = angle; // Update player rotation to face the touch location player.shoot(); // Use the player's shoot method to create and shoot the bullet }; game.update = function () { for (var i = bullets.length - 1; i >= 0; i--) { var bullet = bullets[i]; bullet.update(); if (bullet.x < 0 || bullet.x > 2048 || bullet.y < 0 || bullet.y > 2732) { bullet.destroy(); bullets.splice(i, 1); } } for (var j = zombies.length - 1; j >= 0; j--) { var zombie = zombies[j]; zombie.update(); if (zombie.intersects(player)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } for (var k = bullets.length - 1; k >= 0; k--) { var bullet = bullets[k]; if (bullet.intersects(zombie)) { LK.getSound('zombieHit').play(); score += 10; bullet.destroy(); bullets.splice(k, 1); zombie.destroy(); zombies.splice(j, 1); break; } } } if (LK.ticks % 60 === 0) { spawnZombie(); } }; LK.playMusic('backgroundMusic');
===================================================================
--- original.js
+++ change.js
@@ -101,15 +101,10 @@
game.addChild(zombie);
}
game.down = function (x, y, obj) {
var angle = Math.atan2(y - player.y, x - player.x);
- var bullet = new Bullet();
- bullet.x = player.x;
- bullet.y = player.y;
- bullet.direction = angle;
- bullets.push(bullet);
- game.addChild(bullet);
- LK.getSound('shoot').play();
+ player.rotation = angle; // Update player rotation to face the touch location
+ player.shoot(); // Use the player's shoot method to create and shoot the bullet
};
game.update = function () {
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];