Code edit (1 edits merged)
Please save this source code
User prompt
add another Obstacle or HorizontalObstacle every 10 seconds, do this 5 times
Code edit (1 edits merged)
Please save this source code
User prompt
play the bicycleRing randomly, between 5 and 10 seconds
User prompt
play the backgroundNoise in a loop
Code edit (4 edits merged)
Please save this source code
User prompt
add a sound backgroundNoise
User prompt
make the player start in the center of the game
User prompt
create a background image which covers the whole game
User prompt
implement a gradual rotation approach. Instead of instantly setting the player's rotation to the angle between its current position
User prompt
rotate the player to where it is moving to
User prompt
Rotate the HorizontalObstacle to the direction it is heading
User prompt
the obstacle should rotate to where it is heading
Code edit (2 edits merged)
Please save this source code
User prompt
play the bg music on game start
Code edit (1 edits merged)
Please save this source code
User prompt
if the obstacle starts at the bottom, it should move to the top
User prompt
the Obstacle can either start at the top - like now, or at the bottom and move to the top
User prompt
spawn the HorizontalObstacle just like the Obstacle
User prompt
make a HorizontalObstacle class which moves from side to side
User prompt
make a few obstacles which move from one side to the other, in a cos wave movement
User prompt
make the obstacle fall down in a sin wave
Code edit (1 edits merged)
Please save this source code
User prompt
add a score. Everytime the player hits the safezone increase the score
User prompt
if the player reaches the safe zone, the safe zone spawns randomly on the game canvas. Make sure the safe zone is not outside the game, but within a 100px margin
/**** * Classes ****/ // Define a class for horizontal moving obstacles var HorizontalObstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.x += self.speed; self.y += Math.cos(self.x / 100) * 10; // Rotate the obstacle to the direction it is heading self.rotation = Math.atan2(Math.cos(self.x / 100) * 10, self.speed); if (self.x > 2048) { self.x = -obstacleGraphics.width; self.y = Math.random() * 2732; } }; }); // Define a class for moving obstacles var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.startsBottom = false; self.update = function () { var dir = self.startsBottom ? -1 : 1; self.y += self.speed * dir; self.x += Math.cos(self.y / 100) * 10; // Rotate the obstacle to the direction it is heading self.rotation = Math.atan2(self.speed * dir, Math.cos(self.y / 100) * 10); if (!self.startsBottom && self.y > 2732) { self.y = -obstacleGraphics.height; self.x = Math.random() * 2048; } else if (self.startsBottom && self.y < -obstacleGraphics.height) { self.y = 2732 + obstacleGraphics.height; self.x = Math.random() * 2048; } }; }); //<Assets used in the game will automatically appear here> // Define a class for the player character var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; self.update = function () { // Player update logic if needed }; }); // Define a class for the safe zone var SafeZone = Container.expand(function () { var self = Container.call(this); var safeZoneGraphics = self.attachAsset('safeZone', { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize player var player = new Player(); player.x = 2048 / 2; player.y = 2732 - 150; game.addChild(player); // Initialize obstacles var obstacles = []; for (var i = 0; i < 5; i++) { var startFromTop = Math.random() >= 0.5; var obstacle; if (i % 2 == 0) { obstacle = new Obstacle(); obstacle.startsBottom = !startFromTop; obstacle.y = startFromTop ? Math.random() * -2732 : 2732 - Math.random() * 2732; } else { obstacle = new HorizontalObstacle(); obstacle.x = Math.random() * -2048; } obstacle.x = Math.random() * 2048; obstacles.push(obstacle); game.addChild(obstacle); } // Initialize safe zone var safeZone = new SafeZone(); safeZone.x = 2048 / 2; safeZone.y = 550; game.addChild(safeZone); // Initialize score var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Play the background music // LK.playMusic('bg'); // Handle player movement var dragNode = null; game.down = function (x, y, obj) { dragNode = player; }; game.move = function (x, y, obj) { if (dragNode) { var dx = x - dragNode.x; var dy = y - dragNode.y; dragNode.rotation = Math.atan2(dy, dx); dragNode.x = x; dragNode.y = y; } }; game.up = function (x, y, obj) { dragNode = null; }; // Update game logic game.update = function () { // Update obstacles for (var i = 0; i < obstacles.length; i++) { obstacles[i].update(); if (player.intersects(obstacles[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Check if player is in the safe zone if (player.intersects(safeZone)) { LK.effects.flashScreen(0x00ff00, 1000); // Increase score score++; scoreTxt.setText(score); // Randomly position the safe zone within the game canvas with a 100px margin safeZone.x = Math.random() * (2048 - 200) + 100; safeZone.y = Math.random() * (2732 - 200) + 100; } };
===================================================================
--- original.js
+++ change.js
@@ -119,8 +119,11 @@
dragNode = player;
};
game.move = function (x, y, obj) {
if (dragNode) {
+ var dx = x - dragNode.x;
+ var dy = y - dragNode.y;
+ dragNode.rotation = Math.atan2(dy, dx);
dragNode.x = x;
dragNode.y = y;
}
};
vietnamese on a bike, top down, from above, flat, 8 bit art, pixel art, Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
top down view of a big crossroad, pixelart style, from above. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a round pizza, flat. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat