/****
* Classes
****/
// Define the Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 9
});
self.speed = -15;
self.update = function () {
self.y += self.speed;
};
});
// Define the Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
}
};
});
// Define the Life class
var Life = Container.expand(function () {
var self = Container.call(this);
var lifeGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 10,
scaleY: 10
});
});
// Define the Pillow class
var Pillow = Container.expand(function () {
var self = Container.call(this);
var pillowGraphics = self.attachAsset('pillow', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 10,
scaleY: 10
});
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define the Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 15
});
playerGraphics.rotation = Math.PI / 2; // Rotate the player to point upwards
self.speed = 10;
self.update = function () {
// Player update logic
};
// Add weapon functionality to the player
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
bullets.push(bullet);
game.addChild(bullet);
};
});
// Define the SukurTable class
var SukurTable = Container.expand(function () {
var self = Container.call(this);
var sukurTableGraphics = self.attachAsset('scoreTable', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 10,
scaleY: 10
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Play the happy song in the Monkey music box
LK.playMusic('Monkey');
// Set an interval to change the background color between light blue and black every minute
var isLightBlue = true;
LK.setInterval(function () {
if (isLightBlue) {
game.setBackgroundColor(0xADD8E6);
isLightBlue = false;
} else {
game.setBackgroundColor(0x000000);
isLightBlue = true;
}
}, 60000);
var sky = game.addChild(LK.getAsset('sky', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 3
}));
sky.x = 2048 / 2;
sky.y = 2732 / 2;
// Add clouds to the game
for (var i = 0; i < 5; i++) {
var cloud = game.addChild(LK.getAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 3
}));
cloud.x = Math.random() * 2048;
cloud.y = Math.random() * 2732;
}
// Initialize SukurTable
var sukurTable = game.addChild(new SukurTable());
sukurTable.x = 0;
sukurTable.y = 100;
// Initialize score text
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFF0000
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize player
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 150;
// Initialize clouds
for (var i = 0; i < 5; i++) {
var cloud = game.addChild(LK.getAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
}));
cloud.x = Math.random() * 2048;
cloud.y = Math.random() * 2732;
}
// Initialize enemies
var enemies = [];
for (var i = 0; i < 9; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = Math.random() * 1000;
enemies.push(enemy);
game.addChild(enemy);
}
// Create an infinite stream of enemies
LK.setInterval(function () {
// Check if the number of enemies is less than 5
if (enemies.length < 5) {
// Generate a random number between 4 and 5
var numEnemies = Math.floor(Math.random() * 2) + 4;
for (var i = 0; i < numEnemies - enemies.length; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = 0;
enemies.push(enemy);
game.addChild(enemy);
}
}
}, 2000);
// Initialize bullets
var bullets = [];
// Handle player movement
game.down = function (x, y, obj) {
player.x = x;
player.y = y;
};
// Handle shooting
game.up = function (x, y, obj) {
player.shoot();
};
// Update game state
game.update = function () {
// Update player
player.update();
// Create enemies when the player reaches the middle of the screen
if (player.lastY >= 2732 / 2 && player.y < 2732 / 2) {
for (var i = 0; i < 5; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = 0;
enemies.push(enemy);
game.addChild(enemy);
}
}
// Update enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
// Check if enemy has reached the bottom of the screen
if (enemies[i].y >= 2732 - enemies[i].height) {
// End the game
LK.showGameOver();
return; // Stop the game immediately after game over
}
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
if (bullets[j].y < 0) {
bullets[j].destroy();
bullets.splice(j, 1);
continue;
}
// Check for collision with enemies
for (var i = enemies.length - 1; i >= 0; i--) {
if (bullets[j].intersects(enemies[i])) {
// Destroy bullet and enemy
bullets[j].destroy();
bullets.splice(j, 1);
enemies[i].destroy();
enemies.splice(i, 1);
// Increase score when an enemy is destroyed
LK.setScore(LK.getScore() + 1);
// Update score display
scoreTxt.setText(LK.getScore());
break;
}
}
}
}; /****
* Classes
****/
// Define the Bullet class
var Bullet = Container.expand(function () {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 9
});
self.speed = -15;
self.update = function () {
self.y += self.speed;
};
});
// Define the Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
}
};
});
// Define the Life class
var Life = Container.expand(function () {
var self = Container.call(this);
var lifeGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 10,
scaleY: 10
});
});
// Define the Pillow class
var Pillow = Container.expand(function () {
var self = Container.call(this);
var pillowGraphics = self.attachAsset('pillow', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 10,
scaleY: 10
});
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Define the Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 15
});
playerGraphics.rotation = Math.PI / 2; // Rotate the player to point upwards
self.speed = 10;
self.update = function () {
// Player update logic
};
// Add weapon functionality to the player
self.shoot = function () {
var bullet = new Bullet();
bullet.x = self.x;
bullet.y = self.y;
bullets.push(bullet);
game.addChild(bullet);
};
});
// Define the SukurTable class
var SukurTable = Container.expand(function () {
var self = Container.call(this);
var sukurTableGraphics = self.attachAsset('scoreTable', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 10,
scaleY: 10
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Play the happy song in the Monkey music box
LK.playMusic('Monkey');
// Set an interval to change the background color between light blue and black every minute
var isLightBlue = true;
LK.setInterval(function () {
if (isLightBlue) {
game.setBackgroundColor(0xADD8E6);
isLightBlue = false;
} else {
game.setBackgroundColor(0x000000);
isLightBlue = true;
}
}, 60000);
var sky = game.addChild(LK.getAsset('sky', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 3
}));
sky.x = 2048 / 2;
sky.y = 2732 / 2;
// Add clouds to the game
for (var i = 0; i < 5; i++) {
var cloud = game.addChild(LK.getAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 3,
scaleY: 3
}));
cloud.x = Math.random() * 2048;
cloud.y = Math.random() * 2732;
}
// Initialize SukurTable
var sukurTable = game.addChild(new SukurTable());
sukurTable.x = 0;
sukurTable.y = 100;
// Initialize score text
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFF0000
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize player
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 150;
// Initialize clouds
for (var i = 0; i < 5; i++) {
var cloud = game.addChild(LK.getAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
}));
cloud.x = Math.random() * 2048;
cloud.y = Math.random() * 2732;
}
// Initialize enemies
var enemies = [];
for (var i = 0; i < 9; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = Math.random() * 1000;
enemies.push(enemy);
game.addChild(enemy);
}
// Create an infinite stream of enemies
LK.setInterval(function () {
// Check if the number of enemies is less than 5
if (enemies.length < 5) {
// Generate a random number between 4 and 5
var numEnemies = Math.floor(Math.random() * 2) + 4;
for (var i = 0; i < numEnemies - enemies.length; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = 0;
enemies.push(enemy);
game.addChild(enemy);
}
}
}, 2000);
// Initialize bullets
var bullets = [];
// Handle player movement
game.down = function (x, y, obj) {
player.x = x;
player.y = y;
};
// Handle shooting
game.up = function (x, y, obj) {
player.shoot();
};
// Update game state
game.update = function () {
// Update player
player.update();
// Create enemies when the player reaches the middle of the screen
if (player.lastY >= 2732 / 2 && player.y < 2732 / 2) {
for (var i = 0; i < 5; i++) {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = 0;
enemies.push(enemy);
game.addChild(enemy);
}
}
// Update enemies
for (var i = 0; i < enemies.length; i++) {
enemies[i].update();
// Check if enemy has reached the bottom of the screen
if (enemies[i].y >= 2732 - enemies[i].height) {
// End the game
LK.showGameOver();
return; // Stop the game immediately after game over
}
}
// Update bullets
for (var j = bullets.length - 1; j >= 0; j--) {
bullets[j].update();
if (bullets[j].y < 0) {
bullets[j].destroy();
bullets.splice(j, 1);
continue;
}
// Check for collision with enemies
for (var i = enemies.length - 1; i >= 0; i--) {
if (bullets[j].intersects(enemies[i])) {
// Destroy bullet and enemy
bullets[j].destroy();
bullets.splice(j, 1);
enemies[i].destroy();
enemies.splice(i, 1);
// Increase score when an enemy is destroyed
LK.setScore(LK.getScore() + 1);
// Update score display
scoreTxt.setText(LK.getScore());
break;
}
}
}
};