User prompt
Remove the second hero
User prompt
Remove the hero 3d
User prompt
Remove the zombies 3d
User prompt
Make the hero and zombies 3d
User prompt
Please fix the bug: 'ReferenceError: hero is not defined' in or related to this line: 'if (self.intersects(hero)) {' Line Number: 84
User prompt
Make a space ship
User prompt
When the zombies goes down the zombies get updated
User prompt
When the zombies goes down the score will reduce
User prompt
Make this game hard time to time
User prompt
Make a score board
User prompt
Make zombies level increase time to time
User prompt
Make our player throw bullets
User prompt
Make our player move by our finger
User prompt
Make our player that we can move it
User prompt
And attack on the player
User prompt
Make zombie movable
User prompt
Cancel
Initial prompt
Zombie smash
/****
* Classes
****/
// Define a Bullet class
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.update = function () {
self.y += self.speed;
if (self.y < -bulletGraphics.height) {
self.destroy();
}
};
});
// Define a Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y - heroGraphics.height / 2;
bullets.push(bullet);
game.addChild(bullet);
};
});
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Define a Zombie class
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 () {
self.y += self.speed;
if (self.y > 2732) {
self.respawn();
}
};
self.respawn = function () {
self.y = -zombieGraphics.height;
self.x = Math.random() * 2048;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize game variables
var hero = new Hero();
hero.x = 2048 / 2;
hero.y = 2732 - 150;
game.addChild(hero);
var zombies = [];
for (var i = 0; i < 5; i++) {
var zombie = new Zombie();
zombie.x = Math.random() * 2048;
zombie.y = Math.random() * 2732;
zombies.push(zombie);
game.addChild(zombie);
}
var bullets = [];
// Handle game updates
game.update = function () {
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
for (var j = zombies.length - 1; j >= 0; j--) {
if (bullets[i].intersects(zombies[j])) {
bullets[i].destroy();
bullets.splice(i, 1);
zombies[j].respawn();
break;
}
}
}
for (var k = 0; k < zombies.length; k++) {
zombies[k].update();
if (zombies[k].intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
};
// Handle touch events for shooting
game.down = function (x, y, obj) {
hero.shoot();
}; ===================================================================
--- original.js
+++ change.js
@@ -1,101 +1,103 @@
-/****
+/****
* Classes
-****/
+****/
// Define a Bullet class
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.update = function () {
- self.y += self.speed;
- if (self.y < -bulletGraphics.height) {
- self.destroy();
- }
- };
+ var self = Container.call(this);
+ var bulletGraphics = self.attachAsset('bullet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -10;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y < -bulletGraphics.height) {
+ self.destroy();
+ }
+ };
});
// Define a Hero class
var Hero = Container.expand(function () {
- var self = Container.call(this);
- var heroGraphics = self.attachAsset('hero', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.shoot = function () {
- var bullet = new Bullet();
- bullet.x = self.x;
- bullet.y = self.y - heroGraphics.height / 2;
- bullets.push(bullet);
- game.addChild(bullet);
- };
+ var self = Container.call(this);
+ var heroGraphics = self.attachAsset('hero', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.shoot = function () {
+ var bullet = new Bullet();
+ bullet.x = self.x;
+ bullet.y = self.y - heroGraphics.height / 2;
+ bullets.push(bullet);
+ game.addChild(bullet);
+ };
});
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Define a Zombie class
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 () {
- self.y += self.speed;
- if (self.y > 2732) {
- self.y = -zombieGraphics.height;
- self.x = Math.random() * 2048;
- }
- };
+ var self = Container.call(this);
+ var zombieGraphics = self.attachAsset('zombie', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 2;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.respawn();
+ }
+ };
+ self.respawn = function () {
+ self.y = -zombieGraphics.height;
+ self.x = Math.random() * 2048;
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 // Init game with black background
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize game variables
var hero = new Hero();
hero.x = 2048 / 2;
hero.y = 2732 - 150;
game.addChild(hero);
var zombies = [];
for (var i = 0; i < 5; i++) {
- var zombie = new Zombie();
- zombie.x = Math.random() * 2048;
- zombie.y = Math.random() * 2732;
- zombies.push(zombie);
- game.addChild(zombie);
+ var zombie = new Zombie();
+ zombie.x = Math.random() * 2048;
+ zombie.y = Math.random() * 2732;
+ zombies.push(zombie);
+ game.addChild(zombie);
}
var bullets = [];
// Handle game updates
game.update = function () {
- for (var i = bullets.length - 1; i >= 0; i--) {
- bullets[i].update();
- for (var j = zombies.length - 1; j >= 0; j--) {
- if (bullets[i].intersects(zombies[j])) {
- bullets[i].destroy();
- bullets.splice(i, 1);
- zombies[j].destroy();
- zombies.splice(j, 1);
- break;
- }
- }
- }
- for (var k = 0; k < zombies.length; k++) {
- zombies[k].update();
- if (zombies[k].intersects(hero)) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
- }
+ for (var i = bullets.length - 1; i >= 0; i--) {
+ bullets[i].update();
+ for (var j = zombies.length - 1; j >= 0; j--) {
+ if (bullets[i].intersects(zombies[j])) {
+ bullets[i].destroy();
+ bullets.splice(i, 1);
+ zombies[j].respawn();
+ break;
+ }
+ }
+ }
+ for (var k = 0; k < zombies.length; k++) {
+ zombies[k].update();
+ if (zombies[k].intersects(hero)) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ }
};
// Handle touch events for shooting
game.down = function (x, y, obj) {
- hero.shoot();
+ hero.shoot();
};
\ No newline at end of file