Code edit (13 edits merged)
Please save this source code
User prompt
Fix Bug: 'SecurityError: Permission denied to access property "removeChild" on cross-origin object' in or related to this line: 'baseDestroy();' Line Number: 529
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: t is undefined' in or related to this line: 'symbolAsset = self.attachAsset(newSymbol, {' Line Number: 183
Code edit (2 edits merged)
Please save this source code
User prompt
in the transitionPlanets function, destroy all traders and reset the array
User prompt
in the transitionPlanets function, destroy all asteroids and reset the array
Code edit (6 edits merged)
Please save this source code
User prompt
Remove any remaining console logs
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -1069,10 +1069,14 @@
anchorX: 0.5,
anchorY: 0.5
});
if (setTrade) {
- var traderDialogue = new TraderDialogue(handleTradeCallback, setTrade, {});
- self.addChild(traderDialogue);
+ var traderDialogue = self.addChild(new TraderDialogue(handleTradeCallback, setTrade, {
+ flipX: self.x < GAME_WIDTH / 2 ? -1 : 1,
+ flipY: self.y < GAME_HEIGHT / 2 ? -1 : 1
+ }));
+ } else {
+ // TODO: Calculate trade
}
;
function handleTradeCallback(accepted) {
if (accepted) {
@@ -1085,72 +1089,91 @@
return self;
});
var TraderDialogue = ConfigContainer.expand(function (callback, trade, config) {
var self = ConfigContainer.call(this, config);
+ config = config || {};
+ var flipX = config.flipX;
+ var flipY = config.flipY;
var dialogueBackground = self.attachAsset('traderDialogue', {
- anchorX: 0.5,
- anchorY: 0.5
+ y: -TRADER_SHIP_SPACING * flipY,
+ anchorX: TRADER_FRAME_OFFSET_X,
+ anchorY: 1,
+ scaleX: flipX,
+ scaleY: flipY
});
- var horizonAssets = [];
- var createAssetOrCurrencyText = function createAssetOrCurrencyText(name, amount, isCurrency) {
- if (isCurrency) {
- return self.addChild(new CurrencyText(amount, {
+ 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', {
+ 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), {
+ x: -TRADER_DETAIL_MARGIN / 2,
+ y: TRADER_SHIP_SPACING * flipY,
+ anchorX: 1,
+ anchorY: 0
+ }));
+ var crossButton = buttonContainer.addChild(new BasicButton('cross', callback.bind(false), {
+ x: 60,
+ y: TRADER_SHIP_SPACING * flipY,
+ anchorX: 0,
+ anchorY: 0
+ }));
+ buttonContainer.x = centerFrameX;
+ buttonContainer.y = centerFrameY;
+ ;
+ function createTradePart(name, amount) {
+ if (name === 'credits') {
+ horizontalAssets.push(self.addChild(new CurrencyText(amount, {
anchorX: 0,
anchorY: 0.5
- }));
+ })));
} else {
- var asset = self.attachAsset(name, {
+ horizontalAssets.push(self.addChild(new BorderedText(amount + 'x', {
+ anchorX: 0,
+ anchorY: 0.5
+ })));
+ horizontalAssets.push(self.attachAsset(name, {
anchorX: 0.5,
anchorY: 0.5
- });
- var amountText = self.addChild(new BorderedText(amount.toString(), {
- anchorX: 1,
- anchorY: 0.5
}));
- horizonAssets.push(asset);
- return amountText;
}
- };
- var sellAsset = createAssetOrCurrencyText(trade.sellName, trade.sellAmount, trade.sellName === 'credits');
- var arrowAsset = self.attachAsset('arrow', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- horizonAssets.push(arrowAsset);
- var buyAsset = createAssetOrCurrencyText(trade.buyName, trade.buyAmount, trade.buyName === 'credits');
- // Position the assets horizontally
- var totalWidth = sellAsset.width + arrowAsset.width + buyAsset.width;
- var currentX = -totalWidth / 2;
- for (var i = 0; i < horizonAssets.length; i++) {
- horizonAssets[i].x = currentX + horizonAssets[i].width / 2;
- currentX += horizonAssets[i].width;
}
- // Add interaction
- var buttonContainer = self.addChild(new Container());
- var tickButton = buttonContainer.addChild(new BasicButton('tick', function () {
- callback(true);
- }, {
- x: -50,
- y: dialogueBackground.height / 2 + 20
- }));
- var crossButton = buttonContainer.addChild(new BasicButton('cross', function () {
- callback(false);
- }, {
- x: 50,
- y: dialogueBackground.height / 2 + 20
- }));
- buttonContainer.x = -tickButton.width;
- buttonContainer.y = dialogueBackground.height / 2 + 20;
+ 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: 0.5,
- anchorY: 0.5
+ 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
});
}
@@ -1167,10 +1190,10 @@
imageAsset.destroy();
}
if (newImageName) {
imageAsset = self.attachAsset(newImageName, {
- x: buttonBackground.x,
- y: buttonBackground.y,
+ x: buttonBackground.x - buttonBackground.width * (anchorX - 0.5),
+ y: buttonBackground.y - buttonBackground.height * (anchorY - 0.5),
anchorX: 0.5,
anchorY: 0.5
});
}
@@ -1206,48 +1229,8 @@
/****
* Game Code
****/
// Math constants / pre-calculations
-function _typeof(o) {
- "@babel/helpers - typeof";
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
- return typeof o;
- } : function (o) {
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
- }, _typeof(o);
-}
-function _defineProperty(obj, key, value) {
- key = _toPropertyKey(key);
- if (key in obj) {
- Object.defineProperty(obj, key, {
- value: value,
- enumerable: true,
- configurable: true,
- writable: true
- });
- } else {
- obj[key] = value;
- }
- return obj;
-}
-function _toPropertyKey(t) {
- var i = _toPrimitive(t, "string");
- return "symbol" == _typeof(i) ? i : String(i);
-}
-function _toPrimitive(t, r) {
- if ("object" != _typeof(t) || !t) {
- return t;
- }
- var e = t[Symbol.toPrimitive];
- if (void 0 !== e) {
- var i = e.call(t, r || "default");
- if ("object" != _typeof(i)) {
- return i;
- }
- throw new TypeError("@@toPrimitive must return a primitive value.");
- }
- return ("string" === r ? String : Number)(t);
-}
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;
@@ -1312,8 +1295,12 @@
var TRADER_TIME_VARIANCE = 2 * 60 * GAME_TICKS;
var TRADER_COST_VARIANCE = 0.1;
var TRADER_ASK_MIN = 5; // Minimum quantity of items to buy
var TRADER_ASK_MAX = 1.2; // Maximum of current stock to buy
+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;
@@ -1472,13 +1459,14 @@
var effectsList = [];
var player;
var traders = [];
var traderCountdown = TRADER_TIME_INITIAL;
-var nextTrade = _defineProperty({
+var nextTrade = {
sellName: 'fruitBush',
sellAmount: 1,
- buyName: 'fruitWeeds'
-}, "sellAmount", 5);
+ buyName: 'fruitWeeds',
+ buyAmount: 5
+};
var targetAngle = PLAYER_START_ANGLE;
var currentPlanet = NAVIGATION[0];
var destinationPlanet = NAVIGATION[0];
var background = game.addChild(new Background());
@@ -1557,14 +1545,14 @@
if (!traders[i]) {
available.push(i);
}
}
- if (available > 0) {
- var spawnIndex = Math.floor(Math.random * available.length);
- traders[i] = new Trader({
- x: GAME_WIDTH / 4 * spawnIndex % 2 === 0 ? 1 : 3,
- y: GAME_HEIGHT / 4 * spawnIndex < 2 ? 1 : 3
- }, nextTrade);
+ if (available.length > 0) {
+ var spawnIndex = Math.floor(Math.random() * available.length);
+ traders[i] = game.addChild(new Trader({
+ x: GAME_WIDTH / 4 * (spawnIndex % 2 === 0 ? 1 : 3),
+ y: GAME_HEIGHT / 4 * (spawnIndex < 2 ? 1 : 3)
+ }, nextTrade));
nextTrade = undefined;
}
}
}
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.