User prompt
On tap, make player jump to the next orbit.
Code edit (1 edits merged)
Please save this source code
User prompt
draw a circlular object called orbit1 with a diamter of 1800 pixels in the center
Code edit (1 edits merged)
Please save this source code
User prompt
Make the player circle around the center at a distance of 800 pixels.
Initial prompt
Approaching Orbit
/**** * Classes ****/ // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.jump = function () { // Player jump logic }; self.update = function () { var centerX = 2048 / 2; var centerY = 2732 / 2; var angleSpeed = 0.01; self.angle = (self.angle || 0) + angleSpeed; self.x = centerX + 900 * Math.cos(self.angle); self.y = centerY + 900 * Math.sin(self.angle); }; }); // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.move = function () { // Obstacle move logic }; }); // Orbit class var Orbit = Container.expand(function () { var self = Container.call(this); var orbitGraphics = self.attachAsset('orbit1', { anchorX: 0.5, anchorY: 0.5 }); self.positionOrbit = function () { self.x = 2048 / 2; self.y = 2732 / 2; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize assets used in this game. // Game variables var player; var orbits = []; var obstacles = []; var currentOrbitIndex = 0; // Initialize player player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2 - 200; // Start the player 200px above the center // Initialize orbits function createOrbits() { for (var i = 0; i < 5; i++) { var orbit = game.addChild(new Orbit()); orbit.positionOrbit(i); orbits.push(orbit); } } createOrbits(); // Initialize obstacles function createObstacles() { for (var i = 0; i < 10; i++) { var obstacle = game.addChild(new Obstacle()); obstacle.move(); obstacles.push(obstacle); } } createObstacles(); // Game logic game.on('down', function (obj) { player.jump(); }); LK.on('tick', function () { player.update(); // Update orbits for (var i = 0; i < orbits.length; i++) { orbits[i].positionOrbit(i); } // Update obstacles for (var i = 0; i < obstacles.length; i++) { obstacles[i].move(); if (player.intersects(obstacles[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Check if player reached the center if (player.intersects(orbits[0])) { LK.setScore(LK.getScore() + 1); // Reset player to the last orbit player.x = orbits[orbits.length - 1].x; player.y = orbits[orbits.length - 1].y; currentOrbitIndex = orbits.length - 1; } });
===================================================================
--- original.js
+++ change.js
@@ -33,14 +33,15 @@
});
// Orbit class
var Orbit = Container.expand(function () {
var self = Container.call(this);
- var orbitGraphics = self.attachAsset('orbit', {
+ var orbitGraphics = self.attachAsset('orbit1', {
anchorX: 0.5,
anchorY: 0.5
});
self.positionOrbit = function () {
- // Orbit positioning logic
+ self.x = 2048 / 2;
+ self.y = 2732 / 2;
};
});
/****