/****
* Classes
****/
// BackButton class
var BackButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('backButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
// Add 'Back' text to the button
var backText = new Text2('Back', {
size: 50,
fill: "#ffffff"
});
backText.anchor.set(0.5, 0.5);
self.addChild(backText);
self.up = function (x, y, obj) {
var startButton = new StartButton();
game.addChild(startButton);
self.destroy();
var menuPage = game.children.find(function (child) {
return child instanceof MenuPage;
});
if (menuPage) {
menuPage.destroy();
}
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
//<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,
scaleX: 3,
scaleY: 3
});
self.speed = 10;
self.update = function () {
// Update logic for hero
};
self.shoot = function () {
var bullet = new HeroBullet();
bullet.x = self.x;
bullet.y = self.y - heroGraphics.height / 2;
game.addChild(bullet);
heroBullets.push(bullet);
LK.getSound('firingSound').play();
};
});
// 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 < 0) {
self.destroy();
}
};
});
// Level class
var Level = Container.expand(function () {
var self = Container.call(this);
var levelGraphics = self.attachAsset('level', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4
});
// Add 'level' text to the button
var levelText = new Text2('Level ' + currentLevel, {
// Update the level text to reflect the current level
size: 50,
fill: "#ffffff"
});
levelText.anchor.set(0.5, 0.5);
self.addChild(levelText);
self.x = 2048 / 2;
self.y = 2732 / 2;
self.up = function (x, y, obj) {
initGame();
currentLevel++; // Increase the level after each level
self.destroy();
};
});
// MenuButton class
var MenuButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('menuButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
// Add 'Menu' text to the button
var menuText = new Text2('Menu', {
size: 50,
fill: "#ffffff"
});
menuText.anchor.set(0.5, 0.5);
self.addChild(menuText);
self.up = function (x, y, obj) {
var menuPage = new MenuPage();
game.addChild(menuPage);
self.destroy();
};
});
// MenuPage class
var MenuPage = Container.expand(function () {
var self = Container.call(this);
var background = new Container();
background.width = 2048;
background.height = 2732;
background.color = 0x000000;
self.addChild(background);
// Add 'Sound' button to the menu page
var soundButton = new SoundButton();
soundButton.x = 2048 / 2;
soundButton.y = 2732 / 2 - 100;
self.addChild(soundButton);
// Add 'Back' button to the menu page
var backButton = new BackButton();
backButton.x = 2048 / 2;
backButton.y = 2732 / 2 + 100;
self.addChild(backButton);
// Toggle sound on/off
soundButton.up = function (x, y, obj) {
if (LK.isMusicPlaying()) {
LK.stopMusic();
LK.muteSound();
soundButton.setText('Sound: Off');
} else {
LK.unmuteSound();
LK.playMusic('backgroundMusic');
soundButton.setText('Sound: On');
}
};
// Go back to the start button page
backButton.up = function (x, y, obj) {
var startButton = new StartButton();
game.addChild(startButton);
self.destroy();
};
});
// SoundButton class
var SoundButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('menuButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
// Add 'Sound: On' text to the button
var soundText = new Text2('Sound: On', {
size: 50,
fill: "#ffffff"
});
soundText.anchor.set(0.5, 0.5);
self.addChild(soundText);
self.up = function (x, y, obj) {
// Toggle sound
if (LK.isMusicPlaying()) {
LK.stopMusic();
LK.muteSound();
soundText.setText('Sound: Off');
} else {
LK.unmuteSound();
LK.playMusic('backgroundMusic');
soundText.setText('Sound: On');
}
};
});
// StartButton class
var StartButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 8,
scaleY: 8
});
// Add 'start' text to the button
var startText = new Text2('Start', {
size: 100,
fill: "#ffffff"
});
startText.anchor.set(0.5, 0.5);
self.addChild(startText);
self.x = 2048 / 2;
self.y = 2732 / 2;
self.up = function (x, y, obj) {
// Initialize level
var level = new Level();
game.addChild(level);
self.destroy();
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Add background image
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2048 / 2048,
scaleY: 2732 / 2048,
x: 2048 / 2,
y: 2732 / 2
});
game.addChildAt(background, 0);
// Initialize variables
var hero;
var enemies = [];
var heroBullets = [];
var score = 0;
var scoreTxt;
var currentLevel = 1; // Add a variable to store the current level
// Initialize game elements
function initGame() {
hero = new Hero();
LK.playMusic('backgroundMusic');
LK.playMusic('backgroundMusic');
hero.x = 2048 / 2;
hero.y = 2732 - 200;
game.addChild(hero);
// Create a score board at the top of the screen
scoreTxt = new Text2('Score: 0', {
size: 150,
fill: "#ffffff"
});
// Initialize menu button
var menuButton = new MenuButton();
menuButton.x = 2048 - 100; // Position it at the top right corner
menuButton.y = 100; // A little bit down from the top edge
game.addChild(menuButton);
menuButton.up = function (x, y, obj) {
var menuPage = new MenuPage();
game.addChild(menuPage);
menuButton.destroy();
};
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create a board to display the score
var scoreBoard = new Container();
scoreBoard.x = 2048 / 2;
scoreBoard.y = 2732 / 2;
game.addChild(scoreBoard);
// Add the score text to the score board
scoreBoard.addChild(scoreTxt);
// Create a variable to store the score target for each level and increase it after each level
var scoreTarget = currentLevel * 10 + currentLevel; // For example, the score target for each level could be 10 times the current level plus the current level
// Spawn enemies at intervals
LK.setInterval(function () {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = -100;
game.addChild(enemy);
enemies.push(enemy);
}, 970 / (currentLevel * 1.96)); // Decrease the spawn rate and speed with each level by 4 percent
}
// Update game state
game.update = function () {
if (hero) {
hero.update();
}
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
if (enemies[i].intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
for (var j = heroBullets.length - 1; j >= 0; j--) {
heroBullets[j].update();
for (var k = enemies.length - 1; k >= 0; k--) {
if (heroBullets[j].intersects(enemies[k])) {
enemies[k].destroy();
enemies.splice(k, 1);
heroBullets[j].destroy();
heroBullets.splice(j, 1);
score++;
scoreTxt.setText('Score: ' + score);
// Check if the score has reached the target for the current level
if (score >= scoreTarget) {
// If so, move to the next level
currentLevel++;
// Show the level page
var level = new Level();
game.addChild(level);
// Increase game difficulty by 1.5 percent when player score reaches 20 and by 2 times when score reaches 40
if (score == 20) {
currentLevel += currentLevel * 0.015;
} else if (score == 40) {
currentLevel *= 2;
}
}
break;
}
}
}
};
// Handle touch events
game.down = function (x, y, obj) {
if (hero) {
hero.shoot();
}
hero.x = x;
};
// Handle keyboard events
game.on('keydown', function (event) {
switch (event.key) {
case ' ':
if (hero) {
hero.shoot();
}
break;
case 'a':
if (hero) {
hero.x -= hero.speed;
}
break;
case 'd':
if (hero) {
hero.x += hero.speed;
}
break;
}
});
// Initialize start button
var startButton = new StartButton();
game.addChild(startButton); /****
* Classes
****/
// BackButton class
var BackButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('backButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
// Add 'Back' text to the button
var backText = new Text2('Back', {
size: 50,
fill: "#ffffff"
});
backText.anchor.set(0.5, 0.5);
self.addChild(backText);
self.up = function (x, y, obj) {
var startButton = new StartButton();
game.addChild(startButton);
self.destroy();
var menuPage = game.children.find(function (child) {
return child instanceof MenuPage;
});
if (menuPage) {
menuPage.destroy();
}
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
//<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,
scaleX: 3,
scaleY: 3
});
self.speed = 10;
self.update = function () {
// Update logic for hero
};
self.shoot = function () {
var bullet = new HeroBullet();
bullet.x = self.x;
bullet.y = self.y - heroGraphics.height / 2;
game.addChild(bullet);
heroBullets.push(bullet);
LK.getSound('firingSound').play();
};
});
// 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 < 0) {
self.destroy();
}
};
});
// Level class
var Level = Container.expand(function () {
var self = Container.call(this);
var levelGraphics = self.attachAsset('level', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 4,
scaleY: 4
});
// Add 'level' text to the button
var levelText = new Text2('Level ' + currentLevel, {
// Update the level text to reflect the current level
size: 50,
fill: "#ffffff"
});
levelText.anchor.set(0.5, 0.5);
self.addChild(levelText);
self.x = 2048 / 2;
self.y = 2732 / 2;
self.up = function (x, y, obj) {
initGame();
currentLevel++; // Increase the level after each level
self.destroy();
};
});
// MenuButton class
var MenuButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('menuButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
// Add 'Menu' text to the button
var menuText = new Text2('Menu', {
size: 50,
fill: "#ffffff"
});
menuText.anchor.set(0.5, 0.5);
self.addChild(menuText);
self.up = function (x, y, obj) {
var menuPage = new MenuPage();
game.addChild(menuPage);
self.destroy();
};
});
// MenuPage class
var MenuPage = Container.expand(function () {
var self = Container.call(this);
var background = new Container();
background.width = 2048;
background.height = 2732;
background.color = 0x000000;
self.addChild(background);
// Add 'Sound' button to the menu page
var soundButton = new SoundButton();
soundButton.x = 2048 / 2;
soundButton.y = 2732 / 2 - 100;
self.addChild(soundButton);
// Add 'Back' button to the menu page
var backButton = new BackButton();
backButton.x = 2048 / 2;
backButton.y = 2732 / 2 + 100;
self.addChild(backButton);
// Toggle sound on/off
soundButton.up = function (x, y, obj) {
if (LK.isMusicPlaying()) {
LK.stopMusic();
LK.muteSound();
soundButton.setText('Sound: Off');
} else {
LK.unmuteSound();
LK.playMusic('backgroundMusic');
soundButton.setText('Sound: On');
}
};
// Go back to the start button page
backButton.up = function (x, y, obj) {
var startButton = new StartButton();
game.addChild(startButton);
self.destroy();
};
});
// SoundButton class
var SoundButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('menuButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
// Add 'Sound: On' text to the button
var soundText = new Text2('Sound: On', {
size: 50,
fill: "#ffffff"
});
soundText.anchor.set(0.5, 0.5);
self.addChild(soundText);
self.up = function (x, y, obj) {
// Toggle sound
if (LK.isMusicPlaying()) {
LK.stopMusic();
LK.muteSound();
soundText.setText('Sound: Off');
} else {
LK.unmuteSound();
LK.playMusic('backgroundMusic');
soundText.setText('Sound: On');
}
};
});
// StartButton class
var StartButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 8,
scaleY: 8
});
// Add 'start' text to the button
var startText = new Text2('Start', {
size: 100,
fill: "#ffffff"
});
startText.anchor.set(0.5, 0.5);
self.addChild(startText);
self.x = 2048 / 2;
self.y = 2732 / 2;
self.up = function (x, y, obj) {
// Initialize level
var level = new Level();
game.addChild(level);
self.destroy();
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Add background image
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2048 / 2048,
scaleY: 2732 / 2048,
x: 2048 / 2,
y: 2732 / 2
});
game.addChildAt(background, 0);
// Initialize variables
var hero;
var enemies = [];
var heroBullets = [];
var score = 0;
var scoreTxt;
var currentLevel = 1; // Add a variable to store the current level
// Initialize game elements
function initGame() {
hero = new Hero();
LK.playMusic('backgroundMusic');
LK.playMusic('backgroundMusic');
hero.x = 2048 / 2;
hero.y = 2732 - 200;
game.addChild(hero);
// Create a score board at the top of the screen
scoreTxt = new Text2('Score: 0', {
size: 150,
fill: "#ffffff"
});
// Initialize menu button
var menuButton = new MenuButton();
menuButton.x = 2048 - 100; // Position it at the top right corner
menuButton.y = 100; // A little bit down from the top edge
game.addChild(menuButton);
menuButton.up = function (x, y, obj) {
var menuPage = new MenuPage();
game.addChild(menuPage);
menuButton.destroy();
};
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create a board to display the score
var scoreBoard = new Container();
scoreBoard.x = 2048 / 2;
scoreBoard.y = 2732 / 2;
game.addChild(scoreBoard);
// Add the score text to the score board
scoreBoard.addChild(scoreTxt);
// Create a variable to store the score target for each level and increase it after each level
var scoreTarget = currentLevel * 10 + currentLevel; // For example, the score target for each level could be 10 times the current level plus the current level
// Spawn enemies at intervals
LK.setInterval(function () {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = -100;
game.addChild(enemy);
enemies.push(enemy);
}, 970 / (currentLevel * 1.96)); // Decrease the spawn rate and speed with each level by 4 percent
}
// Update game state
game.update = function () {
if (hero) {
hero.update();
}
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].update();
if (enemies[i].intersects(hero)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
for (var j = heroBullets.length - 1; j >= 0; j--) {
heroBullets[j].update();
for (var k = enemies.length - 1; k >= 0; k--) {
if (heroBullets[j].intersects(enemies[k])) {
enemies[k].destroy();
enemies.splice(k, 1);
heroBullets[j].destroy();
heroBullets.splice(j, 1);
score++;
scoreTxt.setText('Score: ' + score);
// Check if the score has reached the target for the current level
if (score >= scoreTarget) {
// If so, move to the next level
currentLevel++;
// Show the level page
var level = new Level();
game.addChild(level);
// Increase game difficulty by 1.5 percent when player score reaches 20 and by 2 times when score reaches 40
if (score == 20) {
currentLevel += currentLevel * 0.015;
} else if (score == 40) {
currentLevel *= 2;
}
}
break;
}
}
}
};
// Handle touch events
game.down = function (x, y, obj) {
if (hero) {
hero.shoot();
}
hero.x = x;
};
// Handle keyboard events
game.on('keydown', function (event) {
switch (event.key) {
case ' ':
if (hero) {
hero.shoot();
}
break;
case 'a':
if (hero) {
hero.x -= hero.speed;
}
break;
case 'd':
if (hero) {
hero.x += hero.speed;
}
break;
}
});
// Initialize start button
var startButton = new StartButton();
game.addChild(startButton);
make a fighter jet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
make fighter jets bullets. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
make a level logo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
make a space type background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
make a menu button logo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
make a start button logo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
make a back button logo. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.