User prompt
Fix Bug: 'ReferenceError: Can't find variable: HeroBullet' in this line: 'var bullet = new HeroBullet();' Line Number: 84
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: Can't find variable: addChild' in this line: 'var hero = addChild(new Hero());' Line Number: 66
Code edit (1 edits merged)
Please save this source code
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
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
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
add powerups to the game that make the ship shoot two bullets side by side for 5 secs
User prompt
The hero ship should not be stuck to the mouse, but follow the mouse around with a limited speed. The ship should always move towards the mouse.
User prompt
Make enemies shoot at the hero
User prompt
Spawn waves of enemies, only spawn the next wave when the current wave of enemies have all been killed.
User prompt
Make enemies stop moving down at a random position in the top 3rd of the screen
User prompt
Progress the development of the game.
User prompt
Integrate a scrollable star field, behind everything, providing an illusion of ongoing forward movement. Faster moving stars should be more visible.
User prompt
stars
User prompt
Progress the development of the game.
User prompt
The powerups never seem to show up, please fix this?
User prompt
Add powerups to the game that makes the ship shoot two bullets side by side for 5 secs
Initial prompt
make ship shoot twice as fast
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = XS.getAsset('heroBullet', 'Hero Bullet Graphics', 0.5, 0.5);
self.addChild(bulletGraphics);
self.speed = 10;
self.move = function () {
self.y -= self.speed;
};
});
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = XS.getAsset('enemyBullet', 'Enemy Bullet Graphics', 0.5, 0.5);
self.addChild(bulletGraphics);
self.speed = 5;
self.move = function () {
self.x += self.speedX;
self.y += self.speedY;
};
});
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = XS.getAsset('hero', 'Hero Spaceship', 0.5, 0.5);
self.addChild(heroGraphics);
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = XS.getAsset('enemy', 'Enemy Spaceship', 0.5, 0.5);
self.addChild(enemyGraphics);
self.speed = 6;
self.targetY = Math.random() * (2732 / 3);
self.move = function () {
if (self.y < self.targetY) {
self.y += self.speed;
}
self.x += Math.sin(XS.ticks / 30) * 5;
if (self.x < 0) self.x = 0;
if (self.x > 2048 - enemyGraphics.width) self.x = 2048 - enemyGraphics.width;
};
});
var StarField = Container.expand(function () {
var self = Container.call(this);
var starGraphics = XS.getAsset('star', 'Star Graphics', 0.5, 0.5);
self.addChild(starGraphics);
self.speed = Math.random() * 2 + 1;
self.alpha = self.speed / 3;
self.move = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
self.x = Math.random() * 2048;
self.speed = Math.random() * 2 + 1;
self.alpha = self.speed / 3;
}
};
});
var Game = Container.expand(function () {
var self = Container.call(this);
var starField = [];
for (var i = 0; i < 100; i++) {
var star = new StarField();
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
starField.push(star);
self.addChild(star);
}
var hero = self.addChild(new Hero());
hero.x = 1024;
hero.y = 2400;
var enemies = [];
var heroBullets = [];
var enemyBullets = [];
var score = 0;
var currentWave = 0;
var allEnemiesKilled = true;
var scoreText = new Text2('0', {
size: 100,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma",
fill: "#ffffff"
});
scoreText.anchor.set(0.5, 0);
XS.gui.topCenter.addChild(scoreText);
function spawnWave() {
for (var i = 0; i < currentWave + 3; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = -100 - i * 100;
enemies.push(enemy);
self.addChild(enemy);
}
allEnemiesKilled = false;
}
function fireHeroBullet() {
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;
bullet.y = enemy.y + 50;
var angle = Math.atan2(hero.y - bullet.y, hero.x - bullet.x);
bullet.speedX = bullet.speed * Math.cos(angle);
bullet.speedY = bullet.speed * Math.sin(angle);
enemyBullets.push(bullet);
self.addChild(bullet);
}
function updateGameObjects() {
enemies.forEach(function (enemy, index) {
enemy.move();
if (enemy.y > 2732) {
enemy.destroy();
enemies.splice(index, 1);
}
});
heroBullets.forEach(function (bullet, index) {
bullet.move();
if (bullet.y < 0) {
bullet.destroy();
heroBullets.splice(index, 1);
}
});
enemyBullets.forEach(function (bullet, index) {
bullet.move();
if (bullet.y > 2732) {
bullet.destroy();
enemyBullets.splice(index, 1);
}
});
}
function checkCollisions() {
heroBullets.forEach(function (heroBullet, hIndex) {
enemies.forEach(function (enemy, eIndex) {
if (heroBullet.intersects(enemy)) {
heroBullet.destroy();
heroBullets.splice(hIndex, 1);
enemy.destroy();
enemies.splice(eIndex, 1);
score += 100;
scoreText.setText(score);
if (enemies.length === 0) {
allEnemiesKilled = true;
}
}
});
});
enemyBullets.forEach(function (enemyBullet, index) {
if (enemyBullet.intersects(hero)) {
enemyBullet.destroy();
enemyBullets.splice(index, 1);
XS.showGameOver();
}
});
}
var targetPosition = {
x: hero.x,
y: hero.y
};
stage.on('down', function (obj) {
targetPosition = obj.event.getLocalPosition(self);
});
stage.on('move', function (obj) {
targetPosition = obj.event.getLocalPosition(self);
});
function moveHeroTowardsTarget() {
var dx = targetPosition.x - hero.x;
var dy = targetPosition.y - hero.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var maxSpeed = 15;
if (distance > maxSpeed) {
var angle = Math.atan2(dy, dx);
hero.x += maxSpeed * Math.cos(angle);
hero.y += maxSpeed * Math.sin(angle);
} else {
hero.x = targetPosition.x;
hero.y = targetPosition.y;
}
}
function handleTick() {
moveHeroTowardsTarget();
updateGameObjects();
checkCollisions();
starField.forEach(function (star) {
star.move();
});
if (allEnemiesKilled) {
currentWave++;
spawnWave();
}
if (XS.ticks % 15 === 0) {
fireHeroBullet();
}
enemies.forEach(function (enemy, index) {
if (XS.ticks % 90 === 0) {
fireEnemyBullet(enemy);
}
if (XS.ticks % 180 === 0 && index % 2 === 0) {
fireEnemyBullet(enemy);
}
});
}
XS.on('tick', handleTick);
});
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.