User prompt
The game end 1 score
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'intersects')' in or related to this line: 'if (bullets[j].intersects(animes[l])) {' Line Number: 154
User prompt
Add the animes in the game
User prompt
Game speed increase 5time
User prompt
Add a space theme in the background on the game
User prompt
Add a sound
User prompt
Add score board
Initial prompt
Ap
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,21 @@
/****
* Classes
****/
+var Anime = Container.expand(function () {
+ var self = Container.call(this);
+ var animeGraphics = self.attachAsset('anime1', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 10;
+ self.update = function () {
+ self.y += self.speed;
+ if (self.y > 2732) {
+ self.destroy();
+ }
+ };
+});
// Define the Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
@@ -79,8 +93,10 @@
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize enemies array
var enemies = [];
+// Initialize anime array
+var animes = [];
// Initialize bullets array
var bullets = [];
// Handle player movement
game.move = function (x, y, obj) {
@@ -121,8 +137,20 @@
scoreTxt.setText(LK.getScore());
break;
}
}
+ for (var l = animes.length - 1; l >= 0; l--) {
+ if (bullets[j].intersects(animes[l])) {
+ bullets[j].destroy();
+ bullets.splice(j, 1);
+ animes[l].destroy();
+ animes.splice(l, 1);
+ // Update score
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText(LK.getScore());
+ break;
+ }
+ }
}
// Spawn enemies
if (LK.ticks % 60 == 0) {
var enemy = new Enemy();
@@ -130,5 +158,13 @@
enemy.y = -100;
enemies.push(enemy);
game.addChild(enemy);
}
+ // Spawn animes
+ if (LK.ticks % 120 == 0) {
+ var anime = new Anime();
+ anime.x = Math.random() * 2048;
+ anime.y = -100;
+ animes.push(anime);
+ game.addChild(anime);
+ }
};
\ No newline at end of file