/****
* Classes
****/
// BackgroundContainer class
var BackgroundContainer = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2,
width: 2048,
height: 2732
});
});
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self._move_migrated = function () {
self.x += self.speed;
};
});
// Coinsplosion class
var Coinsplosion = Container.expand(function () {
var self = Container.call(this);
var coinsplosionGraphics = self.attachAsset('coinsplosion', {
anchorX: 0.5,
anchorY: 0.5
});
self.show = function () {
self.visible = true;
LK.setTimeout(function () {
self.visible = false;
}, 150);
};
});
// ForegroundContainer class
var ForegroundContainer = Container.expand(function () {
var self = Container.call(this);
});
// Ink class
var Ink = Container.expand(function () {
var self = Container.call(this);
var inkGraphics = self.attachAsset('ink', {
anchorX: 0.5,
anchorY: 0.5
});
self.ySpeed = 20; // Initialize y speed at the root of the class
self.fadeOut = function () {
var moveInterval = LK.setInterval(function () {
self.y += self.ySpeed; // Move the ink based on y speed
self.ySpeed *= 0.9; // Decrease y speed per movement
}, 1);
var fadeInterval = LK.setTimeout(function () {
var fadeInterval = LK.setInterval(function () {
inkGraphics.alpha -= 0.03;
if (inkGraphics.alpha <= 0) {
LK.clearInterval(fadeInterval);
LK.clearInterval(moveInterval);
self.destroy();
}
}, 1);
}, 300); // Delay of 1 second before the ink starts fading away
};
});
// MidgroundContainer class
var MidgroundContainer = Container.expand(function () {
var self = Container.call(this);
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
self.scored = false;
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = gameVariables.enemySpeed;
self.acceleration = gameVariables.enemyAcceleration; // Initialize acceleration for the enemies
self._move_migrated = function () {
self.x += self.speed;
self.speed += self.acceleration; // Add acceleration to the enemy's speed
self.y += Math.sin(self.x / 100) * 5; // Add oscillation to the enemy's movement
};
});
// Assets will be automatically created based on usage in the code.
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
shape: 'circle'
});
self.jumpSpeed = gameVariables.jumpSpeed;
self.gravity = gameVariables.gravity;
self.acceleration = gameVariables.acceleration;
self.velocityY = gameVariables.velocityY;
self.isJumping = gameVariables.isJumping;
self.jump = function () {
if (!self.isJumping) {
self.velocityY = self.jumpSpeed;
self.isJumping = true;
}
};
self._update_migrated = function () {
self.y += self.velocityY;
self.velocityY += self.gravity;
self.gravity += self.acceleration;
// Prevent player from falling below the ground
if (self.y > 2732 - playerGraphics.height / 2) {
self.y = 2732 - playerGraphics.height / 2;
self.isJumping = false;
self.velocityY = gameVariables.velocityY;
self.gravity = gameVariables.gravity;
self.acceleration = gameVariables.acceleration;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
var backgroundContainer = game.addChild(new BackgroundContainer());
LK.playMusic('backgroundMusic');
var midgroundContainer = game.addChild(new MidgroundContainer());
var foregroundContainer = game.addChild(new ForegroundContainer());
var background = backgroundContainer.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2,
width: 2048,
height: 2732
}));
// Game Variables class
var GameVariables = function GameVariables() {
this.jumpSpeed = -15;
this.gravity = 0.15;
this.acceleration = 0.003;
this.enemySpeed = -15;
this.enemyAcceleration = -0.1; // Add enemyAcceleration to the GameVariables class
this.coinSpeed = 12; // Set coin speed as a static value
this.velocityY = 0;
this.isJumping = false;
};
var gameVariables = new GameVariables();
var spawnSide = 'right';
var coinSpawnSide = 'left';
var player = foregroundContainer.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
var obstacles = [];
var coins = [];
var scoreTxt = new Text2('0', {
size: 200,
fill: "#ffffff",
align: "center",
stroke: '#000000',
strokeThickness: 10
});
scoreTxt.anchor.set(0.5, 0.5);
scoreTxt.x = 2048 / 2;
scoreTxt.y = 150;
midgroundContainer.addChild(scoreTxt);
game.on('down', function (x, y, obj) {
// Make the player jump 200 pixels upwards
player.y -= 300;
// Reset the player's speed to its initial state
player.velocityY = gameVariables.velocityY;
player.gravity = gameVariables.gravity;
player.acceleration = gameVariables.acceleration;
// Play the 'Float' sound
LK.getSound('Float').play();
// Generate Ink asset
var ink = midgroundContainer.addChild(new Ink());
ink.x = player.x;
ink.y = player.y + 100;
ink.fadeOut();
// Spawn new obstacles
var newObstacle = new Obstacle();
if (spawnSide === 'right') {
newObstacle.x = 2048;
newObstacle.speed = gameVariables.enemySpeed;
newObstacle.acceleration = gameVariables.enemyAcceleration; // Set acceleration for enemies spawning from the right
newObstacle.scored = false;
spawnSide = 'left';
} else {
newObstacle.x = 0;
newObstacle.speed = -gameVariables.enemySpeed;
newObstacle.acceleration = -gameVariables.enemyAcceleration; // Set negative acceleration for enemies spawning from the left
newObstacle.scale.x = -1; // Flip the fish on its x-axis
newObstacle.scored = false;
spawnSide = 'right';
}
newObstacle.y = Math.random() * (2732 - newObstacle.height - 100) + 130; // Position at a random height on the screen with 200 pixels padding from top and bottom
obstacles.push(newObstacle);
game.addChild(newObstacle);
// Play the 'Fish' sound
LK.getSound('Fish').play();
// Increment score
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
// Spawn a coin every time the score increments by 10
if (LK.getScore() % 10 === 0) {
var newCoin = new Coin();
if (coinSpawnSide === 'left') {
newCoin.x = 0;
newCoin.speed = gameVariables.coinSpeed; // Set coin speed as a negative value
coinSpawnSide = 'right';
} else {
newCoin.x = 2048;
newCoin.speed = -gameVariables.coinSpeed; // Set coin speed as a static value
coinSpawnSide = 'left';
}
newCoin.y = Math.random() * (2732 - newCoin.height - 100) + 100;
coins.push(newCoin);
game.addChild(newCoin);
// Play the 'CoinGen' sound
LK.getSound('CoinGen').play();
}
// Increase the size of the score text by 20%
scoreTxt.scale.set(1.3);
// Return the size of the score text to its original size after 100ms
LK.setTimeout(function () {
scoreTxt.scale.set(1);
}, 100);
});
LK.on('tick', function () {
player._update_migrated();
// Check if any part of the player touches the top or bottom side of the screen
if (player.y - player.height / 2 <= 0 || player.y + player.height / 2 >= 2732) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
obstacles.forEach(function (obstacle, index) {
obstacle._move_migrated();
if (obstacle.x < -100) {
// Remove obstacle if it moves off screen
obstacle.destroy();
obstacles.splice(index, 1);
}
if (player.intersects(obstacle)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
});
coins.forEach(function (coin, index) {
coin._move_migrated();
if (coin.x < -100) {
// Remove coin if it moves off screen
coin.destroy();
coins.splice(index, 1);
}
if (player.intersects(coin)) {
// Increase the score by 3 when the player collects a coin
LK.setScore(LK.getScore() + 3);
scoreTxt.setText(LK.getScore());
// Show Coinsplosion
var coinsplosion = game.addChild(new Coinsplosion());
coinsplosion.x = coin.x;
coinsplosion.y = coin.y;
coinsplosion.show();
// Play the 'CoinCollect' sound
LK.getSound('CoinCollect').play();
// Remove the coin
coin.destroy();
coins.splice(index, 1);
}
});
// Update and display the score
scoreTxt.setText(LK.getScore());
});
cute tiny octopus. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cute angry spearfish. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
inside the depths of the blue ocean background. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
silver octo coin. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
exploded silver fragments. pixelated. 8 bit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.