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
User prompt
the coin speed should be defined as a static value instead of a division from another value
Code edit (10 edits merged)
Please save this source code
User prompt
decrease the speed of the coin
User prompt
a coin is spawned similar to the obstacles, but instead of being spawned by tapping it's spawned when the score incremnts by 10. so at 10 spawn a coin, then another at 20 points then another 30 and so on. the coin spawns similarly to the obstacles in the sense they spawn one time from one side and the next from the other side. but coins start spawning from the left, so the first spawn from left, the second from right and then you repeat again from left. collecting a coin increases the score by 5 points
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
spawn the ink from the center of the player instead of lower from it
Code edit (1 edits merged)
Please save this source code
User prompt
ass a 200 pixels pad to both the top and bottom side of the screen, so enemies can only spawn 200 pixels higher than the bottom and 200 pixels lower than the top side of the screen
Code edit (1 edits merged)
Please save this source code
User prompt
instead of spawning just one enemy on every tap, spawn 2. one from the right and one from the left
User prompt
turn the player's hitbox into a circle instead of a square
Code edit (3 edits merged)
Please save this source code
User prompt
whenever the score incremnents, bump it's size by 20% before returning to it's original size
Code edit (2 edits merged)
Please save this source code
User prompt
fix the acceleration to also consider enemies spawning from the left, as right now the acceelration is setup as a negative value, making the enemies spawning from left reverse direction, which is a bug
User prompt
fix the acceleration to also consider enemies spawning from the left, as right now the acceelration is setup as a negative value, making the enemies spawning from left reverse direction, which is a bug
Code edit (1 edits merged)
Please save this source code
Code edit (1 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
});
});
// 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 += 6; // 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.05;
if (inkGraphics.alpha <= 0) {
LK.clearInterval(fadeInterval);
LK.clearInterval(moveInterval);
self.destroy();
}
}, 1);
}, 200); // 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
});
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.2;
this.acceleration = 0.001;
this.enemySpeed = -10;
this.enemyAcceleration = -1; // Add enemyAcceleration to the GameVariables class
this.velocityY = 0;
this.isJumping = false;
};
var gameVariables = new GameVariables();
var spawnSide = 'right';
var player = foregroundContainer.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
var obstacles = [];
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 + 200;
ink.fadeOut();
// Spawn new obstacles
var newObstacle = new Obstacle();
if (spawnSide === 'right') {
newObstacle.x = 2048;
newObstacle.speed = gameVariables.enemySpeed;
newObstacle.scored = false;
spawnSide = 'left';
} else {
newObstacle.x = 0;
newObstacle.speed = -gameVariables.enemySpeed;
newObstacle.scale.x = -1; // Flip the fish on its x-axis
newObstacle.scored = false;
spawnSide = 'right';
}
newObstacle.y = Math.random() * (2732 - newObstacle.height); // Position at a random height on the screen
obstacles.push(newObstacle);
game.addChild(newObstacle);
// Increment score
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
});
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();
}
});
// 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.