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
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);
self.speed = -5;
self.move = function () {
self.y += self.speed;
};
});
var EnemyBullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = LK.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 = LK.getAsset('hero', 'Hero Spaceship', 0.5, 0.5);
self.addChild(heroGraphics);
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = LK.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(LK.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 = LK.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);
LK.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);
LK.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 (LK.ticks % 30 === 0) {
fireHeroBullet();
}
enemies.forEach(function (enemy, index) {
if (LK.ticks % 90 === 0) {
fireEnemyBullet(enemy);
}
if (LK.ticks % 180 === 0 && index % 2 === 0) {
fireEnemyBullet(enemy);
}
});
}
LK.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.