Code edit (2 edits merged)
Please save this source code
User prompt
the interval for the coin animation doesnt work, it flips much faster than intended which means the code is not correctly made
Code edit (3 edits merged)
Please save this source code
User prompt
the coin should flip horizontally every 500 miliseconds
Code edit (1 edits merged)
Please save this source code
User prompt
remove the speed from the coin itself since it's speed is already declared in the game's variables
Code edit (2 edits merged)
Please save this source code
User prompt
this part of the code sets the coin speed but it should be negative since it's spawning from the right, so making it negative should move it to the left } else { newCoin.x = 2048; newCoin.speed = gameVariables.coinSpeed; // Set coin speed as a static value coinSpawnSide = 'left';
User prompt
the speed of the coin should be set in a single place with the rest of the game variables, so the parts in this code that set it's speed should be dependent o nthat " newCoin.x = 0; newCoin.speed = 10; // Set coin speed as a static value coinSpawnSide = 'right'; } else { newCoin.x = 2048; newCoin.speed = 10; // Set coin speed as a static value coinSpawnSide = 'left';"
User prompt
ensure the coins speed has it's own speed variable and is not dependent on the enemy speed if (coinSpawnSide === 'left') { newCoin.x = 0; newCoin.speed = -gameVariables.enemySpeed; newCoin.acceleration = -gameVariables.enemyAcceleration; coinSpawnSide = 'right'; } else { newCoin.x = 2048; newCoin.speed = gameVariables.enemySpeed; newCoin.acceleration = gameVariables.enemyAcceleration; coinSpawnSide = 'left';
User prompt
ensure the coins speed has it's own speed variable and is not dependent on the enemy speed
Code edit (2 edits merged)
Please save this source code
User prompt
In the Coin class, set the speed to a constant value when defining the class and ensure this value is used directly in the move method without alteration. Ensure there are no calls or logic that modify the self.speed value within the move method or anywhere else after the initial assignment.
Code edit (1 edits merged)
Please save this source code
User prompt
Remove the Acceleration from the Coin Class: Since you want the coins to have a fixed speed, you should remove any lines that alter the speed after the coin is created. This includes removing or commenting out the line self.speed += self.acceleration; within the move function of the Coin class. Set a Fixed Speed Directly: Assign a fixed speed directly in the Coin class without referring to gameVariables. This ensures that the speed of all coins remains constant and unaffected by external variables.
Code edit (2 edits merged)
Please save this source code
User prompt
Change the Coin class so that it uses a fixed speed value directly in its move function. Remove or comment out the line where it sets self.speed = gameVariables.coinSpeed; and directly assign a fixed speed value to self.speed in its place.
Code edit (1 edits merged)
Please save this source code
User prompt
move the coin.s speed in the same place as the rest of the variables
Code edit (2 edits merged)
Please save this source code
User prompt
fix this
Code edit (3 edits merged)
Please save this source code
User prompt
remove acceleration from the coin, it should have a constant speed
User prompt
ensure the coin's speed is set in a single place in the code
Code edit (2 edits merged)
Please save this source code
/****
* 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.speed = 5;
self.acceleration = gameVariables.enemyAcceleration;
self.move = function () {
self.x += self.speed;
self.speed += self.acceleration;
};
});
// 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.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.enemySpeed;
newCoin.acceleration = -gameVariables.enemyAcceleration;
coinSpawnSide = 'right';
} else {
newCoin.x = 2048;
newCoin.speed = gameVariables.enemySpeed;
newCoin.acceleration = gameVariables.enemyAcceleration;
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();
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.