Code edit (1 edits merged)
Please save this source code
User prompt
Create a new UprootButton class that has the same logic as the PlanterButton
User prompt
Duplicate the PlanterButton as UprootButton and PlanterButton classes
Code edit (9 edits merged)
Please save this source code
User prompt
Please remove PLOT_EXTRA_LINGER
Code edit (4 edits merged)
Please save this source code
User prompt
When collecting a fruit, create a PopupEffect (adding it to the effectsList) above the player
User prompt
create a PopupEffect class inheriting from the ConfigContainer class and taking in a fruitName and config params. The class contains a SymbolText element which slowly increases it's y value and disappears after 1 second
Code edit (1 edits merged)
Please save this source code
User prompt
after performing the player collection check, fruit should fall towards the planet at a fixed rate, stopping when it reaches the planet's radius distance
User prompt
fruit should fall towards the planet at a fixed rate
Code edit (9 edits merged)
Please save this source code
User prompt
In the planterButtonCallback function, instead of setting the targetPoint to 0, set targetPoint to the angle between the planet and the self's positions
Code edit (1 edits merged)
Please save this source code
User prompt
When a fruit is collected, increment the cropsHarvested stat
User prompt
When the trader buttoncallback is called, increment the salesRejected stat if the accepted param is false, otherwise increment the salesDone stat if it was fully completed
User prompt
When an asteroid impacts the planet, increase the stats.asteroidImpacts value by 1
Code edit (10 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: trader.handleTradeCallback is not a function' in or related to this line: 'trader.handleTradeCallback(false);' Line Number: 1946
Code edit (4 edits merged)
Please save this source code
User prompt
Add an LK.timeout of 500ms before creating the player in the ship
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
The TraderDialogue's setTint should flash the dialogueBackground object the tint colour for 500ms
Code edit (9 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -360,68 +360,58 @@
flameGraphics.scale.set(remaining);
return --lifetime <= 0;
}
});
-var Plant = ConfigContainer.expand(function (type, growStage, config) {
+var Plant = ConfigContainer.expand(function (type, growStage, potted, config) {
var self = ConfigContainer.call(this, config);
var details = PLANT_DETAILS[type];
;
self.update = update;
self.uproot = uproot;
+ self.action = action;
self.harvest = harvest;
self.updateStage = updateStage;
self.refreshGraphics = refreshGraphics;
self.refreshCountdown = refreshCountdown;
self.type = type;
self.fruit = details.fruit;
+ self.fruitCount = 0;
+ self.potted = potted;
self.growStage = growStage;
self.growStages = details.stages;
self.growthTime = details.growthTime;
self.growthVariance = details.growthVariance;
self.growthCountdown = 0;
- self.strong = false;
- self.harvestable = growStage === self.growStages;
+ self.strong = false; // Whether the plant can prevent weeds overrunning it
+ self.actionable = false; // Whether passive actions can be performed on this plant
+ self.harvestable = false; // Whether the plant can be manually harvested (with the harvest button)
;
function update() {
if (--self.growthCountdown <= 0 && self.growStage < self.growStages) {
self.updateStage(self.growStage + 1);
}
}
function uproot(overrun) {
- var uprooted = false;
if (overrun) {
if (!self.strong) {
- uprooted = true;
stats.cropsOverrun++;
+ return true;
}
} else {
- uprooted = true;
- }
- if (uprooted) {
- self.destroy();
return true;
}
+ return false;
}
+ function action() {
+ return self.actionable;
+ }
function harvest() {
- if (self.harvestable) {
- if (self.growStage === self.growStages) {
- new Fruit(self.fruit, {
- x: self.parent.x,
- y: self.parent.y,
- rotation: self.parent.rotation
- });
- }
- self.parent.plant = undefined;
- self.destroy();
- return true;
- }
+ return self.harvestable;
}
function updateStage(newStage) {
self.growStage = newStage;
self.refreshGraphics();
- if (self.growStage === self.growStages) {
- self.harvestable = true;
- } else {
+ if (self.growStage !== self.growStages) {
self.refreshCountdown();
}
}
function refreshGraphics() {
@@ -442,15 +432,18 @@
refreshCountdown();
refreshGraphics();
return self;
});
-var PlantWeeds = Plant.expand(function (growthStage, config) {
- var self = Plant.call(this, 'plantWeeds', growthStage, config);
+var PlantWeeds = Plant.expand(function (growthStage, potted, config) {
+ var self = Plant.call(this, 'plantWeeds', growthStage, potted, config);
var baseUpdate = self.update;
var spreadCountdown = 0;
+ var fruitOffset = -90;
;
self.update = update;
+ self.action = action;
self.strong = true;
+ self.actionable = !potted;
self.harvestable = true;
;
function update() {
baseUpdate();
@@ -472,17 +465,34 @@
}
refreshCountdown();
}
}
+ function action() {
+ if (self.actionable) {
+ stats.weedsPulled++;
+ if (self.growStage === self.growStages) {
+ var rotation = self.parent.rotation;
+ var fruitX = self.parent.x + Math.cos(rotation + MATH_HALF_PI) * (self.y + fruitOffset);
+ var fruitY = self.parent.y + Math.sin(rotation + MATH_HALF_PI) * (self.y + fruitOffset);
+ new Fruit(self.fruit, {
+ x: fruitX,
+ y: fruitY,
+ rotation: rotation
+ });
+ }
+ self.parent.removePlant();
+ return true;
+ }
+ }
function refreshCountdown() {
var baseTime = WEEDS_SPREAD_TIME + Math.random() * WEEDS_SPREAD_VARIANCE;
spreadCountdown = Math.floor(PLANT_GROWTH_FACTOR * baseTime);
}
;
refreshCountdown();
});
-var PlantBush = Plant.expand(function (growthStage, config) {
- var self = Plant.call(this, 'plantBush', growthStage, config);
+var PlantBush = Plant.expand(function (growthStage, potted, config) {
+ var self = Plant.call(this, 'plantBush', growthStage, potted, config);
var baseUpdateStage = self.updateStage;
var fruitCount = 0;
var maxFruitCount = 3;
;
@@ -506,29 +516,29 @@
return true;
}
}
});
-var PlantStalk = Plant.expand(function (growthStage, config) {
- var self = Plant.call(this, 'plantStalk', growthStage, config);
+var PlantStalk = Plant.expand(function (growthStage, potted, config) {
+ var self = Plant.call(this, 'plantStalk', growthStage, potted, config);
});
-var PlantEyeball = Plant.expand(function (growthStage, config) {
- var self = Plant.call(this, 'plantEyeball', growthStage, config);
+var PlantEyeball = Plant.expand(function (growthStage, potted, config) {
+ var self = Plant.call(this, 'plantEyeball', growthStage, potted, config);
});
-var PlantFlower = Plant.expand(function (growthStage, config) {
- var self = Plant.call(this, 'plantFlower', growthStage, config);
+var PlantFlower = Plant.expand(function (growthStage, potted, config) {
+ var self = Plant.call(this, 'plantFlower', growthStage, potted, config);
});
-var PlantDiamond = Plant.expand(function (growthStage, config) {
- var self = Plant.call(this, 'plantDiamond', growthStage, config);
+var PlantDiamond = Plant.expand(function (growthStage, potted, config) {
+ var self = Plant.call(this, 'plantDiamond', growthStage, potted, config);
;
self.strong = true;
});
var PlantNode = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
;
self.update = update;
self.addPlant = addPlant;
+ self.removePlant = removePlant;
self.tryAction = tryAction;
- self.offset = PLOT_NODE_OFFSET;
self.plant;
self.farm;
self.prev;
self.next;
@@ -537,20 +547,25 @@
if (self.plant) {
self.plant.update();
}
}
- function addPlant(plantName, stage, overrun) {
+ function addPlant(plantName, stage, overrun, potted) {
if (!self.plant || self.plant.uproot(overrun)) {
+ if (self.plant) {
+ self.removePlant();
+ }
var plantBlueprint = PLANT_DETAILS[plantName].blueprint;
- self.plant = self.addChild(new plantBlueprint(stage, {
- y: self.offset
+ self.plant = self.addChild(new plantBlueprint(stage, potted, {
+ y: potted ? PLOT_FARM_OFFSET : PLOT_NODE_OFFSET
}));
}
}
+ function removePlant() {
+ self.plant.destroy();
+ self.plant = undefined;
+ }
function tryAction() {
- if (self.plant && self.plant.harvestable && self.plant.harvest()) {
- return true;
- }
+ return !!self.plant && self.plant.actionable && self.plant.action();
}
;
return self;
});
@@ -566,20 +581,21 @@
;
function update() {
baseUpdate();
if (!self.plant && --spawnCountdown <= 0) {
- self.addPlant('plantWeeds', 1);
+ self.addPlant('plantWeeds', 1, false, false);
}
}
- function addPlant(plantName, stage, overrun) {
- baseAddPlant(plantName, stage, overrun);
+ function addPlant(plantName, stage, overrun, potted) {
+ baseAddPlant(plantName, stage, overrun, potted);
refreshCountdown();
}
function tryAction() {
if (baseTryAction()) {
refreshCountdown();
return true;
}
+ return false;
}
function refreshCountdown() {
var baseTime = WEEDS_SPAWN_TIME + Math.random() * WEEDS_SPAWN_VARIANCE;
spawnCountdown = Math.floor(PLANT_GROWTH_FACTOR * baseTime);
@@ -588,9 +604,8 @@
refreshCountdown();
});
var FarmNode = PlantNode.expand(function (config) {
var self = PlantNode.call(this, config);
- var baseOffset = self.offset;
var baseUpdate = self.update;
var baseAddPlant = self.addPlant;
var baseTryAction = self.tryAction;
var targetAlpha = 0;
@@ -605,10 +620,8 @@
self.update = update;
self.addPlant = addPlant;
self.tryAction = tryAction;
self.tryPlantFruit = tryPlantFruit;
- self.offset = PLOT_FARM_OFFSET;
- self.potted = false;
;
function update() {
baseUpdate();
// Control the in/out fade when overrun
@@ -648,30 +661,25 @@
if (planterRequirements(fruitName)) {
var plantName = FRUIT_DETAILS[fruitName].plant;
self.addPlant(plantName, 1, false, true);
inventory.adjustItem(fruitName, -1);
+ stats.cropsPlanted++;
if (plantName === 'plantWeeds') {
self.plant.harvestable = false;
}
}
}
function addPlant(plantName, stage, overrun, potted) {
- baseAddPlant(plantName, stage, overrun);
- if (!potted && plantName === 'plantWeeds') {
- self.plant.y = baseOffset;
- targetAlpha = 0;
- } else {
- targetAlpha = 1;
- }
- self.potted = potted;
+ baseAddPlant(plantName, stage, overrun, potted);
+ targetAlpha = potted ? 1 : 0;
}
function planterRequirements(fruitName) {
return !self.plant && currentAlpha === 1 && inventory.allowed && inventory.getQuantity(fruitName) > 0;
}
function planterButtonCallback() {
resetTasks();
taskPlanter = inventory.getSelection();
- targetAngle = Math.atan2(planet.y - self.y, planet.x - self.x);
+ targetAngle = Math.atan2(self.y, self.x);
skipRetarget = true;
}
});
var Planet = ConfigContainer.expand(function (planetName, config, barren) {
@@ -891,16 +899,16 @@
var hours = Math.floor(minutes / 60);
seconds = seconds % 60;
minutes = minutes % 60;
var winningTime = (hours > 0 ? hours + 'h ' : '') + (minutes > 0 ? minutes + 'm ' : '') + seconds + 's';
- var messageStatTitles = ['Distance Walked', 'Credits Earned', 'Items Harvested', 'Crops Overrun', 'Weeds Pulled', 'Trades Accepted', 'Trades Declined', 'Rocket Launches', 'Asteroid Impacts'];
- var messageStatKeys = ['distanceRun', 'creditsEarned', 'cropsHarvested', 'cropsOverrun', 'weedsPulled', 'salesDone', 'salesRejected', 'rocketLaunches', 'asteroidImpacts'];
- var timeText = self.addChild(new BorderedText('You reached the Gold Planet in: ' + winningTime, {
+ var messageStatTitles = ['Distance Walked', 'Credits Earned', 'Items Collected', 'Crops Planted', 'Crops Overrun', 'Weeds Pulled', 'Trades Accepted', 'Trades Declined', 'Rocket Launches', 'Asteroid Impacts'];
+ var messageStatKeys = ['distanceRun', 'creditsEarned', 'cropsHarvested', 'cropsPlanted', 'cropsOverrun', 'weedsPulled', 'salesDone', 'salesRejected', 'rocketLaunches', 'asteroidImpacts'];
+ var timeText = self.addChild(new BorderedText('You reached the Gold Planet in ' + winningTime, {
anchorX: .5,
anchorY: 1,
y: -TEXT_WINNING_OFFSET
}));
- self.addChild(new BorderedText('Congratulations, you win!', {
+ self.addChild(new BorderedText('Congratulations, you won!', {
anchorX: .5,
anchorY: 1,
size: TEXT_SIZE_LARGE,
y: timeText.y - timeText.height - 10
@@ -1014,8 +1022,9 @@
function selectSlot(index) {
slots[index].addChild(selector);
selectedIndex = index;
refreshAllowed();
+ resetTasks();
}
function adjustItem(item, quantity) {
var slotIndex = itemIndices[item];
var newItem = false;
@@ -1248,17 +1257,12 @@
self.fruitName = fruitName;
self.update = update;
;
function update() {
- if (player) {
- var dx = self.x - player.x;
- var dy = self.y - player.y;
- var sqrDistance = dx * dx + dy * dy;
- if (sqrDistance < PLAYER_ACTION_SQRDIST) {
- inventory.adjustItem(fruitName, 1);
- stats.cropsHarvested++;
- return true;
- }
+ self.y += GAME_SPEED;
+ if (self.y > planet.y + planet.radius) {
+ // Fruit has reached the planet surface
+ return true;
}
}
;
planet.fruitList.push(planet.addChild(self));
@@ -1317,10 +1321,10 @@
var closeDialogue = false;
skipRetarget = true;
if (accepted) {
if (checkValue(trade.sellName, trade.sellAmount)) {
- makeAdjustment(trade.sellName, -trade.sellAmount);
- makeAdjustment(trade.buyName, trade.buyAmount);
+ makeAdjustment(trade.sellName, -trade.sellAmount, false);
+ makeAdjustment(trade.buyName, trade.buyAmount, true);
stats.salesDone++;
closeDialogue = true;
} else {
traderDialogue.setTint(0xFF0000);
@@ -1381,13 +1385,19 @@
} else {
return inventory.getQuantity(name) >= amount;
}
}
- function makeAdjustment(name, amount) {
+ function makeAdjustment(name, amount, collectStats) {
if (name === 'credits') {
moneyDisplay.setText(money += amount);
+ if (collectStats) {
+ stats.creditsEarned += amount;
+ }
} else {
inventory.adjustItem(name, amount);
+ if (collectStats) {
+ stats.itemsCollected += amount;
+ }
}
}
;
return self;
@@ -1739,8 +1749,9 @@
var planetMap = {};
var asteroidList = [];
var stats = {
creditsEarned: 0,
+ cropsPlanted: 0,
cropsHarvested: 0,
cropsOverrun: 0,
weedsPulled: 0,
salesDone: 0,
@@ -1938,9 +1949,11 @@
taskLaunch = false;
navigation.setDestination(currentPlanet);
}
taskPlanter = false;
- targetAngle = player.angle;
+ if (player) {
+ targetAngle = player.angle;
+ }
}
;
function saveStats() {
for (var key in stats) {
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.