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
User prompt
Fix Bug: 'TypeError: mainAsset.fill is undefined' in or related to this line: 'mainAsset.fill.set(textFill = newFill);' Line Number: 110
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
The traderGraphics should start at scaleX,scaleY of 0,0 and be set in the update statement to: `1 - counter / TRADER_SPAWN_TIME` after setting the position
Code edit (7 edits merged)
Please save this source code
User prompt
The traderGraphics should start at a random point within TRADER_SPAWN_RADIUS, and move towards the 0,0 position over TRADER_SPAWN_TIME
User prompt
Add 5 globals: `TRADER_SPAWN_RADIUS = 1000`, `TRADER_SPAWN_TIME = 2 * GAME_TICKS`, `TRADER_MOVE_ANCHOR = 0.25`, `TRADER_MOVE_ROTATION = 0.15` and `TRADER_MOVE_INTERVAL = 5`
User prompt
Fix Bug: 'ReferenceError: trader is not defined' in or related to this line: 'var traderGraphics = self.attachAsset('trader', {' Line Number: 1300
User prompt
Trader graphics should start off screen and move towards it's 0,0 point
Code edit (1 edits merged)
Please save this source code
Code edit (13 edits merged)
Please save this source code
User prompt
Fix Bug: 'SecurityError: Permission denied to access property "removeChild" on cross-origin object' in or related to this line: 'baseDestroy();' Line Number: 529
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: t is undefined' in or related to this line: 'symbolAsset = self.attachAsset(newSymbol, {' Line Number: 183
Code edit (2 edits merged)
Please save this source code
User prompt
in the transitionPlanets function, destroy all traders and reset the array
User prompt
in the transitionPlanets function, destroy all asteroids and reset the array
Code edit (6 edits merged)
Please save this source code
User prompt
Remove any remaining console logs
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
Add an asset with id "point" to BorderedSymbol and SymbolText
===================================================================
--- original.js
+++ change.js
@@ -230,9 +230,9 @@
var actionCountdown = PLAYER_ACTION_INTERVAL;
var playerGraphics = self.attachAsset('player', {
rotation: MATH_HALF_PI,
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0.75
});
;
self.update = update;
;
@@ -356,8 +356,9 @@
var details = PLANT_DETAILS[type];
;
self.update = update;
self.harvest = harvest;
+ self.overrun = overrun;
self.updateStage = updateStage;
self.refreshGraphics = refreshGraphics;
self.refreshCountdown = refreshCountdown;
self.type = type;
@@ -366,8 +367,9 @@
self.growStages = details.stages;
self.growthTime = details.growthTime;
self.growthVariance = details.growthVariance;
self.growthCountdown = 0;
+ self.strong = false;
self.harvestable = growStage === self.growStages;
;
function update() {
if (--self.growthCountdown <= 0 && self.growStage < self.growStages) {
@@ -387,8 +389,14 @@
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) {
@@ -430,10 +438,10 @@
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.type !== self.type && nextPlant.type !== 'plantDiamond';
- var prevSpreadable = !prevPlant || prevPlant.type !== self.type && prevPlant.type !== 'plantDiamond';
+ var nextSpreadable = !nextPlant || nextPlant.type !== self.type && !nextPlant.strong;
+ var prevSpreadable = !prevPlant || prevPlant.type !== self.type && !prevPlant.strong;
if (nextSpreadable || prevSpreadable) {
var targetNode;
if (nextSpreadable && prevSpreadable) {
targetNode = Math.random() < 0.5 ? node.next : node.prev;
@@ -453,20 +461,15 @@
refreshCountdown();
});
var PlantBush = Plant.expand(function (growthStage, config) {
var self = Plant.call(this, 'plantBush', growthStage, config);
- var baseDestroy = self.destroy;
var baseUpdateStage = self.updateStage;
var fruitCount = 0;
var maxFruitCount = 3;
;
- self.destroy = destroy;
self.updateStage = updateStage;
self.harvest = harvest;
;
- function destroy() {
- baseDestroy();
- }
function updateStage(newStage) {
if (newStage === self.growStages) {
self.refreshCountdown();
if (fruitCount < maxFruitCount) {
@@ -476,14 +479,14 @@
} else {
baseUpdateStage(newStage);
}
}
+ function addFruit() {}
function harvest() {
if (self.harvestable && fruitCount > 0) {
return true;
}
}
- function updateVisibleFruit() {}
});
var PlantStalk = Plant.expand(function (growthStage, config) {
var self = Plant.call(this, 'plantStalk', growthStage, config);
});
@@ -494,8 +497,10 @@
var self = Plant.call(this, 'plantFlower', growthStage, config);
});
var PlantDiamond = Plant.expand(function (growthStage, config) {
var self = Plant.call(this, 'plantDiamond', growthStage, config);
+ ;
+ self.strong = true;
});
var PlantNode = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
;
@@ -513,15 +518,14 @@
self.plant.update();
}
}
function addPlant(plantName, stage) {
- if (self.plant) {
- self.plant.destroy();
+ if (!self.plant || self.plant.overrun()) {
+ var plantBlueprint = PLANT_DETAILS[plantName].blueprint;
+ self.plant = self.addChild(new plantBlueprint(stage, {
+ y: self.offset
+ }));
}
- var plantBlueprint = PLANT_DETAILS[plantName].blueprint;
- self.plant = self.addChild(new plantBlueprint(stage, {
- y: self.offset
- }));
}
function tryAction() {
if (self.plant && self.plant.harvestable && self.plant.harvest()) {
return true;
@@ -1110,17 +1114,17 @@
});
var Background = Container.expand(function () {
var self = Container.call(this);
var backgroundGraphics = self.attachAsset('background', {
+ x: GAME_WIDTH / 2,
+ y: GAME_HEIGHT / 2,
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() {
backgroundGraphics.rotation += Math.PI / 2;
@@ -1205,9 +1209,9 @@
var self = ConfigContainer.call(this, config);
var fruitGraphics = self.attachAsset(fruitName, {
anchorX: 0.5,
anchorY: 0.5,
- scaleX: SCALE_FRUIT_DROP * Math.random() < 0.5 ? 1 : -1,
+ scaleX: SCALE_FRUIT_DROP * (Math.random() < 0.5 ? 1 : -1),
scaleY: SCALE_FRUIT_DROP
});
;
self.fruitName = fruitName;
@@ -1253,34 +1257,44 @@
traders[index] = undefined;
}
}
function generateTrade() {
- // Determine what the trade items are
+ // Determine what the trade items are available
var details = PLANET_DETAILS[planet.name];
var buyList = details.buy;
- var buyName = buyList[Math.floor(Math.random() * buyList.length)];
- var buyValue = buyName !== 'credits' ? FRUIT_DETAILS[buyName] : 1;
+ var buyName = buyList[randomInt(0, buyList.length)];
var sellList = details.sell.filter(function (item) {
return item !== buyName;
});
- var sellName = buyList[Math.floor(Math.random() * sellList.length)];
- // Determine trade value
+ var sellName = sellList[randomInt(0, sellList.length)];
+ // Determine trade value and quantities
+ var sellAmount, buyAmount;
var valueFactor = 1 + TRADER_COST_VARIANCE * (Math.random() * 2 - 1);
- var buyValue = buyName !== 'credits' ? FRUIT_DETAILS[buyName] : 1;
- var sellValue = valueFactor * (sellName !== 'credits' ? FRUIT_DETAILS[sellName] : 1);
- // Determine quantities
- var quantityFactor = TRADER_INVENTORY_MIN + Math.random() * (TRADER_INVENTORY_MAX - TRADER_INVENTORY_MIN);
- var sellAmount = Math.round(quantityFactor * (sellName !== 'credits' ? inventory.getQuantity(sellName) : money));
- var buyAmount = Math.max(1, Math.ceil(buyValue / (sellAmount * sellValue)));
- sellAmount = Math.max(1, Math.round(buyAmount * buyValue / sellValue));
- var trade = {
+ if (sellName === 'credits') {
+ // Player buying Fruit with Credits
+ var value = valueFactor * FRUIT_DETAILS[buyName].value;
+ buyAmount = randomInt(TRADER_FRUIT_OFFER_MIN, TRADER_FRUIT_OFFER_MAX);
+ sellAmount = Math.round(buyAmount * value);
+ } else if (buyName === 'credits') {
+ // Player selling Fruit for Credits
+ var value = valueFactor * FRUIT_DETAILS[sellName].value;
+ var quantity = Math.max(1, inventory.getQuantity(sellName));
+ sellAmount = randomInt(Math.max(1, quantity * TRADER_INVENTORY_MIN), quantity * TRADER_INVENTORY_MAX);
+ buyAmount = Math.round(sellAmount * value);
+ } else {
+ // Fruit exchange
+ var multiplier = 1 + Math.random() * (1 - TRADER_EXCHANGE_MULTIPLIER);
+ var sellValue = valueFactor * FRUIT_DETAILS[buyName].value;
+ var buyValue = FRUIT_DETAILS[sellName].value;
+ sellAmount = Math.ceil(multiplier * sellValue / buyValue);
+ buyAmount = Math.ceil(multiplier * buyValue / sellValue);
+ }
+ return {
sellName: sellName,
sellAmount: sellAmount,
buyName: buyName,
buyAmount: buyAmount
};
- console.log(trade);
- return trade;
}
function checkValue(name, amount) {
if (name === 'credits') {
return money >= amount;
@@ -1466,8 +1480,11 @@
var TRADER_TIME_VARIANCE = 80 * GAME_TICKS;
var TRADER_COST_VARIANCE = 0.1;
var TRADER_INVENTORY_MIN = 0.25;
var TRADER_INVENTORY_MAX = 1.5;
+var TRADER_FRUIT_OFFER_MIN = 1;
+var TRADER_FRUIT_OFFER_MAX = 3;
+var TRADER_EXCHANGE_MULTIPLIER = 5;
var TRADER_FRAME_OFFSET_X = 0.1;
var TRADER_FRAME_OFFSET_Y = -0.56;
var TRADER_DETAIL_MARGIN = 20;
var TRADER_SHIP_SPACING = 50;
@@ -1494,9 +1511,9 @@
plantBush: {
blueprint: PlantBush,
stages: 6,
fruit: 'fruitBush',
- growthTime: 120 * GAME_TICKS,
+ growthTime: 60 * GAME_TICKS,
growthVariance: 30 * GAME_TICKS
},
plantStalk: {
blueprint: PlantStalk,
@@ -1543,14 +1560,14 @@
type: 'red',
plant: 'plantBean'
},
fruitEyeball: {
- value: 10,
+ value: 15,
type: 'red',
plant: 'plantEyeball'
},
fruitFlower: {
- value: 20,
+ value: 25,
type: 'blue',
plant: 'plantFlower'
},
fruitDiamondDust: {
@@ -1566,49 +1583,50 @@
};
;
// Planet & navigation settings
var NAVIGATION = ['planetGrey', 'planetRed', 'planetBlue', 'planetOmni', 'planetGold'];
+var PLANET_LAST = NAVIGATION[NAVIGATION.length - 1];
var PLANET_DETAILS = {
planetGrey: {
cost: 0,
radius: 250,
spin: 0.001,
blueprint: PlanetGrey,
plantTypes: ['green'],
- buy: ['credits', 'fruitBush', 'fruitStalk'],
+ buy: ['credits', 'credits', 'fruitBush', 'fruitStalk'],
sell: ['credits', 'fruitWeeds', 'fruitBush']
},
planetRed: {
cost: 100,
radius: 300,
spin: -0.0002,
blueprint: PlanetRed,
plantTypes: ['green', 'red'],
- buy: ['credits', 'fruitStalk', 'fruitEyeball'],
+ buy: ['credits', 'credits', 'fruitStalk', 'fruitEyeball'],
sell: ['credits', 'fruitWeeds', 'fruitBush', 'fruitStalk', 'fruitEyeball']
},
planetBlue: {
cost: 250,
radius: 250,
spin: 0.001,
blueprint: PlanetBlue,
plantTypes: ['green', 'blue'],
- buy: ['credits', 'fruitFlower'],
+ buy: ['credits', 'credits', 'fruitFlower'],
sell: ['credits', 'fruitWeeds', 'fruitBush', 'fruitFlower']
},
planetOmni: {
cost: 800,
radius: 350,
- spin: 0.0005,
+ spin: -0.0005,
blueprint: PlanetOmni,
plantTypes: ['green', 'blue', 'red', 'omni'],
buy: ['credits'],
sell: ['fruitStalk', 'fruitEyeball', 'fruitFlower', 'fruitDiamond', 'fruitDiamond']
},
planetGold: {
cost: 3000,
radius: 150,
- spin: -0.001,
+ spin: -0.002,
blueprint: PlanetGold,
plantTypes: [],
buy: [],
sell: []
@@ -1647,16 +1665,16 @@
var targetAngle = PLAYER_START_ANGLE;
var currentPlanet = NAVIGATION[0];
var destinationPlanet = NAVIGATION[0];
var background = game.addChild(new Background());
-var planet = game.addChild(new PlanetGrey({
+var midground = game.addChild(new Container());
+var foreground = game.addChild(new Container());
+var planet = background.addChild(new PlanetGrey({
x: GAME_WIDTH / 2,
y: GAME_HEIGHT / 2,
rotation: Math.random() * MATH_2_PI
}));
var ship = planet.background.addChild(new Ship(planet.radius + ROCKET_DIST_REVERSE, 0));
-var midground = game.addChild(new Container());
-var foreground = game.addChild(new Container());
var inventory = LK.gui.top.addChild(new Inventory({
y: INVENTORY_SLOT_SIZE / 2 + 10,
anchorX: .5,
anchorY: .5
@@ -1682,12 +1700,14 @@
}
ship.update();
planet.update();
crosshair.update();
- updateList(asteroidList);
updateList(effectsList);
- trySpawnAsteroid();
- trySpawnTrader();
+ if (planet.name !== PLANET_LAST) {
+ updateList(asteroidList);
+ trySpawnAsteroid();
+ trySpawnTrader();
+ }
});
;
game.on('down', function (obj) {
if (player) {
@@ -1736,9 +1756,9 @@
available.push(i);
}
}
if (available.length > 0) {
- var spawnIndex = Math.floor(Math.random() * available.length);
+ var spawnIndex = available[Math.floor(Math.random() * available.length)];
traders[spawnIndex] = foreground.addChild(new Trader({
index: spawnIndex,
x: GAME_WIDTH / 4 * (spawnIndex % 2 === 0 ? 1 : 3),
y: GAME_HEIGHT / 8 * (spawnIndex < 2 ? 2 : 7)
@@ -1780,9 +1800,9 @@
} else if (winningMessage) {
winningMessage.destroy();
winningMessage = undefined;
}
- game.addChild(planet);
+ background.addChild(planet);
planet.background.addChild(ship);
planet.rotation = Math.random() * MATH_2_PI;
ship.x = planet.radius + ROCKET_DIST_REVERSE;
targetAngle = PLAYER_START_ANGLE;
@@ -1793,8 +1813,12 @@
function mod(x, base) {
return (x % base + base) % base;
}
;
+function randomInt(min, max) {
+ return Math.floor(min + Math.random() * (max - min));
+}
+;
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.