Code edit (4 edits merged)
Please save this source code
User prompt
Add an asset with id "point" to BorderedSymbol and SymbolText
User prompt
Add an asset with id "point" to BorderedText, BorderedSymbol and SymbolText
Code edit (1 edits merged)
Please save this source code
User prompt
Created traders should be added to the foreground
User prompt
Created asteroids should be added to the midground and created traders should be added to the foreground
Code edit (9 edits merged)
Please save this source code
User prompt
add two containers to the game object called foreground and midground. Created asteroids should be added to the midground and created traders should be added to the foreground
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: trySpawnTrader is not defined' in or related to this line: 'trySpawnTrader();' Line Number: 1518
Code edit (1 edits merged)
Please save this source code
User prompt
In the Trader's constructor, if its setTrade object is defined, then create a TraderDialogue (sellName, sellAmount, buyName, buyAmount are all in the setTrade object), and add a new function to handle the callback with a bool param
Code edit (8 edits merged)
Please save this source code
User prompt
Add a new Trader class inheriting from ConfigContainer and has params of config and setTrade, with a trader asset attached
Code edit (1 edits merged)
Please save this source code
User prompt
Thanks for the comment, please remove the dialogueBackground's event
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
===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,26 @@
/****
* Classes
****/
+var ConfigContainer = Container.expand(function (config) {
+ var self = Container.call(this);
+ ;
+ config = config || {};
+ self.x = config.x || 0;
+ self.y = config.y || 0;
+ self.rotation = config.rotation || 0;
+ if (config.width !== undefined) {
+ self.width = config.width;
+ }
+ if (config.height !== undefined) {
+ self.height = config.height;
+ }
+ if (self.anchor) {
+ self.anchor.set(config.anchorX || 0, config.anchorY || 0);
+ }
+ ;
+ return self;
+});
var BorderedText = Container.expand(function (string, config) {
var self = Container.call(this);
config = config || {};
var textList = [];
@@ -57,14 +76,18 @@
size: config.size || TEXT_DEFAULT_SIZE
};
for (var i = 0; i < TEXT_OFFSETS.length; i++) {
var localConfig = i === TEXT_OFFSETS.length - 1 ? symbolSettings : borderSettings;
- var symbol = self.attachAsset('currencySymbol', {});
- symbol.tint = localConfig.fill;
- symbol.anchor.set(anchorX, anchorY);
- symbol.scale.set(localConfig.size / 100);
- symbol.x += TEXT_OFFSETS[i][0] * TEXT_BORDER_WEIGHT;
- symbol.y += TEXT_OFFSETS[i][1] * TEXT_BORDER_WEIGHT;
+ var symbol = self.attachAsset('currencySymbol', {
+ x: TEXT_OFFSETS[i][0] * TEXT_BORDER_WEIGHT,
+ y: TEXT_OFFSETS[i][1] * TEXT_BORDER_WEIGHT,
+ tint: localConfig.fill,
+ scaleX: localConfig.size / 100,
+ scaleY: localConfig.size / 100,
+ anchorX: anchorX,
+ anchorY: anchorY
+ });
+ ;
if (i === TEXT_OFFSETS.length - 1) {
mainSymbol = symbol;
}
}
@@ -107,27 +130,8 @@
}
;
alignText();
});
-var ConfigContainer = Container.expand(function (config) {
- var self = Container.call(this);
- ;
- config = config || {};
- self.x = config.x || 0;
- self.y = config.y || 0;
- self.rotation = config.rotation || 0;
- if (config.width !== undefined) {
- self.width = config.width;
- }
- if (config.height !== undefined) {
- self.height = config.height;
- }
- if (self.anchor) {
- self.anchor.set(config.anchorX || 0, config.anchorY || 0);
- }
- ;
- return self;
-});
var Player = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var actionCountdown = PLAYER_ACTION_INTERVAL;
var playerGraphics = self.attachAsset('player', {
@@ -149,9 +153,9 @@
self.x = Math.cos(newAngle) * planet.radius;
self.y = Math.sin(newAngle) * planet.radius;
playerGraphics.scale.x = direction < 0 ? -1 : 1;
playerGraphics.rotation = newAngle + MATH_HALF_PI;
- actionCountdown = PLAYER_ACTION_INTERVAL;
+ actionCountdown = 0; // Perform action immediately after stopping
} else if (--actionCountdown <= 0) {
actionCountdown = PLAYER_ACTION_INTERVAL;
performAction(currentAngle);
}
@@ -479,9 +483,8 @@
anchorX: 0.5,
anchorY: 0.6,
alpha: currentAlpha
});
- farmGraphics.scale.set(PLOT_SIZE / 100);
;
self.update = update;
self.addPlant = addPlant;
self.tryAction = tryAction;
@@ -498,8 +501,14 @@
currentAlpha = Math.max(targetAlpha, currentAlpha - PLOT_ALPHA_STEP);
}
farmGraphics.alpha = currentAlpha;
}
+ if (planterLinger > 0) {
+ planterLinger--;
+ } else if (planterButton) {
+ planterButton.destroy();
+ planterButton = undefined;
+ }
}
function addPlant(plantName, stage, potted) {
baseAddPlant(plantName, stage);
if (!potted && plantName === 'plantWeeds') {
@@ -517,29 +526,22 @@
} else if (self.alpha === 1 && !self.plant && inventory.allowed) {
var fruitName = inventory.getSelection();
var quantity = inventory.getQuantity(fruitName);
if (quantity > 0) {
- var plant = FRUIT_DETAILS[selection].plant;
if (planterButton) {
- planterButton.updateImage(plant);
+ planterButton.updateImage(fruitName);
} else {
- planterButton = self.addChild(new PlantButton(plant, function () {
+ planterButton = self.addChild(new PlantButton(fruitName, function () {
self.tryPlantFruit(inventory.getSelection());
}, {}));
}
- planterLinger = 5;
+ planterLinger = PLAYER_ACTION_INTERVAL + PLOT_EXTRA_LINGER;
} else {
planterLinger = 0;
}
} else {
planterLinger = 0;
}
- if (planterLinger > 0) {
- planterLinger--;
- } else if (planterButton) {
- planterButton.destroy();
- planterButton = undefined;
- }
}
function tryPlantFruit(fruitName) {
if (!self.plant) {
var plantName = FRUIT_DETAILS[fruitName].plant;
@@ -559,13 +561,15 @@
var numNodes = numPlots * 4;
var nodes = [];
var fruitList = [];
var background = self.addChild(new Container());
+ var planetScale = 2 * details.radius / 1000;
var planetGraphics = self.createAsset(planetName, {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0.5,
+ scaleX: planetScale,
+ scaleY: planetScale
});
- planetGraphics.scale.set(2 * details.radius / 1000);
;
self.update = update;
self.name = planetName;
self.barren = !!barren;
@@ -963,8 +967,10 @@
var randomScale = ASTEROID_SCALE_MIN + Math.random() * ASTEROID_SCALE_VAR;
var asteroidGraphics = self.attachAsset('asteroid', {
anchorX: 0.5,
anchorY: 0.5,
+ scaleX: randomScale,
+ scaleY: randomScale,
rotation: Math.random() * MATH_2_PI
});
var side = self.x < 0;
var targetY = ASTEROID_TARGET_OFFSET + Math.random() * (GAME_HEIGHT - 2 * ASTEROID_TARGET_OFFSET);
@@ -972,9 +978,8 @@
var rotationSpeed = (Math.random() - 0.5) * 2 * ASTEROID_ROTATION_MAX;
var angle = Math.atan2(targetY - self.y, targetX - self.x);
var velocityX = ASTEROID_SPEED * Math.cos(angle);
var velocityY = ASTEROID_SPEED * Math.sin(angle);
- asteroidGraphics.scale.set(randomScale);
;
self.update = update;
;
function update() {
@@ -1007,16 +1012,17 @@
});
var Explosion = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
var baseScale = config.scale;
+ var frameCount = 0;
var explosionGraphics = self.attachAsset('explosion', {
anchorX: 0.25,
anchorY: 0.5,
+ scaleX: baseScale,
+ scaleY: baseScale,
alpha: 0.5,
rotation: Math.atan2(self.y - planet.y, self.x - planet.x)
});
- var frameCount = 0;
- explosionGraphics.scale.set(baseScale);
;
self.update = update;
;
function update() {
@@ -1035,11 +1041,11 @@
var self = ConfigContainer.call(this, config);
var fruitGraphics = self.attachAsset(fruitName, {
anchorX: 0.5,
anchorY: 0.5,
- scaleX: Math.random() < 0.5 ? 1 : -1
+ scaleX: PLANT_FRUIT_SCALE * Math.random() < 0.5 ? 1 : -1,
+ scaleY: PLANT_FRUIT_SCALE
});
- fruitGraphics.scale.set(PLANT_FRUIT_SCALE);
;
self.fruitName = fruitName;
self.update = update;
;
@@ -1152,14 +1158,26 @@
;
buttonBackground.on('down', callback);
return self;
});
+var Trader = ConfigContainer.expand(function (config, setTrade) {
+ var self = ConfigContainer.call(this, config);
+ var traderGraphics = self.attachAsset('trader', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.setTrade = setTrade;
+ // Add any additional setup or methods required for the Trader here.
+ return self;
+});
var PlantButton = BasicButton.expand(function (plantName, callback, config) {
var self = BasicButton.call(this, plantName, callback, config);
var arrow = self.attachAsset('arrow', {
+ y: PLANT_BUTTON_OFFSET / 2,
anchorX: 0.5,
anchorY: 0.5,
- y: PLANT_BUTTON_OFFSET / 2
+ scaleX: 2,
+ scaleY: 2
});
;
self.buttonBackground.y = PLANT_BUTTON_OFFSET;
self.imageAsset.y = PLANT_BUTTON_OFFSET;
@@ -1201,8 +1219,9 @@
// Farm constants
var PLOT_SIZE = 65;
var PLOT_GAP = 90;
var PLOT_ALPHA_STEP = 1 / GAME_TICKS;
+var PLOT_EXTRA_LINGER = Math.floor(GAME_TICKS / 2);
// 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;
@@ -1229,24 +1248,24 @@
var ASTEROID_SCALE_VAR = 0.5;
var ASTEROID_TARGET_OFFSET = 500;
// Player constants
var PLAYER_SPEED = 5;
-var PLAYER_ACTION_INTERVAL = GAME_TICKS / 4;
+var PLAYER_ACTION_INTERVAL = Math.floor(GAME_TICKS / 4);
var PLAYER_ACTION_DIST = 80;
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 PLANT_BUTTON_OFFSET = -250;
var PLAYER_START_ANGLE = Math.PI / 16;
// Plant constants
var WEEDS_SPAWN_CHANCE = 0.3;
var WEEDS_SPAWN_TIME = 5 * 60 * GAME_TICKS;
var WEEDS_SPAWN_VARIANCE = 2 * 60 * GAME_TICKS;
var WEEDS_SPREAD_TIME = 1 * 60 * GAME_TICKS;
var WEEDS_SPREAD_VARIANCE = 20 * GAME_TICKS;
var GROW_WARNING_BARREN = 'Nothing grows on this planet!';
-var GROW_WARNING_GENERAL = 'This cannot grow on the planet';
+var GROW_WARNING_GENERAL = 'Cannot grow this plant here...';
var PLANT_GROWTH_FACTOR = 1.0;
+var PLANT_BUTTON_OFFSET = -220;
var PLANT_FRUIT_SCALE = 0.8;
var PLANT_DETAILS = {
plantWeeds: {
blueprint: PlantWeeds,
@@ -1431,8 +1450,9 @@
updateList(effectsList);
trySpawnAsteroid();
});
game.on('down', function (obj) {
+ console.log(obj);
if (player) {
var clickPosition = obj.event.getLocalPosition(game);
var dx = clickPosition.x - planet.x;
var dy = clickPosition.y - planet.y;
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.