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
@@ -118,17 +118,19 @@
var symbolAsset = symbolAssets[i];
if (symbolAsset) {
symbolAsset.destroy();
}
- symbolAsset = self.attachAsset(newSymbol, {
- // tint: main ? symbolTint : borderTint,
- tint: main ? 0xFFFFFF : 0x000000,
- // NOTE: Tinting is currently broken (cannot use string)
- x: TEXT_OFFSETS[i][0] * TEXT_BORDER_WEIGHT,
- y: TEXT_OFFSETS[i][1] * TEXT_BORDER_WEIGHT,
- anchorX: anchorX,
- anchorY: anchorY
- });
+ if (newSymbol) {
+ symbolAsset = self.attachAsset(newSymbol, {
+ // tint: main ? symbolTint : borderTint,
+ tint: main ? 0xFFFFFF : 0x000000,
+ // NOTE: Tinting is currently broken (cannot use string)
+ x: TEXT_OFFSETS[i][0] * TEXT_BORDER_WEIGHT,
+ y: TEXT_OFFSETS[i][1] * TEXT_BORDER_WEIGHT,
+ anchorX: anchorX,
+ anchorY: anchorY
+ });
+ }
if (width !== undefined && height === undefined) {
height = symbolAsset.height * (width / symbolAsset.width);
} else if (height !== undefined && width === undefined) {
width = symbolAsset.width * (height / symbolAsset.height);
@@ -157,10 +159,11 @@
* 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
+* scale : Number || undefined, // See: BorderedSymbol
+* fill : String || undefined, // See: BorderedText, BorderedSymbol (tint)
+* border : Number || undefined, // See: BorderedText, BorderedSymbol
* }
**/
var SymbolText = ConfigContainer.expand(function (text, symbol, config) {
var self = ConfigContainer.call(this, config);
@@ -170,8 +173,9 @@
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 symbolHeight = config.scale === undefined ? size : undefined;
var textAsset = self.addChild(new BorderedText(text, {
anchorX: 0,
anchorY: 0.5,
font: config.font,
@@ -184,11 +188,13 @@
}));
var symbolAsset = self.addChild(new BorderedSymbol(symbol, {
anchorX: 0,
anchorY: 0.5,
- height: size,
+ height: symbolHeight,
tint: tint ? config.fill : undefined,
- border: config.border // Passthrough
+ border: config.border,
+ // Passthrough
+ scale: config.scale
}));
;
self.setText = setText;
self.setFill = setFill;
@@ -578,9 +584,9 @@
self.update = update;
self.addPlant = addPlant;
self.tryAction = tryAction;
self.tryPlantFruit = tryPlantFruit;
- self.offset = -20;
+ self.offset = -25;
self.potted = false;
;
function update() {
baseUpdate();
@@ -953,11 +959,12 @@
}
}
var selector = new InventorySelector();
var warningText = self.addChild(new BorderedText('', {
+ y: INVENTORY_SLOT_SIZE * INVENTORY_ROWS / 2 + 20,
anchorX: 0.5,
anchorY: 0,
- y: INVENTORY_SLOT_SIZE * INVENTORY_ROWS / 2 + 20
+ size: TEXT_SIZE_SMALL
}));
warningText.visible = false;
;
self.adjustItem = adjustItem;
@@ -1217,28 +1224,64 @@
planet.fruitList.push(planet.addChild(self));
});
var Trader = ConfigContainer.expand(function (config, setTrade) {
var self = ConfigContainer.call(this, config);
+ var index = config.index;
var traderGraphics = self.attachAsset('trader', {
anchorX: 0.5,
anchorY: 0.5
});
- if (setTrade) {
- var traderDialogue = self.addChild(new TraderDialogue(handleTradeCallback, setTrade, {
- y: -traderGraphics.height / 2 - TRADER_SHIP_SPACING,
- flipX: self.x < GAME_WIDTH / 2 ? -1 : 1
- }));
- } else {
- // TODO: Calculate trade
+ var trade = setTrade;
+ if (!trade) {
+ var details = PLANET_DETAILS[planet.name];
+ var sellList = details.sell;
+ var sellName = sellList[Math.floor(Math.random() * sellList.length)];
+ var sellValue = FRUIT_DETAILS[sellName];
+ var buyList = details.buy.filter(function (item) {
+ return item !== sellName;
+ });
+ var buyName = buyList[Math.floor(Math.random() * sellList.length)];
+ var buyValue = FRUIT_DETAILS[buyName];
+ trade = {
+ sellName: sellName,
+ sellAmount: 0,
+ // TEMP
+ buyName: buyName,
+ buyAmount: 0 // TEMP
+ };
}
+ var traderDialogue = self.addChild(new TraderDialogue(handleTradeCallback, trade, {
+ y: -traderGraphics.height / 2 - TRADER_SHIP_SPACING,
+ flipX: self.x < GAME_WIDTH / 2 ? -1 : 1
+ }));
;
function handleTradeCallback(accepted) {
if (accepted) {
- // Logic for accepted trade
+ if (checkValue(trade.sellName, trade.sellAmount)) {
+ makeAdjustment(trade.sellName, -trade.sellAmount);
+ makeAdjustment(trade.buyName, trade.buyAmount);
+ self.destroy();
+ traders[index] = undefined;
+ }
} else {
- // Logic for rejected trade
+ self.destroy();
+ traders[index] = undefined;
}
}
+ function checkValue(name, amount) {
+ if (name === 'credits') {
+ return money >= amount;
+ } else {
+ return inventory.getQuantity(name) >= amount;
+ }
+ }
+ function makeAdjustment(name, amount) {
+ if (name === 'credits') {
+ moneyDisplay.setText(money += amount);
+ } else {
+ inventory.adjustItem(name, amount);
+ }
+ }
;
return self;
});
var TraderDialogue = ConfigContainer.expand(function (callback, trade, config) {
@@ -1249,29 +1292,30 @@
anchorX: TRADER_FRAME_OFFSET_X,
anchorY: 1,
scaleX: flipX
});
- var centerFrameX = dialogueBackground.width * (1 - TRADER_FRAME_OFFSET_X) / 2 * flipX;
+ var centerFrameX = dialogueBackground.width * (0.5 - TRADER_FRAME_OFFSET_X) * flipX;
var centerFrameY = dialogueBackground.height * TRADER_FRAME_OFFSET_Y;
var tradeSymbols = self.addChild(new Container());
var tradeArrow = tradeSymbols.attachAsset('arrow', {
anchorX: 0.5,
anchorY: 0.5,
- scaleX: 2,
- scaleY: 2,
+ scaleX: 1.4,
+ scaleY: 1.4,
rotation: -MATH_HALF_PI
});
var tradeSell = createTradePart(trade.sellName, trade.sellAmount, {
- x: -tradeArrow.height - TRADER_DETAIL_MARGIN,
+ x: -tradeArrow.height * 0.7 - TRADER_DETAIL_MARGIN,
anchorX: 1
});
var tradeBuy = createTradePart(trade.buyName, trade.buyAmount, {
- x: tradeArrow.height + TRADER_DETAIL_MARGIN,
+ x: tradeArrow.height * 0.7 + TRADER_DETAIL_MARGIN,
anchorX: 0
});
self.addChild(new TraderButtons(callback, {
x: -(dialogueBackground.width * TRADER_FRAME_OFFSET_X + TRADER_DETAIL_MARGIN) * flipX,
- y: centerFrameY
+ y: centerFrameY,
+ anchorX: 0.5 + 0.5 * flipX
}));
tradeSymbols.x = centerFrameX;
tradeSymbols.y = centerFrameY;
;
@@ -1281,16 +1325,18 @@
x: config.x,
anchorX: config.anchorX,
anchorY: 0.5,
suffix: true,
+ scale: 0.5,
tint: true
}));
} else {
return tradeSymbols.addChild(new SymbolText(amount + '×', name, {
x: config.x,
anchorX: config.anchorX,
anchorY: 0.5,
- suffix: true
+ suffix: true,
+ scale: 0.5
}));
}
}
;
@@ -1299,14 +1345,14 @@
var TraderButtons = ConfigContainer.expand(function (callback, config) {
var self = ConfigContainer.call(this, config);
var checkButton = self.addChild(new BasicButton('check', callback.bind(true), {
y: -TRADER_DETAIL_MARGIN / 2,
- anchorX: 0,
+ anchorX: config.anchorX,
anchorY: 1
}));
var crossButton = self.addChild(new BasicButton('cross', callback.bind(false), {
y: TRADER_DETAIL_MARGIN / 2,
- anchorX: 0,
+ anchorX: config.anchorX,
anchorY: 0
}));
});
@@ -1414,12 +1460,12 @@
var WEEDS_SPAWN_VARIANCE = 2 * 60 * GAME_TICKS;
var WEEDS_SPREAD_TIME = 1 * 60 * GAME_TICKS;
var WEEDS_SPREAD_VARIANCE = 20 * GAME_TICKS;
var GROW_WARNING_BARREN = 'Nothing grows on this planet!';
-var GROW_WARNING_GENERAL = 'Cannot grow this plant here...';
-var PLANT_GROWTH_FACTOR = 1.0;
+var GROW_WARNING_GENERAL = 'This cannot grow on this plant';
+var PLANT_GROWTH_FACTOR = 0.25;
var PLANT_BUTTON_OFFSET = -220;
-var PLANT_FRUIT_SCALE = 0.8;
+var PLANT_FRUIT_SCALE = 0.6;
var PLANT_DETAILS = {
plantWeeds: {
blueprint: PlantWeeds,
stages: 4,
@@ -1428,9 +1474,9 @@
growthVariance: 10 * GAME_TICKS
},
plantBush: {
blueprint: PlantBush,
- stages: 5,
+ stages: 6,
fruit: 'fruitBush',
growthTime: 120 * GAME_TICKS,
growthVariance: 30 * GAME_TICKS
},
@@ -1674,8 +1720,9 @@
}
if (available.length > 0) {
var spawnIndex = Math.floor(Math.random() * available.length);
traders[i] = foreground.addChild(new Trader({
+ index: spawnIndex,
x: GAME_WIDTH / 4 * (spawnIndex % 2 === 0 ? 1 : 3),
y: GAME_HEIGHT / 4 * (spawnIndex < 2 ? 1 : 3)
}, nextTrade));
nextTrade = undefined;
@@ -1687,16 +1734,18 @@
LK.effects.flashScreen(0x000000, 500);
currentPlanet = destinationPlanet;
planet.parent.removeChild(planet);
planet = planetMap[currentPlanet];
- // Destroy all asteroids, traders and reset the asteroidList and traders arrays
asteroidList.forEach(function (asteroid) {
asteroid.destroy();
});
asteroidList = [];
- traders.forEach(function (trader) {
- trader.destroy();
- });
+ for (var i = 0; i < 4; i++) {
+ var trader = traders[i];
+ if (trader) {
+ trader.destroy();
+ }
+ }
traders = [];
if (!planet) {
var planetClass = PLANET_DETAILS[currentPlanet].blueprint;
planet = planetMap[currentPlanet] = new planetClass({
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.