User prompt
wait 2 seconds before spawning all the different obstacles
User prompt
the player should rotate to where it is moving to
User prompt
the player should not jump to the current pointer position but move to it with a certain speed
User prompt
instead of dragging the player by pointer, the player should move to the current pointer position (on pointer down).
Code edit (5 edits merged)
Please save this source code
User prompt
scale the player by 10% everytime the player intersects with the safezone
Code edit (1 edits merged)
Please save this source code
/**** * 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 ****/ var background = game.addChild(LK.getAsset('background', { anchorX: 0.0, anchorY: 0.0, x: 0, y: 0 })); // Initialize player var player = new Player(); player.x = 2048 / 2; player.y = 2732 / 2; game.addChild(player); background.zIndex = -1; // Initialize obstacles var obstacles = []; for (var i = 0; i < 3; 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'); // Play the background noise in a loop LK.getSound('backgroundNoise').play(); // Play the bicycleRing sound randomly, between 5 and 10 seconds var _playBicycleRing = function playBicycleRing() { LK.getSound('bicycleRing').play(); var nextPlayTime = Math.random() * 5000 + 5000; LK.setTimeout(_playBicycleRing, nextPlayTime); }; // _playBicycleRing(); // 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; var distance = Math.sqrt(dx * dx + dy * dy); var speed = 10; if (distance > speed) { var ratio = speed / distance; dx *= ratio; dy *= ratio; } dragNode.x += dx; dragNode.y += dy; // Rotate the player to the direction it is moving to dragNode.rotation = Math.atan2(dy, dx); } }; 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.getSound('crashSound').play(); LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Check if player is in the safe zone if (player.intersects(safeZone)) { if (Math.random() >= 0.5) { LK.getSound('humanSound').play(); } else { LK.getSound('collectSound').play(); } LK.effects.flashScreen(0x00ff00, 1000); // Increase score score++; scoreTxt.setText(score); // Scale the player by 10% if (player.scale.x < 2) { player.scale.x *= 1.1; player.scale.y *= 1.1; } // 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; } // Add another Obstacle or HorizontalObstacle every 10 seconds, do this 5 times if (LK.ticks % 600 == 0 && obstacles.length < 8 && LK.ticks > 120) { var startFromTop = Math.random() >= 0.5; var obstacle; if (obstacles.length % 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); LK.getSound('bicycleRing').play(); } };
===================================================================
--- original.js
+++ change.js
@@ -185,9 +185,9 @@
safeZone.x = Math.random() * (2048 - 200) + 100;
safeZone.y = Math.random() * (2732 - 200) + 100;
}
// Add another Obstacle or HorizontalObstacle every 10 seconds, do this 5 times
- if (LK.ticks % 600 == 0 && obstacles.length < 8) {
+ if (LK.ticks % 600 == 0 && obstacles.length < 8 && LK.ticks > 120) {
var startFromTop = Math.random() >= 0.5;
var obstacle;
if (obstacles.length % 2 == 0) {
obstacle = new Obstacle();
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