User prompt
how about 0.2
User prompt
make it 0.3
User prompt
add a 0.1 second cooldown on shooting
User prompt
can you make the red enemies face where they're going
User prompt
move it a bit to the left
User prompt
move the score counter to the other corner
User prompt
make enemies spawn 2x faster
User prompt
you broke the player projectiles
User prompt
make the player projectiles work
User prompt
the lasers broke the player projectiles
User prompt
make the lasers stay for a bit
User prompt
make lasers as tall as the screen spawn sometimes
User prompt
even faster
User prompt
make the enemies spawn faster
User prompt
make the green enemies almost as fast as the green ones
User prompt
do that again but backwards
User prompt
make the red enemies worth 3 points and the green enemies worth 1 point
User prompt
make even less rare
User prompt
make the red enemies less rare
User prompt
make the green enemies worth 1 point
/****
* Classes
****/
// RedEnemy class
var RedEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('redEnemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 20;
self.move = function () {
// Calculate direction towards player
var dx = player.x - self.x;
var dy = player.y - self.y;
var len = Math.sqrt(dx * dx + dy * dy);
dx /= len;
dy /= len;
// Move towards player
self.x += dx * self.speed;
self.y += dy * self.speed;
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.move = function (x, y) {
self.x = x;
self.y = y;
};
});
// 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 = 2;
self.move = function () {
self.y += self.speed;
};
});
// Laser class
var Laser = Container.expand(function () {
var self = Container.call(this);
var laserGraphics = self.attachAsset('laser', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.move = function () {
self.y += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Fire lasers when the game area is clicked
// Initialize player, enemy, and laser assets for the game.
var scoreTxt = new Text2('0', {
size: 100,
fill: '#ffffff'
});
LK.gui.topLeft.addChild(scoreTxt);
var score = 0;
game.on('down', function () {
var laser = new Laser();
laser.x = player.x;
laser.y = player.y - 30; // Start slightly above the player
lasers.push(laser);
game.addChild(laser);
});
var player = game.addChild(new Player());
player.x = 1024; // Center horizontally
player.y = 2500; // Position towards the bottom
var enemies = [];
var lasers = [];
// Create enemies at intervals
var enemySpawnTimer = LK.setInterval(function () {
// Randomly decide whether to create a normal enemy or a red enemy
var isRed = Math.random() < 0.05;
var enemy = isRed ? new RedEnemy() : new Enemy();
enemy.x = Math.random() * 2048; // Random horizontal position
enemy.y = 0; // Start at the top
enemies.push(enemy);
game.addChild(enemy);
}, 2000);
// Handle touch move to control player
game.on('move', function (obj) {
var pos = obj.event.getLocalPosition(game);
player.move(pos.x, pos.y);
});
// Main game loop
LK.on('tick', function () {
// Move enemies
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].move();
// Remove enemies that go off screen or go too far to the left or right
if (enemies[i].y > 2732 || enemies[i].x < 0 || enemies[i].x > 2048) {
enemies[i].destroy();
enemies.splice(i, 1);
}
}
// Move lasers
for (var j = lasers.length - 1; j >= 0; j--) {
lasers[j].move();
// Remove lasers that go off screen
if (lasers[j].y < 0) {
lasers[j].destroy();
lasers.splice(j, 1);
}
}
// Check for collisions between lasers and enemies
for (var k = lasers.length - 1; k >= 0; k--) {
for (var l = enemies.length - 1; l >= 0; l--) {
if (lasers[k].intersects(enemies[l])) {
// Destroy both laser and enemy on collision
lasers[k].destroy();
lasers.splice(k, 1);
enemies[l].destroy();
enemies.splice(l, 1);
score += 1;
scoreTxt.setText(score);
break; // Exit the inner loop after a collision
}
}
}
// Check for collisions between player and enemies, and reset the game if a collision occurs
for (var m = enemies.length - 1; m >= 0; m--) {
if (player.intersects(enemies[m])) {
LK.showGameOver('Your score: ' + LK.getScore());
}
}
});
green cartoon laser. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
red cartoon laser. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pink cartoon laser. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
sci-fi cartoon spaceship. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.