Code edit (11 edits merged)
Please save this source code
User prompt
instead of animating the rower every second, remove that automation, and only change the frame when the player moves from one side to the other, so when it leaves from the top towards the bottom, change it to the second frame. and when it moves from bottom to right change back to frame 1
User prompt
each tap should only boost the player by 300 pixels. also, instead of accelerating, the player should decelerate
User prompt
tapping the screen does nothing which is a bug, each tap should give the player a boost moving it upwards
User prompt
let's change how the player moves. instead of fully sending the player to the other edge of the screen, a tap only boosts the player by 400 pixels. and instead of having an acceleration, it needs to decelerate, when the player hits an edge of the screen, the player will now reverse it's direction, so when it touches the top part of the screen, each tap now moves the player towards the bottom
User prompt
the Rower needs to have an animation made of 2 frames. the first frame is the current Rower frame, while the second frame is Rower_1. alernate between these frames once every second
User prompt
attach the Rower to the player
Code edit (2 edits merged)
Please save this source code
User prompt
the player needs to also have acceleration. add the acceleration with the rest of the game variables, and only call it from the player. reset the acceleration when the player hits an edge of the screen. keep in mind the acceleration needs to work both when the player travels up and down
User prompt
the player acceleration needs to work both when the player is moving up and down. so keep it positive when it's traveling from top to bottom, but reverse it when mving from bottom to top
Code edit (1 edits merged)
Please save this source code
User prompt
move the player acceleration in the same place with the rest ofthe game variables
User prompt
add acceleration to the boat. reset it whenever it hits a screen edge
User prompt
actually recycle coins. after a coin is destroyed, insteadf of creating a new one, recycle one that has exited the screen, so tryo to minimize the amount of created coins, by recycling them with ones that have exited the screen
User prompt
the game starts lagging after a while, ensure the coins get destroyed after going off screen
User prompt
stretch the background across the entire screen. override the asset's properties
User prompt
ensure the background image is strectehed across teh entire screen. override the image's properties
Code edit (1 edits merged)
Please save this source code
User prompt
increase the player speed
User prompt
Determine the distance the player has moved from the starting position and use this distance to calculate the rotation angle. This calculation should ensure that the player completes a 360-degree rotation by the time it reaches the opposite edge of the screen. The rotation should be proportional to the distance moved.
User prompt
When the player starts moving from one edge (top or bottom), record the starting position and the direction of the movement (upwards or downwards).
User prompt
you didn't understand me correctly. when the player is moving from the top edge of the screen towards the bottom, it should do a complete 360 degreed clockwise rotation
User prompt
decrease the speed of the player
User prompt
when traveling from the top edge of the screen to the bottom one, the pklayer should do a full 360 clockwise rotation
User prompt
the player should stand still while touching an edge of the screen. it only needs to rotate while it's traveling either up or down
/**** * Classes ****/ // 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 () { if (self.spawnDirection === 'right') { self.x -= coinSpeed; } else { self.x += coinSpeed; } // Destroy coin when it moves off screen and remove it from the coins array if (self.x < -100 || self.x > 2048 + 100) { self.destroy(); var index = coins.indexOf(self); if (index > -1) { coins.splice(index, 1); } } }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.acceleration = 0; self.move = function () { self.acceleration += 0.2; if (self.spawnDirection === 'right') { self.x -= enemySpeed + self.acceleration; } else { self.x += enemySpeed + self.acceleration; } // Destroy enemy when it moves off screen and remove it from the enemies array if (self.x < -100 || self.x > 2048 + 100) { self.destroy(); var index = enemies.indexOf(self); if (index > -1) { enemies.splice(index, 1); } // Spawn a new enemy if the current number of enemies is less than the maximum number of enemies if (enemies.length < maxEnemies) { spawnEnemy(); } } }; }); // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = obstacleSpeed; self.move = function () { self.x += self.speed; // Destroy obstacle when it moves off screen if (self.x < -100) { self.destroy(); } }; }); // Assets will be automatically generated based on usage in the code. // Player class var Player = Container.expand(function () { var self = Container.call(this); playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.rowerFrame = 0; self.rowerGraphics = []; self.rowerGraphics.push(self.attachAsset('rower', { anchorX: 0.5, anchorY: 0.5 })); self.rowerGraphics.push(self.attachAsset('Rower_1', { anchorX: 0.5, anchorY: 0.5 })); self.rowerGraphics[1].visible = false; self.gravity = -1; // Start with gravity pulling upwards self.acceleration = 0; // Initialize acceleration self.flipGravity = function () { self.gravity *= -1; }; self.touchingEdge = false; self.update = function () { self.y += (playerSpeed + self.acceleration) * self.gravity; // Update Rower animation if (LK.ticks % 60 == 0) { self.rowerGraphics[self.rowerFrame].visible = false; self.rowerFrame = (self.rowerFrame + 1) % 2; self.rowerGraphics[self.rowerFrame].visible = true; } self.acceleration += 0.8; // Increase acceleration // Prevent player from going out of bounds if (self.y - playerGraphics.height / 2 <= 0) { self.y = playerGraphics.height / 2; self.acceleration = 0; // Reset acceleration if (self.gravity == -1 && !self.touchingEdge) { self.touchingEdge = true; LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore().toString()); scoreTxt.scale.set(1.2, 1.2); LK.setTimeout(function () { scoreTxt.scale.set(1, 1); }, 100); maxEnemies = Math.floor(LK.getScore() / 10); if (enemies.length < maxEnemies) { spawnEnemy(); } } } else if (self.y + playerGraphics.height / 2 >= 2732) { self.y = 2732 - playerGraphics.height / 2; self.acceleration = 0; // Reset acceleration if (self.gravity == 1 && !self.touchingEdge) { self.touchingEdge = true; LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore().toString()); maxEnemies = Math.floor(LK.getScore() / 10); if (enemies.length < maxEnemies) { spawnEnemy(); } } } else { self.touchingEdge = false; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var BackgroundContainer = new Container(); var MidgroundContainer = new Container(); var ForegroundContainer = new Container(); game.addChild(BackgroundContainer); game.addChild(MidgroundContainer); game.addChild(ForegroundContainer); var background = BackgroundContainer.attachAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366, width: 2048, height: 2732 }); // Game Variables // Assets will be automatically generated based on usage in the code. var playerGraphics; var player; var playerSpeed = 5; var score = 0; var scoreTxt; var obstacles = []; // Array to keep track of obstacles var obstacleSpeed = -10; var coins = []; // Initialize coins array var coinSpeed = 10; var coinSpawnDirection = 'right'; // Initialize coin spawn direction var enemies = []; // Initialize enemies array var maxEnemies = 0; // Initialize maximum number of enemies that can be spawned var enemySpawnDirection = 'left'; // Initialize enemy spawn direction var enemySpeed = 5; // Define enemy speed // Initialize Player player = game.addChild(new Player()); player.x = 1024; // Center horizontally player.y = 1366; // Center vertically // Initialize Score Display scoreTxt = new Text2(score.toString(), { size: 200, fill: "#ffffff", stroke: "#000000", strokeThickness: 20 }); scoreTxt.anchor.set(0.5, 0.5); scoreTxt.x = 1024; scoreTxt.y = 1366; MidgroundContainer.addChild(scoreTxt); // Create obstacles and coins at intervals function spawnEnemy() { // Check if the score is less than 10 if (LK.getScore() < 10) { return; } // Determine the number of enemies to spawn based on the player's score var numEnemies = Math.floor(LK.getScore() / 15); // Determine the spawn side based on the last spawn side var spawnSide = enemySpawnDirection; // Alternate the spawn side enemySpawnDirection = enemySpawnDirection === 'right' ? 'left' : 'right'; // Spawn enemies if the current number of enemies is less than the maximum number of enemies if (enemies.length < numEnemies) { var enemy = new Enemy(); enemy.spawnDirection = spawnSide; enemy.x = spawnSide === 'right' ? 2048 + 100 : -100; enemy.y = Math.random() * (2732 - 800) + 400; // Random height with 200 pixel padding at the top and bottom enemy.acceleration = 0; enemies.push(enemy); game.addChild(enemy); } } var enemyTimer = LK.setInterval(spawnEnemy, 1000); // Create an enemy every 1 second var coinTimer = LK.setInterval(function () { var coin; // Check if there are any coins that have exited the screen var exitedCoins = coins.filter(function (coin) { return coin.x < -100 || coin.x > 2048 + 100; }); // If there are exited coins, recycle the first one if (exitedCoins.length > 0) { coin = exitedCoins[0]; // Reset coin properties coin.spawnDirection = coinSpawnDirection; coin.y = Math.random() * (2732 - 600) + 300; // Random height with 200 pixel padding at the top and bottom } else { // If there are no exited coins, create a new one coin = new Coin(); coin.spawnDirection = coinSpawnDirection; coin.y = Math.random() * (2732 - 600) + 300; // Random height with 200 pixel padding at the top and bottom coins.push(coin); game.addChild(coin); } // Spawn coin from right or left alternately if (coinSpawnDirection === 'right') { coin.x = 2048; } else { coin.x = 0; } // Switch coin spawn direction coinSpawnDirection = coinSpawnDirection === 'right' ? 'left' : 'right'; }, 200); // Create a coin every 200 milliseconds // Listen for touch events to flip gravity game.on('down', function () { if (player.touchingEdge) { player.flipGravity(); } }); // Update game state on each tick LK.on('tick', function () { player.update(); obstacles.forEach(function (obstacle) { obstacle.move(); // Check for collision with player if (player.intersects(obstacle)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }); // Update coins and remove destroyed coins coins.forEach(function (coin, index) { coin.move(); // Check for collision with player if (player.intersects(coin)) { // Increase score by 1 LK.setScore(LK.getScore() + 1); // Update score text scoreTxt.setText(LK.getScore().toString()); // Add a small bump to the score whenever it increments by 1 scoreTxt.scale.set(1.2, 1.2); LK.setTimeout(function () { scoreTxt.scale.set(1, 1); }, 100); // Destroy the coin coin.destroy(); // Remove the coin from the coins array coins.splice(index, 1); } }); // Update enemies and remove destroyed enemies enemies.forEach(function (enemy, index) { enemy.move(); // Check for collision with player if (player.intersects(enemy)) { // Flash screen red for 1 second (1000ms) to show we are dead. LK.effects.flashScreen(0xff0000, 1000); // Show game over. The game will be automatically paused while game over is showing. LK.showGameOver(); } }); // Remove obstacles that have been destroyed obstacles = obstacles.filter(function (obstacle) { return !obstacle._destroyed; }); });
===================================================================
--- original.js
+++ change.js
@@ -76,20 +76,33 @@
playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
- var rowerGraphics = self.attachAsset('rower', {
+ self.rowerFrame = 0;
+ self.rowerGraphics = [];
+ self.rowerGraphics.push(self.attachAsset('rower', {
anchorX: 0.5,
anchorY: 0.5
- });
+ }));
+ self.rowerGraphics.push(self.attachAsset('Rower_1', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ self.rowerGraphics[1].visible = false;
self.gravity = -1; // Start with gravity pulling upwards
self.acceleration = 0; // Initialize acceleration
self.flipGravity = function () {
self.gravity *= -1;
};
self.touchingEdge = false;
self.update = function () {
self.y += (playerSpeed + self.acceleration) * self.gravity;
+ // Update Rower animation
+ if (LK.ticks % 60 == 0) {
+ self.rowerGraphics[self.rowerFrame].visible = false;
+ self.rowerFrame = (self.rowerFrame + 1) % 2;
+ self.rowerGraphics[self.rowerFrame].visible = true;
+ }
self.acceleration += 0.8; // Increase acceleration
// Prevent player from going out of bounds
if (self.y - playerGraphics.height / 2 <= 0) {
self.y = playerGraphics.height / 2;