User prompt
In the TraderDialogue class, add 2 horizonally aligned BasicButtons underneath the dialogueBackground; the first button has a 'tick' asset and its callback calls the TraderDialogue's callback with a true, while the second button has a "cross" asset and similarly returns false in the callback
Code edit (1 edits merged)
Please save this source code
User prompt
Move the PlantButton class below the BasicButton
User prompt
The BasicButton should return self at the bottom and the PlantButton should inherit from the BasicButton
Code edit (1 edits merged)
Please save this source code
User prompt
Only create the BasicButton's imageAsset if the imageName is defined, including in the updateImage function
User prompt
Add an updateImage function to the basicbutton class which destroys and replaces the imageAsset if it exists
User prompt
Replace the PlantButton's button asset with a BasicButton
Code edit (1 edits merged)
Please save this source code
User prompt
Add a new BasicButton class that inherits from ConfigContainer and takes in 3 params: imageName, callback and config. The button should be comprised of a buttonBackground asset and an asset derived from the imageName, positioned on top of each other. When the buttonBackground asset is clicked, it should fire off the callback
User prompt
Rename the "button" asset to "navigationButton" and update the asset usage in the NavigationButton class
User prompt
Create a new TraderDialogue class which extends the ConfigContainer class and takes in 6 params: sellName, sellAmount, buyName, buyAmount, callback and config. The class should be comprised of a traderDialogue background, with 3 horizon assets, the first has the id of sellName and has a borderText showing the sellAmount before it, the second is an arrow, and the third has the id of buyName and has a borderText showing the buyAmount. If either the sellName or buyName is "credits" then the respective asset and borderText should be replaced with a CurrencyText instead.
User prompt
fruit should have a random x flip
Code edit (5 edits merged)
Please save this source code
User prompt
Add an update function to the PlantButton class that takes in a plantName param and checks whether the plantName param is different from the cached plantName var and creates an asset at the same position as the button with an id of the plantName, destroying the previous plantName asset if it exists
User prompt
The PlantButton should have an update method that takes in a plantName parameter and does the following: cache the plantName in a plantName var, and if the plantName is different from the cached plantName then create an asset with an id of plantName and destroy the previous one if it exists.
User prompt
Create a new PlantButton class which will have a plantButton asset offset at y = PLANT_BUTTON_OFFSET, and an arrow asset offset at y = PLANT_BUTTON_OFFSET/2
User prompt
Add a new global called PLANT_BUTTON_OFFSET = -250, then create a new PlantButton class which will have a plantButton asset offset at y = PLANT_BUTTON_OFFSET, and an arrow asset offset at y = PLANT_BUTTON_OFFSET/2
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: t is undefined' in or related to this line: 'var planetGraphics = self.createAsset(details.planet, {' Line Number: 677
Code edit (12 edits merged)
Please save this source code
User prompt
Fix Bug: 'TypeError: t is undefined' in or related to this line: 'var planetGraphics = self.createAsset(details.planet, {' Line Number: 677
Code edit (6 edits merged)
Please save this source code
User prompt
In the ship's update function, it should emit a rocket flame particle downward, while the ship's direction is not 0
===================================================================
--- original.js
+++ change.js
@@ -186,8 +186,9 @@
anchorY: 0.5
});
var counter = 0;
var particles = [];
+ background.rotation = -MATH_HALF_PI;
;
self.update = update;
self.launch = launch;
self.x = x;
@@ -217,10 +218,9 @@
}
}
if (self.direction) {
particles.push(background.addChild(new FlameParticle({
- x: self.x,
- y: self.y
+ x: (Math.random() - 0.5) * ROCKET_FLAME_BREDTH
})));
}
updateList(particles);
}
@@ -234,24 +234,25 @@
}
}
});
var FlameParticle = ConfigContainer.expand(function (config) {
- var self = ConfigContainer.call(this);
+ var self = ConfigContainer.call(this, config);
var flameGraphics = self.attachAsset('flame', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5
});
- var lifetime = FLAME_PARTICLE_LIFETIME;
+ var lifetime = ROCKET_FLAME_LIFETIME;
;
self.update = update;
;
function update() {
- self.y += FLAME_PARTICLE_SPEED;
- flameGraphics.alpha = 0.5 * (lifetime / FLAME_PARTICLE_LIFETIME);
+ var remaining = lifetime / ROCKET_FLAME_LIFETIME;
+ self.y -= ROCKET_FLAME_SPEED;
+ flameGraphics.alpha = 0.5 * remaining;
+ flameGraphics.scale.set(remaining);
return --lifetime <= 0;
}
- ;
});
var Plant = ConfigContainer.expand(function (type, growStage, config) {
var self = ConfigContainer.call(this, config);
var details = PLANT_DETAILS[type];
@@ -533,29 +534,32 @@
}
}
});
});
-var Planet = Container.expand(function (x, y, radius, assetName, barren) {
- var self = Container.call(this);
- var perimeter = MATH_2_PI * radius;
+var Planet = ConfigContainer.expand(function (planetName, config, barren) {
+ var self = ConfigContainer.call(this);
+ var details = PLANET_DETAILS[planetName];
+ var perimeter = MATH_2_PI * details.radius;
var numPlots = Math.floor(perimeter / (PLOT_SIZE + PLOT_GAP));
var numNodes = numPlots * 4;
var nodes = [];
var fruitList = [];
- self.background = self.addChild(new Container());
- var planetGraphics = self.createAsset(assetName, {
- anchorX: 0.5,
- anchorY: 0.5
- });
- planetGraphics.scale.set(2 * radius / 1000);
+ var background = self.addChild(new Container());
+ var planetGraphics;
+ if (details && details.planet) {
+ planetGraphics = self.createAsset(details.planet, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ }
+ planetGraphics.scale.set(2 * details.radius / 1000);
;
self.update = update;
- self.x = x;
- self.y = y;
- self.name = assetName;
- self.nodes = nodes;
- self.radius = radius;
+ self.name = planetName;
self.barren = barren;
+ self.nodes = nodes;
+ self.background = background;
+ self.radius = details.radius;
self.fruitList = fruitList;
self.rotation = Math.random() * MATH_2_PI;
self.spin = 0;
;
@@ -569,10 +573,10 @@
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 = radius * Math.cos(angle);
- var nodeY = radius * Math.sin(angle);
+ 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 node = self.addChild(new nodeType({
@@ -600,32 +604,22 @@
;
createNodes();
return self;
});
-var PlanetGrey = Planet.expand(function (x, y) {
- var self = Planet.call(this, x, y, PLANET_RADIUS_GREY, 'planetGrey');
- ;
- self.spin = PLANET_SPIN_GREY;
+var PlanetGrey = Planet.expand(function (config) {
+ var self = Planet.call(this, 'planetGrey', config);
});
-var PlanetRed = Planet.expand(function (x, y) {
- var self = Planet.call(this, x, y, PLANET_RADIUS_RED, 'planetRed');
- ;
- self.spin = PLANET_SPIN_RED;
+var PlanetRed = Planet.expand(function (config) {
+ var self = Planet.call(this, 'planetRed', config);
});
-var PlanetBlue = Planet.expand(function (x, y) {
- var self = Planet.call(this, x, y, PLANET_RADIUS_BLUE, 'planetBlue');
- ;
- self.spin = PLANET_SPIN_BLUE;
+var PlanetBlue = Planet.expand(function (config) {
+ var self = Planet.call(this, 'planetBlue', config);
});
-var PlanetOmni = Planet.expand(function (x, y) {
- var self = Planet.call(this, x, y, PLANET_RADIUS_OMNI, 'planetOmni');
- ;
- self.spin = PLANET_SPIN_OMNI;
+var PlanetOmni = Planet.expand(function (config) {
+ var self = Planet.call(this, 'planetOmni', config);
});
-var PlanetGold = Planet.expand(function (x, y) {
- var self = Planet.call(this, x, y, PLANET_RADIUS_GOLD, 'planetGold', true);
- ;
- self.spin = PLANET_SPIN_GOLD;
+var PlanetGold = Planet.expand(function (config) {
+ var self = Planet.call(this, 'planetGold', config, true);
});
var Crosshair = Container.expand(function () {
var self = Container.call(this);
var counter = 0;
@@ -674,11 +668,11 @@
}
;
setDistance(CROSSHAIR_DIST);
});
-var NavigationButton = Container.expand(function (x, y, index, callback) {
- var self = Container.call(this);
- var details = NAVIGATION[index];
+var NavigationButton = ConfigContainer.expand(function (planetName, callback, config) {
+ var self = ConfigContainer.call(this, config);
+ var details = PLANET_DETAILS[planetName];
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xFFAAAA
@@ -697,9 +691,9 @@
self.cost = details.cost;
self.planet = details.planet;
self.unlocked = false;
self.on('down', function () {
- callback(index);
+ callback(PLANET_DETAILS.indexOf(planetName));
});
;
function unlock() {
self.unlocked = true;
@@ -709,11 +703,15 @@
});
var NavigationInterface = Container.expand(function (x, y) {
var self = Container.call(this);
var buttons = [];
+ var baseOffset = -NAVIGATION.length / 2 + 0.5;
for (var i = 0; i < NAVIGATION.length; i++) {
- var buttonX = (-NAVIGATION.length / 2 + 0.5 + i) * 200;
- buttons.push(self.addChild(new NavigationButton(buttonX, 0, i, buttonCallback)));
+ var buttonX = (baseOffset + i) * 200;
+ buttons.push(self.addChild(new NavigationButton(NAVIGATION[i], buttonCallback, {
+ x: buttonX,
+ y: 0
+ })));
}
buttons[0].addChild(crosshair);
self.x = x;
self.y = y;
@@ -975,9 +973,9 @@
var angle = Math.atan2(self.y - planet.y, self.x - planet.x) - planet.rotation;
var fruitX = Math.cos(angle) * planet.radius;
var fruitY = Math.sin(angle) * planet.radius;
var fruit = planet.addChild(new Fruit('fruitDiamondDust', {
- rotation: angle,
+ rotation: angle + MATH_HALF_PI,
x: fruitX,
y: fruitY
}));
}
@@ -1052,12 +1050,9 @@
/****
* Game Code
****/
-// Constants for flame particle
// Math constants / pre-calculations
-var FLAME_PARTICLE_LIFETIME = 30; // Number of ticks before the particle disappears
-var FLAME_PARTICLE_SPEED = 5; // Speed at which the particle moves downward
var MATH_2_PI = Math.PI * 2;
var MATH_HALF_PI = Math.PI / 2;
var MATH_QUARTER_PI = Math.PI / 4;
var MATH_HALF_ROOT_3 = Math.sqrt(3) / 2;
@@ -1066,29 +1061,23 @@
// Game constants
var GAME_TICKS = 60;
var GAME_WIDTH = 2048;
var GAME_HEIGHT = 2732;
-// Planet constants (TODO: Move to PLANET_DETAILS map)
-var PLANET_RADIUS_GREY = 200;
-var PLANET_RADIUS_RED = 400;
-var PLANET_RADIUS_BLUE = 350;
-var PLANET_RADIUS_OMNI = 500;
-var PLANET_RADIUS_GOLD = 250;
-var PLANET_SPIN_GREY = 0.001;
-var PLANET_SPIN_RED = -0.0002;
-var PLANET_SPIN_BLUE = 0.001;
-var PLANET_SPIN_OMNI = 0.005;
-var PLANET_SPIN_GOLD = -0.001;
// Rocket constants
var ROCKET_DIST_REVERSE = 300;
var ROCKET_DIST_LEAVE = 2500;
var ROCKET_SPEED_BASE = 1.2;
var ROCKET_SPEED_DIV = 5;
var ROCKET_SPEED_DELAY = 10;
var ROCKET_SPEED_REVERSE = 2;
+var ROCKET_FLAME_BREDTH = 30;
+var ROCKET_FLAME_LIFETIME = 30;
+var ROCKET_FLAME_SPEED = 5;
+// Farm constants
var PLOT_SIZE = 65;
var PLOT_GAP = 90;
var PLOT_ALPHA_STEP = 1 / GAME_TICKS;
+// Interface settings
var TEXT_OFFSETS = [[0, 1], [MATH_HALF_ROOT_3, 0.5], [MATH_HALF_ROOT_3, -0.5], [0, -1], [-MATH_HALF_ROOT_3, -0.5], [-MATH_HALF_ROOT_3, 0.5], [0, 0]];
var TEXT_BORDER_WEIGHT = 4;
var TEXT_DEFAULT_SIZE = 50;
var TEXT_DEFAULT_FONT = 'Arial';
@@ -1211,71 +1200,57 @@
type: 'none',
plant: 'none'
}
};
+// Planet & navigation settings
+var NAVIGATION = ['planetGrey', 'planetRed', 'planetBlue', 'planetOmni', 'planetGold'];
var PLANET_DETAILS = {
planetGrey: {
cost: 0,
+ radius: 200,
+ spin: 0.001,
blueprint: PlanetGrey,
plantTypes: ['green'],
buy: ['credits', 'fruitBush', 'fruitStalk'],
sell: ['credits', 'fruitWeeds', 'fruitBush']
},
planetRed: {
cost: 100,
+ radius: 400,
+ spin: -0.0002,
blueprint: PlanetRed,
plantTypes: ['green', 'red'],
buy: ['credits', 'fruitStalk', 'fruitEyeball'],
sell: ['credits', 'fruitWeeds', 'fruitBush', 'fruitStalk', 'fruitEyeball']
},
planetBlue: {
cost: 250,
+ radius: 350,
+ spin: 0.001,
blueprint: PlanetBlue,
plantTypes: ['green', 'blue'],
buy: ['credits', 'fruitFlower'],
sell: ['credits', 'fruitWeeds', 'fruitBush', 'fruitFlower']
},
planetOmni: {
cost: 800,
+ radius: 500,
+ spin: 0.005,
blueprint: PlanetOmni,
plantTypes: ['green', 'blue', 'red', 'omni'],
buy: ['credits'],
sell: ['fruitStalk', 'fruitEyeball', 'fruitFlower', 'fruitDiamond', 'fruitDiamond']
},
planetGold: {
cost: 3000,
+ radius: 250,
+ spin: -0.001,
blueprint: PlanetGold,
plantTypes: [],
buy: [],
sell: []
}
};
-var NAVIGATION = [{
- cost: 0,
- "class": PlanetGrey,
- planet: 'planetGrey',
- description: 'Small moon, with no special bonuses.'
-}, {
- cost: 100,
- "class": PlanetRed,
- planet: 'planetRed',
- description: ''
-}, {
- cost: 250,
- "class": PlanetBlue,
- planet: 'planetBlue',
- description: ''
-}, {
- cost: 800,
- "class": PlanetOmni,
- planet: 'planetOmni',
- description: ''
-}, {
- cost: 3000,
- "class": PlanetGold,
- planet: 'planetGold',
- description: 'A wealthy planet with vast resources.'
-}];
;
var money = 10000;
var asteroidList = [];
var stats = {
@@ -1295,9 +1270,13 @@
var targetAngle = PLAYER_START_ANGLE;
var currentPlanet = 0;
var destinationPlanet = 0;
var background = game.addChild(new Background());
-var planet = game.addChild(new PlanetGrey(GAME_WIDTH / 2, GAME_HEIGHT / 2));
+var planet = game.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 planets = [planet];
var inventory = LK.gui.top.addChild(new Inventory({
y: INVENTORY_SLOT_SIZE / 2 + 10,
@@ -1367,9 +1346,12 @@
}
asteroidList = [];
if (!planet) {
var planetClass = NAVIGATION[currentPlanet]["class"];
- planet = planets[currentPlanet] = new planetClass(GAME_WIDTH / 2, GAME_HEIGHT / 2);
+ planet = planets[currentPlanet] = new planetClass({
+ x: GAME_WIDTH / 2,
+ y: GAME_HEIGHT / 2
+ });
}
if (currentPlanet === NAVIGATION.length - 1) {
if (winningTick < 0) {
saveStats();
@@ -1381,8 +1363,9 @@
winningMessage = undefined;
}
game.addChild(planet);
planet.background.addChild(ship);
+ planet.rotation = Math.random() * MATH_2_PI;
ship.x = planet.radius + ROCKET_DIST_REVERSE;
background.refresh();
inventory.refreshAllowed();
}
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.