Code edit (17 edits merged)
Please save this source code
User prompt
add a global PLANT_DEAD_COLOUR variable which is a hex-tint for brown
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -359,9 +359,9 @@
flameGraphics.scale.set(remaining);
return --lifetime <= 0;
}
});
-var Plant = ConfigContainer.expand(function (type, growStage, potted, config) {
+var Plant = ConfigContainer.expand(function (type, growthStage, potted, config) {
var self = ConfigContainer.call(this, config);
var details = PLANT_DETAILS[type];
;
self.update = update;
@@ -374,51 +374,72 @@
self.type = type;
self.fruit = details.fruit;
self.fruitCount = 0;
self.potted = potted;
- self.growStage = growStage;
- self.growStages = details.stages;
+ self.graphics;
+ self.growthStage = growthStage;
+ self.growthStages = details.stages;
self.growthTime = details.growthTime;
self.growthVariance = details.growthVariance;
self.growthCountdown = 0;
+ self.skipFinalGrowth = false;
+ self.harvestOffsetMin = 0;
+ self.harvestOffsetMax = 0;
+ self.harvest;
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)
+ self.uprootable = false; // Whether the plant can be manually uprooted (with the uproot button)
;
function update() {
- if (--self.growthCountdown <= 0 && self.growStage < self.growStages) {
- self.updateStage(self.growStage + 1);
+ if (--self.growthCountdown <= 0 && self.growthStage < self.growthStages) {
+ self.updateStage(self.growthStage + 1);
}
}
function uproot(overrun) {
if (overrun) {
if (!self.strong) {
stats.cropsOverrun++;
+ self.harvest();
return true;
}
- } else {
+ } else if (self.uprootable) {
+ self.harvest();
return true;
}
return false;
}
function action() {
return self.actionable;
}
- function harvest() {
- return self.harvestable;
+ function harvest(quantity) {
+ var max = Math.min(self.fruitCount, quantity || Infinity);
+ for (var i = 0; i < max; i++) {
+ // TODO: add x position variations
+ var fruitOffset = randomFloatInRange(self.harvestOffsetMin, self.harvestOffsetMax);
+ 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
+ });
+ }
}
function updateStage(newStage) {
- self.growStage = newStage;
- self.refreshGraphics();
- if (self.growStage !== self.growStages) {
+ if (newStage !== self.growthStages || !self.skipFinalGrowth) {
+ self.growthStage = newStage;
+ self.refreshGraphics();
+ }
+ if (self.growthStage !== self.growthStages) {
self.refreshCountdown();
}
}
function refreshGraphics() {
if (self.graphics) {
self.graphics.destroy();
}
- self.graphics = self.createAsset(self.type + self.growStage, {
+ self.graphics = self.createAsset(self.type + self.growthStage, {
anchorX: 0.5,
anchorY: 1,
scaleX: Math.random() < 0.5 ? 1 : -1
});
@@ -427,28 +448,30 @@
var baseTime = self.growthTime + Math.random() * self.growthVariance;
self.growthCountdown = Math.floor(PLANT_GROWTH_FACTOR * baseTime);
}
;
- refreshCountdown();
- refreshGraphics();
+ updateStage(growthStage);
return self;
});
var PlantWeeds = Plant.expand(function (growthStage, potted, config) {
var self = Plant.call(this, 'plantWeeds', growthStage, potted, config);
var baseUpdate = self.update;
+ var baseUpdateStage = self.updateStage;
var spreadCountdown = 0;
- var fruitOffset = -90;
;
self.update = update;
self.action = action;
+ self.updateStage = updateStage;
self.strong = true;
self.actionable = !potted;
- self.harvestable = true;
+ self.uprootable = potted;
+ self.fruitOffsetMin = 85;
+ self.fruitOffsetMax = 95;
;
function update() {
baseUpdate();
;
- if (self.growStage === self.growStages && --spreadCountdown <= 0) {
+ if (self.growthStage === self.growthStages && --spreadCountdown <= 0) {
var node = self.parent;
var nextPlant = node.next.plant;
var prevPlant = node.prev.plant;
var nextSpreadable = !nextPlant || !nextPlant.strong;
@@ -467,22 +490,20 @@
}
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.harvest();
self.parent.removePlant();
return true;
}
}
+ function updateStage(newStage) {
+ baseUpdateStage(newStage);
+ ;
+ if (newStage === self.growthStages) {
+ self.fruitCount = 1;
+ }
+ }
function refreshCountdown() {
var baseTime = WEEDS_SPREAD_TIME + Math.random() * WEEDS_SPREAD_VARIANCE;
spreadCountdown = Math.floor(PLANT_GROWTH_FACTOR * baseTime);
}
@@ -491,40 +512,58 @@
});
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 baseHarvest = self.harvest;
var maxFruitCount = 3;
;
self.updateStage = updateStage;
self.harvest = harvest;
+ self.action = action;
+ self.skipFinalGrowth = true;
;
function updateStage(newStage) {
- if (newStage === self.growStages) {
- self.refreshCountdown();
- if (fruitCount < maxFruitCount) {
- fruitCount++;
- self.harvestable = true;
+ baseUpdateStage(newStage);
+ ;
+ if (newStage === self.growthStages) {
+ if (self.fruitCount < maxFruitCount) {
+ self.fruitCount++;
+ self.actionable = true;
+ updateVisibleFruit();
}
- } else {
- baseUpdateStage(newStage);
}
}
- function addFruit() {}
- function harvest() {
- if (self.harvestable && fruitCount > 0) {
+ function harvest(quantity) {
+ baseHarvest(quantity);
+ ;
+ self.actionable = self.fruitCount > 0;
+ updateVisibleFruit();
+ }
+ function action() {
+ if (self.actionable && self.fruitCount > 0) {
+ self.harvest(1);
return true;
}
+ return false;
}
+ function updateVisibleFruit() {
+ // TODO
+ }
});
var PlantStalk = Plant.expand(function (growthStage, potted, config) {
var self = Plant.call(this, 'plantStalk', growthStage, potted, config);
+ ;
+ self.skipFinalGrowth = true;
});
var PlantEyeball = Plant.expand(function (growthStage, potted, config) {
var self = Plant.call(this, 'plantEyeball', growthStage, potted, config);
+ ;
+ self.skipFinalGrowth = true;
});
var PlantFlower = Plant.expand(function (growthStage, potted, config) {
var self = Plant.call(this, 'plantFlower', growthStage, potted, config);
+ ;
+ self.skipFinalGrowth = true;
});
var PlantDiamond = Plant.expand(function (growthStage, potted, config) {
var self = Plant.call(this, 'plantDiamond', growthStage, potted, config);
;
@@ -695,8 +734,9 @@
var baseAddPlant = self.addPlant;
var baseTryAction = self.tryAction;
var targetAlpha = 0;
var planterButton;
+ var uprootButton;
var currentAlpha = targetAlpha;
var farmGraphics = self.attachAsset('farm', {
anchorX: 0.5,
anchorY: 0.6,
@@ -718,9 +758,9 @@
currentAlpha = Math.max(targetAlpha, currentAlpha - PLOT_ALPHA_STEP);
}
farmGraphics.alpha = currentAlpha;
}
- // Show/hide planter button
+ // Show/hide the planter button
var fruitName = inventory.getSelection();
if (planterRequirements(fruitName)) {
if (!planterButton) {
planterButton = self.addChild(new PlanterButton(fruitName, planterButtonCallback, {
@@ -732,18 +772,37 @@
} else if (planterButton) {
planterButton.destroy();
planterButton = undefined;
}
+ // Show/hide the uproot button
+ if (uprootRequirements()) {
+ if (!uprootButton) {
+ uprootButton = self.addChild(new UprootButton(fruitName, uprootButtonCallback, {}));
+ }
+ } else if (uprootButton) {
+ uprootButton.destroy();
+ uprootButton = undefined;
+ }
}
function tryAction() {
if (baseTryAction()) {
targetAlpha = 1;
return true;
} else if (taskPlanter) {
tryPlantFruit(taskPlanter);
taskPlanter = false;
+ } else if (taskUproot) {
+ tryUproot();
+ taskPlanter = true;
}
}
+ function tryUproot() {
+ if (uprootRequirements()) {
+ if (self.plant.uproot(false)) {
+ self.removePlant();
+ }
+ }
+ }
function tryPlantFruit(fruitName) {
if (planterRequirements(fruitName)) {
var plantName = FRUIT_DETAILS[fruitName].plant;
self.addPlant(plantName, 1, false, true);
@@ -766,8 +825,17 @@
taskPlanter = inventory.getSelection();
targetAngle = Math.atan2(self.y, self.x);
skipRetarget = true;
}
+ function uprootRequirements() {
+ return !!self.plant && self.plant.harvestable && self.plant.potted;
+ }
+ function uprootButtonCallback() {
+ resetTasks();
+ taskUproot = true;
+ targetAngle = Math.atan2(self.y, self.x);
+ skipRetarget = true;
+ }
});
var Planet = ConfigContainer.expand(function (planetName, config, barren) {
var self = ConfigContainer.call(this, config);
var details = PLANET_DETAILS[planetName];
@@ -1863,8 +1931,9 @@
var retargetAngle;
var targetAngle = PLAYER_START_ANGLE;
var taskLaunch = false;
var taskPlanter = false;
+var taskUproot = false;
var currentPlanet = NAVIGATION[0];
var destinationPlanet = NAVIGATION[0];
var background = game.addChild(new Background());
var midground = game.addChild(new Container());
@@ -2033,8 +2102,9 @@
if (taskLaunch) {
taskLaunch = false;
navigation.setDestination(currentPlanet);
}
+ taskUproot = false;
taskPlanter = false;
if (player) {
targetAngle = player.angle;
}
@@ -2049,11 +2119,18 @@
function mod(x, base) {
return (x % base + base) % base;
}
;
+// TODO: Remove
function randomInt(min, max) {
- return Math.floor(min + Math.random() * (max - min));
+ return min === max ? min : Math.floor(min + Math.random() * (max - min));
}
+function randomIntInRange(min, max) {
+ return min === max ? min : Math.floor(min + Math.random() * (max - min));
+}
+function randomFloatInRange(min, max) {
+ return min === max ? min : min + Math.random() * (max - min);
+}
;
function approxZero(value) {
return value > -MATH_APPROX_ZERO && value < MATH_APPROX_ZERO;
}
\ 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.