/****
* 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 = 8;
self.directionX = 0;
self.directionY = 0;
self.isDestroyed = false;
self.update = function () {
if (self.isDestroyed) return;
self.x += self.directionX * self.speed;
self.y += self.directionY * self.speed;
// Remove if off screen
if (self.x < -50 || self.x > 2098 || self.y < -50 || self.y > 2782) {
self.isDestroyed = true;
self.shouldRemove = true;
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
// Add weapon visual
var weapon = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 1,
scaleX: 0.8,
scaleY: 2,
y: -25
});
self.aimAtPoint = function (targetX, targetY) {
var dx = targetX - self.x;
var dy = targetY - self.y;
var angle = Math.atan2(dy, dx) - Math.PI / 2;
weapon.rotation = angle;
};
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 = 1.5;
self.targetX = 1024;
self.targetY = 1366;
self.isDestroyed = false;
self.update = function () {
if (self.isDestroyed) return;
// Move toward center
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
};
self.down = function (x, y, obj) {
if (self.isDestroyed) return;
self.isDestroyed = true;
LK.setScore(LK.getScore() + 10);
scoreTxt.setText(LK.getScore());
// Create explosion effect
var explosion = game.addChild(LK.getAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5,
x: self.x,
y: self.y,
scaleX: 0.1,
scaleY: 0.1
}));
// Animate explosion
tween(explosion, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
explosion.destroy();
}
});
LK.getSound('zombieHit').play();
// Mark for removal
for (var i = 0; i < zombies.length; i++) {
if (zombies[i] === self) {
zombies[i].shouldRemove = true;
break;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2F4F4F
});
/****
* Game Code
****/
// Game variables
var zombies = [];
var bullets = [];
var player;
var scoreTxt;
var waveLevel = 1;
var zombieSpawnRate = 120; // Spawn every 2 seconds initially
var zombieSpeed = 1.5;
var lastZombieSpawn = 0;
var lastShot = 0;
var shootCooldown = 15; // 15 frames between shots (4 shots per second)
// Create player at center
player = game.addChild(new Player());
player.x = 1024;
player.y = 1366;
// Create score display
scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 100;
// Wave level display
var waveTxt = new Text2('Wave 1', {
size: 60,
fill: 0xFFFF00
});
waveTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(waveTxt);
waveTxt.x = -200;
waveTxt.y = 50;
// Shooting function
function shootBullet(targetX, targetY) {
if (LK.ticks - lastShot < shootCooldown) return;
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
// Calculate direction
var dx = targetX - player.x;
var dy = targetY - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
bullet.directionX = dx / distance;
bullet.directionY = dy / distance;
bullets.push(bullet);
game.addChild(bullet);
LK.getSound('gunShot').play();
lastShot = LK.ticks;
}
// Touch/click controls
game.down = function (x, y, obj) {
player.aimAtPoint(x, y);
shootBullet(x, y);
};
function spawnZombie() {
var zombie = new Zombie();
// Random spawn from edges
var edge = Math.floor(Math.random() * 4);
switch (edge) {
case 0:
// Top
zombie.x = Math.random() * 2048;
zombie.y = -40;
break;
case 1:
// Right
zombie.x = 2088;
zombie.y = Math.random() * 2732;
break;
case 2:
// Bottom
zombie.x = Math.random() * 2048;
zombie.y = 2772;
break;
case 3:
// Left
zombie.x = -40;
zombie.y = Math.random() * 2732;
break;
}
zombie.speed = zombieSpeed;
zombies.push(zombie);
game.addChild(zombie);
LK.getSound('zombieSpawn').play();
}
function checkBulletCollisions() {
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
if (bullet.isDestroyed) continue;
for (var j = 0; j < zombies.length; j++) {
var zombie = zombies[j];
if (zombie.isDestroyed) continue;
var dx = bullet.x - zombie.x;
var dy = bullet.y - zombie.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 35) {
// Hit zombie
bullet.isDestroyed = true;
bullet.shouldRemove = true;
zombie.isDestroyed = true;
LK.setScore(LK.getScore() + 10);
scoreTxt.setText(LK.getScore());
// Create explosion effect
var explosion = game.addChild(LK.getAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5,
x: zombie.x,
y: zombie.y,
scaleX: 0.1,
scaleY: 0.1
}));
// Animate explosion
tween(explosion, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
explosion.destroy();
}
});
LK.getSound('zombieHit').play();
// Mark zombie for removal
for (var k = 0; k < zombies.length; k++) {
if (zombies[k] === zombie) {
zombies[k].shouldRemove = true;
break;
}
}
break;
}
}
}
}
function checkGameOver() {
for (var i = 0; i < zombies.length; i++) {
var zombie = zombies[i];
if (zombie.isDestroyed) continue;
var dx = zombie.x - player.x;
var dy = zombie.y - player.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 50) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
}
function updateWave() {
var currentScore = LK.getScore();
var newWaveLevel = Math.floor(currentScore / 100) + 1;
if (newWaveLevel > waveLevel) {
waveLevel = newWaveLevel;
waveTxt.setText('Wave ' + waveLevel);
// Increase difficulty
zombieSpawnRate = Math.max(30, zombieSpawnRate - 10);
zombieSpeed += 0.3;
LK.effects.flashScreen(0x00ff00, 500);
}
}
game.update = function () {
// Spawn zombies
if (LK.ticks - lastZombieSpawn > zombieSpawnRate) {
spawnZombie();
lastZombieSpawn = LK.ticks;
}
// Clean up destroyed bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
if (bullet.shouldRemove) {
bullet.destroy();
bullets.splice(i, 1);
}
}
// Clean up destroyed zombies
for (var i = zombies.length - 1; i >= 0; i--) {
var zombie = zombies[i];
if (zombie.shouldRemove) {
zombie.destroy();
zombies.splice(i, 1);
}
}
// Check bullet collisions
checkBulletCollisions();
// Check for game over
checkGameOver();
// Update wave progression
updateWave();
}; ===================================================================
--- original.js
+++ change.js
@@ -5,14 +5,50 @@
/****
* Classes
****/
+var Bullet = Container.expand(function () {
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 8;
+ self.directionX = 0;
+ self.directionY = 0;
+ self.isDestroyed = false;
+ self.update = function () {
+ if (self.isDestroyed) return;
+ self.x += self.directionX * self.speed;
+ self.y += self.directionY * self.speed;
+ // Remove if off screen
+ if (self.x < -50 || self.x > 2098 || self.y < -50 || self.y > 2782) {
+ self.isDestroyed = true;
+ self.shouldRemove = true;
+ }
+ };
+ return self;
+});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
+ // Add weapon visual
+ var weapon = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 1,
+ scaleX: 0.8,
+ scaleY: 2,
+ y: -25
+ });
+ self.aimAtPoint = function (targetX, targetY) {
+ var dx = targetX - self.x;
+ var dy = targetY - self.y;
+ var angle = Math.atan2(dy, dx) - Math.PI / 2;
+ weapon.rotation = angle;
+ };
return self;
});
var Zombie = Container.expand(function () {
var self = Container.call(this);
@@ -84,14 +120,17 @@
* Game Code
****/
// Game variables
var zombies = [];
+var bullets = [];
var player;
var scoreTxt;
var waveLevel = 1;
var zombieSpawnRate = 120; // Spawn every 2 seconds initially
var zombieSpeed = 1.5;
var lastZombieSpawn = 0;
+var lastShot = 0;
+var shootCooldown = 15; // 15 frames between shots (4 shots per second)
// Create player at center
player = game.addChild(new Player());
player.x = 1024;
player.y = 1366;
@@ -111,8 +150,30 @@
waveTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(waveTxt);
waveTxt.x = -200;
waveTxt.y = 50;
+// Shooting function
+function shootBullet(targetX, targetY) {
+ if (LK.ticks - lastShot < shootCooldown) return;
+ var bullet = new Bullet();
+ bullet.x = player.x;
+ bullet.y = player.y;
+ // Calculate direction
+ var dx = targetX - player.x;
+ var dy = targetY - player.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ bullet.directionX = dx / distance;
+ bullet.directionY = dy / distance;
+ bullets.push(bullet);
+ game.addChild(bullet);
+ LK.getSound('gunShot').play();
+ lastShot = LK.ticks;
+}
+// Touch/click controls
+game.down = function (x, y, obj) {
+ player.aimAtPoint(x, y);
+ shootBullet(x, y);
+};
function spawnZombie() {
var zombie = new Zombie();
// Random spawn from edges
var edge = Math.floor(Math.random() * 4);
@@ -142,8 +203,59 @@
zombies.push(zombie);
game.addChild(zombie);
LK.getSound('zombieSpawn').play();
}
+function checkBulletCollisions() {
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ var bullet = bullets[i];
+ if (bullet.isDestroyed) continue;
+ for (var j = 0; j < zombies.length; j++) {
+ var zombie = zombies[j];
+ if (zombie.isDestroyed) continue;
+ var dx = bullet.x - zombie.x;
+ var dy = bullet.y - zombie.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance < 35) {
+ // Hit zombie
+ bullet.isDestroyed = true;
+ bullet.shouldRemove = true;
+ zombie.isDestroyed = true;
+ LK.setScore(LK.getScore() + 10);
+ scoreTxt.setText(LK.getScore());
+ // Create explosion effect
+ var explosion = game.addChild(LK.getAsset('explosion', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: zombie.x,
+ y: zombie.y,
+ scaleX: 0.1,
+ scaleY: 0.1
+ }));
+ // Animate explosion
+ tween(explosion, {
+ scaleX: 2,
+ scaleY: 2,
+ alpha: 0
+ }, {
+ duration: 300,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ explosion.destroy();
+ }
+ });
+ LK.getSound('zombieHit').play();
+ // Mark zombie for removal
+ for (var k = 0; k < zombies.length; k++) {
+ if (zombies[k] === zombie) {
+ zombies[k].shouldRemove = true;
+ break;
+ }
+ }
+ break;
+ }
+ }
+ }
+}
function checkGameOver() {
for (var i = 0; i < zombies.length; i++) {
var zombie = zombies[i];
if (zombie.isDestroyed) continue;
@@ -174,16 +286,26 @@
if (LK.ticks - lastZombieSpawn > zombieSpawnRate) {
spawnZombie();
lastZombieSpawn = LK.ticks;
}
+ // Clean up destroyed bullets
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ var bullet = bullets[i];
+ if (bullet.shouldRemove) {
+ bullet.destroy();
+ bullets.splice(i, 1);
+ }
+ }
// Clean up destroyed zombies
for (var i = zombies.length - 1; i >= 0; i--) {
var zombie = zombies[i];
if (zombie.shouldRemove) {
zombie.destroy();
zombies.splice(i, 1);
}
}
+ // Check bullet collisions
+ checkBulletCollisions();
// Check for game over
checkGameOver();
// Update wave progression
updateWave();
9mm mermi . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
glock29 . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
zombi . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
zombi . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
zombi. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Bir adet bandanası olsun ve yüzünde savaş çizikleri olsun