User prompt
playerpistol olunca 10 tane bullets atınca tekrar player olsun
User prompt
playerpistol olunca bullet olsun
User prompt
mermiyi %25 büyüt ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
mermiyi %75 büyüt pistolu %25 büyüt
User prompt
pistol %50 büyüt ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Uncaught ReferenceError: Bullet is not defined' in or related to this line: 'bullet = new Bullet();' Line Number: 305
User prompt
player pistol olunca yumruk yerine mermi atsın
User prompt
pistol alınca player pistol olsun
User prompt
ölen zombiler silah düşürsün ve onu alınca kullanabileyim
User prompt
kirmizi alan sinirina carpan yumruklar yavaşlasin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
yumruk hızları sabit olsun ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
kırmızı alan sınırına çarpan yumrukların hızını %50 düşür ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
kirmizi alan sinirina çarpan yurmuk hızını %50 düşür ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
kırmızı alan sınırına çarpan yumruklar geri playere çarpşın ve mermi olarak eklensin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
kırmızı alan sınırına değen yumruklar sağ ve sol olmak üzere ala içinde 3 tur daire çizsin yok olsun ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
yumruklar kırmızı alan etrafını 360 derece yani güzel bir şekilde dolansın 3 tur attığında kendiliğinden yokolsun ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
yumruklar daire şekldin dönsün ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
yumruklar alan etrafında dönerken sadece player haraketsizken
User prompt
kırmızı alanın sınırına değen yumruklar alanın etrafında dönsün ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
yumruklar sağ ve sol falsolu şekilde kirmizi alandaki zombilere gitsin
User prompt
yumruklar falsolu gitsin
User prompt
yumruklar rangecircle sınırına değerse yokolsun
User prompt
yumruklar rangecircle dışına çıkmasın
User prompt
yumruklar %50 daha yavaşlat
User prompt
redcircle sil
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.value = 10;
self.lastPlayerDistance = Infinity;
// Start small and grow when spawned
self.scaleX = 0.1;
self.scaleY = 0.1;
tween(self, {
scaleX: 1.75,
scaleY: 1.75
}, {
duration: 800,
easing: tween.bounceOut
});
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Collect coin if player is close
if (self.lastPlayerDistance > 40 && distance <= 40) {
player.coins += self.value;
LK.getSound('coin').play();
// Animate coin growing before collection
tween(self, {
scaleX: 2.8,
scaleY: 2.8,
alpha: 0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
var index = coins.indexOf(self);
if (index !== -1) {
coins.splice(index, 1);
}
self.destroy();
}
});
}
self.lastPlayerDistance = distance;
};
return self;
});
var HealthDrop = Container.expand(function () {
var self = Container.call(this);
var healthDropGraphics = self.attachAsset('healthDrop', {
anchorX: 0.5,
anchorY: 0.5
});
// Tint the health drop red to look like a heart
healthDropGraphics.tint = 0xFF0000;
self.healAmount = 10; // 10% heal
self.lastPlayerDistance = Infinity;
// Start small and grow when spawned
self.scaleX = 0.1;
self.scaleY = 0.1;
tween(self, {
scaleX: 1.75,
scaleY: 1.75
}, {
duration: 800,
easing: tween.bounceOut
});
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Collect health drop if player is close
if (self.lastPlayerDistance > 40 && distance <= 40) {
// Heal player by 10% of max health
var healAmount = Math.floor(player.maxHealth * 0.1);
player.health = Math.min(player.maxHealth, player.health + healAmount);
if (player.healthText) {
player.healthText.setText(player.health.toString());
}
LK.getSound('coin').play();
// Animate health drop growing before collection
tween(self, {
scaleX: 2.8,
scaleY: 2.8,
alpha: 0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
var index = healthDrops.indexOf(self);
if (index !== -1) {
healthDrops.splice(index, 1);
}
self.destroy();
}
});
}
self.lastPlayerDistance = distance;
};
return self;
});
var LeftPunch = Container.expand(function () {
var self = Container.call(this);
// Create left punch
var punchGraphics = self.attachAsset('leftPunch', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.damage = 25;
self.isInstantKill = false;
self.target = null; // Target zombie in red area
self.isRotating = false; // Track if punch is rotating around circle
self.rotationAngle = 0; // Current rotation angle
self.rotationSpeed = 0; // Speed of rotation
self.update = function () {
// Find nearest zombie in red area if we don't have a target
if (!self.target) {
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 distanceFromPlayer = Math.sqrt(dx * dx + dy * dy);
if (distanceFromPlayer <= player.range && distanceFromPlayer < minDistance) {
minDistance = distanceFromPlayer;
nearestZombie = zombie;
}
}
self.target = nearestZombie;
}
// Apply gravity to create parabolic arc
self.velocityY += 0.3; // Gravity effect
// If we have a target zombie, adjust trajectory towards it
if (self.target && zombies.indexOf(self.target) !== -1) {
var targetDx = self.target.x - self.x;
var targetDy = self.target.y - self.y;
var targetDistance = Math.sqrt(targetDx * targetDx + targetDy * targetDy);
// Add slight homing effect (adjust velocity slightly towards target)
if (targetDistance > 20) {
var homingStrength = 0.1;
self.velocityX += targetDx / targetDistance * homingStrength;
self.velocityY += targetDy / targetDistance * homingStrength;
}
} else {
// Clear target if zombie no longer exists
self.target = null;
}
// Move punch with parabolic trajectory
self.x += self.velocityX;
self.y += self.velocityY;
// Calculate distance from player center
var dx = self.x - player.x;
var dy = self.y - player.y;
var distanceFromPlayer = Math.sqrt(dx * dx + dy * dy);
// Check if punch is at range circle boundary
if (distanceFromPlayer >= player.range) {
// Position punch exactly on the circle boundary
var angle = Math.atan2(dy, dx);
self.x = player.x + Math.cos(angle) * player.range;
self.y = player.y + Math.sin(angle) * player.range;
// Start rotating around the circle if not already doing so
if (!self.isRotating) {
self.isRotating = true;
self.rotationAngle = angle;
self.rotationSpeed = 0.05; // Speed of rotation around circle
}
// Use tween for smooth circular rotation only when player is not moving
if (self.isRotating && !playerIsMoving) {
// Stop any existing rotation tween
tween.stop(self, {
rotationAngle: true
});
// Start continuous circular rotation
var targetAngle = self.rotationAngle + Math.PI * 2; // Full circle
tween(self, {
rotationAngle: targetAngle
}, {
duration: 4000,
// 4 seconds for full rotation
easing: tween.linear,
onFinish: function onFinish() {
// Reset angle to prevent overflow and continue rotation
self.rotationAngle = self.rotationAngle - Math.PI * 2;
if (self.isRotating && !playerIsMoving) {
// Continue rotating if still conditions are met
var nextTarget = self.rotationAngle + Math.PI * 2;
tween(self, {
rotationAngle: nextTarget
}, {
duration: 4000,
easing: tween.linear
});
}
}
});
self.x = player.x + Math.cos(self.rotationAngle) * player.range;
self.y = player.y + Math.sin(self.rotationAngle) * player.range;
} else if (self.isRotating && playerIsMoving) {
// Stop rotation tween when player moves
tween.stop(self, {
rotationAngle: true
});
// Update position to follow player but maintain angle
self.x = player.x + Math.cos(self.rotationAngle) * player.range;
self.y = player.y + Math.sin(self.rotationAngle) * player.range;
}
}
// Remove if off screen
if (self.x < -50 || self.x > 2098 || self.y < -50 || self.y > 2782) {
var index = bullets.indexOf(self);
if (index !== -1) {
bullets.splice(index, 1);
}
self.destroy();
}
};
return self;
});
// Game arrays
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.speed = 5;
self.damage = 25;
self.armor = 0;
self.coins = 0;
self.shootCooldown = 0;
self.range = 375;
// Create range circle
var rangeCircle = self.attachAsset('rangeCircle', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.2
});
rangeCircle.width = self.range * 2;
rangeCircle.height = self.range * 2;
// Create health text above player
var healthText = new Text2(self.health.toString(), {
size: 60,
fill: 0x00FF00
});
healthText.anchor.set(0.5, 1);
healthText.x = 0;
healthText.y = -100;
self.addChild(healthText);
self.healthText = healthText;
self.update = function () {
if (self.shootCooldown > 0) {
self.shootCooldown--;
}
};
self.takeDamage = function (damage) {
var actualDamage = Math.max(1, damage - self.armor);
self.health -= actualDamage;
if (self.healthText) {
self.healthText.setText(Math.max(0, self.health).toString());
}
if (self.health <= 0) {
self.health = 0;
LK.showGameOver();
}
};
self.shoot = function (targetX, targetY) {
if (self.shootCooldown > 0 || bulletCount <= 0 || isReloading) return;
var dx = targetX - self.x;
var dy = targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Check if target is within range
if (distance > self.range) return;
// Alternate between left and right punches
var bullet;
if (bulletsFired % 2 === 0) {
bullet = new LeftPunch();
} else {
bullet = new RightPunch();
}
bullet.x = self.x;
bullet.y = self.y;
bullet.velocityX = dx / distance * 7.5;
bullet.velocityY = dy / distance * 7.5 - 2; // Subtract initial upward velocity for arc
bullet.damage = self.damage;
// Track bullets fired and assign instant kill property
bulletsFired++;
if (bulletsFired % 10 === 1) {
// Every 10 bullets, randomly select 3 positions for instant kills
instantKillBullets = [];
var positions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (var k = 0; k < 3; k++) {
var randomIndex = Math.floor(Math.random() * positions.length);
instantKillBullets.push(positions[randomIndex]);
positions.splice(randomIndex, 1);
}
}
// Check if this bullet should be instant kill
var currentBulletPosition = (bulletsFired - 1) % 10 + 1;
bullet.isInstantKill = instantKillBullets.indexOf(currentBulletPosition) !== -1;
bullets.push(bullet);
game.addChild(bullet);
LK.getSound('shoot').play();
self.shootCooldown = 10;
bulletCount--;
// Start reloading if out of bullets
if (bulletCount <= 0) {
isReloading = true;
reloadTimer = 180; // 3 seconds at 60fps
}
};
return self;
});
var RightPunch = Container.expand(function () {
var self = Container.call(this);
// Create right punch
var punchGraphics = self.attachAsset('rightPunch', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.damage = 25;
self.isInstantKill = false;
self.target = null; // Target zombie in red area
self.isRotating = false; // Track if punch is rotating around circle
self.rotationAngle = 0; // Current rotation angle
self.rotationSpeed = 0; // Speed of rotation
self.update = function () {
// Find nearest zombie in red area if we don't have a target
if (!self.target) {
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 distanceFromPlayer = Math.sqrt(dx * dx + dy * dy);
if (distanceFromPlayer <= player.range && distanceFromPlayer < minDistance) {
minDistance = distanceFromPlayer;
nearestZombie = zombie;
}
}
self.target = nearestZombie;
}
// Apply gravity to create parabolic arc
self.velocityY += 0.3; // Gravity effect
// If we have a target zombie, adjust trajectory towards it
if (self.target && zombies.indexOf(self.target) !== -1) {
var targetDx = self.target.x - self.x;
var targetDy = self.target.y - self.y;
var targetDistance = Math.sqrt(targetDx * targetDx + targetDy * targetDy);
// Add slight homing effect (adjust velocity slightly towards target)
if (targetDistance > 20) {
var homingStrength = 0.1;
self.velocityX += targetDx / targetDistance * homingStrength;
self.velocityY += targetDy / targetDistance * homingStrength;
}
} else {
// Clear target if zombie no longer exists
self.target = null;
}
// Move punch with parabolic trajectory
self.x += self.velocityX;
self.y += self.velocityY;
// Calculate distance from player center
var dx = self.x - player.x;
var dy = self.y - player.y;
var distanceFromPlayer = Math.sqrt(dx * dx + dy * dy);
// Check if punch is at range circle boundary
if (distanceFromPlayer >= player.range) {
// Position punch exactly on the circle boundary
var angle = Math.atan2(dy, dx);
self.x = player.x + Math.cos(angle) * player.range;
self.y = player.y + Math.sin(angle) * player.range;
// Start rotating around the circle if not already doing so
if (!self.isRotating) {
self.isRotating = true;
self.rotationAngle = angle;
self.rotationSpeed = -0.05; // Negative speed to rotate in opposite direction from left punch
}
// Use tween for smooth circular rotation only when player is not moving
if (self.isRotating && !playerIsMoving) {
// Stop any existing rotation tween
tween.stop(self, {
rotationAngle: true
});
// Start continuous circular rotation (opposite direction from left punch)
var targetAngle = self.rotationAngle - Math.PI * 2; // Full circle in opposite direction
tween(self, {
rotationAngle: targetAngle
}, {
duration: 4000,
// 4 seconds for full rotation
easing: tween.linear,
onFinish: function onFinish() {
// Reset angle to prevent overflow and continue rotation
self.rotationAngle = self.rotationAngle + Math.PI * 2;
if (self.isRotating && !playerIsMoving) {
// Continue rotating if still conditions are met
var nextTarget = self.rotationAngle - Math.PI * 2;
tween(self, {
rotationAngle: nextTarget
}, {
duration: 4000,
easing: tween.linear
});
}
}
});
self.x = player.x + Math.cos(self.rotationAngle) * player.range;
self.y = player.y + Math.sin(self.rotationAngle) * player.range;
} else if (self.isRotating && playerIsMoving) {
// Stop rotation tween when player moves
tween.stop(self, {
rotationAngle: true
});
// Update position to follow player but maintain angle
self.x = player.x + Math.cos(self.rotationAngle) * player.range;
self.y = player.y + Math.sin(self.rotationAngle) * player.range;
}
}
// Remove if off screen
if (self.x < -50 || self.x > 2098 || self.y < -50 || self.y > 2782) {
var index = bullets.indexOf(self);
if (index !== -1) {
bullets.splice(index, 1);
}
self.destroy();
}
};
return self;
});
var Zombie = Container.expand(function () {
var self = Container.call(this);
var zombieGraphics = self.attachAsset('zombie', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 100;
self.maxHealth = 100;
self.speed = 2;
self.damage = 20;
self.coinValue = 10;
self.lastPlayerDistance = Infinity;
self.isPatrolling = false;
self.patrolTimer = 0;
self.patrolDuration = 0;
self.targetX = 0;
self.targetY = 0;
self.waypoints = [];
self.currentWaypointIndex = 0;
self.pathUpdateTimer = 0;
self.lastPlayerX = 0;
self.lastPlayerY = 0;
// Create health text above zombie
var healthText = new Text2(self.health.toString(), {
size: 40,
fill: 0xFF0000
});
healthText.anchor.set(0.5, 1);
healthText.x = 0;
healthText.y = -80;
self.addChild(healthText);
self.healthText = healthText;
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Check if zombie is inside red area (player range)
var insideRedArea = distance <= player.range;
// If zombie enters red area while patrolling, stop patrolling and attack
if (self.isPatrolling && insideRedArea) {
self.isPatrolling = false;
}
if (insideRedArea) {
// Inside red area - use AI pathfinding behavior
self.pathUpdateTimer++;
// Update path every 30 frames (0.5 seconds) or if player moved significantly
var playerMoved = Math.abs(player.x - self.lastPlayerX) > 50 || Math.abs(player.y - self.lastPlayerY) > 50;
if (self.pathUpdateTimer >= 30 || playerMoved || self.waypoints.length === 0) {
self.pathUpdateTimer = 0;
self.lastPlayerX = player.x;
self.lastPlayerY = player.y;
// Generate waypoints for AI movement
self.waypoints = [];
self.currentWaypointIndex = 0;
// Create 2-4 waypoints between zombie and player
var waypointCount = Math.floor(Math.random() * 3) + 2; // 2-4 waypoints
var stepX = (player.x - self.x) / (waypointCount + 1);
var stepY = (player.y - self.y) / (waypointCount + 1);
for (var w = 1; w <= waypointCount; w++) {
var baseX = self.x + stepX * w;
var baseY = self.y + stepY * w;
// Add random offset to create non-linear path
var offsetRange = 150;
var offsetX = (Math.random() - 0.5) * offsetRange;
var offsetY = (Math.random() - 0.5) * offsetRange;
var waypointX = Math.max(50, Math.min(1998, baseX + offsetX));
var waypointY = Math.max(50, Math.min(2682, baseY + offsetY));
self.waypoints.push({
x: waypointX,
y: waypointY
});
}
// Add final waypoint near player
self.waypoints.push({
x: player.x,
y: player.y
});
}
// Move towards current waypoint
if (self.waypoints.length > 0 && self.currentWaypointIndex < self.waypoints.length) {
var currentWaypoint = self.waypoints[self.currentWaypointIndex];
var waypointDx = currentWaypoint.x - self.x;
var waypointDy = currentWaypoint.y - self.y;
var waypointDistance = Math.sqrt(waypointDx * waypointDx + waypointDy * waypointDy);
if (waypointDistance > 20) {
// Move towards waypoint with slight speed variation for more natural movement
var speedVariation = 0.8 + Math.random() * 0.4; // 0.8 to 1.2 speed multiplier
self.x += waypointDx / waypointDistance * self.speed * speedVariation;
self.y += waypointDy / waypointDistance * self.speed * speedVariation;
} else {
// Reached waypoint, move to next one
self.currentWaypointIndex++;
}
} else {
// Fallback to direct movement if no waypoints
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
}
} else if (self.isPatrolling) {
// Outside red area - use patrol behavior
// Move towards target patrol position
var targetDx = self.targetX - self.x;
var targetDy = self.targetY - self.y;
var targetDistance = Math.sqrt(targetDx * targetDx + targetDy * targetDy);
if (targetDistance > 5) {
self.x += targetDx / targetDistance * self.speed;
self.y += targetDy / targetDistance * self.speed;
}
// Update patrol duration
self.patrolDuration--;
if (self.patrolDuration <= 0) {
self.isPatrolling = false;
} else {
// Update patrol timer for position changes
self.patrolTimer--;
if (self.patrolTimer <= 0) {
// Choose new patrol position around red area border
var angle = Math.random() * Math.PI * 2;
var radius = player.range + 20; // Just outside red area
self.targetX = player.x + Math.cos(angle) * radius;
self.targetY = player.y + Math.sin(angle) * radius;
// Keep patrol position within screen bounds
self.targetX = Math.max(50, Math.min(1998, self.targetX));
self.targetY = Math.max(50, Math.min(2682, self.targetY));
// Set new patrol timer (1-5 seconds)
self.patrolTimer = Math.floor(Math.random() * 240) + 60; // 60-300 frames (1-5 seconds)
}
}
} else {
// Outside red area and not patrolling - direct movement towards player
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
}
// Check collision with player
if (self.lastPlayerDistance > 30 && distance <= 30 && !self.isPatrolling) {
player.takeDamage(self.damage);
LK.getSound('hit').play();
// Add visual feedback with tween
tween(self, {
alpha: 0.5
}, {
duration: 200
});
tween(self, {
alpha: 1
}, {
duration: 200,
onFinish: function onFinish() {}
});
// Start patrolling after damaging player
self.isPatrolling = true;
self.patrolDuration = 180; // 3 seconds at 60 FPS
var angle = Math.random() * Math.PI * 2;
var radius = player.range + 20; // Just outside red area
self.targetX = player.x + Math.cos(angle) * radius;
self.targetY = player.y + Math.sin(angle) * radius;
// Keep patrol position within screen bounds
self.targetX = Math.max(50, Math.min(1998, self.targetX));
self.targetY = Math.max(50, Math.min(2682, self.targetY));
// Set patrol timer (1-5 seconds)
self.patrolTimer = Math.floor(Math.random() * 240) + 60; // 60-300 frames (1-5 seconds)
}
self.lastPlayerDistance = distance;
};
self.takeDamage = function (damage) {
self.health -= damage;
if (self.healthText) {
self.healthText.setText(Math.max(0, self.health).toString());
}
if (self.health <= 0) {
self.die();
}
};
self.die = function () {
// If player health is not 100, 75% chance to drop health, otherwise drop coin
// If player health is 100, 3% chance to drop health, otherwise drop coin
var healthDropChance = player.health < 100 ? 0.75 : 0.03;
if (Math.random() < healthDropChance) {
var healthDrop = new HealthDrop();
healthDrop.x = self.x;
healthDrop.y = self.y;
healthDrops.push(healthDrop);
game.addChild(healthDrop);
} else {
var coin = new Coin();
coin.x = self.x;
coin.y = self.y;
coin.value = self.coinValue;
coins.push(coin);
game.addChild(coin);
}
var index = zombies.indexOf(self);
if (index !== -1) {
zombies.splice(index, 1);
}
self.destroy();
};
return self;
});
var Zombie2 = Container.expand(function () {
var self = Container.call(this);
var zombieGraphics = self.attachAsset('zombie2', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 150; // More health than regular zombie
self.maxHealth = 150;
self.speed = 3; // Faster than regular zombie
self.damage = 30; // More damage than regular zombie
self.coinValue = 15; // More coins when killed
self.lastPlayerDistance = Infinity;
self.isPatrolling = false;
self.patrolTimer = 0;
self.patrolDuration = 0;
self.targetX = 0;
self.targetY = 0;
self.waypoints = [];
self.currentWaypointIndex = 0;
self.pathUpdateTimer = 0;
self.lastPlayerX = 0;
self.lastPlayerY = 0;
// Create health text above zombie (orange to match stronger zombie)
var healthText = new Text2(self.health.toString(), {
size: 40,
fill: 0xFF8800
});
healthText.anchor.set(0.5, 1);
healthText.x = 0;
healthText.y = -80;
self.addChild(healthText);
self.healthText = healthText;
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Check if zombie is inside red area (player range)
var insideRedArea = distance <= player.range;
// If zombie enters red area while patrolling, stop patrolling and attack
if (self.isPatrolling && insideRedArea) {
self.isPatrolling = false;
}
if (insideRedArea) {
// Inside red area - use AI pathfinding behavior
self.pathUpdateTimer++;
// Update path every 30 frames (0.5 seconds) or if player moved significantly
var playerMoved = Math.abs(player.x - self.lastPlayerX) > 50 || Math.abs(player.y - self.lastPlayerY) > 50;
if (self.pathUpdateTimer >= 30 || playerMoved || self.waypoints.length === 0) {
self.pathUpdateTimer = 0;
self.lastPlayerX = player.x;
self.lastPlayerY = player.y;
// Generate waypoints for AI movement
self.waypoints = [];
self.currentWaypointIndex = 0;
// Create 2-4 waypoints between zombie and player
var waypointCount = Math.floor(Math.random() * 3) + 2; // 2-4 waypoints
var stepX = (player.x - self.x) / (waypointCount + 1);
var stepY = (player.y - self.y) / (waypointCount + 1);
for (var w = 1; w <= waypointCount; w++) {
var baseX = self.x + stepX * w;
var baseY = self.y + stepY * w;
// Add random offset to create non-linear path
var offsetRange = 150;
var offsetX = (Math.random() - 0.5) * offsetRange;
var offsetY = (Math.random() - 0.5) * offsetRange;
var waypointX = Math.max(50, Math.min(1998, baseX + offsetX));
var waypointY = Math.max(50, Math.min(2682, baseY + offsetY));
self.waypoints.push({
x: waypointX,
y: waypointY
});
}
// Add final waypoint near player
self.waypoints.push({
x: player.x,
y: player.y
});
}
// Move towards current waypoint
if (self.waypoints.length > 0 && self.currentWaypointIndex < self.waypoints.length) {
var currentWaypoint = self.waypoints[self.currentWaypointIndex];
var waypointDx = currentWaypoint.x - self.x;
var waypointDy = currentWaypoint.y - self.y;
var waypointDistance = Math.sqrt(waypointDx * waypointDx + waypointDy * waypointDy);
if (waypointDistance > 20) {
// Move towards waypoint with slight speed variation for more natural movement
var speedVariation = 0.8 + Math.random() * 0.4; // 0.8 to 1.2 speed multiplier
self.x += waypointDx / waypointDistance * self.speed * speedVariation;
self.y += waypointDy / waypointDistance * self.speed * speedVariation;
} else {
// Reached waypoint, move to next one
self.currentWaypointIndex++;
}
} else {
// Fallback to direct movement if no waypoints
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
}
} else if (self.isPatrolling) {
// Outside red area - use patrol behavior
// Move towards target patrol position
var targetDx = self.targetX - self.x;
var targetDy = self.targetY - self.y;
var targetDistance = Math.sqrt(targetDx * targetDx + targetDy * targetDy);
if (targetDistance > 5) {
self.x += targetDx / targetDistance * self.speed;
self.y += targetDy / targetDistance * self.speed;
}
// Update patrol duration
self.patrolDuration--;
if (self.patrolDuration <= 0) {
self.isPatrolling = false;
} else {
// Update patrol timer for position changes
self.patrolTimer--;
if (self.patrolTimer <= 0) {
// Choose new patrol position around red area border
var angle = Math.random() * Math.PI * 2;
var radius = player.range + 20; // Just outside red area
self.targetX = player.x + Math.cos(angle) * radius;
self.targetY = player.y + Math.sin(angle) * radius;
// Keep patrol position within screen bounds
self.targetX = Math.max(50, Math.min(1998, self.targetX));
self.targetY = Math.max(50, Math.min(2682, self.targetY));
// Set new patrol timer (1-5 seconds)
self.patrolTimer = Math.floor(Math.random() * 240) + 60; // 60-300 frames (1-5 seconds)
}
}
} else {
// Outside red area and not patrolling - direct movement towards player
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
}
// Check collision with player
if (self.lastPlayerDistance > 30 && distance <= 30 && !self.isPatrolling) {
player.takeDamage(self.damage);
LK.getSound('hit').play();
// Add visual feedback with tween
tween(self, {
alpha: 0.5
}, {
duration: 200
});
tween(self, {
alpha: 1
}, {
duration: 200,
onFinish: function onFinish() {}
});
// Start patrolling after damaging player
self.isPatrolling = true;
self.patrolDuration = 180; // 3 seconds at 60 FPS
var angle = Math.random() * Math.PI * 2;
var radius = player.range + 20; // Just outside red area
self.targetX = player.x + Math.cos(angle) * radius;
self.targetY = player.y + Math.sin(angle) * radius;
// Keep patrol position within screen bounds
self.targetX = Math.max(50, Math.min(1998, self.targetX));
self.targetY = Math.max(50, Math.min(2682, self.targetY));
// Set patrol timer (1-5 seconds)
self.patrolTimer = Math.floor(Math.random() * 240) + 60; // 60-300 frames (1-5 seconds)
}
self.lastPlayerDistance = distance;
};
self.takeDamage = function (damage) {
self.health -= damage;
if (self.healthText) {
self.healthText.setText(Math.max(0, self.health).toString());
}
if (self.health <= 0) {
self.die();
}
};
self.die = function () {
// If player health is not 100, 75% chance to drop health, otherwise drop coin
// If player health is 100, 3% chance to drop health, otherwise drop coin
var healthDropChance = player.health < 100 ? 0.75 : 0.03;
if (Math.random() < healthDropChance) {
var healthDrop = new HealthDrop();
healthDrop.x = self.x;
healthDrop.y = self.y;
healthDrops.push(healthDrop);
game.addChild(healthDrop);
} else {
var coin = new Coin();
coin.x = self.x;
coin.y = self.y;
coin.value = self.coinValue;
coins.push(coin);
game.addChild(coin);
}
var index = zombies.indexOf(self);
if (index !== -1) {
zombies.splice(index, 1);
}
self.destroy();
};
return self;
});
var Zombie3 = Container.expand(function () {
var self = Container.call(this);
var zombieGraphics = self.attachAsset('zombie3', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 200; // Even more health than zombie2
self.maxHealth = 200;
self.speed = 4; // Fastest zombie
self.damage = 40; // Highest damage
self.coinValue = 25; // Most coins when killed
self.lastPlayerDistance = Infinity;
self.isPatrolling = false;
self.patrolTimer = 0;
self.patrolDuration = 0;
self.targetX = 0;
self.targetY = 0;
self.waypoints = [];
self.currentWaypointIndex = 0;
self.pathUpdateTimer = 0;
self.lastPlayerX = 0;
self.lastPlayerY = 0;
// Create health text above zombie (purple to match strongest zombie)
var healthText = new Text2(self.health.toString(), {
size: 40,
fill: 0xFF00FF
});
healthText.anchor.set(0.5, 1);
healthText.x = 0;
healthText.y = -80;
self.addChild(healthText);
self.healthText = healthText;
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Check if zombie is inside red area (player range)
var insideRedArea = distance <= player.range;
// If zombie enters red area while patrolling, stop patrolling and attack
if (self.isPatrolling && insideRedArea) {
self.isPatrolling = false;
}
if (insideRedArea) {
// Inside red area - use AI pathfinding behavior
self.pathUpdateTimer++;
// Update path every 30 frames (0.5 seconds) or if player moved significantly
var playerMoved = Math.abs(player.x - self.lastPlayerX) > 50 || Math.abs(player.y - self.lastPlayerY) > 50;
if (self.pathUpdateTimer >= 30 || playerMoved || self.waypoints.length === 0) {
self.pathUpdateTimer = 0;
self.lastPlayerX = player.x;
self.lastPlayerY = player.y;
// Generate waypoints for AI movement
self.waypoints = [];
self.currentWaypointIndex = 0;
// Create 2-4 waypoints between zombie and player
var waypointCount = Math.floor(Math.random() * 3) + 2; // 2-4 waypoints
var stepX = (player.x - self.x) / (waypointCount + 1);
var stepY = (player.y - self.y) / (waypointCount + 1);
for (var w = 1; w <= waypointCount; w++) {
var baseX = self.x + stepX * w;
var baseY = self.y + stepY * w;
// Add random offset to create non-linear path
var offsetRange = 150;
var offsetX = (Math.random() - 0.5) * offsetRange;
var offsetY = (Math.random() - 0.5) * offsetRange;
var waypointX = Math.max(50, Math.min(1998, baseX + offsetX));
var waypointY = Math.max(50, Math.min(2682, baseY + offsetY));
self.waypoints.push({
x: waypointX,
y: waypointY
});
}
// Add final waypoint near player
self.waypoints.push({
x: player.x,
y: player.y
});
}
// Move towards current waypoint
if (self.waypoints.length > 0 && self.currentWaypointIndex < self.waypoints.length) {
var currentWaypoint = self.waypoints[self.currentWaypointIndex];
var waypointDx = currentWaypoint.x - self.x;
var waypointDy = currentWaypoint.y - self.y;
var waypointDistance = Math.sqrt(waypointDx * waypointDx + waypointDy * waypointDy);
if (waypointDistance > 20) {
// Move towards waypoint with slight speed variation for more natural movement
var speedVariation = 0.8 + Math.random() * 0.4; // 0.8 to 1.2 speed multiplier
self.x += waypointDx / waypointDistance * self.speed * speedVariation;
self.y += waypointDy / waypointDistance * self.speed * speedVariation;
} else {
// Reached waypoint, move to next one
self.currentWaypointIndex++;
}
} else {
// Fallback to direct movement if no waypoints
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
}
} else if (self.isPatrolling) {
// Outside red area - use patrol behavior
// Move towards target patrol position
var targetDx = self.targetX - self.x;
var targetDy = self.targetY - self.y;
var targetDistance = Math.sqrt(targetDx * targetDx + targetDy * targetDy);
if (targetDistance > 5) {
self.x += targetDx / targetDistance * self.speed;
self.y += targetDy / targetDistance * self.speed;
}
// Update patrol duration
self.patrolDuration--;
if (self.patrolDuration <= 0) {
self.isPatrolling = false;
} else {
// Update patrol timer for position changes
self.patrolTimer--;
if (self.patrolTimer <= 0) {
// Choose new patrol position around red area border
var angle = Math.random() * Math.PI * 2;
var radius = player.range + 20; // Just outside red area
self.targetX = player.x + Math.cos(angle) * radius;
self.targetY = player.y + Math.sin(angle) * radius;
// Keep patrol position within screen bounds
self.targetX = Math.max(50, Math.min(1998, self.targetX));
self.targetY = Math.max(50, Math.min(2682, self.targetY));
// Set new patrol timer (1-5 seconds)
self.patrolTimer = Math.floor(Math.random() * 240) + 60; // 60-300 frames (1-5 seconds)
}
}
} else {
// Outside red area and not patrolling - direct movement towards player
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
}
// Check collision with player
if (self.lastPlayerDistance > 30 && distance <= 30 && !self.isPatrolling) {
player.takeDamage(self.damage);
LK.getSound('hit').play();
// Add visual feedback with tween
tween(self, {
alpha: 0.5
}, {
duration: 200
});
tween(self, {
alpha: 1
}, {
duration: 200,
onFinish: function onFinish() {}
});
// Start patrolling after damaging player
self.isPatrolling = true;
self.patrolDuration = 180; // 3 seconds at 60 FPS
var angle = Math.random() * Math.PI * 2;
var radius = player.range + 20; // Just outside red area
self.targetX = player.x + Math.cos(angle) * radius;
self.targetY = player.y + Math.sin(angle) * radius;
// Keep patrol position within screen bounds
self.targetX = Math.max(50, Math.min(1998, self.targetX));
self.targetY = Math.max(50, Math.min(2682, self.targetY));
// Set patrol timer (1-5 seconds)
self.patrolTimer = Math.floor(Math.random() * 240) + 60; // 60-300 frames (1-5 seconds)
}
self.lastPlayerDistance = distance;
};
self.takeDamage = function (damage) {
self.health -= damage;
if (self.healthText) {
self.healthText.setText(Math.max(0, self.health).toString());
}
if (self.health <= 0) {
self.die();
}
};
self.die = function () {
// If player health is not 100, 75% chance to drop health, otherwise drop coin
// If player health is 100, 3% chance to drop health, otherwise drop coin
var healthDropChance = player.health < 100 ? 0.75 : 0.03;
if (Math.random() < healthDropChance) {
var healthDrop = new HealthDrop();
healthDrop.x = self.x;
healthDrop.y = self.y;
healthDrops.push(healthDrop);
game.addChild(healthDrop);
} else {
var coin = new Coin();
coin.x = self.x;
coin.y = self.y;
coin.value = self.coinValue;
coins.push(coin);
game.addChild(coin);
}
var index = zombies.indexOf(self);
if (index !== -1) {
zombies.splice(index, 1);
}
self.destroy();
};
return self;
});
var Zombie4 = Container.expand(function () {
var self = Container.call(this);
var zombieGraphics = self.attachAsset('zombie4', {
anchorX: 0.5,
anchorY: 0.5
});
self.health = 250; // Highest health
self.maxHealth = 250;
self.speed = 5; // Very fast
self.damage = 50; // Highest damage
self.coinValue = 35; // Most coins when killed
self.lastPlayerDistance = Infinity;
self.isPatrolling = false;
self.patrolTimer = 0;
self.patrolDuration = 0;
self.targetX = 0;
self.targetY = 0;
self.waypoints = [];
self.currentWaypointIndex = 0;
self.pathUpdateTimer = 0;
self.lastPlayerX = 0;
self.lastPlayerY = 0;
// Create health text above zombie (cyan to match elite zombie)
var healthText = new Text2(self.health.toString(), {
size: 40,
fill: 0x00FFFF
});
healthText.anchor.set(0.5, 1);
healthText.x = 0;
healthText.y = -80;
self.addChild(healthText);
self.healthText = healthText;
self.update = function () {
var dx = player.x - self.x;
var dy = player.y - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Check if zombie is inside red area (player range)
var insideRedArea = distance <= player.range;
// If zombie enters red area while patrolling, stop patrolling and attack
if (self.isPatrolling && insideRedArea) {
self.isPatrolling = false;
}
if (insideRedArea) {
// Inside red area - use AI pathfinding behavior
self.pathUpdateTimer++;
// Update path every 30 frames (0.5 seconds) or if player moved significantly
var playerMoved = Math.abs(player.x - self.lastPlayerX) > 50 || Math.abs(player.y - self.lastPlayerY) > 50;
if (self.pathUpdateTimer >= 30 || playerMoved || self.waypoints.length === 0) {
self.pathUpdateTimer = 0;
self.lastPlayerX = player.x;
self.lastPlayerY = player.y;
// Generate waypoints for AI movement
self.waypoints = [];
self.currentWaypointIndex = 0;
// Create 2-4 waypoints between zombie and player
var waypointCount = Math.floor(Math.random() * 3) + 2; // 2-4 waypoints
var stepX = (player.x - self.x) / (waypointCount + 1);
var stepY = (player.y - self.y) / (waypointCount + 1);
for (var w = 1; w <= waypointCount; w++) {
var baseX = self.x + stepX * w;
var baseY = self.y + stepY * w;
// Add random offset to create non-linear path
var offsetRange = 150;
var offsetX = (Math.random() - 0.5) * offsetRange;
var offsetY = (Math.random() - 0.5) * offsetRange;
var waypointX = Math.max(50, Math.min(1998, baseX + offsetX));
var waypointY = Math.max(50, Math.min(2682, baseY + offsetY));
self.waypoints.push({
x: waypointX,
y: waypointY
});
}
// Add final waypoint near player
self.waypoints.push({
x: player.x,
y: player.y
});
}
// Move towards current waypoint
if (self.waypoints.length > 0 && self.currentWaypointIndex < self.waypoints.length) {
var currentWaypoint = self.waypoints[self.currentWaypointIndex];
var waypointDx = currentWaypoint.x - self.x;
var waypointDy = currentWaypoint.y - self.y;
var waypointDistance = Math.sqrt(waypointDx * waypointDx + waypointDy * waypointDy);
if (waypointDistance > 20) {
// Move towards waypoint with slight speed variation for more natural movement
var speedVariation = 0.8 + Math.random() * 0.4; // 0.8 to 1.2 speed multiplier
self.x += waypointDx / waypointDistance * self.speed * speedVariation;
self.y += waypointDy / waypointDistance * self.speed * speedVariation;
} else {
// Reached waypoint, move to next one
self.currentWaypointIndex++;
}
} else {
// Fallback to direct movement if no waypoints
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
}
} else if (self.isPatrolling) {
// Outside red area - use patrol behavior
// Move towards target patrol position
var targetDx = self.targetX - self.x;
var targetDy = self.targetY - self.y;
var targetDistance = Math.sqrt(targetDx * targetDx + targetDy * targetDy);
if (targetDistance > 5) {
self.x += targetDx / targetDistance * self.speed;
self.y += targetDy / targetDistance * self.speed;
}
// Update patrol duration
self.patrolDuration--;
if (self.patrolDuration <= 0) {
self.isPatrolling = false;
} else {
// Update patrol timer for position changes
self.patrolTimer--;
if (self.patrolTimer <= 0) {
// Choose new patrol position around red area border
var angle = Math.random() * Math.PI * 2;
var radius = player.range + 20; // Just outside red area
self.targetX = player.x + Math.cos(angle) * radius;
self.targetY = player.y + Math.sin(angle) * radius;
// Keep patrol position within screen bounds
self.targetX = Math.max(50, Math.min(1998, self.targetX));
self.targetY = Math.max(50, Math.min(2682, self.targetY));
// Set new patrol timer (1-5 seconds)
self.patrolTimer = Math.floor(Math.random() * 240) + 60; // 60-300 frames (1-5 seconds)
}
}
} else {
// Outside red area and not patrolling - direct movement towards player
if (distance > 5) {
self.x += dx / distance * self.speed;
self.y += dy / distance * self.speed;
}
}
// Check collision with player
if (self.lastPlayerDistance > 30 && distance <= 30 && !self.isPatrolling) {
player.takeDamage(self.damage);
LK.getSound('hit').play();
// Add visual feedback with tween
tween(self, {
alpha: 0.5
}, {
duration: 200
});
tween(self, {
alpha: 1
}, {
duration: 200,
onFinish: function onFinish() {}
});
// Start patrolling after damaging player
self.isPatrolling = true;
self.patrolDuration = 180; // 3 seconds at 60 FPS
var angle = Math.random() * Math.PI * 2;
var radius = player.range + 20; // Just outside red area
self.targetX = player.x + Math.cos(angle) * radius;
self.targetY = player.y + Math.sin(angle) * radius;
// Keep patrol position within screen bounds
self.targetX = Math.max(50, Math.min(1998, self.targetX));
self.targetY = Math.max(50, Math.min(2682, self.targetY));
// Set patrol timer (1-5 seconds)
self.patrolTimer = Math.floor(Math.random() * 240) + 60; // 60-300 frames (1-5 seconds)
}
self.lastPlayerDistance = distance;
};
self.takeDamage = function (damage) {
self.health -= damage;
if (self.healthText) {
self.healthText.setText(Math.max(0, self.health).toString());
}
if (self.health <= 0) {
self.die();
}
};
self.die = function () {
// If player health is not 100, 75% chance to drop health, otherwise drop coin
// If player health is 100, 3% chance to drop health, otherwise drop coin
var healthDropChance = player.health < 100 ? 0.75 : 0.03;
if (Math.random() < healthDropChance) {
var healthDrop = new HealthDrop();
healthDrop.x = self.x;
healthDrop.y = self.y;
healthDrops.push(healthDrop);
game.addChild(healthDrop);
} else {
var coin = new Coin();
coin.x = self.x;
coin.y = self.y;
coin.value = self.coinValue;
coins.push(coin);
game.addChild(coin);
}
var index = zombies.indexOf(self);
if (index !== -1) {
zombies.splice(index, 1);
}
self.destroy();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2a2a2a
});
/****
* Game Code
****/
// Game state
var gameStarted = false;
var bulletCount = 10;
var maxBullets = 10;
var isReloading = false;
var reloadTimer = 0;
var fireButtonActive = false;
var bulletsFired = 0;
var instantKillBullets = [];
// Player movement tracking
var playerLastX = 0;
var playerLastY = 0;
var playerIsMoving = false;
// Start menu elements
var titleText = new Text2('ZOMBIE SURVIVAL', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(titleText);
titleText.y = -200;
var playButton = new Text2('TAP TO START', {
size: 60,
fill: 0x00FF00
});
playButton.anchor.set(0.5, 0.5);
LK.gui.center.addChild(playButton);
playButton.y = 100;
// Game arrays
var zombies = [];
var bullets = [];
var coins = [];
var healthDrops = [];
// Game variables
var waveNumber = 1;
var zombiesPerWave = 5;
var spawnTimer = 0;
var zombiesSpawned = 0;
// Player variable (will be created when game starts)
var player = null;
// UI Elements (will be created when game starts)
var healthText = null;
var coinsText = null;
var waveText = null;
var bulletText = null;
function startGame() {
gameStarted = true;
// Hide start menu
titleText.visible = false;
playButton.visible = false;
// Create player
player = game.addChild(new Player());
player.x = 1024;
player.y = 1366;
// Create UI Elements
healthText = new Text2('Health: 100/100', {
size: 40,
fill: 0xFF0000
});
healthText.anchor.set(0, 0);
LK.gui.topLeft.addChild(healthText);
healthText.x = 120;
healthText.y = 20;
coinsText = new Text2('Coins: 0', {
size: 40,
fill: 0xFFD700
});
coinsText.anchor.set(0, 0);
LK.gui.topRight.addChild(coinsText);
coinsText.x = -200;
coinsText.y = 20;
waveText = new Text2('Wave: 1 (5 zombies)', {
size: 40,
fill: 0xFFFFFF
});
waveText.anchor.set(0.5, 0);
LK.gui.top.addChild(waveText);
waveText.y = 20;
bulletText = new Text2('', {
size: 40,
fill: 0x00FFFF
});
bulletText.anchor.set(0.5, 0);
player.addChild(bulletText);
bulletText.x = 0;
bulletText.y = 120;
}
// Touch controls
var touchStartX = 0;
var touchStartY = 0;
var isMoving = false;
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
return;
}
touchStartX = x;
touchStartY = y;
isMoving = true;
// Shoot at nearest zombie or forward if no zombies
if (player && bulletCount > 0 && !isReloading) {
// Find nearest zombie within range as target
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 <= player.range && distance < minDistance) {
minDistance = distance;
nearestZombie = zombie;
}
}
// Shoot at nearest zombie within range only
if (nearestZombie) {
player.shoot(nearestZombie.x, nearestZombie.y);
}
}
};
game.move = function (x, y, obj) {
if (!gameStarted || !player) return;
if (isMoving) {
var dx = x - touchStartX;
var dy = y - touchStartY;
var newX = player.x + dx * 0.5;
var newY = player.y + dy * 0.5;
// Keep player within bounds
player.x = Math.max(30, Math.min(2018, newX));
player.y = Math.max(30, Math.min(2702, newY));
touchStartX = x;
touchStartY = y;
}
};
game.up = function (x, y, obj) {
if (!gameStarted) return;
isMoving = false;
};
// Game update loop
game.update = function () {
if (!gameStarted || !player) return;
// Track player movement
if (playerLastX === 0 && playerLastY === 0) {
playerLastX = player.x;
playerLastY = player.y;
}
var playerMoved = Math.abs(player.x - playerLastX) > 2 || Math.abs(player.y - playerLastY) > 2;
playerIsMoving = playerMoved;
playerLastX = player.x;
playerLastY = player.y;
// Handle reloading
if (isReloading) {
reloadTimer--;
if (reloadTimer <= 0) {
bulletCount = maxBullets;
isReloading = false;
}
}
// Update UI
if (healthText && coinsText && waveText && bulletText) {
healthText.setText('Health: ' + player.health + '/' + player.maxHealth);
coinsText.setText('Coins: ' + player.coins);
var remainingZombies = zombiesPerWave - zombiesSpawned + zombies.length;
waveText.setText('Wave: ' + waveNumber + ' (' + remainingZombies + ' zombies)');
if (isReloading) {
var reloadTimeLeft = Math.ceil(reloadTimer / 60);
bulletText.setText('Reloading... ' + reloadTimeLeft + 's');
} else {
bulletText.setText('Bullets: ' + bulletCount + '/' + maxBullets);
}
}
// Spawn zombies
if (zombiesSpawned < zombiesPerWave) {
spawnTimer++;
if (spawnTimer >= 60) {
// Spawn every second
spawnTimer = 0;
spawnZombie();
zombiesSpawned++;
}
} else if (zombies.length === 0) {
// Start next wave
waveNumber++;
zombiesPerWave += 2;
zombiesSpawned = 0;
}
// Check bullet-zombie collisions
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
var bulletHit = false;
for (var j = zombies.length - 1; j >= 0; j--) {
var zombie = zombies[j];
if (bullet.intersects(zombie)) {
if (bullet.isInstantKill) {
// Instant kill bullet
zombie.takeDamage(zombie.health);
} else {
// Random damage between 1 and zombie's current health (can kill in one shot)
var randomDamage = Math.floor(Math.random() * zombie.health) + 1;
zombie.takeDamage(randomDamage);
}
bullets.splice(i, 1);
bullet.destroy();
bulletHit = true;
break;
}
}
}
};
function spawnZombie() {
// Randomly spawn zombies with different probabilities
var rand = Math.random();
var zombie;
if (rand < 0.15) {
// 15% chance for zombie4 (elite)
zombie = new Zombie4();
} else if (rand < 0.35) {
// 20% chance for zombie3 (strongest)
zombie = new Zombie3();
} else if (rand < 0.65) {
// 30% chance for zombie2 (medium strength)
zombie = new Zombie2();
} else {
// 35% chance for regular zombie (weakest)
zombie = new Zombie();
}
// Spawn at random edge of screen
var side = Math.floor(Math.random() * 4);
switch (side) {
case 0:
// Top
zombie.x = Math.random() * 2048;
zombie.y = -50;
break;
case 1:
// Right
zombie.x = 2098;
zombie.y = Math.random() * 2732;
break;
case 2:
// Bottom
zombie.x = Math.random() * 2048;
zombie.y = 2782;
break;
case 3:
// Left
zombie.x = -50;
zombie.y = Math.random() * 2732;
break;
}
zombie.health += (waveNumber - 1) * 10; // Increase health with waves
zombie.maxHealth = zombie.health;
zombie.coinValue += Math.floor((waveNumber - 1) * 2);
// Update health text to show new health value
if (zombie.healthText) {
zombie.healthText.setText(zombie.health.toString());
}
zombies.push(zombie);
game.addChild(zombie);
} ===================================================================
--- original.js
+++ change.js
@@ -174,14 +174,44 @@
self.isRotating = true;
self.rotationAngle = angle;
self.rotationSpeed = 0.05; // Speed of rotation around circle
}
- // Rotate around the circle only when player is not moving
+ // Use tween for smooth circular rotation only when player is not moving
if (self.isRotating && !playerIsMoving) {
- self.rotationAngle += self.rotationSpeed;
+ // Stop any existing rotation tween
+ tween.stop(self, {
+ rotationAngle: true
+ });
+ // Start continuous circular rotation
+ var targetAngle = self.rotationAngle + Math.PI * 2; // Full circle
+ tween(self, {
+ rotationAngle: targetAngle
+ }, {
+ duration: 4000,
+ // 4 seconds for full rotation
+ easing: tween.linear,
+ onFinish: function onFinish() {
+ // Reset angle to prevent overflow and continue rotation
+ self.rotationAngle = self.rotationAngle - Math.PI * 2;
+ if (self.isRotating && !playerIsMoving) {
+ // Continue rotating if still conditions are met
+ var nextTarget = self.rotationAngle + Math.PI * 2;
+ tween(self, {
+ rotationAngle: nextTarget
+ }, {
+ duration: 4000,
+ easing: tween.linear
+ });
+ }
+ }
+ });
self.x = player.x + Math.cos(self.rotationAngle) * player.range;
self.y = player.y + Math.sin(self.rotationAngle) * player.range;
} else if (self.isRotating && playerIsMoving) {
+ // Stop rotation tween when player moves
+ tween.stop(self, {
+ rotationAngle: true
+ });
// Update position to follow player but maintain angle
self.x = player.x + Math.cos(self.rotationAngle) * player.range;
self.y = player.y + Math.sin(self.rotationAngle) * player.range;
}
@@ -360,14 +390,44 @@
self.isRotating = true;
self.rotationAngle = angle;
self.rotationSpeed = -0.05; // Negative speed to rotate in opposite direction from left punch
}
- // Rotate around the circle only when player is not moving
+ // Use tween for smooth circular rotation only when player is not moving
if (self.isRotating && !playerIsMoving) {
- self.rotationAngle += self.rotationSpeed;
+ // Stop any existing rotation tween
+ tween.stop(self, {
+ rotationAngle: true
+ });
+ // Start continuous circular rotation (opposite direction from left punch)
+ var targetAngle = self.rotationAngle - Math.PI * 2; // Full circle in opposite direction
+ tween(self, {
+ rotationAngle: targetAngle
+ }, {
+ duration: 4000,
+ // 4 seconds for full rotation
+ easing: tween.linear,
+ onFinish: function onFinish() {
+ // Reset angle to prevent overflow and continue rotation
+ self.rotationAngle = self.rotationAngle + Math.PI * 2;
+ if (self.isRotating && !playerIsMoving) {
+ // Continue rotating if still conditions are met
+ var nextTarget = self.rotationAngle - Math.PI * 2;
+ tween(self, {
+ rotationAngle: nextTarget
+ }, {
+ duration: 4000,
+ easing: tween.linear
+ });
+ }
+ }
+ });
self.x = player.x + Math.cos(self.rotationAngle) * player.range;
self.y = player.y + Math.sin(self.rotationAngle) * player.range;
} else if (self.isRotating && playerIsMoving) {
+ // Stop rotation tween when player moves
+ tween.stop(self, {
+ rotationAngle: true
+ });
// Update position to follow player but maintain angle
self.x = player.x + Math.cos(self.rotationAngle) * player.range;
self.y = player.y + Math.sin(self.rotationAngle) * player.range;
}
bitcoin sembollü sarı eski madeni para. In-Game asset. 2d. High contrast. No shadows
kırmızı kalp. In-Game asset. 2d. High contrast. No shadows
kadın zombi. In-Game asset. 2d. High contrast. No shadows
daire kırmıza alan. In-Game asset. 2d. High contrast. No shadows
boss zombie şişko. In-Game asset. 2d. High contrast. No shadows
boss zombie şişko kadın makyajlı. In-Game asset. 2d. High contrast. No shadows
tek yumruk boks eldiveni. In-Game asset. 2d. High contrast. No shadows
şakaci komik yüzlü salak gözüken ama cesur bir karakter pistol tutuyor.
boss zombi çok kaslı akıllı ve silahlı sinirli kızgın ve ten rengi kırmızı. In-Game asset. 2d. High contrast. No shadows