User prompt
When updating score textg also call LK.setScore
User prompt
Make ship shoot twice as fast
Code edit (1 edits merged)
Please save this source code
User prompt
Make ship shoot twice as fast
User prompt
Add powerups to the game that makes the ship shoot two bullets side by side for 5 seconds.
User prompt
Make ship shoot twice as fast
User prompt
Make ship shoot twice as fast
User prompt
Fix Bug: 'ReferenceError: Can't find variable: HeroBullet' in this line: 'var bullet = new HeroBullet();' Line Number: 84
===================================================================
--- original.js
+++ change.js
@@ -1,4 +1,13 @@
+var PowerUp = Container.expand(function () {
+ var self = Container.call(this);
+ var powerUpGraphics = LK.getAsset('powerUp', 'Power Up Graphics', 0.5, 0.5);
+ self.addChild(powerUpGraphics);
+ self.speed = 2;
+ self.move = function () {
+ self.y += self.speed;
+ };
+});
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = LK.getAsset('heroBullet', 'Hero Bullet Graphics', 0.5, 0.5);
self.addChild(bulletGraphics);
@@ -68,8 +77,10 @@
hero.y = 2400;
var enemies = [];
var heroBullets = [];
var enemyBullets = [];
+ var powerUps = [];
+ var powerUpTimer = 0;
var score = 0;
var currentWave = 0;
var allEnemiesKilled = true;
var scoreText = new Text2('0', {
@@ -89,13 +100,26 @@
}
allEnemiesKilled = false;
}
function fireHeroBullet() {
- var bullet = new HeroBullet();
- bullet.x = hero.x;
- bullet.y = hero.y - 50;
- heroBullets.push(bullet);
- self.addChild(bullet);
+ if (powerUpTimer > 0) {
+ var bullet1 = new HeroBullet();
+ bullet1.x = hero.x - 20;
+ bullet1.y = hero.y - 50;
+ heroBullets.push(bullet1);
+ self.addChild(bullet1);
+ var bullet2 = new HeroBullet();
+ bullet2.x = hero.x + 20;
+ bullet2.y = hero.y - 50;
+ heroBullets.push(bullet2);
+ self.addChild(bullet2);
+ } else {
+ var bullet = new HeroBullet();
+ bullet.x = hero.x;
+ bullet.y = hero.y - 50;
+ heroBullets.push(bullet);
+ self.addChild(bullet);
+ }
}
function fireEnemyBullet(enemy) {
var bullet = new EnemyBullet();
bullet.x = enemy.x;
@@ -187,11 +211,32 @@
if (allEnemiesKilled) {
currentWave++;
spawnWave();
}
- if (LK.ticks % 15 === 0) {
+ if (LK.ticks % 600 === 0) {
+ var powerUp = new PowerUp();
+ powerUp.x = Math.random() * 2048;
+ powerUp.y = -100;
+ powerUps.push(powerUp);
+ self.addChild(powerUp);
+ }
+ if (powerUpTimer > 0) {
+ powerUpTimer--;
+ }
+ if (LK.ticks % 30 === 0) {
fireHeroBullet();
}
+ powerUps.forEach(function (powerUp, index) {
+ powerUp.move();
+ if (powerUp.y > 2732) {
+ powerUp.destroy();
+ powerUps.splice(index, 1);
+ } else if (powerUp.intersects(hero)) {
+ powerUp.destroy();
+ powerUps.splice(index, 1);
+ powerUpTimer = 300;
+ }
+ });
enemies.forEach(function (enemy, index) {
if (LK.ticks % 90 === 0) {
fireEnemyBullet(enemy);
}
Single space torpedo flying upwards Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Single enemy slime bullet flying downwards. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
single alien enemy spaceship facing down, looking like space alien adopted to living in space. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.
Hero spaceship facing upwards, with a single cannon in the center. Game Texture. In-Game asset. 2d. Pixelart. White background. Blank background. Low detail. High contrast.