/****
* 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.direction = {
x: 0,
y: -1
};
self.update = function () {
self.x += self.direction.x * self.speed;
self.y += self.direction.y * self.speed;
};
return self;
});
var HealthPack = Container.expand(function () {
var self = Container.call(this);
var healthGraphics = self.attachAsset('healthPack', {
anchorX: 0.5,
anchorY: 0.5
});
self.healAmount = 25;
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.lastShotTime = 0;
self.shootCooldown = 200; // milliseconds
self.facing = {
x: 0,
y: -1
}; // initially facing up
return self;
});
var WeaponUpgrade = Container.expand(function () {
var self = Container.call(this);
var weaponGraphics = self.attachAsset('weaponUpgrade', {
anchorX: 0.5,
anchorY: 0.5
});
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;
self.health = 1;
self.update = function () {
if (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;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2d2d2d
});
/****
* Game Code
****/
var player = null;
var zombies = [];
var bullets = [];
var healthPacks = [];
var weaponUpgrades = [];
var gameTime = 0;
var zombieSpawnRate = 120; // frames between spawns
var lastZombieSpawn = 0;
var lastPickupSpawn = 0;
var pickupSpawnRate = 300; // frames between pickups
var dragNode = null;
var lastPlayerPosition = {
x: 0,
y: 0
};
// UI Elements
var healthBar = LK.getAsset('healthPack', {
anchorX: 0,
anchorY: 0,
scaleX: 5,
scaleY: 0.5
});
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
var healthTxt = new Text2('Health: 100', {
size: 50,
fill: 0xFFFFFF
});
healthTxt.anchor.set(0, 0);
LK.gui.top.addChild(scoreTxt);
LK.gui.topRight.addChild(healthTxt);
LK.gui.topRight.addChild(healthBar);
healthBar.x = -200;
healthBar.y = 60;
// Initialize player
player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
lastPlayerPosition.x = player.x;
lastPlayerPosition.y = player.y;
function spawnZombie() {
var zombie = new Zombie();
var side = Math.floor(Math.random() * 4);
// Spawn from edges
switch (side) {
case 0:
// top
zombie.x = Math.random() * 2048;
zombie.y = -30;
break;
case 1:
// right
zombie.x = 2048 + 30;
zombie.y = Math.random() * 2732;
break;
case 2:
// bottom
zombie.x = Math.random() * 2048;
zombie.y = 2732 + 30;
break;
case 3:
// left
zombie.x = -30;
zombie.y = Math.random() * 2732;
break;
}
// Increase speed over time
zombie.speed = 1 + gameTime / 3600 * 0.5;
zombies.push(zombie);
game.addChild(zombie);
}
function spawnHealthPack() {
var healthPack = new HealthPack();
healthPack.x = Math.random() * (2048 - 100) + 50;
healthPack.y = Math.random() * (2732 - 100) + 50;
healthPacks.push(healthPack);
game.addChild(healthPack);
}
function spawnWeaponUpgrade() {
var weaponUpgrade = new WeaponUpgrade();
weaponUpgrade.x = Math.random() * (2048 - 100) + 50;
weaponUpgrade.y = Math.random() * (2732 - 100) + 50;
weaponUpgrades.push(weaponUpgrade);
game.addChild(weaponUpgrade);
}
function shootBullet() {
if (Date.now() - player.lastShotTime > player.shootCooldown) {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y;
bullet.direction.x = player.facing.x;
bullet.direction.y = player.facing.y;
bullets.push(bullet);
game.addChild(bullet);
player.lastShotTime = Date.now();
LK.getSound('shoot').play();
}
}
function updatePlayerFacing() {
var dx = player.x - lastPlayerPosition.x;
var dy = player.y - lastPlayerPosition.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 2) {
player.facing.x = dx / distance;
player.facing.y = dy / distance;
}
lastPlayerPosition.x = player.x;
lastPlayerPosition.y = player.y;
}
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;
};
game.update = function () {
gameTime++;
// Update player facing direction
updatePlayerFacing();
// Auto shoot
shootBullet();
// Spawn zombies
if (gameTime - lastZombieSpawn > zombieSpawnRate) {
spawnZombie();
lastZombieSpawn = gameTime;
// Increase spawn rate over time
zombieSpawnRate = Math.max(30, 120 - Math.floor(gameTime / 600));
}
// Spawn pickups
if (gameTime - lastPickupSpawn > pickupSpawnRate) {
if (Math.random() > 0.5) {
spawnHealthPack();
} else {
spawnWeaponUpgrade();
}
lastPickupSpawn = gameTime;
}
// Update bullets
for (var i = bullets.length - 1; i >= 0; i--) {
var bullet = bullets[i];
// Remove off-screen bullets
if (bullet.x < -50 || bullet.x > 2098 || bullet.y < -50 || bullet.y > 2782) {
bullet.destroy();
bullets.splice(i, 1);
continue;
}
// Check bullet-zombie collisions
for (var j = zombies.length - 1; j >= 0; j--) {
var zombie = zombies[j];
if (bullet.intersects(zombie)) {
LK.setScore(LK.getScore() + 10);
scoreTxt.setText('Score: ' + LK.getScore());
LK.getSound('zombieHit').play();
bullet.destroy();
bullets.splice(i, 1);
zombie.destroy();
zombies.splice(j, 1);
break;
}
}
}
// Update zombies and check player collision
for (var i = zombies.length - 1; i >= 0; i--) {
var zombie = zombies[i];
if (zombie.intersects(player)) {
player.health -= 2;
LK.getSound('damage').play();
LK.effects.flashObject(player, 0xff0000, 200);
if (player.health <= 0) {
LK.showGameOver();
return;
}
healthTxt.setText('Health: ' + player.health);
healthBar.scaleX = player.health / player.maxHealth * 5;
}
}
// Check health pack collection
for (var i = healthPacks.length - 1; i >= 0; i--) {
var healthPack = healthPacks[i];
if (player.intersects(healthPack)) {
player.health = Math.min(player.maxHealth, player.health + healthPack.healAmount);
healthTxt.setText('Health: ' + player.health);
healthBar.scaleX = player.health / player.maxHealth * 5;
LK.getSound('pickup').play();
healthPack.destroy();
healthPacks.splice(i, 1);
}
}
// Check weapon upgrade collection
for (var i = weaponUpgrades.length - 1; i >= 0; i--) {
var weaponUpgrade = weaponUpgrades[i];
if (player.intersects(weaponUpgrade)) {
player.shootCooldown = Math.max(50, player.shootCooldown - 20);
LK.getSound('pickup').play();
weaponUpgrade.destroy();
weaponUpgrades.splice(i, 1);
}
}
// Increase score over time
if (gameTime % 60 === 0) {
LK.setScore(LK.getScore() + 1);
scoreTxt.setText('Score: ' + LK.getScore());
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,305 @@
-/****
+/****
+* 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.direction = {
+ x: 0,
+ y: -1
+ };
+ self.update = function () {
+ self.x += self.direction.x * self.speed;
+ self.y += self.direction.y * self.speed;
+ };
+ return self;
+});
+var HealthPack = Container.expand(function () {
+ var self = Container.call(this);
+ var healthGraphics = self.attachAsset('healthPack', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.healAmount = 25;
+ 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.lastShotTime = 0;
+ self.shootCooldown = 200; // milliseconds
+ self.facing = {
+ x: 0,
+ y: -1
+ }; // initially facing up
+ return self;
+});
+var WeaponUpgrade = Container.expand(function () {
+ var self = Container.call(this);
+ var weaponGraphics = self.attachAsset('weaponUpgrade', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ 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;
+ self.health = 1;
+ self.update = function () {
+ if (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;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2d2d2d
+});
+
+/****
+* Game Code
+****/
+var player = null;
+var zombies = [];
+var bullets = [];
+var healthPacks = [];
+var weaponUpgrades = [];
+var gameTime = 0;
+var zombieSpawnRate = 120; // frames between spawns
+var lastZombieSpawn = 0;
+var lastPickupSpawn = 0;
+var pickupSpawnRate = 300; // frames between pickups
+var dragNode = null;
+var lastPlayerPosition = {
+ x: 0,
+ y: 0
+};
+// UI Elements
+var healthBar = LK.getAsset('healthPack', {
+ anchorX: 0,
+ anchorY: 0,
+ scaleX: 5,
+ scaleY: 0.5
+});
+var scoreTxt = new Text2('Score: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+var healthTxt = new Text2('Health: 100', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+healthTxt.anchor.set(0, 0);
+LK.gui.top.addChild(scoreTxt);
+LK.gui.topRight.addChild(healthTxt);
+LK.gui.topRight.addChild(healthBar);
+healthBar.x = -200;
+healthBar.y = 60;
+// Initialize player
+player = game.addChild(new Player());
+player.x = 2048 / 2;
+player.y = 2732 / 2;
+lastPlayerPosition.x = player.x;
+lastPlayerPosition.y = player.y;
+function spawnZombie() {
+ var zombie = new Zombie();
+ var side = Math.floor(Math.random() * 4);
+ // Spawn from edges
+ switch (side) {
+ case 0:
+ // top
+ zombie.x = Math.random() * 2048;
+ zombie.y = -30;
+ break;
+ case 1:
+ // right
+ zombie.x = 2048 + 30;
+ zombie.y = Math.random() * 2732;
+ break;
+ case 2:
+ // bottom
+ zombie.x = Math.random() * 2048;
+ zombie.y = 2732 + 30;
+ break;
+ case 3:
+ // left
+ zombie.x = -30;
+ zombie.y = Math.random() * 2732;
+ break;
+ }
+ // Increase speed over time
+ zombie.speed = 1 + gameTime / 3600 * 0.5;
+ zombies.push(zombie);
+ game.addChild(zombie);
+}
+function spawnHealthPack() {
+ var healthPack = new HealthPack();
+ healthPack.x = Math.random() * (2048 - 100) + 50;
+ healthPack.y = Math.random() * (2732 - 100) + 50;
+ healthPacks.push(healthPack);
+ game.addChild(healthPack);
+}
+function spawnWeaponUpgrade() {
+ var weaponUpgrade = new WeaponUpgrade();
+ weaponUpgrade.x = Math.random() * (2048 - 100) + 50;
+ weaponUpgrade.y = Math.random() * (2732 - 100) + 50;
+ weaponUpgrades.push(weaponUpgrade);
+ game.addChild(weaponUpgrade);
+}
+function shootBullet() {
+ if (Date.now() - player.lastShotTime > player.shootCooldown) {
+ var bullet = new Bullet();
+ bullet.x = player.x;
+ bullet.y = player.y;
+ bullet.direction.x = player.facing.x;
+ bullet.direction.y = player.facing.y;
+ bullets.push(bullet);
+ game.addChild(bullet);
+ player.lastShotTime = Date.now();
+ LK.getSound('shoot').play();
+ }
+}
+function updatePlayerFacing() {
+ var dx = player.x - lastPlayerPosition.x;
+ var dy = player.y - lastPlayerPosition.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ if (distance > 2) {
+ player.facing.x = dx / distance;
+ player.facing.y = dy / distance;
+ }
+ lastPlayerPosition.x = player.x;
+ lastPlayerPosition.y = player.y;
+}
+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;
+};
+game.update = function () {
+ gameTime++;
+ // Update player facing direction
+ updatePlayerFacing();
+ // Auto shoot
+ shootBullet();
+ // Spawn zombies
+ if (gameTime - lastZombieSpawn > zombieSpawnRate) {
+ spawnZombie();
+ lastZombieSpawn = gameTime;
+ // Increase spawn rate over time
+ zombieSpawnRate = Math.max(30, 120 - Math.floor(gameTime / 600));
+ }
+ // Spawn pickups
+ if (gameTime - lastPickupSpawn > pickupSpawnRate) {
+ if (Math.random() > 0.5) {
+ spawnHealthPack();
+ } else {
+ spawnWeaponUpgrade();
+ }
+ lastPickupSpawn = gameTime;
+ }
+ // Update bullets
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ var bullet = bullets[i];
+ // Remove off-screen bullets
+ if (bullet.x < -50 || bullet.x > 2098 || bullet.y < -50 || bullet.y > 2782) {
+ bullet.destroy();
+ bullets.splice(i, 1);
+ continue;
+ }
+ // Check bullet-zombie collisions
+ for (var j = zombies.length - 1; j >= 0; j--) {
+ var zombie = zombies[j];
+ if (bullet.intersects(zombie)) {
+ LK.setScore(LK.getScore() + 10);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ LK.getSound('zombieHit').play();
+ bullet.destroy();
+ bullets.splice(i, 1);
+ zombie.destroy();
+ zombies.splice(j, 1);
+ break;
+ }
+ }
+ }
+ // Update zombies and check player collision
+ for (var i = zombies.length - 1; i >= 0; i--) {
+ var zombie = zombies[i];
+ if (zombie.intersects(player)) {
+ player.health -= 2;
+ LK.getSound('damage').play();
+ LK.effects.flashObject(player, 0xff0000, 200);
+ if (player.health <= 0) {
+ LK.showGameOver();
+ return;
+ }
+ healthTxt.setText('Health: ' + player.health);
+ healthBar.scaleX = player.health / player.maxHealth * 5;
+ }
+ }
+ // Check health pack collection
+ for (var i = healthPacks.length - 1; i >= 0; i--) {
+ var healthPack = healthPacks[i];
+ if (player.intersects(healthPack)) {
+ player.health = Math.min(player.maxHealth, player.health + healthPack.healAmount);
+ healthTxt.setText('Health: ' + player.health);
+ healthBar.scaleX = player.health / player.maxHealth * 5;
+ LK.getSound('pickup').play();
+ healthPack.destroy();
+ healthPacks.splice(i, 1);
+ }
+ }
+ // Check weapon upgrade collection
+ for (var i = weaponUpgrades.length - 1; i >= 0; i--) {
+ var weaponUpgrade = weaponUpgrades[i];
+ if (player.intersects(weaponUpgrade)) {
+ player.shootCooldown = Math.max(50, player.shootCooldown - 20);
+ LK.getSound('pickup').play();
+ weaponUpgrade.destroy();
+ weaponUpgrades.splice(i, 1);
+ }
+ }
+ // Increase score over time
+ if (gameTime % 60 === 0) {
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ }
+};
\ No newline at end of file
With out the background
A medkit. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A suitcase. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A bullet. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A zombie with legs No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat