/****
* Plugins
****/
var storage = LK.import("@upit/storage.v1", {
highestScore: 0
});
/****
* Classes
****/
// Class for bullets
var Bullet = Container.expand(function (startX, startY) {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.5,
scaleY: 0.5
});
self.x = startX;
self.y = startY;
self.speed = -10;
self.update = function () {
self.y += self.speed;
if (self.y < -50) {
self.destroy();
bullets.splice(bullets.indexOf(self), 1);
}
};
});
// Class for enemies
var Enemy = Container.expand(function (type) {
var self = Container.call(this);
var enemyGraphics;
if (type === 'boss') {
enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2,
shape: 'ellipse'
});
} else {
enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
}
self.x = Math.random() * 2048;
self.y = -100;
self.speed = 2 + level * 0.5;
self.health = type === 'boss' ? 10 : 1;
self.update = function () {
if (type === 'boss') {
self.y += self.speed / 2; // Make the boss move slower
} else {
self.y += self.speed;
}
if (self.y > 2732) {
self.destroy();
enemies.splice(enemies.indexOf(self), 1);
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the player's paintball shooter
var Shooter = Container.expand(function () {
var self = Container.call(this);
var shooterGraphics = self.attachAsset('shooter', {
anchorX: 0.5,
anchorY: 0.5
});
self.shoot = function () {
var bullet = new Bullet(self.x, self.y);
game.addChild(bullet);
bullets.push(bullet);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
//<Write imports for supported plugins here>
//<Assets used in the game will automatically appear here>
// Set the 'arkaplan' image as the game background and apply a blur filter
var background = LK.getAsset('arkaplan', {
width: 2048,
height: 2732,
anchorX: 0.0,
anchorY: 0.0
});
game.addChild(background);
var shooter = new Shooter();
shooter.x = 1024;
shooter.y = 2500;
game.addChild(shooter);
var bullets = [];
var enemies = [];
var level = 1;
var enemyCount = 0;
var highestScore = storage.highestScore || 0; // Initialize the highest score from storage
game.update = function () {
if (LK.ticks % 60 === 0) {
if (enemyCount < 15) {
var enemy = new Enemy('normal');
enemy.x = 100 + Math.random() * 1848; // Spawn enemies between the red stripes
game.addChild(enemy);
enemies.push(enemy);
enemyCount++;
} else if (enemyCount === 15) {
var boss = new Enemy('boss');
boss.x = 100 + Math.random() * 1848; // Spawn boss between the red stripes
game.addChild(boss);
enemies.push(boss);
enemyCount++;
}
}
bullets.forEach(function (bullet) {
bullet.update();
});
enemies.forEach(function (enemy) {
enemy.update();
bullets.forEach(function (bullet) {
if (bullet.intersects(enemy)) {
enemy.health--;
bullet.destroy();
bullets.splice(bullets.indexOf(bullet), 1);
if (enemy.health <= 0) {
enemy.destroy();
enemies.splice(enemies.indexOf(enemy), 1);
LK.getSound('death').play(); // Play the 'death' sound effect when an enemy is destroyed
LK.setScore(LK.getScore() + 1); // Increment score by 1 when a box is broken
if (LK.getScore() > highestScore) {
// Check if the current score is higher than the highest score
highestScore = LK.getScore(); // Update the highest score
storage.highestScore = highestScore; // Persist the new highest score
highScoreTxt.setText('High Score: ' + highestScore);
} else {
highScoreTxt.setText('High Score: ' + highestScore);
}
scoreTxt.setText(LK.getScore().toString()); // Update the score display with the current score
if (enemyCount > 15) {
level++;
enemyCount = 0;
LK.setScore(LK.getScore() + 50); // Increment score by 50 when the boss is broken
if (LK.getScore() > highestScore) {
// Check if the current score is higher than the highest score
highestScore = LK.getScore(); // Update the highest score
storage.highestScore = highestScore; // Persist the new highest score
highScoreTxt.setText('High Score: ' + highestScore);
} else {
highScoreTxt.setText('High Score: ' + highestScore);
}
scoreTxt.setText('Score: ' + LK.getScore()); // Update the score display with the current score
}
}
}
});
// Check if the enemy has passed the shooter or collided with it
if (enemy.y >= shooter.y || enemy.intersects(shooter)) {
// There is no LK.setHighScore() function. We will use a variable to store the highest score.
// highestScore = LK.getScore() > highestScore ? LK.getScore() : highestScore;
LK.showGameOver(); // End the game
}
});
};
game.down = function (x, y, obj) {
shooter.shoot();
LK.getSound('ates').play(); // Play the 'ates' sound effect when shooting
if (LK.getScore() > highestScore) {
highestScore = LK.getScore();
storage.highestScore = highestScore; // Persist the new highest score
highScoreTxt.setText('High Score: ' + highestScore);
} else {
highScoreTxt.setText('High Score: ' + highestScore);
}
};
// Create a score display
var scoreTxt = new Text2('0', {
size: 100,
// Reduce the size of the score display
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0); // Sets anchor to the center of the top edge of the text.
LK.gui.center.addChild(scoreTxt); // Add the score text to the GUI overlay at the center of the screen.
// Create a high score display
var highScoreTxt = new Text2('High Score: 0', {
size: 50,
fill: 0xFFFFFF
});
highScoreTxt.anchor.set(1, 0); // Sets anchor to the right of the top edge of the text.
LK.gui.topRight.addChild(highScoreTxt); // Add the high score text to the GUI overlay at the top right of the screen.
// Create red stripes on the left and right side of the screen
var leftStripe = LK.getAsset('leftStripe', {});
game.addChild(leftStripe);
var rightStripe = LK.getAsset('rightStripe', {
x: 1948
});
game.addChild(rightStripe);
game.move = function (x, y, obj) {
shooter.x = x;
}; /****
* Plugins
****/
var storage = LK.import("@upit/storage.v1", {
highestScore: 0
});
/****
* Classes
****/
// Class for bullets
var Bullet = Container.expand(function (startX, startY) {
var self = Container.call(this);
var bulletGraphics = self.attachAsset('bullet', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.5,
scaleY: 0.5
});
self.x = startX;
self.y = startY;
self.speed = -10;
self.update = function () {
self.y += self.speed;
if (self.y < -50) {
self.destroy();
bullets.splice(bullets.indexOf(self), 1);
}
};
});
// Class for enemies
var Enemy = Container.expand(function (type) {
var self = Container.call(this);
var enemyGraphics;
if (type === 'boss') {
enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2,
shape: 'ellipse'
});
} else {
enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
}
self.x = Math.random() * 2048;
self.y = -100;
self.speed = 2 + level * 0.5;
self.health = type === 'boss' ? 10 : 1;
self.update = function () {
if (type === 'boss') {
self.y += self.speed / 2; // Make the boss move slower
} else {
self.y += self.speed;
}
if (self.y > 2732) {
self.destroy();
enemies.splice(enemies.indexOf(self), 1);
}
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the player's paintball shooter
var Shooter = Container.expand(function () {
var self = Container.call(this);
var shooterGraphics = self.attachAsset('shooter', {
anchorX: 0.5,
anchorY: 0.5
});
self.shoot = function () {
var bullet = new Bullet(self.x, self.y);
game.addChild(bullet);
bullets.push(bullet);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
//<Write imports for supported plugins here>
//<Assets used in the game will automatically appear here>
// Set the 'arkaplan' image as the game background and apply a blur filter
var background = LK.getAsset('arkaplan', {
width: 2048,
height: 2732,
anchorX: 0.0,
anchorY: 0.0
});
game.addChild(background);
var shooter = new Shooter();
shooter.x = 1024;
shooter.y = 2500;
game.addChild(shooter);
var bullets = [];
var enemies = [];
var level = 1;
var enemyCount = 0;
var highestScore = storage.highestScore || 0; // Initialize the highest score from storage
game.update = function () {
if (LK.ticks % 60 === 0) {
if (enemyCount < 15) {
var enemy = new Enemy('normal');
enemy.x = 100 + Math.random() * 1848; // Spawn enemies between the red stripes
game.addChild(enemy);
enemies.push(enemy);
enemyCount++;
} else if (enemyCount === 15) {
var boss = new Enemy('boss');
boss.x = 100 + Math.random() * 1848; // Spawn boss between the red stripes
game.addChild(boss);
enemies.push(boss);
enemyCount++;
}
}
bullets.forEach(function (bullet) {
bullet.update();
});
enemies.forEach(function (enemy) {
enemy.update();
bullets.forEach(function (bullet) {
if (bullet.intersects(enemy)) {
enemy.health--;
bullet.destroy();
bullets.splice(bullets.indexOf(bullet), 1);
if (enemy.health <= 0) {
enemy.destroy();
enemies.splice(enemies.indexOf(enemy), 1);
LK.getSound('death').play(); // Play the 'death' sound effect when an enemy is destroyed
LK.setScore(LK.getScore() + 1); // Increment score by 1 when a box is broken
if (LK.getScore() > highestScore) {
// Check if the current score is higher than the highest score
highestScore = LK.getScore(); // Update the highest score
storage.highestScore = highestScore; // Persist the new highest score
highScoreTxt.setText('High Score: ' + highestScore);
} else {
highScoreTxt.setText('High Score: ' + highestScore);
}
scoreTxt.setText(LK.getScore().toString()); // Update the score display with the current score
if (enemyCount > 15) {
level++;
enemyCount = 0;
LK.setScore(LK.getScore() + 50); // Increment score by 50 when the boss is broken
if (LK.getScore() > highestScore) {
// Check if the current score is higher than the highest score
highestScore = LK.getScore(); // Update the highest score
storage.highestScore = highestScore; // Persist the new highest score
highScoreTxt.setText('High Score: ' + highestScore);
} else {
highScoreTxt.setText('High Score: ' + highestScore);
}
scoreTxt.setText('Score: ' + LK.getScore()); // Update the score display with the current score
}
}
}
});
// Check if the enemy has passed the shooter or collided with it
if (enemy.y >= shooter.y || enemy.intersects(shooter)) {
// There is no LK.setHighScore() function. We will use a variable to store the highest score.
// highestScore = LK.getScore() > highestScore ? LK.getScore() : highestScore;
LK.showGameOver(); // End the game
}
});
};
game.down = function (x, y, obj) {
shooter.shoot();
LK.getSound('ates').play(); // Play the 'ates' sound effect when shooting
if (LK.getScore() > highestScore) {
highestScore = LK.getScore();
storage.highestScore = highestScore; // Persist the new highest score
highScoreTxt.setText('High Score: ' + highestScore);
} else {
highScoreTxt.setText('High Score: ' + highestScore);
}
};
// Create a score display
var scoreTxt = new Text2('0', {
size: 100,
// Reduce the size of the score display
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0); // Sets anchor to the center of the top edge of the text.
LK.gui.center.addChild(scoreTxt); // Add the score text to the GUI overlay at the center of the screen.
// Create a high score display
var highScoreTxt = new Text2('High Score: 0', {
size: 50,
fill: 0xFFFFFF
});
highScoreTxt.anchor.set(1, 0); // Sets anchor to the right of the top edge of the text.
LK.gui.topRight.addChild(highScoreTxt); // Add the high score text to the GUI overlay at the top right of the screen.
// Create red stripes on the left and right side of the screen
var leftStripe = LK.getAsset('leftStripe', {});
game.addChild(leftStripe);
var rightStripe = LK.getAsset('rightStripe', {
x: 1948
});
game.addChild(rightStripe);
game.move = function (x, y, obj) {
shooter.x = x;
};
bullet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
enemy. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
siyah arkaplan. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
siyah arkaplan. background. black