/****
* Classes
****/
// Bullet class for player
var Bullet = Container.expand(function () {
var self = Container.call(this);
self.assetId = 'playerBullet';
var bulletGraphics = self.attachAsset(self.assetId, {
anchorX: 0.5,
anchorY: 0.5
});
// Bullet speed
self.speed = -15;
// Bullet update method
self.update = function () {
self.y += self.speed;
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemyShip', {
anchorX: 0.5,
anchorY: 0.5,
width: 200,
height: 200
});
// Enemy update method
self.update = function () {
// Enemies will slowly descend
self.y += 0.5;
// If enemy reaches the bottom of the screen
if (self.y >= 2732) {
// Destroy the enemy
self.destroy();
}
};
});
// New enemy class
var EnemyPan = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemyPan', {
anchorX: 0.5,
anchorY: 0.5,
width: 200,
height: 200
});
// Enemy update method
self.update = function () {
// Enemies will slowly descend
self.y += 0.5;
// If enemy reaches the bottom of the screen
if (self.y >= 2732) {
// Destroy the enemy
self.destroy();
}
};
});
// Assets are automatically created and managed by the LK engine based on usage in the game code.
// Player spaceship class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('playerShip', {
anchorX: 0.5,
anchorY: 0.5
});
// Player movement speed
self.speed = 10;
// Update method for player movement
self.update = function () {
if (this.moveLeft) {
this.x -= this.speed;
}
if (this.moveRight) {
this.x += this.speed;
}
};
// Ensure player stays within game bounds
self.limitBounds = function () {
this.x = Math.max(this.x, 0);
this.x = Math.min(this.x, 2048);
};
});
// PowerUp class
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
// PowerUp update method
self.update = function () {
// PowerUps will slowly descend
self.y += 0.5;
// If PowerUp reaches the bottom of the screen
if (self.y >= 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Initialize game with black background
});
/****
* Game Code
****/
// Initialize background
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0,
width: 2048,
height: 2732
}));
// Initialize player
var player = game.addChild(new Player());
player.x = 1024; // Start in the middle of the game width
player.y = 2500; // Start near the bottom of the game height
// Initialize enemies
var enemies = [];
for (var i = 0; i < 5; i++) {
for (var j = 0; j < 10; j++) {
var enemy;
// Replace one enemy with a power up
if (i == 2 && j == 5) {
enemy = new PowerUp();
} else {
// Add the new enemy type to every second row
if (i % 2 == 0) {
enemy = new EnemyPan();
} else {
enemy = new Enemy();
}
}
enemy.x = 100 + j * 325; // Increase horizontal spacing between enemies
enemy.y = 100 + i * 325; // Increase vertical spacing between enemies
game.addChild(enemy);
enemies.push(enemy);
}
}
// Initialize bullets array
var bullets = [];
// Touch controls for player movement
game.down = function (x, y, obj) {
if (x < 1024) {
player.moveLeft = true;
player.moveRight = false;
} else {
player.moveRight = true;
player.moveLeft = false;
}
};
game.up = function (x, y, obj) {
player.moveLeft = false;
player.moveRight = false;
};
// Fire bullet on touch
game.move = function (x, y, obj) {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y - 50; // Start bullet at the top of the player
game.addChild(bullet);
bullets.push(bullet);
};
// Game update function
game.update = function () {
// Update player position and keep within bounds
player.update();
player.limitBounds();
// Update all bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
// Remove bullets that go off screen
if (bullets[i].y < 0) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
// Update all enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
}
// Collision detection between bullets and enemies
for (var i = bullets.length - 1; i >= 0; i--) {
for (var j = enemies.length - 1; j >= 0; j--) {
if (bullets[i].intersects(enemies[j])) {
bullets[i].destroy();
bullets.splice(i, 1);
if (!(enemies[j] instanceof PowerUp)) {
enemies[j].destroy();
enemies.splice(j, 1);
}
break; // Exit the inner loop if a collision is detected
}
}
}
// Collision detection between player and enemies
for (var j = 0; j < enemies.length; j++) {
if (player.intersects(enemies[j])) {
if (enemies[j] instanceof PowerUp) {
// Handle power up
enemies[j].destroy();
enemies.splice(j, 1);
// Change the player's bullet asset to the power up's asset
Bullet.prototype.assetId = 'powerUp';
} else {
// Flash screen red for 1 second (1000ms) to show we are dead.
LK.effects.flashScreen(0xff0000, 1000);
// Show game over. The game will be automatically paused while game over is showing.
LK.showGameOver(); // Calling this will destroy the 'Game' and reset entire game state.
break; // Exit the loop if a collision is detected
}
}
}
}; /****
* Classes
****/
// Bullet class for player
var Bullet = Container.expand(function () {
var self = Container.call(this);
self.assetId = 'playerBullet';
var bulletGraphics = self.attachAsset(self.assetId, {
anchorX: 0.5,
anchorY: 0.5
});
// Bullet speed
self.speed = -15;
// Bullet update method
self.update = function () {
self.y += self.speed;
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemyShip', {
anchorX: 0.5,
anchorY: 0.5,
width: 200,
height: 200
});
// Enemy update method
self.update = function () {
// Enemies will slowly descend
self.y += 0.5;
// If enemy reaches the bottom of the screen
if (self.y >= 2732) {
// Destroy the enemy
self.destroy();
}
};
});
// New enemy class
var EnemyPan = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemyPan', {
anchorX: 0.5,
anchorY: 0.5,
width: 200,
height: 200
});
// Enemy update method
self.update = function () {
// Enemies will slowly descend
self.y += 0.5;
// If enemy reaches the bottom of the screen
if (self.y >= 2732) {
// Destroy the enemy
self.destroy();
}
};
});
// Assets are automatically created and managed by the LK engine based on usage in the game code.
// Player spaceship class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('playerShip', {
anchorX: 0.5,
anchorY: 0.5
});
// Player movement speed
self.speed = 10;
// Update method for player movement
self.update = function () {
if (this.moveLeft) {
this.x -= this.speed;
}
if (this.moveRight) {
this.x += this.speed;
}
};
// Ensure player stays within game bounds
self.limitBounds = function () {
this.x = Math.max(this.x, 0);
this.x = Math.min(this.x, 2048);
};
});
// PowerUp class
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
// PowerUp update method
self.update = function () {
// PowerUps will slowly descend
self.y += 0.5;
// If PowerUp reaches the bottom of the screen
if (self.y >= 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Initialize game with black background
});
/****
* Game Code
****/
// Initialize background
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
y: 0,
width: 2048,
height: 2732
}));
// Initialize player
var player = game.addChild(new Player());
player.x = 1024; // Start in the middle of the game width
player.y = 2500; // Start near the bottom of the game height
// Initialize enemies
var enemies = [];
for (var i = 0; i < 5; i++) {
for (var j = 0; j < 10; j++) {
var enemy;
// Replace one enemy with a power up
if (i == 2 && j == 5) {
enemy = new PowerUp();
} else {
// Add the new enemy type to every second row
if (i % 2 == 0) {
enemy = new EnemyPan();
} else {
enemy = new Enemy();
}
}
enemy.x = 100 + j * 325; // Increase horizontal spacing between enemies
enemy.y = 100 + i * 325; // Increase vertical spacing between enemies
game.addChild(enemy);
enemies.push(enemy);
}
}
// Initialize bullets array
var bullets = [];
// Touch controls for player movement
game.down = function (x, y, obj) {
if (x < 1024) {
player.moveLeft = true;
player.moveRight = false;
} else {
player.moveRight = true;
player.moveLeft = false;
}
};
game.up = function (x, y, obj) {
player.moveLeft = false;
player.moveRight = false;
};
// Fire bullet on touch
game.move = function (x, y, obj) {
var bullet = new Bullet();
bullet.x = player.x;
bullet.y = player.y - 50; // Start bullet at the top of the player
game.addChild(bullet);
bullets.push(bullet);
};
// Game update function
game.update = function () {
// Update player position and keep within bounds
player.update();
player.limitBounds();
// Update all bullets
for (var i = bullets.length - 1; i >= 0; i--) {
bullets[i].update();
// Remove bullets that go off screen
if (bullets[i].y < 0) {
bullets[i].destroy();
bullets.splice(i, 1);
}
}
// Update all enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
}
// Collision detection between bullets and enemies
for (var i = bullets.length - 1; i >= 0; i--) {
for (var j = enemies.length - 1; j >= 0; j--) {
if (bullets[i].intersects(enemies[j])) {
bullets[i].destroy();
bullets.splice(i, 1);
if (!(enemies[j] instanceof PowerUp)) {
enemies[j].destroy();
enemies.splice(j, 1);
}
break; // Exit the inner loop if a collision is detected
}
}
}
// Collision detection between player and enemies
for (var j = 0; j < enemies.length; j++) {
if (player.intersects(enemies[j])) {
if (enemies[j] instanceof PowerUp) {
// Handle power up
enemies[j].destroy();
enemies.splice(j, 1);
// Change the player's bullet asset to the power up's asset
Bullet.prototype.assetId = 'powerUp';
} else {
// Flash screen red for 1 second (1000ms) to show we are dead.
LK.effects.flashScreen(0xff0000, 1000);
// Show game over. The game will be automatically paused while game over is showing.
LK.showGameOver(); // Calling this will destroy the 'Game' and reset entire game state.
break; // Exit the loop if a collision is detected
}
}
}
};
Intergalactic tub of congealed lard armed with integrated Gatling guns. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Blue Laser blast. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Mechanical hot dog spacecraft piloted by a cheeky, morbidly obese astronaut cat playing a fender stratocaster. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
weapon power up icon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Epic clash of intergalactic tubs of lard and anthropomorphic skillets cooking bacon while brandishing a switchblade knife versus a morbidly obese astronaut cat with a funny expression shooting sonic blasts from the fender Stratocaster being played, cinematic, exciting, 16-bit pixel art. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Outterspace above, terra firma below. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Amorphous gelatinous blob of congealed lard. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.