User prompt
Please add health points and a health bar to the hero spaceship.
User prompt
make the auto-fire rate on the player 50% faster.
User prompt
Make the Hero Spaceship auto-fire bullets at a fixed rate rather than firing bullets when you press the mouse.
User prompt
Double the speed of the enemy bullets.
User prompt
Make the enemy bullets twice as fast.
User prompt
Enemy bullets should fly towards the player, or rather where the player was when the enemy bullet was fired.
User prompt
Make the enemy shoot bullets towards the player.
User prompt
Make the enemy shoot bullets towards where the hero currently is. Make sure that the bullets get garbage collected when they fly off screen.
User prompt
Any bullet should fly towards the hero spaceship from the original firing position.
User prompt
Please make enemies shoot bullets in my general direction.
User prompt
Please make the enemy shoot bullets in my general direction.
User prompt
Please add code that allows me to be game over. I should game over if I touch an enemy.
User prompt
I get zero health when I get hit by an enemy now, regardless if a bullet is on the screen, but the game over method does not seem to be called. Please fix that.
User prompt
The code to determine if I'm game over should always run regardless if there is an active player bullet on the screen.
User prompt
I only seem to be able to be game over if there is a bullet on the screen. Please fix this.
User prompt
If the hero spaceship touches an enemy, it should instantly die, so HP should be set to zero and game over should be called.
User prompt
Please call the game over method if my hero spaceship intersects with an enemy.
User prompt
Please make me be game over if I intersect with an enemy.
User prompt
So, you should be game over when you are out of HP and you have a health bar on your spaceship and you lose HP when you're hit by a bullet or you die instantly if you're hit by an enemy. Please implement this based on the previous conversation.
User prompt
Please make the hero spaceship follow the mouse at a fixed pace. The spaceship should always move towards the last known location of the mouse.
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'hero.update = function () {' Line Number: 79
User prompt
Please update the mouse movement code to always have the spaceship move towards the last known location of the mouse.
User prompt
Please make the Hero Spaceship follow the mouse at a fixed pace.
Initial prompt
Space Shooter
/****
* Classes
****/
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + enemyGraphics.height) {
self.destroy();
enemies.splice(enemies.indexOf(self), 1);
}
};
});
//<Assets used in the game will automatically appear here>
// Hero class
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Hero update logic
};
self.shoot = function () {
var bullet = new HeroBullet();
bullet.x = self.x;
bullet.y = self.y - heroGraphics.height / 2;
game.addChild(bullet);
heroBullets.push(bullet);
};
});
// HeroBullet class
var HeroBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('heroBullet', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -15;
self.update = function () {
self.y += self.speed;
if (self.y < -bulletGraphics.height) {
self.destroy();
heroBullets.splice(heroBullets.indexOf(self), 1);
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize arrays and variables
var hero;
var heroBullets = [];
var enemies = [];
var score = 0;
var scoreTxt;
// Initialize game elements
function initGame() {
// Create hero
hero = new Hero();
hero.x = 2048 / 2;
hero.y = 2732 - 200;
game.addChild(hero);
// Create score text
scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Set up game update loop
game.update = function () {
// Update hero
hero.update();
// Update hero bullets
for (var i = heroBullets.length - 1; i >= 0; i--) {
heroBullets[i].update();
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
}
// Check for collisions
checkCollisions();
// Spawn enemies
if (LK.ticks % 60 == 0) {
spawnEnemy();
}
};
// Set up game controls
game.down = function (x, y, obj) {
hero.shoot();
};
}
// Check for collisions between hero bullets and enemies
function checkCollisions() {
for (var i = heroBullets.length - 1; i >= 0; i--) {
for (var j = enemies.length - 1; j >= 0; j--) {
if (heroBullets[i].intersects(enemies[j])) {
// Destroy enemy and bullet
enemies[j].destroy();
heroBullets[i].destroy();
enemies.splice(j, 1);
heroBullets.splice(i, 1);
// Update score
score += 10;
scoreTxt.setText(score);
break;
}
}
}
}
// Spawn a new enemy
function spawnEnemy() {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = -enemy.height;
game.addChild(enemy);
enemies.push(enemy);
}
// Initialize the game
initGame();