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
User prompt
tint NavigationButtons red. When the unlock function is called, reset the tint and destroy the buttonText
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: b is not defined' in this line: 'b;' Line Number: 142
Code edit (1 edits merged)
Please save this source code
User prompt
Convert the buttonContainer into a class called NavigationInterface
/**** * Classes ****/ var BorderedText = Container.expand(function (string, settings) { var self = Container.call(this); settings = settings || {}; var textList = []; var borderSettings = { fill: settings.border || TEXT_DEFAULT_BORDER, font: settings.font || TEXT_DEFAULT_FONT, size: settings.size || TEXT_DEFAULT_SIZE }; var textSettings = { fill: settings.fill || TEXT_DEFAULT_FILL, font: settings.font || TEXT_DEFAULT_FONT, size: settings.size || TEXT_DEFAULT_SIZE }; for (var i = 0; i < TEXT_OFFSETS.length; i++) { var localSettings = i === TEXT_OFFSETS.length - 1 ? textSettings : borderSettings; var text = self.addChild(new Text2(string, localSettings)); text.x += TEXT_OFFSETS[i][0] * TEXT_BORDER_WEIGHT; text.y += TEXT_OFFSETS[i][1] * TEXT_BORDER_WEIGHT; if (settings.anchor) { text.anchor.set(settings.anchor.x || 0, settings.anchor.y || 0); } textList.push(text); } ; self.x = settings.x; self.y = settings.y; self.setText = setText; self.setFill = setFill; ; function setText(string) { for (var i = 0; i < textList.length; i++) { textList[i].setText(string); } } function setFill(newFill) { textList[textList.length - 1].fill = newFill; } }); var CurrencySymbol = Container.expand(function (settings) { var self = Container.call(this); settings = settings || {}; var mainSymbol; var anchor = settings.anchor || { x: .5, y: .5 }; var anchorX = anchor.x !== undefined ? anchor.x : .5; var anchorY = anchor.y !== undefined ? anchor.y : .5; var borderSettings = { fill: 0x000000, // fill: settings.border || TEXT_DEFAULT_BORDER, size: settings.size || TEXT_DEFAULT_SIZE }; var symbolSettings = { fill: 0xFFFFFF, // fill: settings.fill || TEXT_DEFAULT_FILL, size: settings.size || TEXT_DEFAULT_SIZE }; for (var i = 0; i < TEXT_OFFSETS.length; i++) { var localSettings = i === TEXT_OFFSETS.length - 1 ? symbolSettings : borderSettings; var symbol = self.createAsset('currencySymbol', 'Currency symbol asset', anchorX, anchorY); symbol.tint = localSettings.fill; symbol.scale.set(localSettings.size / 100); symbol.x += TEXT_OFFSETS[i][0] * TEXT_BORDER_WEIGHT; symbol.y += TEXT_OFFSETS[i][1] * TEXT_BORDER_WEIGHT; if (i === TEXT_OFFSETS.length - 1) { mainSymbol = symbol; } } ; self.x = settings.x; self.y = settings.y; self.setFill = setFill; ; function setFill(newFill) { mainSymbol.tint = newFill; } }); var CurrencyText = Container.expand(function (amount, settings) { var self = Container.call(this); settings = settings || {}; var anchor = settings.anchor || { x: .5, y: .5 }; var anchorX = anchor.x != undefined ? anchor.x : .5; var anchorY = anchor.y != undefined ? anchor.y : .5; var margin = settings.margin || CURRENCY_DEFAULT_MARGIN; var currencySymbol = self.addChild(new CurrencySymbol({ anchor: { x: 0, y: anchorY } })); var textAmount = self.addChild(new BorderedText(amount, { anchor: { y: anchorY } })); ; self.x = settings.x || 0; self.y = settings.y || 0; self.setAmount = setAmount; ; function alignText() { var totalWidth = currencySymbol.width + margin + textAmount.width; currencySymbol.x = -totalWidth * anchorX; textAmount.x = currencySymbol.x + currencySymbol.width + margin; } function setAmount(newAmount) { textAmount.setText(newAmount); alignText(); } ; alignText(); }); var Farm = Container.expand(function (x, y, rotation) { var self = Container.call(this); var farmGraphics = self.createAsset('farm', 'Farm asset', 0.5, 0.65); farmGraphics.width = PLOT_SIZE; ; self.x = x; self.y = y; self.rotation = rotation; }); var Ship = Container.expand(function (x, y) { var self = Container.call(this); var shipGraphics = self.createAsset('ship', 'Ship asset', 0.35, 0.5); ; self.x = x; self.y = y; self.direction = 0; self.launch = launch; ; function launch(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.rotation = Math.random() * MATH_2_PI; self.spin = 0; ; function update(ticks) { self.rotation += self.spin; } function launch(direction) {} function createFarms() { for (var i = 1; i < numPlots; i++) { var angle = i / numPlots * MATH_2_PI; var farmX = radius * Math.cos(angle); var farmY = radius * Math.sin(angle); var rotation = angle + MATH_HALF_PI; farms.push(self.addChild(new Farm(farmX, farmY, rotation))); } } ; createFarms(); return self; }); var PlanetGrey = Planet.expand(function (x, y) { var self = Planet.call(this, x, y, PLANET_RADIUS_GREY, 'planetGrey'); ; self.spin = PLANET_SPIN_GREY; }); var PlanetRed = Planet.expand(function (x, y) { var self = Planet.call(this, x, y, PLANET_RADIUS_RED, 'planetRed'); ; self.spin = PLANET_SPIN_RED; }); var PlanetBlue = Planet.expand(function (x, y) { var self = Planet.call(this, x, y, PLANET_RADIUS_BLUE, 'planetBlue'); ; self.spin = PLANET_SPIN_BLUE; }); var PlanetOmni = Planet.expand(function (x, y) { var self = Planet.call(this, x, y, PLANET_RADIUS_OMNI, 'planetOmni'); ; self.spin = PLANET_SPIN_OMNI; }); var Crosshair = Container.expand(function () { var self = Container.call(this); var counter = 0; var arrows = []; var arrowOffsets = [{ x: 0, y: -1 }, { x: 1, y: 0 }, { x: 0, y: 1 }, { x: -1, y: 0 }]; for (var i = 0; i < arrowOffsets.length; i++) { var arrow = self.createAsset('arrow', 'Arrow asset', 0.5, 1); arrow.rotation = MATH_HALF_PI * i; arrows.push(arrow); self.addChild(arrow); } ; self.rotation = MATH_QUARTER_PI; self.update = update; function update() { counter++; var distance = CROSSHAIR_DIST + CROSSHAIR_VARIANCE * Math.sin(counter * CROSSHAIR_PERIOD); setDistance(distance); } ; function update() { counter++; var distance = CROSSHAIR_DIST + CROSSHAIR_VARIANCE * Math.sin(counter * CROSSHAIR_PERIOD); setDistance(distance); } function setDistance(distance) { for (var i = 0; i < arrows.length; i++) { arrows[i].x = arrowOffsets[i].x * distance; arrows[i].y = arrowOffsets[i].y * distance; } } ; setDistance(CROSSHAIR_DIST); }); var NavigationButton = Container.expand(function (x, y, index, callback) { var self = Container.call(this); var details = NAVIGATION[index]; var buttonGraphics = self.createAsset('button', 'Button asset', 0.5, 0.5); var planetGraphics = self.createAsset(details.planet, 'Planet asset', 0.5, 0.5); var currencyText = self.addChild(new CurrencyText(details.cost)); buttonGraphics.tint = 0xFFAAAA; planetGraphics.width = buttonGraphics.width * 0.4; planetGraphics.height = buttonGraphics.width * 0.4; ; self.unlock = unlock; self.x = x; self.y = y; self.cost = details.cost; self.planet = details.planet; self.unlocked = false; self.on('down', function () { callback(index); }); ; function unlock() { self.unlocked = true; buttonGraphics.tint = 0xFFFFFF; currencyText.destroy(); } }); var NavigationInterface = Container.expand(function (x, y) { var self = Container.call(this); var buttons = []; for (var i = 0; i < NAVIGATION.length; i++) { var buttonX = (-NAVIGATION.length / 2 + 0.5 + i) * 200; buttons.push(self.addChild(new NavigationButton(buttonX, 0, i, buttonCallback))); } ; self.x = x; self.y = y; ; function buttonCallback(index) { var button = buttons[index]; if (button.unlocked) { // TODO: navigation } 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; } } ; function setCurrent(index) { var button = buttons[index]; button.addChild(crosshair); } buttonCallback(0); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var MATH_2_PI = Math.PI * 2; var MATH_HALF_PI = Math.PI / 2; var MATH_QUARTER_PI = Math.PI / 4; var MATH_HALF_ROOT_3 = Math.sqrt(3) / 2; ; var GAME_TICKS = 60; var GAME_WIDTH = 2048; var GAME_HEIGHT = 2732; var PLANET_RADIUS_GREY = 200; var PLANET_RADIUS_RED = 400; var PLANET_RADIUS_BLUE = 350; var PLANET_RADIUS_OMNI = 500; var PLANET_SPIN_GREY = 0.001; 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_SPEED_MAX = 30; var ROCKET_SPEED_REVERSE = 5; 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; var TEXT_DEFAULT_SIZE = 50; var TEXT_DEFAULT_FONT = 'Arial'; 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.PI; var NAVIGATION = [{ cost: 0, planet: 'planetGrey', description: 'Small moon, with no special bonuses.' }, { cost: 100, planet: 'planetRed', description: '' }, { cost: 250, planet: 'planetBlue', description: '' }, { cost: 800, 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 planets = [planet]; var moneyDisplay = LK.gui.top.addChild(new CurrencyText(money, { x: 20, y: 50, size: 70, anchor: { x: 0 } })); var crosshair = new Crosshair(); var navigation = LK.gui.bottom.addChild(new NavigationInterface(0, -100)); navigation.setCurrent(currentPlanet); ; LK.on('tick', function () { planet.update(); crosshair.update(); });
===================================================================
--- original.js
+++ change.js
@@ -340,10 +340,10 @@
var TEXT_DEFAULT_FILL = '#FFFFFF';
var TEXT_DEFAULT_BORDER = '#000000';
var CURRENCY_DEFAULT_MARGIN = 0;
var CROSSHAIR_DIST = 40;
-var CROSSHAIR_VARIANCE = 20;
-var CROSSHAIR_PERIOD = 1 * GAME_TICKS / Math.PI;
+var CROSSHAIR_VARIANCE = 15;
+var CROSSHAIR_PERIOD = 2 * GAME_TICKS / Math.PI;
var NAVIGATION = [{
cost: 0,
planet: 'planetGrey',
description: 'Small moon, with no special bonuses.'
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.