Code edit (1 edits merged)
Please save this source code
User prompt
tint the inventory's selector red
Code edit (5 edits merged)
Please save this source code
User prompt
Create an inventorySelector asset and a selectSlot function (that takes in an index) in the Inventory class. When clicking on a InventorySlot, it should call the parent (Inventory) selectSlot function and the Inventory should attach the inventorySelector asset to that InventorySlot instance.
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: self.anchor is undefined' in or related to this line: 'self.anchor.set(config.anchorX || 0, config.anchorY || 0);' Line Number: 459
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: config is undefined' in or related to this line: 'self.x = config.x || 0;' Line Number: 456
User prompt
Fix Bug: 'TypeError: LK.attachAsset is not a function' in or related to this line: 'var frameAsset = LK.attachAsset('inventoryFrame', {});' Line Number: 447
Code edit (5 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: LK.attachAsset is not a function' in or related to this line: 'var frameAsset = LK.attachAsset('inventoryFrame', {' Line Number: 455
Code edit (1 edits merged)
Please save this source code
User prompt
Remove the margin from the inventory
User prompt
Fix Bug: 'TypeError: this.scale is undefined' in or related to this line: 'var slotX = col * (InventorySlot.prototype.width + 10); // Assuming a 10px margin' Line Number: 455
Code edit (2 edits merged)
Please save this source code
User prompt
Create an instance of the Inventory class and add it to the LK.gui.top container with anchor of 1,.5
User prompt
Create an Inventory class which contains a 2x5 grid of inventory slots. Make sure the 2 and the 5 are pulled from global variables called INVENTORY_ROWS and INVENTORY_COLS
User prompt
Create an InventorySlot class which takes x,y and index parameters in its constructor
Code edit (12 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: messageStatValues is not defined' in or related to this line: 'self.addChild(new BorderedText(messageStatValues.map(mapKey).join('\n'), {' Line Number: 396
User prompt
Replace the TODO comment in saveStats with an implementation. Iterate through the stats object copying all keys and associated values to the winningStats object
Code edit (1 edits merged)
Please save this source code
User prompt
transitionPlanets should call the background's refresh function
User prompt
The Background's refresh function rotates the backgroundGraphics by 90 degrees (in radians)
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -1,34 +1,34 @@
/****
* Classes
****/
-var BorderedText = Container.expand(function (string, settings) {
+var BorderedText = Container.expand(function (string, config) {
var self = Container.call(this);
- settings = settings || {};
+ config = config || {};
var textList = [];
- var borderSettings = {
- fill: settings.border || TEXT_DEFAULT_BORDER,
- font: settings.font || TEXT_DEFAULT_FONT,
- size: settings.size || TEXT_DEFAULT_SIZE
+ 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 textSettings = {
- fill: settings.fill || TEXT_DEFAULT_FILL,
- font: settings.font || TEXT_DEFAULT_FONT,
- size: settings.size || TEXT_DEFAULT_SIZE
+ var textConfig = {
+ fill: config.fill || TEXT_DEFAULT_FILL,
+ font: config.font || TEXT_DEFAULT_FONT,
+ size: config.size || TEXT_DEFAULT_SIZE
};
for (var i = 0; i < TEXT_OFFSETS.length; i++) {
- var localSettings = i === TEXT_OFFSETS.length - 1 ? textSettings : borderSettings;
+ 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;
- if (settings.anchor) {
- text.anchor.set(settings.anchor.x || 0, settings.anchor.y || 0);
- }
+ text.anchor.set(anchorX, anchorY);
textList.push(text);
}
;
- self.x = settings.x;
- self.y = settings.y;
+ self.x = config.x || 0;
+ self.y = config.y || 0;
self.setText = setText;
self.setFill = setFill;
;
function setText(string) {
@@ -39,74 +39,62 @@
function setFill(newFill) {
textList[textList.length - 1].fill = newFill;
}
});
-var CurrencySymbol = Container.expand(function (settings) {
+var CurrencySymbol = Container.expand(function (config) {
var self = Container.call(this);
- settings = settings || {};
+ config = config || {};
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 anchorX = config.anchorX !== undefined ? config.anchorX : .5;
+ var anchorY = config.anchorY !== undefined ? config.anchorY : .5;
var borderSettings = {
fill: 0x000000,
- // fill: settings.border || TEXT_DEFAULT_BORDER,
- size: settings.size || TEXT_DEFAULT_SIZE
+ // fill: config.border || TEXT_DEFAULT_BORDER,
+ size: config.size || TEXT_DEFAULT_SIZE
};
var symbolSettings = {
fill: 0xFFFFFF,
- // fill: settings.fill || TEXT_DEFAULT_FILL,
- size: settings.size || TEXT_DEFAULT_SIZE
+ // fill: config.fill || TEXT_DEFAULT_FILL,
+ size: config.size || TEXT_DEFAULT_SIZE
};
for (var i = 0; i < TEXT_OFFSETS.length; i++) {
- var localSettings = i === TEXT_OFFSETS.length - 1 ? symbolSettings : borderSettings;
+ var localConfig = i === TEXT_OFFSETS.length - 1 ? symbolSettings : borderSettings;
var symbol = self.attachAsset('currencySymbol', {});
- symbol.anchorX = anchorX;
- symbol.anchorY = anchorY;
- symbol.tint = localSettings.fill;
- symbol.scale.set(localSettings.size / 100);
+ symbol.tint = localConfig.fill;
+ symbol.anchor.set(anchorX, anchorY);
+ symbol.scale.set(localConfig.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.x = config.x || 0;
+ self.y = config.y || 0;
self.setFill = setFill;
;
function setFill(newFill) {
mainSymbol.tint = newFill;
}
});
-var CurrencyText = Container.expand(function (amount, settings) {
+var CurrencyText = Container.expand(function (amount, config) {
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;
+ 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({
- anchor: {
- x: 0,
- y: anchorY
- }
+ anchorX: 0,
+ anchorY: anchorY
}));
var textAmount = self.addChild(new BorderedText(amount, {
- anchor: {
- y: anchorY
- }
+ anchorX: 0,
+ anchorY: anchorY
}));
;
- self.x = settings.x || 0;
- self.y = settings.y || 0;
+ self.x = config.x || 0;
+ self.y = config.y || 0;
self.setAmount = setAmount;
;
function alignText() {
var totalWidth = currencySymbol.width + margin + textAmount.width;
@@ -385,35 +373,44 @@
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
seconds = seconds % 60;
minutes = minutes % 60;
- var winningTime = hours + 'h ' + minutes + 'm ' + seconds + 's';
- var messages = [' + Crops Harvested: ' + stats.cropsHarvested, ' + Crops Overrun: ' + stats.cropsOverrun, ' + Weeds Pulled: ' + stats.weedsPulled, ' + Credits Earned: ' + stats.creditsEarned, ' + Successful Sales: ' + stats.salesDone, ' + Sales Rejected: ' + stats.salesRejected];
- var messageTime = self.addChild(new BorderedText('You reached the Gold Planet in: ' + winningTime, {
- y: -400,
- anchor: {
- x: .5,
- y: 1
- }
+ var winningTime = (hours > 0 ? hours + 'h ' : '') + (minutes > 0 ? minutes + 'm ' : '') + seconds + 's';
+ var messageStatTitles = ['Credits', 'Harvests', 'Weeds', 'Trades'];
+ var messageStatKeys = ['creditsEarned', 'cropsHarvested', 'weedsPulled', 'salesDone'];
+ var timeText = self.addChild(new BorderedText('You reached the Gold Planet in: ' + winningTime, {
+ anchorX: .5,
+ anchorY: 1,
+ y: -TEXT_WINNING_OFFSET
}));
- var headingText = self.addChild(new BorderedText('Congratulations, you win!', {
+ self.addChild(new BorderedText('Congratulations, you win!', {
+ anchorX: .5,
+ anchorY: 1,
size: 80,
- y: messageTime.y - messageTime.height - 10,
- anchor: {
- x: .5,
- y: 1
- }
+ y: timeText.y - timeText.height - 10
}));
- var messageStats = self.addChild(new BorderedText(messages.join('\n'), {
- y: 400,
- anchor: {
- x: .5,
- y: 0
- }
+ self.addChild(new BorderedText(messageStatTitles.map(mapTitle).join('\n'), {
+ anchorX: 1,
+ anchorY: 0,
+ y: TEXT_WINNING_OFFSET
}));
+ self.addChild(new BorderedText(messageStatValues.map(mapKey).join('\n'), {
+ anchorX: 0,
+ anchorY: 0,
+ y: TEXT_WINNING_OFFSET
+ }));
;
self.x = x;
self.y = y;
+ ;
+ function mapTitle(title) {
+ return '• ' + title + ' ';
+ }
+ function mapKey(key) {
+ var stat = winningStats[key];
+ var extra = stat - stats[key];
+ return ': ' + stat + (extra ? ' (+ ' + extra + ')' : 0);
+ }
});
var Background = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background', {
@@ -474,8 +471,9 @@
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;
@@ -507,16 +505,16 @@
}];
;
var money = 10000;
var stats = {
+ creditsEarned: 0,
cropsHarvested: 0,
cropsOverrun: 0,
weedsPulled: 0,
- creditsEarned: 0,
salesDone: 0,
salesRejected: 0
};
-var winningStats;
+var winningStats = {};
var winningTick = -1;
var winningTime = '';
var winningMessage;
var currentPlanet = 0;
@@ -528,11 +526,9 @@
var moneyDisplay = LK.gui.top.addChild(new CurrencyText(money, {
x: 20,
y: 50,
size: 70,
- anchor: {
- x: 0
- }
+ anchorX: 0
}));
var crosshair = new Crosshair();
var navigation = LK.gui.bottom.addChild(new NavigationInterface(0, -100));
;
@@ -553,8 +549,9 @@
planet = planets[currentPlanet] = new planetClass(GAME_WIDTH / 2, GAME_HEIGHT / 2);
}
if (currentPlanet === NAVIGATION.length - 1) {
if (winningTick < 0) {
+ saveStats();
winningTick = LK.ticks;
}
winningMessage = LK.gui.center.addChild(new WinningMessage(0, -100, winningTick));
} else if (winningMessage) {
@@ -563,5 +560,10 @@
}
game.addChild(planet);
planet.addChild(ship);
ship.x = planet.radius + ROCKET_DIST_REVERSE;
+}
+function saveStats() {
+ for (var key in stats) {
+ winningStats[key] = stats[key];
+ }
}
\ No newline at end of file
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.