/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// New Creature class representing a different enemy
var Creature = Container.expand(function () {
var self = Container.call(this);
var creatureGraphics = self.attachAsset('creature', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
// Move the creature down the screen
self.y += self.speed;
// Add a simple bounce animation to the creature
tween(self, {
y: self.y + 20
}, {
duration: 500,
easing: tween.bounceInOut,
onFinish: function onFinish() {
tween(self, {
y: self.y - 20
}, {
duration: 500,
easing: tween.bounceInOut
});
}
});
// Removed rotation animation for performance optimization
};
});
// Enemy class representing the enemies
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.update = function () {
// Move the enemy down the screen
self.y += self.speed;
// Add a simple animation to the enemy
// Removed rotation animation for performance optimization
};
});
// New HorizontalCreature class representing a creature that moves horizontally across the screen
var HorizontalCreature = Container.expand(function () {
var self = Container.call(this);
var creatureGraphics = self.attachAsset('creature', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.direction = 1; // 1 for right, -1 for left
self.update = function () {
// Move the creature horizontally across the screen
self.x += self.speed * self.direction;
// Change direction if it reaches the screen edges
if (self.x > 2048 || self.x < 0) {
self.direction *= -1;
}
};
});
// Maze class representing the maze box
var Maze = Container.expand(function () {
var self = Container.call(this);
var mazeGraphics = self.attachAsset('maze', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for the maze
};
});
// New MazeCreature class representing a creature that spawns randomly in the maze and moves downward
var MazeCreature = Container.expand(function () {
var self = Container.call(this);
var creatureGraphics = self.attachAsset('creature', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Move the creature down the screen
self.y += self.speed;
// Check if the creature has moved off the bottom of the screen
if (self.y > 2732 + 100) {
self.destroy();
}
};
});
// Monster class representing a monster that spawns above the player
var Monster = Container.expand(function () {
var self = Container.call(this);
var monsterGraphics = self.attachAsset('creature', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Move the monster down the screen
self.y += self.speed;
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Ninja class representing the player character
var Ninja = Container.expand(function () {
var self = Container.call(this);
var ninjaGraphics = self.attachAsset('ninja', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
// Update logic for the ninja
// Move left if the ninja is not at the left edge of the screen
if (self.x > 0) {
self.x -= self.speed;
// Removed rotation animation for performance optimization
}
// Move right if the ninja is not at the right edge of the screen
if (self.x < 2048) {
self.x += self.speed;
}
// Reset rotation when the ninja is not moving
if (self.speed == 0) {}
};
self.dodge = function () {
// Logic for dodging obstacles
// Add a visual effect when dodging obstacles
LK.effects.flashObject(self, 0x0000FF, 500); // Flash blue for 500ms
};
self.slice = function () {
// Logic for slicing through enemies
// Add a visual effect when slicing through enemies
LK.effects.flashObject(self, 0x00FF00, 500); // Flash green for 500ms
};
});
// Obstacle class representing the obstacles
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Move the obstacle down the screen
// Check if we reached the Y position (0) right at this frame now as we were not there before (last update tick)
self.y += self.speed * 1.9; // Apply 90% gravity effect to the obstacle
if (self.lastY <= 0 && self.y > 0) {
// Additional logic if needed when the obstacle moves past the top
self.y = 0; // Ensure the obstacle is not stuck at the top
// Additional logic if needed when the obstacle moves past the top
}
self.lastY = self.y;
};
});
// PowerUp class representing a power-up item
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Move the power-up down the screen
self.y += self.speed;
};
});
// New RandomCreature class representing a creature that spawns randomly and moves downward
var RandomCreature = Container.expand(function () {
var self = Container.call(this);
var creatureGraphics = self.attachAsset('creature', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Move the creature down the screen
self.y += self.speed;
// Check if the creature has moved off the bottom of the screen
if (self.y > 2732 + 100) {
self.destroy();
}
};
});
// New UpwardCreature class representing a creature that moves from bottom to top
var UpwardCreature = Container.expand(function () {
var self = Container.call(this);
var creatureGraphics = self.attachAsset('creature', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Move the creature up the screen
self.y -= self.speed;
// Check if the creature has moved off the top of the screen
if (self.y < -100) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x6F4E37 // Set background color to a coffee brown
});
/****
* Game Code
****/
// Function to darken background color dynamically every second
function changeBackgroundColor() {
var currentColor = game.backgroundColor;
var red = currentColor >> 16 & 0xFF;
var green = currentColor >> 8 & 0xFF;
var blue = currentColor & 0xFF;
// Calculate new darker color values
red = Math.max(0, red - 5);
green = Math.max(0, green - 5);
blue = Math.max(0, blue - 5);
// Tween to the new darker color
tween(game, {
backgroundColor: red << 16 | green << 8 | blue
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Continue the animation loop
changeBackgroundColor();
}
});
}
// Set interval to change background color every second
LK.setInterval(changeBackgroundColor, 1000);
// Update ninja
LK.playMusic('bgmusic', {
loop: true,
fade: {
start: 0,
end: 1,
duration: 2000
}
});
//<Assets used in the game will automatically appear here>
// Function to spawn horizontal moving creatures
function spawnHorizontalCreature() {
var horizontalCreature = new HorizontalCreature();
horizontalCreature.x = Math.random() * 2048; // Random x position
horizontalCreature.y = Math.random() * 2732; // Random y position
creatures.push(horizontalCreature);
game.addChild(horizontalCreature);
}
// Set interval to spawn horizontal moving creatures
var horizontalCreatureSpawnInterval = 6000;
var horizontalCreatureSpawnTimer = LK.setInterval(spawnHorizontalCreature, horizontalCreatureSpawnInterval);
// Set interval to spawn random creatures
var randomCreatureSpawnInterval = 3000;
var randomCreatureSpawnTimer = LK.setInterval(spawnRandomCreature, randomCreatureSpawnInterval);
// Function to spawn random creatures
function spawnRandomCreature() {
var randomCreature = new RandomCreature();
randomCreature.x = Math.random() * 2048; // Random x position
randomCreature.y = -100; // Start above the screen
creatures.push(randomCreature);
game.addChild(randomCreature);
}
// Function to spawn MazeCreatures
function spawnMazeCreature() {
var mazeCreature = new MazeCreature();
mazeCreature.x = 1024; // Fixed x position within the maze
mazeCreature.y = 1366; // Fixed y position within the maze
creatures.push(mazeCreature);
game.addChild(mazeCreature);
}
// Set interval to spawn maze creatures
var mazeCreatureSpawnInterval = 5000;
var mazeCreatureSpawnTimer = LK.setInterval(spawnMazeCreature, mazeCreatureSpawnInterval);
// Set interval to spawn upward moving creatures
var upwardCreatureSpawnInterval = 4000;
var upwardCreatureSpawnTimer = LK.setInterval(spawnUpwardCreature, upwardCreatureSpawnInterval);
// Set interval to spawn power-ups
var powerUpSpawnInterval = 10000;
var powerUpSpawnTimer = LK.setInterval(spawnPowerUp, powerUpSpawnInterval);
// Function to spawn power-ups
function spawnPowerUp() {
var powerUp = new PowerUp();
powerUp.x = Math.random() * 2048;
powerUp.y = -100;
powerUps.push(powerUp);
game.addChild(powerUp);
}
// Initialize array to keep track of power-ups
var powerUps = [];
// Set interval to spawn monsters
var monsterSpawnInterval = 3000;
var monsterSpawnTimer = LK.setInterval(spawnMonster, monsterSpawnInterval);
// Function to spawn monsters
function spawnMonster() {
var monster = new Monster();
monster.x = ninja.x; // Spawn above the ninja
monster.y = -100;
monsters.push(monster);
game.addChild(monster);
}
// Set interval to spawn creatures
var creatureSpawnInterval = 2000;
var creatureSpawnTimer = LK.setInterval(spawnCreature, creatureSpawnInterval);
// Function to spawn creatures
function spawnCreature() {
var creature = new Creature();
creature.x = Math.random() * 2048;
creature.y = -100;
creatures.push(creature);
game.addChild(creature);
}
// Initialize arrays to keep track of enemies, obstacles, creatures, and monsters
var enemies = [];
var obstacles = [];
var creatures = [];
var monsters = [];
// Create the ninja character and add to the game
var ninja = game.addChild(new Ninja());
ninja.x = 2048 / 2;
ninja.y = 2732 - 200;
// Create the maze and add to the game
var maze = game.addChild(new Maze());
maze.x = ninja.x;
maze.y = -100;
// Function to handle game updates
game.update = function () {
// Update ninja
ninja.update();
// Update enemies
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
if (enemy.y <= 2732) {
enemy.update();
} else {
enemy.destroy();
enemies.splice(i, 1);
}
}
// Update creatures
for (var c = creatures.length - 1; c >= 0; c--) {
var creature = creatures[c];
if (creature.y <= 2732) {
creature.update();
} else {
creature.destroy();
creatures.splice(c, 1);
}
}
// Update monsters
for (var m = monsters.length - 1; m >= 0; m--) {
var monster = monsters[m];
if (monster.y <= 2732) {
monster.update();
} else {
monster.destroy();
monsters.splice(m, 1);
}
}
// Update obstacles
for (var j = obstacles.length - 1; j >= 0; j--) {
var obstacle = obstacles[j];
if (obstacle.y <= 2732) {
obstacle.update();
} else {
obstacle.destroy();
obstacles.splice(j, 1);
}
}
// Update the score text
scoreText.setText(LK.getScore());
// Check for collisions between ninja and enemies
for (var k = 0; k < enemies.length; k++) {
if (ninja.intersects(enemies[k])) {
// Handle collision with enemy
// Add a visual effect when colliding with an enemy
LK.effects.flashScreen(0xFF0000, 1000); // Flash screen red for 1 second
// Removed screen flash effect for performance optimization
// Display the score when the game is over
var score = LK.getScore();
scoreText.setText("Score: " + score);
LK.showGameOver();
}
}
// Check for collisions between ninja and creatures
for (var m = 0; m < creatures.length; m++) {
if (ninja.intersects(creatures[m])) {
// Handle collision with creature
// Removed screen flash effect for performance optimization
// Display the score when the game is over
var score = LK.getScore();
scoreText.setText("Score: " + score);
LK.showGameOver();
}
}
// Check for collisions between ninja and power-ups
for (var p = 0; p < powerUps.length; p++) {
if (ninja.intersects(powerUps[p])) {
// Handle collision with power-up
ninja.speed += 5; // Increase ninja's speed temporarily
// Add a visual effect when collecting a power-up
LK.effects.flashObject(ninja, 0xFFFF00, 500); // Flash yellow for 500ms
powerUps[p].destroy();
powerUps.splice(p, 1);
}
}
// Check for collisions between ninja and obstacles
for (var l = 0; l < obstacles.length; l++) {
if (ninja.intersects(obstacles[l])) {
// Handle collision with obstacle
ninja.dodge();
}
}
};
// Create a Text2 object to display the score
var scoreText = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
// Add the score text to the GUI overlay at the top-center of the screen
LK.gui.top.addChild(scoreText);
// Function to spawn enemies
function spawnEnemy() {
var enemy = new Enemy();
enemy.x = Math.random() * 2048;
enemy.y = -100;
enemies.push(enemy);
game.addChild(enemy);
}
// Function to increase score every second
function increaseScore() {
LK.setScore(LK.getScore() + 1);
if (LK.ticks % 60 === 0) {
// Update score text every second
scoreText.setText(LK.getScore());
}
}
var scoreIncreaseTimer = LK.setInterval(increaseScore, 1000);
// Function to spawn obstacles
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048;
obstacle.y = -100;
obstacle.lastY = obstacle.y; // Initialize lastY for tracking changes on Y
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Set intervals to spawn enemies and obstacles
var enemySpawnInterval = 3000;
var obstacleSpawnInterval = 7000;
var enemySpawnTimer = LK.setInterval(spawnEnemy, enemySpawnInterval);
var obstacleSpawnTimer = LK.setInterval(spawnObstacle, obstacleSpawnInterval);
// Increase difficulty every 5 seconds
var difficultyIncreaseTimer = LK.setInterval(function () {
enemySpawnInterval = Math.max(1000, enemySpawnInterval - 50);
obstacleSpawnInterval = Math.max(2000, obstacleSpawnInterval - 100);
LK.clearInterval(enemySpawnTimer);
LK.clearInterval(obstacleSpawnTimer);
enemySpawnTimer = LK.setInterval(spawnEnemy, enemySpawnInterval);
obstacleSpawnTimer = LK.setInterval(spawnObstacle, obstacleSpawnInterval);
}, 10000);
// Handle touch events for ninja actions
game.down = function (x, y, obj) {
// Move the ninja to the touched position
ninja.x = x;
};
game.up = function (x, y, obj) {
// Stop the ninja's movement when the touch is released
ninja.speed = 0;
};
// Function to spawn upward moving creatures
function spawnUpwardCreature() {
var upwardCreature = new UpwardCreature();
upwardCreature.x = Math.random() * 2048;
upwardCreature.y = 2732 + 100; // Start below the screen
creatures.push(upwardCreature);
game.addChild(upwardCreature);
}
Ninja. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Zombie pixer. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Canavar örüncek. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Kanatları açık canavar bir tavuk. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows