User prompt
add a looping background music to the game
User prompt
when a fish is generated play the Fish sound
User prompt
when a coin is collected play the CoinCollect sound
User prompt
play the CoinGen soound when a new coin is being generated
User prompt
attach the Float sound to the player's tap
User prompt
Migrate to the latest version of LK
Code edit (1 edits merged)
Please save this source code
User prompt
display the coinsplosion for only 250 milisecs
User prompt
create a new asset called Coinsplosion and attach it to the coin when collect. as soon as the coin is collected, siplay this asset for 500 miliseconds
User prompt
the coin should increase the score by 3
Code edit (1 edits merged)
Please save this source code
User prompt
Consider implementing the flip animation through a different mechanism that might offer more consistent timing. This could involve manually updating the scale.x property on each game tick based on a custom timing counter that increments each tick and triggers the flip when reaching a certain threshold.
Code edit (1 edits merged)
Please save this source code
User prompt
the flipping coin animation code doesnt work use a different method to flip it
User prompt
the flipping coin animation code doesnt work use a different method to flip it
Code edit (1 edits merged)
Please save this source code
User prompt
the flipping coin animation code doesnt work use a different method to flip it
User prompt
the flipping coin animation code doesnt work use a different method to flip it
Code edit (1 edits merged)
Please save this source code
User prompt
the flipping coin animation code doesnt work use a different method to flip it
User prompt
the coin should flip horizontally every second
User prompt
this animation code soesnt work as intended. the problem is not the value but the code itself LK.setInterval(function () { self.flip(); }, 5000);
/**** * 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 = function () { self.x += self.speed; }; self.flip = function () { self.scale.x *= -1; }; // Initialize a tick counter for the coin flip animation self.flipTickCounter = 0; // Update the coin flip animation every tick self.update = function () { self.flipTickCounter++; if (self.flipTickCounter >= 300) { // 300 ticks is approximately 5000ms self.flip(); self.flipTickCounter = 0; } }; }); // 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.fadeOut = function () { // Start moving the ink instantly var moveInterval = LK.setInterval(function () { self.y += 8; // Move the ink 100 pixels lower over 1 second (1000ms) }, 1); // Delay the fading away of the ink 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 = 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 = 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()); 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 (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; // 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) + 100; // Position at a random height on the screen with 200 pixels padding from top and bottom obstacles.push(newObstacle); game.addChild(newObstacle); // 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); } // 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(); // 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(); 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(); coin.flip(); 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 5 when the player collects a coin LK.setScore(LK.getScore() + 5); scoreTxt.setText(LK.getScore()); // Remove the coin coin.destroy(); coins.splice(index, 1); } }); // Update and display the score scoreTxt.setText(LK.getScore()); });
/****
* 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 = function () {
self.x += self.speed;
};
self.flip = function () {
self.scale.x *= -1;
};
// Initialize a tick counter for the coin flip animation
self.flipTickCounter = 0;
// Update the coin flip animation every tick
self.update = function () {
self.flipTickCounter++;
if (self.flipTickCounter >= 300) {
// 300 ticks is approximately 5000ms
self.flip();
self.flipTickCounter = 0;
}
};
});
// 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.fadeOut = function () {
// Start moving the ink instantly
var moveInterval = LK.setInterval(function () {
self.y += 8; // Move the ink 100 pixels lower over 1 second (1000ms)
}, 1);
// Delay the fading away of the ink
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 = 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 = 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());
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 (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;
// 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) + 100; // Position at a random height on the screen with 200 pixels padding from top and bottom
obstacles.push(newObstacle);
game.addChild(newObstacle);
// 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);
}
// 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();
// 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();
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();
coin.flip();
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 5 when the player collects a coin
LK.setScore(LK.getScore() + 5);
scoreTxt.setText(LK.getScore());
// 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.