Code edit (12 edits merged)
Please save this source code
User prompt
Instead of calling `planet.update()` in the onTick callback, iterate through the planetMap object and update all planets
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -381,10 +381,11 @@
self.growthTime = details.growthTime;
self.growthVariance = details.growthVariance;
self.growthCountdown = 0;
self.skipFinalGrowth = false;
- self.harvestOffsetMin = 0;
- self.harvestOffsetMax = 0;
+ self.fruitOffsetMin = 0;
+ self.fruitOffsetMax = 0;
+ self.fruitRange = 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.uprootable = false; // Whether the plant can be manually uprooted (with the uproot button)
@@ -412,13 +413,19 @@
}
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);
+ self.fruitCount--;
+ var fruitOffset = randomFloatInRange(self.fruitOffsetMin, self.fruitOffsetMax);
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);
+ if (self.fruitRange > 0) {
+ var rangeRotation = Math.random() * MATH_2_PI;
+ var rangeDistance = Math.random() * self.fruitRange;
+ fruitX += Math.cos(rangeRotation) * rangeDistance;
+ fruitY += Math.sin(rangeRotation) * rangeDistance;
+ }
new Fruit(self.fruit, {
x: fruitX,
y: fruitY,
rotation: rotation
@@ -448,9 +455,8 @@
var baseTime = self.growthTime + Math.random() * self.growthVariance;
self.growthCountdown = Math.floor(PLANT_GROWTH_FACTOR * baseTime);
}
;
- updateStage(growthStage);
return self;
});
var PlantWeeds = Plant.expand(function (growthStage, potted, config) {
var self = Plant.call(this, 'plantWeeds', growthStage, potted, config);
@@ -494,8 +500,9 @@
self.harvest();
self.parent.removePlant();
return true;
}
+ return false;
}
function updateStage(newStage) {
baseUpdateStage(newStage);
;
@@ -507,20 +514,26 @@
var baseTime = WEEDS_SPREAD_TIME + Math.random() * WEEDS_SPREAD_VARIANCE;
spreadCountdown = Math.floor(PLANT_GROWTH_FACTOR * baseTime);
}
;
- refreshCountdown();
+ self.updateStage(growthStage);
});
var PlantBush = Plant.expand(function (growthStage, potted, config) {
var self = Plant.call(this, 'plantBush', growthStage, potted, config);
var baseUpdateStage = self.updateStage;
var baseHarvest = self.harvest;
var maxFruitCount = 3;
+ var fruitScale = 0.9;
+ var fruitYFactor = 0.5;
+ var fruitAssets = [];
;
self.updateStage = updateStage;
self.harvest = harvest;
self.action = action;
self.skipFinalGrowth = true;
+ self.fruitOffsetMin = 45;
+ self.fruitOffsetMax = 45;
+ self.fruitRange = 30;
;
function updateStage(newStage) {
baseUpdateStage(newStage);
;
@@ -545,30 +558,79 @@
}
return false;
}
function updateVisibleFruit() {
- // TODO
+ var assetSlots = [];
+ var emptySlots = [];
+ for (var i = 0; i < maxFruitCount; i++) {
+ (fruitAssets[i] ? assetSlots : emptySlots).push(i);
+ }
+ var change = self.fruitCount - assetSlots.length;
+ while (change !== 0) {
+ if (change < 0) {
+ // Remove asset
+ var index = randomIntInRange(0, assetSlots.length);
+ var slot = assetSlots[index];
+ fruitAssets[slot].destroy();
+ fruitAssets[slot] = undefined;
+ assetSlots.splice(index, 1);
+ change++;
+ } else if (change > 0) {
+ // Make new asset
+ var index = randomIntInRange(0, emptySlots.length);
+ var slot = emptySlots[index];
+ var offset = slot - (maxFruitCount / 2 - 0.5);
+ var fruitX = offset * self.fruitRange;
+ var fruitY = -randomFloatInRange(self.fruitOffsetMin, self.fruitOffsetMax) - Math.cos(offset * MATH_HALF_PI) * self.fruitRange * fruitYFactor;
+ fruitAssets[slot] = self.attachAsset(self.fruit, {
+ x: fruitX,
+ y: fruitY,
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: fruitScale,
+ scaleY: fruitScale,
+ rotation: -MATH_QUARTER_PI
+ });
+ emptySlots.splice(index, 1);
+ change--;
+ }
+ }
}
+ ;
+ self.updateStage(growthStage);
+ return self;
});
var PlantStalk = Plant.expand(function (growthStage, potted, config) {
var self = Plant.call(this, 'plantStalk', growthStage, potted, config);
;
self.skipFinalGrowth = true;
+ ;
+ self.updateStage(growthStage);
+ return self;
});
var PlantEyeball = Plant.expand(function (growthStage, potted, config) {
var self = Plant.call(this, 'plantEyeball', growthStage, potted, config);
;
self.skipFinalGrowth = true;
+ ;
+ self.updateStage(growthStage);
+ return self;
});
var PlantFlower = Plant.expand(function (growthStage, potted, config) {
var self = Plant.call(this, 'plantFlower', growthStage, potted, config);
;
self.skipFinalGrowth = true;
+ ;
+ self.updateStage(growthStage);
+ return self;
});
var PlantDiamond = Plant.expand(function (growthStage, potted, config) {
var self = Plant.call(this, 'plantDiamond', growthStage, potted, config);
;
self.strong = true;
+ ;
+ self.updateStage(growthStage);
+ return self;
});
var Fruit = ConfigContainer.expand(function (fruitName, config) {
var self = ConfigContainer.call(this, config);
var falling = true;
@@ -807,11 +869,8 @@
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, potted);
@@ -826,18 +885,18 @@
targetAngle = Math.atan2(self.y, self.x);
skipRetarget = true;
}
function uprootRequirements() {
- return !!self.plant && self.plant.harvestable && self.plant.potted;
+ return !!self.plant && self.plant.uprootable && 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 Planet = ConfigContainer.expand(function (planetName, config) {
var self = ConfigContainer.call(this, config);
var details = PLANET_DETAILS[planetName];
var perimeter = MATH_2_PI * details.radius;
var numPlots = Math.floor(perimeter / (PLOT_SIZE + PLOT_GAP));
@@ -854,9 +913,10 @@
});
;
self.update = update;
self.name = planetName;
- self.barren = !!barren;
+ self.barren = !!details.barren; // No plant life
+ self.coarse = !!details.coarse; // No weed nodes (still starts + grows + spreads)
self.nodes = nodes;
self.background = background;
self.fruitList = fruitList;
self.spin = details.spin;
@@ -867,18 +927,18 @@
updateList(nodes);
updateList(fruitList);
}
function createNodes() {
- if (!barren) {
+ if (!self.barren) {
var defaultPlant = 'plantWeeds';
var maxPlantStage = PLANT_DETAILS[defaultPlant].stages;
for (var i = 0; i < numNodes; i++) {
var angle = i / numNodes * MATH_2_PI;
var nodeX = self.radius * Math.cos(angle);
var nodeY = self.radius * Math.sin(angle);
var rotation = angle + MATH_HALF_PI;
var farmNode = i !== 0 && i % 4 === 0;
- var nodeType = farmNode ? FarmNode : i % 2 === 0 ? WeedsNode : PlantNode;
+ var nodeType = farmNode ? FarmNode : i % 2 === 0 && !self.coarse ? WeedsNode : PlantNode;
var node = self.addChild(new nodeType({
x: nodeX,
y: nodeY,
rotation: rotation
@@ -916,9 +976,9 @@
var PlanetOmni = Planet.expand(function (config) {
var self = Planet.call(this, 'planetOmni', config);
});
var PlanetGold = Planet.expand(function (config) {
- var self = Planet.call(this, 'planetGold', config, true);
+ var self = Planet.call(this, 'planetGold', config);
});
var Crosshair = Container.expand(function () {
var self = Container.call(this);
var counter = 0;
@@ -1292,32 +1352,25 @@
});
var PlanterButton = BasicButton.expand(function (plantName, callback, config) {
var self = BasicButton.call(this, plantName, callback, config);
var arrow = self.attachAsset('arrow', {
- y: PLANT_BUTTON_OFFSET / 2,
+ y: PLOT_BUTTON_OFFSET / 2,
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.4,
scaleY: 1.4
});
;
- self.buttonBackground.y = PLANT_BUTTON_OFFSET;
- self.imageAsset.y = PLANT_BUTTON_OFFSET;
+ self.buttonBackground.y = PLOT_BUTTON_OFFSET;
+ self.imageAsset.y = PLOT_BUTTON_OFFSET;
;
return self;
});
var UprootButton = BasicButton.expand(function (plantName, callback, config) {
var self = BasicButton.call(this, 'cross', callback, config);
- var arrow = self.attachAsset('arrow', {
- y: PLANT_BUTTON_OFFSET / 2,
- anchorX: 0.5,
- anchorY: 0.5,
- scaleX: 1.4,
- scaleY: -1.4
- });
;
- self.buttonBackground.y = PLANT_BUTTON_OFFSET;
- self.imageAsset.y = PLANT_BUTTON_OFFSET;
+ self.buttonBackground.y = PLOT_BUTTON_OFFSET;
+ self.imageAsset.y = PLOT_BUTTON_OFFSET;
;
return self;
});
var Background = Container.expand(function () {
@@ -1683,8 +1736,9 @@
var PLOT_GAP = 120;
var PLOT_NODE_OFFSET = 20;
var PLOT_FARM_OFFSET = -30;
var PLOT_ALPHA_STEP = 1 / GAME_TICKS;
+var PLOT_BUTTON_OFFSET = -220;
;
// Interface settings
var SCALE_FRUIT_DROP = 0.8;
var SCALE_FRUIT_INVENTORY = 0.6;
@@ -1726,11 +1780,12 @@
var PLAYER_BUFFER_DIST = 400;
var PLAYER_BUFFER_SQRDIST = PLAYER_BUFFER_DIST * PLAYER_BUFFER_DIST;
var PLAYER_START_ANGLE = Math.PI / 16;
var PLAYER_DISTANCE_SCALE = 0.01;
+var PLANT_DEAD_COLOUR = 0x964B00; // Hex color for brown
;
// Trader settings
-var TRADER_TIME_INITIAL = 15 * GAME_TICKS;
+var TRADER_TIME_INITIAL = 10 * GAME_TICKS;
var TRADER_TIME_MIN = 10 * GAME_TICKS;
var TRADER_TIME_MAX = 50 * GAME_TICKS;
var TRADER_COST_VARIANCE = 0.1;
var TRADER_INVENTORY_MIN = 0.25;
@@ -1759,9 +1814,8 @@
var GROW_WARNING_GENERAL = 'This cannot grow on this planet';
var GROW_WARNING_DIAMOND = 'This cannot be planted, only sold';
var FRUIT_FALL_SPEED = 3;
var PLANT_GROWTH_FACTOR = 0.1;
-var PLANT_BUTTON_OFFSET = -220;
var PLANT_FRUIT_SCALE = 0.6;
var PLANT_DETAILS = {
plantWeeds: {
blueprint: PlantWeeds,
@@ -1876,8 +1930,9 @@
planetOmni: {
cost: 800,
radius: 350,
spin: -0.0005,
+ coarse: true,
blueprint: PlanetOmni,
plantTypes: ['green', 'blue', 'red', 'omni'],
buy: ['credits'],
sell: ['fruitStalk', 'fruitEyeball', 'fruitFlower', 'fruitDiamond', 'fruitDiamond']
@@ -1885,8 +1940,9 @@
planetGold: {
cost: 3000,
radius: 150,
spin: -0.002,
+ barren: true,
blueprint: PlanetGold,
plantTypes: [],
buy: [],
sell: []
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.