User prompt
make at 30 score a golden zombie
User prompt
make it move more with every click
User prompt
make the zombies go faster the high score
User prompt
add score
User prompt
make a backgriund
User prompt
make a highscore board with every enemy killed
User prompt
make it move more with every click
User prompt
make it move more with every click
User prompt
when hit by zombie the game end
User prompt
Fix Bug: 'Uncaught TypeError: window.addEventListener is not a function' in this line: 'window.addEventListener('keydown', function (e) {' Line Number: 77
User prompt
use A keybind to move left
Initial prompt
Soccer survival
/****
* Classes
****/
// Define the Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.createAsset('soccerPlayer', 'Hero character', 0.5, 0.5);
self.speed = 5;
self.shootInterval = 30;
self.shootTick = 0;
self.moveLeft = function () {
self.x = Math.max(self.width / 2, self.x - self.speed);
};
self.moveRight = function () {
self.x = Math.min(2048 - self.width / 2, self.x + self.speed);
};
self.shoot = function () {
if (self.shootTick <= 0) {
var bullet = new HeroBullet();
bullet.x = self.x;
bullet.y = self.y - self.height / 2;
game.addChild(bullet);
heroBullets.push(bullet);
self.shootTick = self.shootInterval;
}
};
self.update = function () {
if (self.shootTick > 0) {
self.shootTick--;
}
};
});
// Define the HeroBullet class
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.createAsset('heroBullet', 'Hero Bullet', 0.5, 1);
self.speed = -10;
self.move = function () {
self.y += self.speed;
};
});
// Define the Zombie class
var Zombie = Container.expand(function () {
var self = Container.call(this);
var zombieGraphics = self.createAsset('zombie', 'Zombie enemy', 0.5, 0.5);
self.speed = 2;
self.move = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 - 100;
var heroBullets = [];
var zombies = [];
// Handle touch events for hero movement and shooting
game.on('down', function (obj) {
var touchPos = obj.event.getLocalPosition(game);
if (touchPos.x < 2048 / 2) {
hero.moveLeft();
} else {
hero.moveRight();
}
hero.shoot();
});
// Main game loop
LK.on('tick', function () {
// Update hero
hero.update();
// Move hero bullets
for (var i = heroBullets.length - 1; i >= 0; i--) {
heroBullets[i].move();
if (heroBullets[i].y < -50) {
heroBullets[i].destroy();
heroBullets.splice(i, 1);
}
}
// Spawn zombies
if (LK.ticks % 120 == 0) {
var zombie = new Zombie();
zombie.x = Math.random() * (2048 - zombie.width) + zombie.width / 2;
zombie.y = -zombie.height / 2;
zombies.push(zombie);
game.addChild(zombie);
}
// Move zombies
for (var j = zombies.length - 1; j >= 0; j--) {
zombies[j].move();
if (zombies[j].y > 2732 + 50) {
zombies[j].destroy();
zombies.splice(j, 1);
}
}
// Check for bullet-zombie collisions
for (var k = heroBullets.length - 1; k >= 0; k--) {
for (var l = zombies.length - 1; l >= 0; l--) {
if (heroBullets[k].intersects(zombies[l])) {
heroBullets[k].destroy();
heroBullets.splice(k, 1);
zombies[l].destroy();
zombies.splice(l, 1);
break;
}
}
}
});
zombie from top. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
foot ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a soccer player top down running with a ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
soccer field from the top. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.