Code edit (4 edits merged)
Please save this source code
User prompt
Add an asset with id "point" to BorderedSymbol and SymbolText
User prompt
Add an asset with id "point" to BorderedText, BorderedSymbol and SymbolText
Code edit (1 edits merged)
Please save this source code
User prompt
Created traders should be added to the foreground
User prompt
Created asteroids should be added to the midground and created traders should be added to the foreground
Code edit (9 edits merged)
Please save this source code
User prompt
add two containers to the game object called foreground and midground. Created asteroids should be added to the midground and created traders should be added to the foreground
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: trySpawnTrader is not defined' in or related to this line: 'trySpawnTrader();' Line Number: 1518
Code edit (1 edits merged)
Please save this source code
User prompt
In the Trader's constructor, if its setTrade object is defined, then create a TraderDialogue (sellName, sellAmount, buyName, buyAmount are all in the setTrade object), and add a new function to handle the callback with a bool param
Code edit (8 edits merged)
Please save this source code
User prompt
Add a new Trader class inheriting from ConfigContainer and has params of config and setTrade, with a trader asset attached
Code edit (1 edits merged)
Please save this source code
User prompt
Thanks for the comment, please remove the dialogueBackground's event
User prompt
In the TraderDialogue class, add 2 horizonally aligned BasicButtons underneath the dialogueBackground; the first button has a 'tick' asset and its callback calls the TraderDialogue's callback with a true, while the second button has a "cross" asset and similarly returns false in the callback
Code edit (1 edits merged)
Please save this source code
User prompt
Move the PlantButton class below the BasicButton
User prompt
The BasicButton should return self at the bottom and the PlantButton should inherit from the BasicButton
Code edit (1 edits merged)
Please save this source code
User prompt
Only create the BasicButton's imageAsset if the imageName is defined, including in the updateImage function
User prompt
Add an updateImage function to the basicbutton class which destroys and replaces the imageAsset if it exists
User prompt
Replace the PlantButton's button asset with a BasicButton
===================================================================
--- original.js
+++ change.js
@@ -2,135 +2,232 @@
* Classes
****/
var ConfigContainer = Container.expand(function (config) {
var self = Container.call(this);
- ;
config = config || {};
+ ;
self.x = config.x || 0;
self.y = config.y || 0;
self.rotation = config.rotation || 0;
- if (config.width !== undefined) {
- self.width = config.width;
- }
- if (config.height !== undefined) {
- self.height = config.height;
- }
- if (self.anchor) {
- self.anchor.set(config.anchorX || 0, config.anchorY || 0);
- }
;
return self;
});
-var BorderedText = Container.expand(function (string, config) {
- var self = Container.call(this);
+/**
+* var config = {
+* x : Number || 0, // See: ConfigContainer
+* y : Number || 0, // See: ConfigContainer
+* rotation : Number || 0, // See: ConfigContainer
+* anchorX : Number || 0,
+* anchorY : Number || 1,
+* size : Number || TEXT_DEFAULT_SIZE,
+* font : String || TEXT_DEFAULT_FONT,
+* fill : String || TEXT_DEFAULT_FILL,
+* border : String || TEXT_DEFAULT_BORDER,
+* }
+**/
+var BorderedText = ConfigContainer.expand(function (text, config) {
+ var self = ConfigContainer.call(this, config);
config = config || {};
- var textList = [];
var anchorX = config.anchorX !== undefined ? config.anchorX : 0;
- var anchorY = config.anchorY !== undefined ? config.anchorY : 0;
- var borderConfig = {
- fill: config.border || TEXT_DEFAULT_BORDER,
- font: config.font || TEXT_DEFAULT_FONT,
- size: config.size || TEXT_DEFAULT_SIZE
- };
+ var anchorY = config.anchorY !== undefined ? config.anchorY : 1;
+ var size = config.size !== undefined ? config.size : TEXT_DEFAULT_SIZE;
+ var font = config.font !== undefined ? config.font : TEXT_DEFAULT_FONT;
+ var textFill = config.fill !== undefined ? config.fill : TEXT_DEFAULT_FILL;
+ var borderFill = config.border !== undefined ? config.border : TEXT_DEFAULT_BORDER;
var textConfig = {
- fill: config.fill || TEXT_DEFAULT_FILL,
- font: config.font || TEXT_DEFAULT_FONT,
- size: config.size || TEXT_DEFAULT_SIZE
+ fill: textFill,
+ font: font,
+ size: size,
+ anchorX: anchorX,
+ anchorY: anchorY
};
- for (var i = 0; i < TEXT_OFFSETS.length; i++) {
- var localSettings = i === TEXT_OFFSETS.length - 1 ? textConfig : borderConfig;
- 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;
- text.anchor.set(anchorX, anchorY);
- textList.push(text);
- }
+ var borderConfig = {
+ fill: borderFill,
+ font: font,
+ size: size,
+ anchorX: anchorX,
+ anchorY: anchorY
+ };
+ var mainAsset;
+ var textAssets = [];
;
- self.x = config.x || 0;
- self.y = config.y || 0;
self.setText = setText;
self.setFill = setFill;
;
- function setText(string) {
- for (var i = 0; i < textList.length; i++) {
- textList[i].setText(string);
+ function setText(newText) {
+ for (var i = 0; i < textAssets.length; i++) {
+ textAssets[i].setText(newText);
}
}
function setFill(newFill) {
- textList[textList.length - 1].fill = newFill;
+ mainAsset.fill = newFill;
}
+ function buildTextAssets(newText) {
+ for (var i = 0; i < TEXT_OFFSETS.length; i++) {
+ var textAsset = textAssets[i];
+ if (textAsset) {
+ textAsset.destroy();
+ }
+ textAsset = self.addChild(new Text2(newText, i === TEXT_OFFSETS.length - 1 ? textConfig : borderConfig));
+ textAsset.x = TEXT_OFFSETS[i][0] * TEXT_BORDER_WEIGHT;
+ textAsset.y = TEXT_OFFSETS[i][1] * TEXT_BORDER_WEIGHT;
+ textAssets[i] = textAsset;
+ }
+ mainAsset = textAssets[TEXT_OFFSETS.length - 1];
+ }
+ ;
+ buildTextAssets(text);
+ return self;
});
-var CurrencySymbol = Container.expand(function (config) {
- var self = Container.call(this);
+/**
+* var config = {
+* x : Number || 0, // See: ConfigContainer
+* y : Number || 0, // See: ConfigContainer
+* rotation : Number || 0, // See: ConfigContainer
+* anchorX : Number || .5,
+* anchorY : Number || .5,
+* scale : Number || undefined,
+* scaleX : Number || scale,
+* scaleY : Number || scale,
+* width : Number || undefined, // Auto-calculated if left undefined and height is set
+* height : Number || undefined, // Auto-calculated if left undefined and width is set
+* tint : String || 0xFFFFFF, // Not tinted by default
+* border : String || TEXT_DEFAULT_BORDER,
+* }
+**/
+var BorderedSymbol = ConfigContainer.expand(function (symbol, config) {
+ var self = ConfigContainer.call(this, config);
config = config || {};
- var mainSymbol;
+ var width = config.width !== undefined ? config.width : undefined;
+ var height = config.height !== undefined ? config.height : undefined;
+ var scale = config.scale !== undefined ? config.scale : undefined;
+ var scaleX = config.scaleX !== undefined ? config.scaleX : scale;
+ var scaleY = config.scaleY !== undefined ? config.scaleX : scale;
var anchorX = config.anchorX !== undefined ? config.anchorX : .5;
var anchorY = config.anchorY !== undefined ? config.anchorY : .5;
- var borderSettings = {
- fill: 0x000000,
- // fill: config.border || TEXT_DEFAULT_BORDER,
- size: config.size || TEXT_DEFAULT_SIZE
+ var symbolTint = config.tint !== undefined ? config.tint : 0xFFFFFF;
+ var borderTint = config.border !== undefined ? config.border : TEXT_DEFAULT_BORDER;
+ var symbolConfig = {
+ tint: symbolTint,
+ anchorX: anchorX,
+ anchorY: anchorY
};
- var symbolSettings = {
- fill: 0xFFFFFF,
- // fill: config.fill || TEXT_DEFAULT_FILL,
- size: config.size || TEXT_DEFAULT_SIZE
+ var borderConfig = {
+ tint: borderTint,
+ anchorX: anchorX,
+ anchorY: anchorY
};
- for (var i = 0; i < TEXT_OFFSETS.length; i++) {
- var localConfig = i === TEXT_OFFSETS.length - 1 ? symbolSettings : borderSettings;
- var symbol = self.attachAsset('currencySymbol', {
- x: TEXT_OFFSETS[i][0] * TEXT_BORDER_WEIGHT,
- y: TEXT_OFFSETS[i][1] * TEXT_BORDER_WEIGHT,
- tint: localConfig.fill,
- scaleX: localConfig.size / 100,
- scaleY: localConfig.size / 100,
- anchorX: anchorX,
- anchorY: anchorY
- });
- ;
- if (i === TEXT_OFFSETS.length - 1) {
- mainSymbol = symbol;
- }
- }
+ var mainSymbol;
+ var symbolAssets = [];
;
- self.x = config.x || 0;
- self.y = config.y || 0;
- self.setFill = setFill;
+ self.setSymbol = buildSymbolAssets;
+ self.setTint = setTint;
;
- function setFill(newFill) {
- mainSymbol.tint = newFill;
+ function setTint(newTint) {
+ mainSymbol.tint = newTint;
+ symbolConfig.tint = newTint;
}
+ function buildSymbolAssets(newSymbol) {
+ for (var i = 0; i < TEXT_OFFSETS.length; i++) {
+ var symbolAsset = symbolAssets[i];
+ if (symbolAsset) {
+ symbolAsset.destroy();
+ }
+ symbolAsset = self.attachAsset(newSymbol, {});
+ symbolAsset.x = TEXT_OFFSETS[i][0] * TEXT_BORDER_WEIGHT;
+ symbolAsset.y = TEXT_OFFSETS[i][1] * TEXT_BORDER_WEIGHT;
+ if (width !== undefined && height === undefined) {
+ height = symbolAsset.height * (width / symbolAsset.width);
+ } else if (height !== undefined && width === undefined) {
+ width = symbolAsset.width * (height / symbolAsset.height);
+ }
+ symbolAsset.width = width;
+ symbolAsset.height = height;
+ if (scaleX !== undefined && scaleY !== undefined) {
+ symbolAsset.scale.set(scaleX, scaleY);
+ }
+ symbolAssets[i] = symbolAsset;
+ }
+ mainSymbol = symbolAssets[TEXT_OFFSETS.length - 1];
+ }
+ ;
+ buildSymbolAssets(symbol);
+ return self;
});
-var CurrencyText = Container.expand(function (amount, config) {
- var self = Container.call(this);
+/**
+* var config = {
+* x : Number || 0, // See: ConfigContainer
+* y : Number || 0, // See: ConfigContainer
+* rotation : Number || 0, // See: ConfigContainer
+* prefix : Boolean || true,
+* suffix : Boolean || false, // Overriden by prefix
+* tint : Boolean || false, // Whether to tint the symbol
+* anchorX : Number || 0,
+* anchorY : Number || 1,
+* margin : Number || TEXT_DEFAULT_MARGIN,
+* size : Number || TEXT_DEFAULT_SIZE,
+* fill : String || undefined, // See: BorderedText, BorderedText (tint)
+* border : Number || undefined, // See: BorderedText, BorderedText
+* }
+**/
+var SymbolText = ConfigContainer.expand(function (text, symbol, config) {
+ var self = ConfigContainer.call(this, config);
config = config || {};
- var anchorX = config.anchorX !== undefined ? config.anchorX : .5;
- var anchorY = config.anchorY !== undefined ? config.anchorY : .5;
- var margin = config.margin || CURRENCY_DEFAULT_MARGIN;
- var currencySymbol = self.addChild(new CurrencySymbol({
+ var prefix = !!config.prefix || !config.suffix;
+ var tint = !!config.tint;
+ var anchorX = config.anchorX !== undefined ? config.anchorX : 0;
+ var anchorY = config.anchorY !== undefined ? config.anchorY : 1;
+ var margin = config.margin !== undefined ? config.margin : TEXT_DEFAULT_MARGIN;
+ var size = config.size !== undefined ? config.size : TEXT_DEFAULT_SIZE;
+ var textAsset = self.addChild(new BorderedText(text, {
anchorX: 0,
- anchorY: anchorY
+ anchorY: 0.5,
+ font: config.font,
+ // Passthrough
+ fill: config.fill,
+ // Passthrough
+ border: config.border,
+ // Passthrough
+ size: size
}));
- var textAmount = self.addChild(new BorderedText(amount, {
+ var symbolAsset = self.addChild(new BorderedSymbol(symbol, {
anchorX: 0,
- anchorY: anchorY
+ anchorY: 0.5,
+ height: size,
+ tint: tint ? config.fill : undefined,
+ border: config.border // Passthrough
}));
;
- self.x = config.x || 0;
- self.y = config.y || 0;
- self.setAmount = setAmount;
+ self.setText = setText;
+ self.setFill = setFill;
+ self.setSymbol = setSymbol;
;
- function alignText() {
- var totalWidth = currencySymbol.width + margin + textAmount.width;
- currencySymbol.x = -totalWidth * anchorX;
- textAmount.x = currencySymbol.x + currencySymbol.width + margin;
+ function alignAssets() {
+ var first = prefix ? symbolAsset : textAsset;
+ var second = prefix ? textAsset : symbolAsset;
+ var totalWidth = symbolAsset.width + margin + textAsset.width;
+ var heightOffset = Math.max(first.height, second.height) * (0.5 - anchorY);
+ first.x = -totalWidth * anchorX;
+ first.y = heightOffset;
+ second.x = first.x + first.width + margin;
+ second.y = heightOffset;
}
- function setAmount(newAmount) {
- textAmount.setText(newAmount);
- alignText();
+ function setText(newText) {
+ textAsset.setText(newText);
+ alignAssets();
}
+ function setFill(newFill) {
+ textAsset.setFill(newFill);
+ if (tint) {
+ symbolAsset.setTint(newFill);
+ }
+ }
+ function setSymbol(newSymbol) {
+ symbolAsset.setSymbol(newSymbol);
+ alignAssets();
+ }
;
- alignText();
+ alignAssets();
});
var Player = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var actionCountdown = PLAYER_ACTION_INTERVAL;
@@ -698,9 +795,13 @@
anchorY: 0.5,
width: buttonGraphics.width * 0.4,
height: buttonGraphics.width * 0.4
});
- var currencyText = self.addChild(new CurrencyText(details.cost));
+ var currencyText = self.addChild(new SymbolText(details.cost, 'currencySymbol', {
+ anchorX: .5,
+ anchorY: .5,
+ tint: true
+ }));
;
self.unlock = unlock;
self.cost = details.cost;
self.planet = planetName;
@@ -799,26 +900,8 @@
var extra = stat - stats[key];
return ': ' + stat + (extra ? ' (+ ' + extra + ')' : '');
}
});
-var Background = Container.expand(function () {
- var self = Container.call(this);
- var backgroundGraphics = self.attachAsset('background', {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.5
- });
- backgroundGraphics.width = GAME_WIDTH * 1.05;
- backgroundGraphics.height = GAME_WIDTH * 1.05;
- ;
- self.x = GAME_WIDTH / 2;
- self.y = GAME_HEIGHT / 2;
- self.refresh = refresh;
- ;
- function refresh() {
- backgroundGraphics.rotation += Math.PI / 2;
- }
-});
var InventorySlot = ConfigContainer.expand(function (index, config) {
var self = ConfigContainer.call(this, config);
var itemDisplay;
var frame = self.attachAsset('inventoryFrame', {
@@ -961,8 +1044,85 @@
function toggleAllowed(bool) {
crossAsset.alpha = bool ? 0 : 1;
}
});
+var BasicButton = ConfigContainer.expand(function (imageName, callback, config) {
+ var self = ConfigContainer.call(this, config);
+ config = config || {};
+ var anchorX = config.anchorX || 0.5;
+ var anchorY = config.anchorY || 0.5;
+ var buttonBackground = self.attachAsset('buttonBackground', {
+ anchorX: anchorX,
+ anchorY: anchorY
+ });
+ var imageAsset;
+ if (imageName) {
+ imageAsset = self.attachAsset(imageName, {
+ x: buttonBackground.x - buttonBackground.width * (anchorX - 0.5),
+ y: buttonBackground.y - buttonBackground.height * (anchorY - 0.5),
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ }
+ ;
+ self.updateImage = updateImage;
+ self.imageName = imageName;
+ self.imageAsset = imageAsset;
+ self.buttonBackground = buttonBackground;
+ ;
+ function updateImage(newImageName) {
+ if (newImageName !== self.imageName) {
+ self.imageName = newImageName;
+ if (imageAsset) {
+ imageAsset.destroy();
+ }
+ if (newImageName) {
+ imageAsset = self.attachAsset(newImageName, {
+ x: buttonBackground.x - buttonBackground.width * (anchorX - 0.5),
+ y: buttonBackground.y - buttonBackground.height * (anchorY - 0.5),
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ }
+ }
+ }
+ ;
+ buttonBackground.on('down', callback);
+ return self;
+});
+var PlantButton = BasicButton.expand(function (plantName, callback, config) {
+ var self = BasicButton.call(this, plantName, callback, config);
+ var arrow = self.attachAsset('arrow', {
+ y: PLANT_BUTTON_OFFSET / 2,
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 2,
+ scaleY: 2
+ });
+ ;
+ self.buttonBackground.y = PLANT_BUTTON_OFFSET;
+ self.imageAsset.y = PLANT_BUTTON_OFFSET;
+ ;
+ return self;
+});
+var Background = Container.expand(function () {
+ var self = Container.call(this);
+ var backgroundGraphics = self.attachAsset('background', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.5
+ });
+ backgroundGraphics.width = GAME_WIDTH * 1.05;
+ backgroundGraphics.height = GAME_WIDTH * 1.05;
+ ;
+ self.x = GAME_WIDTH / 2;
+ self.y = GAME_HEIGHT / 2;
+ self.refresh = refresh;
+ ;
+ function refresh() {
+ backgroundGraphics.rotation += Math.PI / 2;
+ }
+});
var Asteroid = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var randomScale = ASTEROID_SCALE_MIN + Math.random() * ASTEROID_SCALE_VAR;
var asteroidGraphics = self.attachAsset('asteroid', {
@@ -1101,124 +1261,58 @@
scaleY: flipY
});
var centerFrameX = dialogueBackground.width * (1 - TRADER_FRAME_OFFSET_X / 2) * flipX;
var centerFrameY = dialogueBackground.height * TRADER_FRAME_OFFSET_Y * flipY;
- createTradePart(trade.sellName, trade.sellAmount);
- horizontalAssets.push(self.attachAsset('arrow', {
+ var tradeSymbols = self.addChild(new Container());
+ var tradeArrow = tradeSymbols.attachAsset('arrow', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2,
rotation: -MATH_HALF_PI
- }));
- createTradePart(trade.buyName, trade.buyAmount);
- var buttonContainer = self.addChild(new Container());
- var checkButton = buttonContainer.addChild(new BasicButton('check', callback.bind(true), {
+ });
+ var tradeSell = createTradePart(trade.sellName, trade.sellAmount, {
+ x: tradeArrow.height + TRADER_SHIP_SPACING,
+ anchorX: 1
+ });
+ var tradeBuy = createTradePart(trade.buyName, trade.buyAmount, {
+ x: tradeArrow.height + TRADER_SHIP_SPACING,
+ anchorX: 0
+ });
+ var checkButton = self.addChild(new BasicButton('check', callback.bind(true), {
x: -TRADER_DETAIL_MARGIN / 2,
y: TRADER_SHIP_SPACING * flipY,
anchorX: 1,
anchorY: 0
}));
- var crossButton = buttonContainer.addChild(new BasicButton('cross', callback.bind(false), {
+ var crossButton = self.addChild(new BasicButton('cross', callback.bind(false), {
x: 60,
y: TRADER_SHIP_SPACING * flipY,
anchorX: 0,
anchorY: 0
}));
- buttonContainer.x = centerFrameX;
- buttonContainer.y = centerFrameY;
+ tradeSymbols.x = centerFrameX;
+ tradeSymbols.y = centerFrameY;
;
- function createTradePart(name, amount) {
+ function createTradePart(name, amount, config) {
if (name === 'credits') {
- horizontalAssets.push(self.addChild(new CurrencyText(amount, {
- anchorX: 0,
+ return tradeSymbols.addChild(new SymbolText(amount, 'currencySymbol', {
+ x: config.x,
+ tint: true,
+ anchorX: config.anchorX,
anchorY: 0.5
- })));
+ }));
} else {
- horizontalAssets.push(self.addChild(new BorderedText(amount + 'x', {
- anchorX: 0,
+ return tradeSymbols.addChild(new SymbolText(amount + 'x', name, {
+ x: config.x,
+ anchorX: config.anchorX,
anchorY: 0.5
- })));
- horizontalAssets.push(self.attachAsset(name, {
- anchorX: 0.5,
- anchorY: 0.5
}));
}
}
- function alignItems(array) {
- var totalWidth = 0;
- for (var i = 0; i < array.length; i++) {
- totalWidth += array[i].width;
- }
- var currentX = -totalWidth / 2;
- for (var i = 0; i < array.length; i++) {
- array[i].x = currentX + array[i].width / 2;
- currentX += array[i].width;
- }
- }
;
- alignItems(horizontalAssets);
return self;
});
-var BasicButton = ConfigContainer.expand(function (imageName, callback, config) {
- var self = ConfigContainer.call(this, config);
- config = config || {};
- var anchorX = config.anchorX || 0.5;
- var anchorY = config.anchorY || 0.5;
- var buttonBackground = self.attachAsset('buttonBackground', {
- anchorX: anchorX,
- anchorY: anchorY
- });
- var imageAsset;
- if (imageName) {
- imageAsset = self.attachAsset(imageName, {
- x: buttonBackground.x - buttonBackground.width * (anchorX - 0.5),
- y: buttonBackground.y - buttonBackground.height * (anchorY - 0.5),
- anchorX: 0.5,
- anchorY: 0.5
- });
- }
- ;
- self.updateImage = updateImage;
- self.imageName = imageName;
- self.imageAsset = imageAsset;
- self.buttonBackground = buttonBackground;
- ;
- function updateImage(newImageName) {
- if (newImageName !== self.imageName) {
- self.imageName = newImageName;
- if (imageAsset) {
- imageAsset.destroy();
- }
- if (newImageName) {
- imageAsset = self.attachAsset(newImageName, {
- x: buttonBackground.x - buttonBackground.width * (anchorX - 0.5),
- y: buttonBackground.y - buttonBackground.height * (anchorY - 0.5),
- anchorX: 0.5,
- anchorY: 0.5
- });
- }
- }
- }
- ;
- buttonBackground.on('down', callback);
- return self;
-});
-var PlantButton = BasicButton.expand(function (plantName, callback, config) {
- var self = BasicButton.call(this, plantName, callback, config);
- var arrow = self.attachAsset('arrow', {
- y: PLANT_BUTTON_OFFSET / 2,
- anchorX: 0.5,
- anchorY: 0.5,
- scaleX: 2,
- scaleY: 2
- });
- ;
- self.buttonBackground.y = PLANT_BUTTON_OFFSET;
- self.imageAsset.y = PLANT_BUTTON_OFFSET;
- ;
- return self;
-});
/****
* Initialize Game
****/
@@ -1228,19 +1322,36 @@
/****
* Game Code
****/
+var midground = game.addChild(new Container());
+var foreground = game.addChild(new Container());
+;
+//==============================================================================
+// Global constants & settings
+//==============================================================================
+;
// Math constants / pre-calculations
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 MATH_HALF_ROOT_3 = Math.sqrt(3) / 2; // Required by: TEXT_OFFSETS, BorderedText, BorderedSymbol, SymbolText
var MATH_APPROX_ZERO = 0.0000001;
-var EXPLOSION_FRAMES = 15; // Number of frames for the explosion animation to last
+;
+// Text settings
+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]]; // Required by: BorderedText, BorderedSymbol, SymbolText
+var TEXT_BORDER_WEIGHT = 4; // Required by: BorderedText, BorderedSymbol, SymbolText
+var TEXT_DEFAULT_BORDER = '#000000'; // Required by: BorderedText, BorderedSymbol, SymbolText
+var TEXT_DEFAULT_FILL = '#FFFFFF'; // Required by: BorderedText, SymbolText
+var TEXT_DEFAULT_FONT = 'Arial'; // Required by: BorderedText, SymbolText
+var TEXT_DEFAULT_SIZE = 50; // Required by: BorderedText, SymbolText
+var TEXT_DEFAULT_MARGIN = 10; // Required by: SymbolText
+;
// Game constants
var GAME_TICKS = 60;
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
+;
// Rocket constants
var ROCKET_DIST_REVERSE = 300;
var ROCKET_DIST_LEAVE = 2500;
var ROCKET_SPEED_BASE = 1.2;
@@ -1249,30 +1360,27 @@
var ROCKET_SPEED_REVERSE = 2;
var ROCKET_FLAME_BREDTH = 30;
var ROCKET_FLAME_LIFETIME = 30;
var ROCKET_FLAME_SPEED = 5;
+;
// Farm constants
var PLOT_SIZE = 65;
var PLOT_GAP = 90;
var PLOT_ALPHA_STEP = 1 / GAME_TICKS;
var PLOT_EXTRA_LINGER = Math.floor(GAME_TICKS / 2);
+;
// Interface settings
-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 TEXT_WINNING_OFFSET = 300;
-var CURRENCY_DEFAULT_MARGIN = 0;
var CROSSHAIR_DIST = 40;
var CROSSHAIR_VARIANCE = 10;
var CROSSHAIR_PERIOD = 1.25 * GAME_TICKS / MATH_2_PI;
+;
// Inventory settings
var INVENTORY_ROWS = 1;
var INVENTORY_COLS = 8;
var INVENTORY_ICON_SCALE = 0.5;
var INVENTORY_SLOT_SIZE = 100;
+;
// Asteroid settings
var ASTEROID_SPAWN_CHANCE = 0.001;
var ASTEROID_DROP_CHANCE = 0.1; // 10% chance
var ASTEROID_ROTATION_MAX = 0.02;
@@ -1280,16 +1388,19 @@
var ASTEROID_MARGIN = 100;
var ASTEROID_SCALE_MIN = 0.75;
var ASTEROID_SCALE_VAR = 0.5;
var ASTEROID_TARGET_OFFSET = 500;
+var EXPLOSION_FRAMES = 15; // Number of frames for the explosion animation to last
+;
// Player settings
var PLAYER_SPEED = 5;
var PLAYER_ACTION_INTERVAL = Math.floor(GAME_TICKS / 4);
var PLAYER_ACTION_DIST = 80;
var PLAYER_ACTION_SQRDIST = PLAYER_ACTION_DIST * PLAYER_ACTION_DIST;
var PLAYER_BUFFER_DIST = 400;
var PLAYER_BUFFER_SQRDIST = PLAYER_BUFFER_DIST * PLAYER_BUFFER_DIST;
var PLAYER_START_ANGLE = Math.PI / 16;
+;
// Trader settings
var TRADER_TIME_INITIAL = 10 * GAME_TICKS;
var TRADER_TIME_BASE = 2 * GAME_TICKS;
var TRADER_TIME_VARIANCE = 2 * 60 * GAME_TICKS;
@@ -1299,8 +1410,9 @@
var TRADER_FRAME_OFFSET_X = 0.13;
var TRADER_FRAME_OFFSET_Y = -0.56;
var TRADER_DETAIL_MARGIN = 20;
var TRADER_SHIP_SPACING = 200;
+;
// Plant settings
var WEEDS_SPAWN_CHANCE = 0.3;
var WEEDS_SPAWN_TIME = 5 * 60 * GAME_TICKS;
var WEEDS_SPAWN_VARIANCE = 2 * 60 * GAME_TICKS;
@@ -1391,8 +1503,9 @@
type: 'none',
plant: 'none'
}
};
+;
// Planet & navigation settings
var NAVIGATION = ['planetGrey', 'planetRed', 'planetBlue', 'planetOmni', 'planetGold'];
var PLANET_DETAILS = {
planetGrey: {
@@ -1441,8 +1554,12 @@
sell: []
}
};
;
+//==============================================================================
+// Global variables
+//==============================================================================
+;
var money = 10000;
var asteroidList = [];
var stats = {
creditsEarned: 0,
@@ -1481,18 +1598,24 @@
y: INVENTORY_SLOT_SIZE / 2 + 10,
anchorX: .5,
anchorY: .5
}));
-var moneyDisplay = LK.gui.top.addChild(new CurrencyText(money, {
+var moneyDisplay = LK.gui.top.addChild(new SymbolText(money, 'currencySymbol', {
x: inventory.width / 2 + 25,
y: inventory.y,
+ tint: true,
size: 70,
- anchorX: 0
+ anchorX: 0,
+ anchorY: .5
}));
var crosshair = new Crosshair();
var navigation = LK.gui.bottom.addChild(new NavigationInterface(0, -100));
planetMap[planet.name] = planet;
;
+//==============================================================================
+// Gameplay events
+//==============================================================================
+;
LK.on('tick', function () {
if (player) {
player.update();
}
@@ -1503,8 +1626,9 @@
updateList(effectsList);
trySpawnAsteroid();
trySpawnTrader();
});
+;
game.on('down', function (obj) {
console.log(obj);
if (player) {
var clickPosition = obj.event.getLocalPosition(game);
@@ -1517,8 +1641,12 @@
}
}
});
;
+//==============================================================================
+// Global functions
+//==============================================================================
+;
function updateList(list) {
for (var i = list.length - 1; i >= 0; i--) {
var item = list[i];
if (item.update && item.update()) {
@@ -1526,8 +1654,9 @@
list.splice(i, 1);
}
}
}
+;
function trySpawnAsteroid() {
if (Math.random() < ASTEROID_SPAWN_CHANCE) {
var side = Math.random() < 0.5;
asteroidList.push(game.addChild(new Asteroid({
@@ -1536,8 +1665,9 @@
vx: side ? ASTEROID_SPEED : -ASTEROID_SPEED
})));
}
}
+;
function trySpawnTrader() {
if (--traderCountdown <= 0) {
traderCountdown = Math.floor(TRADER_TIME_BASE + Math.random() * TRADER_TIME_VARIANCE);
var available = [];
@@ -1555,8 +1685,9 @@
nextTrade = undefined;
}
}
}
+;
function transitionPlanets() {
LK.effects.flashScreen(0x000000, 500);
currentPlanet = destinationPlanet;
planet.parent.removeChild(planet);
@@ -1584,11 +1715,13 @@
ship.x = planet.radius + ROCKET_DIST_REVERSE;
background.refresh();
inventory.refreshAllowed();
}
+;
function mod(x, base) {
return (x % base + base) % base;
}
+;
function saveStats() {
for (var key in stats) {
winningStats[key] = stats[key];
}
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.