Code edit (4 edits merged)
Please save this source code
User prompt
When calling transitionPlanets flash the screen black
Code edit (12 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: NAVIGATION[currentPlanet] is not a constructor' in this line: 'planet = planets[currentPlanet] = new NAVIGATION[currentPlanet](GAME_WIDTH / 2, GAME_HEIGHT / 2);' Line Number: 416
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: crosshair.update is not a function' in this line: 'crosshair.update();' Line Number: 377
Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: navigation.setCurrent is not a function' in this line: 'navigation.setCurrent(currentPlanet);' Line Number: 359
User prompt
Fix Bug: 'ReferenceError: centerX is not defined' in this line: 'arrows[i].x = centerX + arrowOffsets[i].x * distance;' Line Number: 225
Code edit (6 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: moneyDisplay is undefined' in this line: 'moneyDisplay.setAmount(money -= button.cost);' Line Number: 275
Code edit (2 edits merged)
Please save this source code
User prompt
add a new CurrencyText in the top-center of the screen, with the settings of: {x:20, y: 100, anchor:{x:0}}, displaying the money variable
Code edit (3 edits merged)
Please save this source code
User prompt
add a Crosshair class that's comprised of 4 arrow assets pointing towards the center. There should also be a function to adjust the distance all the arrows are from the center
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: setText is not defined' in this line: 'self.setText = setText;' Line Number: 21
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: buttonText is not defined' in this line: 'currencySymbol.x = -buttonText.width / 2 - currencySymbol.width / 2;' Line Number: 88
User prompt
Create a CurrencyText class
Code edit (1 edits merged)
Please save this source code
User prompt
Add a currency symbol asset to the left of the buttonText. Similarly it should be destroyed when destroying the buttonText
Code edit (5 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -129,31 +129,53 @@
});
var Ship = Container.expand(function (x, y) {
var self = Container.call(this);
var shipGraphics = self.createAsset('ship', 'Ship asset', 0.35, 0.5);
+ var speed = 0;
;
+ self.update = update;
+ self.launch = launch;
self.x = x;
self.y = y;
- self.direction = 0;
- self.launch = launch;
+ self.direction = -1;
;
- function launch(direction) {}
+ function update() {
+ if (self.direction < 0) {
+ self.x -= ROCKET_SPEED_REVERSE;
+ if (self.x <= self.parent.radius) {
+ self.x = self.parent.radius;
+ self.direction = 0;
+ }
+ } else if (self.direction > 0) {
+ speed += ROCKET_SPEED_BASE;
+ speed = Math.min(ROCKET_SPEED_MAX, speed * ROCKET_SPEED_MULTI);
+ self.x += speed;
+ if (self.x > ROCKET_DIST_LEAVE) {
+ self.direction = -1;
+ transitionPlanets();
+ }
+ }
+ }
+ function launch(direction) {
+ speed = 0;
+ self.direction = direction;
+ }
});
var Planet = Container.expand(function (x, y, radius, assetName) {
var self = Container.call(this);
var perimeter = MATH_2_PI * radius;
var numPlots = Math.floor(perimeter / (PLOT_SIZE + PLOT_GAP));
var numNodes = numPlots / 4;
var farms = [];
- var ship = self.addChild(new Ship(radius, 0));
var planetGraphics = self.createAsset(assetName, assetName + ' asset', 0.5, 0.5);
planetGraphics.width = radius * 2;
planetGraphics.height = radius * 2;
;
self.update = update;
self.launch = launch;
self.x = x;
self.y = y;
+ self.radius = radius;
self.rotation = Math.random() * MATH_2_PI;
self.spin = 0;
;
function update(ticks) {
@@ -220,11 +242,16 @@
self.rotation = MATH_QUARTER_PI;
self.update = update;
;
function update() {
- counter++;
- var distance = CROSSHAIR_DIST + CROSSHAIR_VARIANCE * Math.sin(counter / CROSSHAIR_PERIOD);
- setDistance(distance);
+ if (currentPlanet !== destinationPlanet) {
+ counter++;
+ var distance = CROSSHAIR_DIST + CROSSHAIR_VARIANCE * Math.sin(counter / CROSSHAIR_PERIOD);
+ setDistance(distance);
+ } else if (counter > 0) {
+ counter = 0;
+ setDistance(CROSSHAIR_DIST);
+ }
}
function setDistance(distance) {
for (var i = 0; i < arrows.length; i++) {
arrows[i].x = arrowOffsets[i].x * distance;
@@ -273,25 +300,23 @@
;
function buttonCallback(index) {
var button = buttons[index];
if (button.unlocked) {
- // TODO: navigation
+ setDestination(index);
} else if (money >= button.cost) {
moneyDisplay.setAmount(money -= button.cost);
button.unlock();
}
}
- self.setCurrent = setCurrent;
- function setCurrent(index) {
- for (var i = 0; i < buttons.length; i++) {
- buttons[i].alpha = i === index ? 1 : 0.5;
+ self.setDestination = setDestination;
+ ;
+ function setDestination(index) {
+ destinationPlanet = index;
+ if (currentPlanet !== destinationPlanet && ship.direction === 0) {
+ buttons[index].addChild(crosshair);
+ ship.launch(1);
}
}
- ;
- function setCurrent(index) {
- var button = buttons[index];
- button.addChild(crosshair);
- }
buttonCallback(0);
});
/****
@@ -320,13 +345,13 @@
var PLANET_SPIN_RED = -0.0002;
var PLANET_SPIN_BLUE = 0.001;
var PLANET_SPIN_OMNI = 0.005;
var ROCKET_DIST_REVERSE = 200;
-var ROCKET_DIST_LEAVE = 1200;
-var ROCKET_SPEED_BASE = 0.05;
-var ROCKET_SPEED_MULTI = 1.5;
+var ROCKET_DIST_LEAVE = GAME_HEIGHT / 2;
+var ROCKET_SPEED_BASE = 0.001;
+var ROCKET_SPEED_MULTI = 1.2;
var ROCKET_SPEED_MAX = 30;
-var ROCKET_SPEED_REVERSE = 5;
+var ROCKET_SPEED_REVERSE = 2;
var PLOT_SIZE = 100;
var PLOT_GAP = 40;
var TEXT_OFFSETS = [[0, 1], [MATH_HALF_ROOT_3, 0.5], [MATH_HALF_ROOT_3, -0.5], [0, -1], [-MATH_HALF_ROOT_3, -0.5], [-MATH_HALF_ROOT_3, 0.5], [0, 0]];
var TEXT_BORDER_WEIGHT = 4;
@@ -335,32 +360,37 @@
var TEXT_DEFAULT_FILL = '#FFFFFF';
var TEXT_DEFAULT_BORDER = '#000000';
var CURRENCY_DEFAULT_MARGIN = 0;
var CROSSHAIR_DIST = 40;
-var CROSSHAIR_VARIANCE = 15;
-var CROSSHAIR_PERIOD = 2 * GAME_TICKS / MATH_2_PI;
+var CROSSHAIR_VARIANCE = 10;
+var CROSSHAIR_PERIOD = 1.25 * GAME_TICKS / MATH_2_PI;
var NAVIGATION = [{
cost: 0,
+ "class": PlanetGrey,
planet: 'planetGrey',
description: 'Small moon, with no special bonuses.'
}, {
cost: 100,
+ "class": PlanetRed,
planet: 'planetRed',
description: ''
}, {
cost: 250,
+ "class": PlanetBlue,
planet: 'planetBlue',
description: ''
}, {
cost: 800,
+ "class": PlanetOmni,
planet: 'planetOmni',
description: ''
}];
;
var money = 10000;
var currentPlanet = 0;
var destinationPlanet = currentPlanet;
var planet = game.addChild(new PlanetGrey(GAME_WIDTH / 2, GAME_HEIGHT / 2));
+var ship = planet.addChild(new Ship(planet.radius + ROCKET_DIST_REVERSE, 0));
var planets = [planet];
var moneyDisplay = LK.gui.top.addChild(new CurrencyText(money, {
x: 20,
y: 50,
@@ -370,10 +400,20 @@
}
}));
var crosshair = new Crosshair();
var navigation = LK.gui.bottom.addChild(new NavigationInterface(0, -100));
-navigation.setCurrent(currentPlanet);
+navigation.setDestination(0);
;
LK.on('tick', function () {
+ ship.update();
planet.update();
crosshair.update();
-});
\ No newline at end of file
+});
+;
+function transitionPlanets() {
+ currentPlanet = destinationPlanet;
+ planet = planets[currentPlanet];
+ if (!planet) {
+ planet = planets[currentPlanet] = new NAVIGATION[currentPlanet]['class'](GAME_WIDTH / 2, GAME_HEIGHT / 2);
+ }
+ ship.x = planet.radius + ROCKET_DIST_REVERSE;
+}
\ No newline at end of file
pixel art of a tiny planet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a planet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of an alien currency symbol. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a planet made of gold ore. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
plain black background with stars. 2d repeating Texture.
pixel art of a asteroid. Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a cute alien farmer, side view. Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a rocky explosion.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art flame particle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a large white, empty, rectangular, speech bubble. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art of a red chevron. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixel art of yellow grapes. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.