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
@@ -1069,11 +1069,12 @@
anchorX: 0.5,
anchorY: 0.5
});
if (setTrade) {
- var traderDialogue = new TraderDialogue(setTrade.sellName, setTrade.sellAmount, setTrade.buyName, setTrade.buyAmount, handleTradeCallback, {});
+ var traderDialogue = new TraderDialogue(handleTradeCallback, setTrade, {});
self.addChild(traderDialogue);
}
+ ;
function handleTradeCallback(accepted) {
if (accepted) {
// Logic for accepted trade
} else {
@@ -1082,9 +1083,9 @@
}
;
return self;
});
-var TraderDialogue = ConfigContainer.expand(function (sellName, sellAmount, buyName, buyAmount, callback, config) {
+var TraderDialogue = ConfigContainer.expand(function (callback, trade, config) {
var self = ConfigContainer.call(this, config);
var dialogueBackground = self.attachAsset('traderDialogue', {
anchorX: 0.5,
anchorY: 0.5
@@ -1108,15 +1109,15 @@
horizonAssets.push(asset);
return amountText;
}
};
- var sellAsset = createAssetOrCurrencyText(sellName, sellAmount, sellName === 'credits');
+ 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(buyName, buyAmount, buyName === 'credits');
+ 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++) {
@@ -1205,8 +1206,48 @@
/****
* 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;
@@ -1242,31 +1283,38 @@
var CURRENCY_DEFAULT_MARGIN = 0;
var CROSSHAIR_DIST = 40;
var CROSSHAIR_VARIANCE = 10;
var CROSSHAIR_PERIOD = 1.25 * GAME_TICKS / MATH_2_PI;
-// Inventory constants
+// Inventory settings
var INVENTORY_ROWS = 1;
var INVENTORY_COLS = 8;
var INVENTORY_ICON_SCALE = 0.5;
var INVENTORY_SLOT_SIZE = 100;
-// Asteroid constants
+// Asteroid settings
var ASTEROID_SPAWN_CHANCE = 0.001;
var ASTEROID_DROP_CHANCE = 0.1; // 10% chance
var ASTEROID_ROTATION_MAX = 0.02;
var ASTEROID_SPEED = 5;
var ASTEROID_MARGIN = 100;
var ASTEROID_SCALE_MIN = 0.75;
var ASTEROID_SCALE_VAR = 0.5;
var ASTEROID_TARGET_OFFSET = 500;
-// Player constants
+// 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;
-// Plant constants
+// Trader settings
+var TRADER_TIME_INITIAL = 10 * GAME_TICKS;
+var TRADER_TIME_BASE = 2 * GAME_TICKS;
+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
+// Plant settings
var WEEDS_SPAWN_CHANCE = 0.3;
var WEEDS_SPAWN_TIME = 5 * 60 * GAME_TICKS;
var WEEDS_SPAWN_VARIANCE = 2 * 60 * GAME_TICKS;
var WEEDS_SPREAD_TIME = 1 * 60 * GAME_TICKS;
@@ -1422,8 +1470,15 @@
var winningTime = '';
var winningMessage;
var effectsList = [];
var player;
+var traders = [];
+var traderCountdown = TRADER_TIME_INITIAL;
+var nextTrade = _defineProperty({
+ sellName: 'fruitBush',
+ sellAmount: 1,
+ buyName: 'fruitWeeds'
+}, "sellAmount", 5);
var targetAngle = PLAYER_START_ANGLE;
var currentPlanet = NAVIGATION[0];
var destinationPlanet = NAVIGATION[0];
var background = game.addChild(new Background());
@@ -1458,8 +1513,9 @@
crosshair.update();
updateList(asteroidList);
updateList(effectsList);
trySpawnAsteroid();
+ trySpawnTrader();
});
game.on('down', function (obj) {
console.log(obj);
if (player) {
@@ -1492,8 +1548,27 @@
vx: side ? ASTEROID_SPEED : -ASTEROID_SPEED
})));
}
}
+function trySpawnTraders() {
+ if (--traderCountdown <= 0) {
+ traderCountdown = Math.floor(TRADER_TIME_BASE + Math.random() * TRADER_TIME_VARIANCE);
+ var available = [];
+ for (var i = 0; i < 4; i++) {
+ 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);
+ nextTrade = undefined;
+ }
+ }
+}
function transitionPlanets() {
LK.effects.flashScreen(0x000000, 500);
currentPlanet = destinationPlanet;
planet.parent.removeChild(planet);
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.