User prompt
every 30 seconds, spawn slightly more balloons
User prompt
a balloon is missed if it makes it off the top of the screen
User prompt
players lose a point for every balloon missed
User prompt
if a balloon is not popped and reaches the top of the player's screen, then the game ends
User prompt
balloons that can explode are a different color
User prompt
every balloon popped is a point earned
User prompt
if a balloon explodes, it launches spikes in random directions that can pop other balloons
User prompt
Please fix the bug: 'Uncaught TypeError: balloons[i].containsPoint is not a function' in or related to this line: 'if (balloons[i].containsPoint({' Line Number: 113
Initial prompt
Balloon Surprise
===================================================================
--- original.js
+++ change.js
@@ -49,8 +49,28 @@
self.destroy();
}
};
});
+var Spike = Container.expand(function () {
+ var self = Container.call(this);
+ var spikeGraphics = self.attachAsset('spike', {
+ width: 20,
+ height: 20,
+ color: 0x000000,
+ shape: 'box',
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speedX = Math.random() * 10 - 5;
+ self.speedY = Math.random() * 10 - 5;
+ self.update = function () {
+ self.x += self.speedX;
+ self.y += self.speedY;
+ if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
+ self.destroy();
+ }
+ };
+});
/****
* Initialize Game
****/
@@ -80,8 +100,15 @@
var explosion = new Explosion();
explosion.x = x;
explosion.y = y;
game.addChild(explosion);
+ // Launch spikes in random directions
+ for (var i = 0; i < 10; i++) {
+ var spike = new Spike();
+ spike.x = x;
+ spike.y = y;
+ game.addChild(spike);
+ }
// Destroy nearby balloons
for (var i = balloons.length - 1; i >= 0; i--) {
if (Math.abs(balloons[i].x - x) < 200 && Math.abs(balloons[i].y - y) < 200) {
balloons[i].destroy();
@@ -97,8 +124,24 @@
if (balloons[i].y < -100) {
balloons.splice(i, 1);
}
}
+ // Update spikes
+ var spikes = game.children.filter(function (child) {
+ return child instanceof Spike;
+ });
+ for (var i = spikes.length - 1; i >= 0; i--) {
+ spikes[i].update();
+ // Check for collision with balloons
+ for (var j = balloons.length - 1; j >= 0; j--) {
+ if (spikes[i].intersects(balloons[j])) {
+ balloons[j].destroy();
+ balloons.splice(j, 1);
+ score++;
+ scoreTxt.setText(score);
+ }
+ }
+ }
if (LK.ticks % 60 == 0) {
spawnBalloon();
}
};