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
@@ -254,12 +254,14 @@
}
} else {
var direction = angleDifference / Math.abs(angleDifference);
var angleStep = PLAYER_SPEED / planet.radius;
- var newAngle = currentAngle + direction * Math.min(Math.abs(angleDifference), angleStep);
+ var angleIncrease = Math.min(Math.abs(angleDifference), angleStep);
+ var newAngle = currentAngle + direction * angleIncrease;
self.x = Math.cos(newAngle) * planet.radius;
self.y = Math.sin(newAngle) * planet.radius;
self.angle = newAngle;
+ stats.distanceRun += angleIncrease * planet.radius;
playerGraphics.scale.x = direction < 0 ? -1 : 1;
playerGraphics.rotation = newAngle + MATH_HALF_PI;
actionCountdown = 0; // Perform action immediately after stopping
}
@@ -363,10 +365,10 @@
var self = ConfigContainer.call(this, config);
var details = PLANT_DETAILS[type];
;
self.update = update;
+ self.uproot = uproot;
self.harvest = harvest;
- self.overrun = overrun;
self.updateStage = updateStage;
self.refreshGraphics = refreshGraphics;
self.refreshCountdown = refreshCountdown;
self.type = type;
@@ -383,8 +385,23 @@
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++;
+ }
+ } else {
+ uprooted = true;
+ }
+ if (uprooted) {
+ self.destroy();
+ return true;
+ }
+ }
function harvest() {
if (self.harvestable) {
if (self.growStage === self.growStages) {
new Fruit(self.fruit, {
@@ -397,14 +414,8 @@
self.destroy();
return true;
}
}
- function overrun() {
- if (!self.strong) {
- self.destroy();
- return true;
- }
- }
function updateStage(newStage) {
self.growStage = newStage;
self.refreshGraphics();
if (self.growStage === self.growStages) {
@@ -447,18 +458,18 @@
if (self.growStage === self.growStages && --spreadCountdown <= 0) {
var node = self.parent;
var nextPlant = node.next.plant;
var prevPlant = node.prev.plant;
- var nextSpreadable = !nextPlant && !nextPlant.strong;
- var prevSpreadable = !prevPlant && !prevPlant.strong;
+ var nextSpreadable = !nextPlant || !nextPlant.strong;
+ var prevSpreadable = !prevPlant || !prevPlant.strong;
if (nextSpreadable || prevSpreadable) {
var targetNode;
if (nextSpreadable && prevSpreadable) {
targetNode = Math.random() < 0.5 ? node.next : node.prev;
} else {
targetNode = nextSpreadable ? node.next : node.prev;
}
- targetNode.addPlant(self.type, 1);
+ targetNode.addPlant(self.type, 1, true);
}
refreshCountdown();
}
}
@@ -526,10 +537,10 @@
if (self.plant) {
self.plant.update();
}
}
- function addPlant(plantName, stage) {
- if (!self.plant || self.plant.overrun()) {
+ function addPlant(plantName, stage, overrun) {
+ if (!self.plant || self.plant.uproot(overrun)) {
var plantBlueprint = PLANT_DETAILS[plantName].blueprint;
self.plant = self.addChild(new plantBlueprint(stage, {
y: self.offset
}));
@@ -558,10 +569,10 @@
if (!self.plant && --spawnCountdown <= 0) {
self.addPlant('plantWeeds', 1);
}
}
- function addPlant(plantName, stage) {
- baseAddPlant(plantName, stage);
+ function addPlant(plantName, stage, overrun) {
+ baseAddPlant(plantName, stage, overrun);
refreshCountdown();
}
function tryAction() {
if (baseTryAction()) {
@@ -583,9 +594,8 @@
var baseAddPlant = self.addPlant;
var baseTryAction = self.tryAction;
var targetAlpha = 0;
var planterButton;
- var planterLinger = 0;
var currentAlpha = targetAlpha;
var farmGraphics = self.attachAsset('farm', {
anchorX: 0.5,
anchorY: 0.6,
@@ -600,69 +610,72 @@
self.potted = false;
;
function update() {
baseUpdate();
+ // Control the in/out fade when overrun
if (currentAlpha !== targetAlpha) {
if (currentAlpha < targetAlpha) {
currentAlpha = Math.min(targetAlpha, currentAlpha + PLOT_ALPHA_STEP);
} else {
currentAlpha = Math.max(targetAlpha, currentAlpha - PLOT_ALPHA_STEP);
}
farmGraphics.alpha = currentAlpha;
}
- if (planterLinger > 0) {
- planterLinger--;
+ // Show/hide planter button
+ var fruitName = inventory.getSelection();
+ if (planterRequirements(fruitName)) {
+ if (!planterButton) {
+ planterButton = self.addChild(new PlanterButton(fruitName, planterButtonCallback, {
+ scale: SCALE_FRUIT_PLANTER
+ }));
+ } else {
+ planterButton.updateImage(fruitName);
+ }
} else if (planterButton) {
planterButton.destroy();
planterButton = undefined;
}
}
- function addPlant(plantName, stage, potted) {
- baseAddPlant(plantName, stage);
- if (!potted && plantName === 'plantWeeds') {
- self.plant.y = baseOffset;
- targetAlpha = 0;
- } else {
- targetAlpha = 1;
- }
- self.potted = potted;
- }
function tryAction() {
if (baseTryAction()) {
targetAlpha = 1;
return true;
- } else if (self.alpha === 1 && !self.plant && inventory.allowed) {
- var fruitName = inventory.getSelection();
- var quantity = inventory.getQuantity(fruitName);
- if (quantity > 0) {
- if (planterButton) {
- planterButton.updateImage(fruitName);
- } else {
- planterButton = self.addChild(new PlanterButton(fruitName, function () {
- self.tryPlantFruit(inventory.getSelection());
- skipRetarget = true;
- }, {
- scale: SCALE_FRUIT_PLANTER
- }));
- }
- planterLinger = PLAYER_ACTION_INTERVAL + PLOT_EXTRA_LINGER;
- } else {
- planterLinger = 0;
- }
- } else {
- planterLinger = 0;
+ } else if (taskPlanter) {
+ tryPlantFruit(taskPlanter);
+ taskPlanter = false;
}
}
function tryPlantFruit(fruitName) {
- if (!self.plant) {
+ if (planterRequirements(fruitName)) {
var plantName = FRUIT_DETAILS[fruitName].plant;
- self.addPlant(plantName, 1, true);
+ self.addPlant(plantName, 1, false, true);
inventory.adjustItem(fruitName, -1);
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;
+ }
+ function planterRequirements(fruitName) {
+ return !self.plant && currentAlpha === 1 && inventory.allowed && inventory.getQuantity(fruitName) > 0;
+ }
+ function planterButtonCallback() {
+ resetTasks();
+ taskPlanter = inventory.getSelection();
+ var dx = planet.x - self.x;
+ var dy = planet.y - self.y;
+ targetPoint = Math.atan2(dy, dx);
+ skipRetarget = true;
+ }
});
var Planet = ConfigContainer.expand(function (planetName, config, barren) {
var self = ConfigContainer.call(this, config);
var details = PLANET_DETAILS[planetName];
@@ -861,14 +874,12 @@
function setDestination(destPlanet) {
if (player) {
destinationPlanet = destPlanet;
buttons[destPlanet].addChild(crosshair);
+ resetTasks();
if (destinationPlanet !== currentPlanet) {
taskLaunch = true;
targetAngle = 0;
- } else {
- taskLaunch = false;
- targetAngle = player.angle;
}
}
}
;
@@ -882,10 +893,10 @@
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', 'Asteroid Impacts'];
- var messageStatKeys = ['distanceRun', 'creditsEarned', 'cropsHarvested', 'cropsOverrun', 'weedsPulled', 'salesDone', 'salesRejected', 'asteroidImpacts'];
+ 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, {
anchorX: .5,
anchorY: 1,
y: -TEXT_WINNING_OFFSET
@@ -916,10 +927,15 @@
return title + ' ';
}
function mapKey(key) {
var stat = winningStats[key];
- var extra = stat - stats[key];
- return ': ' + stat + (extra ? ' (+ ' + extra + ')' : '');
+ var extra = stats[key] - stat;
+ switch (key) {
+ case 'distanceRun':
+ return ': ' + Math.round(stat * PLAYER_DISTANCE_SCALE) + 'm' + (extra ? ' [+' + Math.round(extra * PLAYER_DISTANCE_SCALE) + 'm]' : '');
+ default:
+ return ': ' + stat + (extra ? ' [+' + extra + ']' : '');
+ }
}
});
var InventorySlot = ConfigContainer.expand(function (index, config) {
var self = ConfigContainer.call(this, config);
@@ -1516,9 +1532,9 @@
// Interface settings
var SCALE_FRUIT_DROP = 0.8;
var SCALE_FRUIT_INVENTORY = 0.6;
var SCALE_FRUIT_TRADE = 0.65;
-var SCALE_FRUIT_PLANTER = 0.3;
+var SCALE_FRUIT_PLANTER = 0.25;
var TEXT_WINNING_OFFSET = 300;
var TEXT_SIZE_SMALL = 35;
var TEXT_SIZE_LARGE = 75;
var CROSSHAIR_DIST = 40;
@@ -1550,8 +1566,9 @@
var PLAYER_ACTION_SQRDIST = PLAYER_ACTION_DIST * PLAYER_ACTION_DIST;
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;
;
// Trader settings
var TRADER_TIME_INITIAL = 15 * GAME_TICKS;
var TRADER_TIME_MIN = 10 * GAME_TICKS;
@@ -1730,8 +1747,9 @@
weedsPulled: 0,
salesDone: 0,
salesRejected: 0,
distanceRun: 0,
+ rocketLaunches: 0,
asteroidImpacts: 0
};
var winningStats = {};
var winningTick = -1;
@@ -1817,16 +1835,11 @@
if (player) {
var clickPosition = obj.event.getLocalPosition(game);
var dx = clickPosition.x - planet.x;
var dy = clickPosition.y - planet.y;
- var sqrDistance = dx * dx + dy * dy;
var range = planet.radius + PLAYER_BUFFER_DIST;
- if (sqrDistance <= range * range) {
- if (taskLaunch) {
- taskLaunch = false;
- navigation.setDestination(currentPlanet);
- }
- taskPlanter = false;
+ if (dx * dx + dy * dy <= range * range) {
+ resetTasks();
retargetAngle = Math.atan2(dy, dx) - planet.rotation;
}
}
});
@@ -1881,8 +1894,9 @@
LK.effects.flashScreen(0x000000, 500);
currentPlanet = destinationPlanet;
planet.parent.removeChild(planet);
planet = planetMap[currentPlanet];
+ stats.rocketLaunches++;
asteroidList.forEach(function (asteroid) {
asteroid.destroy();
});
asteroidList = [];
@@ -1910,19 +1924,27 @@
} else if (winningMessage) {
winningMessage.destroy();
winningMessage = undefined;
}
- taskLaunch = false;
- taskPlanter = false;
midground.addChild(planet);
planet.background.addChild(ship);
planet.rotation = Math.random() * MATH_2_PI;
ship.x = planet.radius + ROCKET_DIST_REVERSE;
+ resetTasks();
targetAngle = PLAYER_START_ANGLE;
background.refresh();
inventory.refreshAllowed();
}
;
+function resetTasks() {
+ if (taskLaunch) {
+ taskLaunch = false;
+ navigation.setDestination(currentPlanet);
+ }
+ taskPlanter = false;
+ targetAngle = player.angle;
+}
+;
function saveStats() {
for (var key in stats) {
winningStats[key] = stats[key];
}
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.