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
/****
* Classes
****/
var BorderedText = Container.expand(function (string, settings) {
var self = Container.call(this);
settings = settings || {};
var textList = [];
var borderSettings = {
fill: settings.border || TEXT_DEFAULT_BORDER,
font: settings.font || TEXT_DEFAULT_FONT,
size: settings.size || TEXT_DEFAULT_SIZE
};
var textSettings = {
fill: settings.fill || TEXT_DEFAULT_FILL,
font: settings.font || TEXT_DEFAULT_FONT,
size: settings.size || TEXT_DEFAULT_SIZE
};
for (var i = 0; i < TEXT_OFFSETS.length; i++) {
var localSettings = i === TEXT_OFFSETS.length - 1 ? textSettings : borderSettings;
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);
}
textList.push(text);
}
;
self.x = settings.x;
self.y = settings.y;
self.setText = setText;
self.setFill = setFill;
;
function setText(string) {
for (var i = 0; i < textList.length; i++) {
textList[i].setText(string);
}
}
function setFill(newFill) {
textList[textList.length - 1].fill = newFill;
}
});
var CurrencySymbol = Container.expand(function (settings) {
var self = Container.call(this);
settings = settings || {};
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 borderSettings = {
fill: 0x000000,
// fill: settings.border || TEXT_DEFAULT_BORDER,
size: settings.size || TEXT_DEFAULT_SIZE
};
var symbolSettings = {
fill: 0xFFFFFF,
// fill: settings.fill || TEXT_DEFAULT_FILL,
size: settings.size || TEXT_DEFAULT_SIZE
};
for (var i = 0; i < TEXT_OFFSETS.length; i++) {
var localSettings = i === TEXT_OFFSETS.length - 1 ? symbolSettings : borderSettings;
var symbol = self.attachAsset('currencySymbol', {});
symbol.tint = localSettings.fill;
symbol.scale.set(localSettings.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.setFill = setFill;
;
function setFill(newFill) {
mainSymbol.tint = newFill;
}
});
var CurrencyText = Container.expand(function (amount, settings) {
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;
var currencySymbol = self.addChild(new CurrencySymbol({
anchor: {
x: 0,
y: anchorY
}
}));
var textAmount = self.addChild(new BorderedText(amount, {
anchor: {
y: anchorY
}
}));
;
self.x = settings.x || 0;
self.y = settings.y || 0;
self.setAmount = setAmount;
;
function alignText() {
var totalWidth = currencySymbol.width + margin + textAmount.width;
currencySymbol.x = -totalWidth * anchorX;
textAmount.x = currencySymbol.x + currencySymbol.width + margin;
}
function setAmount(newAmount) {
textAmount.setText(newAmount);
alignText();
}
;
alignText();
});
var Ship = Container.expand(function (x, y) {
var self = Container.call(this);
var shipGraphics = self.attachAsset('ship', {
anchorX: 0.35,
anchorY: 0.5
});
var counter = 0;
;
self.update = update;
self.launch = launch;
self.x = x;
self.y = y;
self.direction = -1;
;
function update() {
if (self.direction < 0) {
self.x -= ROCKET_SPEED_REVERSE;
if (self.x <= self.parent.radius) {
self.x = self.parent.radius;
self.direction = 0;
}
} else if (self.direction > 0) {
counter++;
var speed = Math.pow(ROCKET_SPEED_BASE, counter / ROCKET_SPEED_DIV - ROCKET_SPEED_DELAY);
self.x += speed;
if (self.x > ROCKET_DIST_LEAVE) {
counter = 0;
self.direction = -1;
transitionPlanets();
}
}
}
function launch(direction) {
if (!self.direction) {
self.direction = direction;
}
}
});
var Farm = Container.expand(function () {
var self = Container.call(this);
var farmGraphics = self.attachAsset('farm', {
anchorX: 0.5,
anchorY: 0.6
});
farmGraphics.scale.set(PLOT_SIZE / 100);
;
self.update = update;
;
function update() {}
});
var PlantNode = Container.expand(function (x, y, rotation) {
var self = Container.call(this);
;
self.update = update;
self.x = x;
self.y = y;
self.rotation = rotation;
self.plant;
self.farm;
self.prev;
self.next;
;
function update() {}
});
var Plant = Container.expand(function () {
var self = Container.call(this);
;
return self;
});
var PlantWeed = Plant.expand(function (stage) {
var self = Plant.call(this);
var weedGraphics = self.createAsset('plant0Stage' + stage, {
anchorX: 0.5,
anchorY: 1
});
});
var Planet = Container.expand(function (x, y, radius, assetName, barren) {
var self = Container.call(this);
var perimeter = MATH_2_PI * radius;
var numPlots = Math.floor(perimeter / (PLOT_SIZE + PLOT_GAP));
var numNodes = numPlots / 4;
var nodes = [];
var planetGraphics = self.createAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
planetGraphics.scale.set(2 * radius / 1000);
;
self.update = update;
self.launch = launch;
self.x = x;
self.y = y;
self.radius = radius;
self.rotation = Math.random() * MATH_2_PI;
self.spin = 0;
;
function update(ticks) {
self.rotation += self.spin;
}
function launch(direction) {}
function createNodes() {
if (!barren) {
for (var i = 0; i < numPlots * 4; i++) {
var angle = i / (numPlots * 4) * MATH_2_PI;
var nodeX = radius * Math.cos(angle);
var nodeY = radius * Math.sin(angle);
var rotation = angle + MATH_HALF_PI;
var node = self.addChild(new PlantNode(nodeX, nodeY, rotation));
if (Math.random() < 0.2) {
var stage = Math.floor(Math.random() * 4);
node.plant = node.addChild(new PlantWeed(stage));
} else if (i !== 0 && i % 4 === 0) {
node.farm = node.addChild(new Farm());
}
nodes.push(node);
}
}
}
;
createNodes();
return self;
});
var PlanetGrey = Planet.expand(function (x, y) {
var self = Planet.call(this, x, y, PLANET_RADIUS_GREY, 'planetGrey');
;
self.spin = PLANET_SPIN_GREY;
});
var PlanetRed = Planet.expand(function (x, y) {
var self = Planet.call(this, x, y, PLANET_RADIUS_RED, 'planetRed');
;
self.spin = PLANET_SPIN_RED;
});
var PlanetBlue = Planet.expand(function (x, y) {
var self = Planet.call(this, x, y, PLANET_RADIUS_BLUE, 'planetBlue');
;
self.spin = PLANET_SPIN_BLUE;
});
var PlanetOmni = Planet.expand(function (x, y) {
var self = Planet.call(this, x, y, PLANET_RADIUS_OMNI, 'planetOmni');
;
self.spin = PLANET_SPIN_OMNI;
});
var PlanetGold = Planet.expand(function (x, y) {
var self = Planet.call(this, x, y, PLANET_RADIUS_GOLD, 'planetGold', true);
;
self.spin = PLANET_SPIN_GOLD;
});
var Crosshair = Container.expand(function () {
var self = Container.call(this);
var counter = 0;
var arrows = [];
var arrowOffsets = [{
x: 0,
y: -1
}, {
x: 1,
y: 0
}, {
x: 0,
y: 1
}, {
x: -1,
y: 0
}];
for (var i = 0; i < arrowOffsets.length; i++) {
var arrow = self.attachAsset('arrow', {
anchorX: 0.5,
anchorY: 1
});
arrow.rotation = MATH_HALF_PI * i;
arrows.push(arrow);
self.addChild(arrow);
}
;
self.rotation = MATH_QUARTER_PI;
self.update = update;
;
function update() {
if (currentPlanet !== destinationPlanet) {
counter++;
var distance = CROSSHAIR_DIST + CROSSHAIR_VARIANCE * Math.sin(counter / CROSSHAIR_PERIOD);
setDistance(distance);
} else if (counter > 0) {
counter = 0;
setDistance(CROSSHAIR_DIST);
}
}
function setDistance(distance) {
for (var i = 0; i < arrows.length; i++) {
arrows[i].x = arrowOffsets[i].x * distance;
arrows[i].y = arrowOffsets[i].y * distance;
}
}
;
setDistance(CROSSHAIR_DIST);
});
var NavigationButton = Container.expand(function (x, y, index, callback) {
var self = Container.call(this);
var details = NAVIGATION[index];
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
var planetGraphics = self.createAsset(details.planet, {
anchorX: 0.5,
anchorY: 0.5
});
var currencyText = self.addChild(new CurrencyText(details.cost));
buttonGraphics.tint = 0xFFAAAA;
planetGraphics.width = buttonGraphics.width * 0.4;
planetGraphics.height = buttonGraphics.width * 0.4;
;
self.unlock = unlock;
self.x = x;
self.y = y;
self.cost = details.cost;
self.planet = details.planet;
self.unlocked = false;
self.on('down', function () {
callback(index);
});
;
function unlock() {
self.unlocked = true;
buttonGraphics.tint = 0xFFFFFF;
currencyText.destroy();
}
});
var NavigationInterface = Container.expand(function (x, y) {
var self = Container.call(this);
var buttons = [];
for (var i = 0; i < NAVIGATION.length; i++) {
var buttonX = (-NAVIGATION.length / 2 + 0.5 + i) * 200;
buttons.push(self.addChild(new NavigationButton(buttonX, 0, i, buttonCallback)));
}
buttons[0].addChild(crosshair);
self.x = x;
self.y = y;
;
function buttonCallback(index) {
var button = buttons[index];
if (button.unlocked) {
setDestination(index);
} else if (money >= button.cost) {
moneyDisplay.setAmount(money -= button.cost);
button.unlock();
}
}
self.setDestination = setDestination;
;
function setDestination(index) {
if (destinationPlanet !== index && ship.direction === 0) {
destinationPlanet = index;
buttons[index].addChild(crosshair);
ship.launch(1);
}
}
buttonCallback(0);
});
var WinningMessage = Container.expand(function (x, y, completionTicks) {
var self = Container.call(this);
var seconds = Math.floor(completionTicks / 60);
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 headingText = self.addChild(new BorderedText('Congratulations, you win!', {
size: 80,
y: messageTime.y - messageTime.height - 10,
anchor: {
x: .5,
y: 1
}
}));
var messageStats = self.addChild(new BorderedText(messages.join('\n'), {
y: 400,
anchor: {
x: .5,
y: 0
}
}));
;
self.x = x;
self.y = y;
});
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() {
// Refresh logic to be implemented here
}
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
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 GAME_TICKS = 60;
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
var PLANET_RADIUS_GREY = 200;
var PLANET_RADIUS_RED = 400;
var PLANET_RADIUS_BLUE = 350;
var PLANET_RADIUS_OMNI = 500;
var PLANET_RADIUS_GOLD = 250;
var PLANET_SPIN_GREY = 0.001;
var PLANET_SPIN_RED = -0.0002;
var PLANET_SPIN_BLUE = 0.001;
var PLANET_SPIN_OMNI = 0.005;
var PLANET_SPIN_GOLD = -0.001;
var ROCKET_DIST_REVERSE = 300;
var ROCKET_DIST_LEAVE = 2500;
var ROCKET_SPEED_BASE = 1.2;
var ROCKET_SPEED_DIV = 5;
var ROCKET_SPEED_DELAY = 10;
var ROCKET_SPEED_REVERSE = 2;
var PLOT_SIZE = 65;
var PLOT_GAP = 90;
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 CURRENCY_DEFAULT_MARGIN = 0;
var CROSSHAIR_DIST = 40;
var CROSSHAIR_VARIANCE = 10;
var CROSSHAIR_PERIOD = 1.25 * GAME_TICKS / MATH_2_PI;
var NAVIGATION = [{
cost: 0,
"class": PlanetGrey,
planet: 'planetGrey',
description: 'Small moon, with no special bonuses.'
}, {
cost: 100,
"class": PlanetRed,
planet: 'planetRed',
description: ''
}, {
cost: 250,
"class": PlanetBlue,
planet: 'planetBlue',
description: ''
}, {
cost: 800,
"class": PlanetOmni,
planet: 'planetOmni',
description: ''
}, {
cost: 3000,
"class": PlanetGold,
planet: 'planetGold',
description: 'A wealthy planet with vast resources.'
}];
;
var money = 10000;
var stats = {
cropsHarvested: 0,
cropsOverrun: 0,
weedsPulled: 0,
creditsEarned: 0,
salesDone: 0,
salesRejected: 0
};
var winningStats;
var winningTick = -1;
var winningTime = '';
var winningMessage;
var currentPlanet = 0;
var destinationPlanet = 0;
var background = game.addChild(new Background());
var planet = game.addChild(new PlanetGrey(GAME_WIDTH / 2, GAME_HEIGHT / 2));
var ship = planet.addChild(new Ship(planet.radius + ROCKET_DIST_REVERSE, 0));
var planets = [planet];
var moneyDisplay = LK.gui.top.addChild(new CurrencyText(money, {
x: 20,
y: 50,
size: 70,
anchor: {
x: 0
}
}));
var crosshair = new Crosshair();
var navigation = LK.gui.bottom.addChild(new NavigationInterface(0, -100));
;
LK.on('tick', function () {
ship.update();
planet.update();
crosshair.update();
});
;
function transitionPlanets() {
LK.effects.flashScreen(0x000000, 500);
currentPlanet = destinationPlanet;
planet.parent.removeChild(planet);
planet = planets[currentPlanet];
if (!planet) {
var planetClass = NAVIGATION[currentPlanet]["class"];
planet = planets[currentPlanet] = new planetClass(GAME_WIDTH / 2, GAME_HEIGHT / 2);
}
if (currentPlanet === NAVIGATION.length - 1) {
if (winningTick < 0) {
winningTick = LK.ticks;
}
winningMessage = LK.gui.center.addChild(new WinningMessage(0, -100, winningTick));
} else if (winningMessage) {
winningMessage.destroy();
winningMessage = undefined;
}
game.addChild(planet);
planet.addChild(ship);
ship.x = planet.radius + ROCKET_DIST_REVERSE;
}
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.