Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
in the planet update method, update all nodes as well
Code edit (2 edits merged)
Please save this source code
User prompt
move the fruitList array onto the planet. Instead of updating all fruits on tick callback, update the list in the planet update method
Code edit (2 edits merged)
Please save this source code
User prompt
Fix Bug: 'ReferenceError: angle is not defined' in or related to this line: 'var baseIndex = mod(Math.round(angle / MATH_2_PI * count), count);' Line Number: 161
Code edit (2 edits merged)
Please save this source code
User prompt
add a new action function to plantNodes that checks if its plant exists, and is harvestable and calls the harvest function on it. Returning whether the harvest was callable
User prompt
Replace `// TODO: Create fruit at node's position` with: spawn a new fruit with the self.fruit variable as the name, at the parent node's position and attach it to the planet
Code edit (4 edits merged)
Please save this source code
User prompt
add a harvest function and a harvestable variable to the Plant class
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
create an interval on the player that checks to see which planet node's index is closest to the player's angle every PLAYER_ACTION_INTERVAL ticks
Code edit (16 edits merged)
Please save this source code
User prompt
Rename the globals: PLAYER_PICKUP_DIST and PLAYER_PICKUP_SQRDIST to: PLAYER_ACTION_DIST and PLAYER_ACTION_SQRDIST, and update all old usages of the variables
Code edit (4 edits merged)
Please save this source code
User prompt
destroy and clear the player variable in the launch function if direction > 0
Code edit (1 edits merged)
Please save this source code
User prompt
destroy and clear the player variable on ship launch (in the launch function)
User prompt
destroy and clear the player variable on ship launch
Code edit (1 edits merged)
Please save this source code
User prompt
flip the player's graphic based on the direction it's moving
Code edit (3 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -136,11 +136,10 @@
});
self.update = function () {
var currentAngle = Math.atan2(self.y, self.x);
var angleDifference = targetAngle - currentAngle;
- // Normalize the angle difference to the range [-Math.PI, Math.PI]
- angleDifference = (angleDifference + Math.PI) % MATH_2_PI - Math.PI;
- if (angleDifference !== 0) {
+ angleDifference = mod(angleDifference + Math.PI, MATH_2_PI) - Math.PI;
+ if (angleDifference < -MATH_APPROX_ZERO || angleDifference > MATH_APPROX_ZERO) {
var direction = angleDifference / Math.abs(angleDifference);
var angleStep = PLAYER_SPEED / planet.radius;
var newAngle = currentAngle + direction * Math.min(Math.abs(angleDifference), angleStep);
self.x = Math.cos(newAngle) * planet.radius;
@@ -196,8 +195,65 @@
}
}
}
});
+var Plant = ConfigContainer.expand(function (type, stage, config) {
+ var self = ConfigContainer.call(this, config);
+ var details = PLANT_DETAILS[type];
+ ;
+ self.update = update;
+ self.newStage = newStage;
+ self.refreshGraphics = refreshGraphics;
+ self.refreshCountdown = refreshCountdown;
+ self.type = type;
+ self.fruit = details.fruit;
+ self.stage = stage;
+ self.stages = details.stages;
+ self.growthTime = details.growthTime;
+ self.growthVariance = details.growthVariance;
+ self.stageCountdown = 0;
+ ;
+ function update() {
+ if (self.stageCountdown > 0) {
+ self.stageCountdown--;
+ } else if (self.stage < self.stages - 1) {
+ self.newStage(self.stage + 1);
+ }
+ }
+ function newStage(stage) {
+ self.stage = stage;
+ self.refreshGraphics();
+ self.refreshCountdown();
+ }
+ function refreshGraphics() {
+ if (self.graphics) {
+ self.graphics.destroy();
+ }
+ self.graphics = self.createAsset(self.type + self.stage, {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ }
+ function refreshCountdown() {
+ self.stageCountdown = Math.floor(self.growthTime + Math.random() * self.growthVariance);
+ }
+ ;
+ self.refreshCountdown();
+ self.refreshGraphics();
+ return self;
+});
+var PlantWeeds = Plant.expand(function (stage, config) {
+ var self = Plant.call(this, 'plantWeeds', stage, config);
+});
+var PlantBush = Plant.expand(function (stage, config) {
+ var self = Plant.call(this, 'plantBush', stage, config);
+});
+var PlantStalk = Plant.expand(function (stage, config) {
+ var self = Plant.call(this, 'plantStalk', stage, config);
+});
+var PlantEyeball = Plant.expand(function (stage, config) {
+ var self = Plant.call(this, 'plantEyeball', stage, config);
+});
var PlantNode = ConfigContainer.expand(function (config) {
var self = ConfigContainer.call(this, config);
;
self.update = update;
@@ -208,43 +264,57 @@
self.prev;
self.next;
;
function update() {}
- function tryPlantFruit(fruitName) {}
function addPlant(plantName, stage) {
- var plantType = PLANT_DETAILS[plantName].blueprint;
- self.plant = self.addChild(new plantType(stage, {
+ var plantBlueprint = PLANT_DETAILS[plantName].blueprint;
+ self.plant = self.addChild(new plantBlueprint(stage, {
y: self.offset
}));
}
;
return self;
});
var FarmNode = PlantNode.expand(function (config) {
var self = PlantNode.call(this, config);
+ var baseOffset = self.offset;
+ var baseUpdate = self.update;
+ var baseAddPlant = self.addPlant;
+ var targetAlpha = 0;
+ var currentAlpha = targetAlpha;
var farmGraphics = self.attachAsset('farm', {
anchorX: 0.5,
- anchorY: 0.6
+ anchorY: 0.6,
+ alpha: currentAlpha
});
farmGraphics.scale.set(PLOT_SIZE / 100);
;
self.update = update;
+ self.addPlant = addPlant;
+ self.tryPlantFruit = tryPlantFruit;
self.offset = -20;
;
- function update() {}
+ function update() {
+ baseUpdate();
+ if (currentAlpha !== targetAlpha) {
+ if (currentAlpha < targetAlpha) {
+ currentAlpha = Math.min(1, currentAlpha + PLOT_ALPHA_STEP);
+ } else {
+ currentAlpha = Math.max(0, currentAlpha - PLOT_ALPHA_STEP);
+ }
+ }
+ }
+ function addPlant(plantName, stage) {
+ baseAddPlant(plantName, stage);
+ if (plantName === 'plantWeeds') {
+ self.plant.y = baseOffset;
+ targetAlpha = 0;
+ } else {
+ targetAlpha = 1;
+ }
+ }
+ function tryPlantFruit(fruitName) {}
});
-var Plant = ConfigContainer.expand(function (config) {
- var self = ConfigContainer.call(this, config);
- ;
- return self;
-});
-var PlantWeeds = Plant.expand(function (stage, config) {
- var self = Plant.call(this, config);
- var weedGraphics = self.createAsset('plant0Stage' + stage, {
- anchorX: 0.5,
- anchorY: 1
- });
-});
var Planet = Container.expand(function (x, y, radius, assetName, barren) {
var self = Container.call(this);
var perimeter = MATH_2_PI * radius;
var numPlots = Math.floor(perimeter / (PLOT_SIZE + PLOT_GAP));
@@ -256,9 +326,8 @@
});
planetGraphics.scale.set(2 * radius / 1000);
;
self.update = update;
- self.launch = launch;
self.x = x;
self.y = y;
self.radius = radius;
self.rotation = Math.random() * MATH_2_PI;
@@ -266,9 +335,8 @@
;
function update(ticks) {
self.rotation += self.spin;
}
- function launch(direction) {}
function createNodes() {
if (!barren) {
var defaultPlant = 'plantWeeds';
var maxPlantStage = PLANT_DETAILS[defaultPlant].stages;
@@ -639,9 +707,9 @@
if (player) {
var dx = self.x - player.x;
var dy = self.y - player.y;
var sqrDistance = dx * dx + dy * dy;
- if (sqrDistance < PLAYER_PICKUP_SQRDIST) {
+ if (sqrDistance < PLAYER_ACTION_SQRDIST) {
inventory.adjustItem(fruitName, 1);
return true;
}
}
@@ -659,16 +727,19 @@
/****
* Game Code
****/
+// Math constants / pre-calculations
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;
-;
+var MATH_APPROX_ZERO = 0.0000001;
+// 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;
@@ -677,16 +748,18 @@
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 PLOT_SIZE = 65;
var PLOT_GAP = 90;
+var PLOT_ALPHA_STEP = 1 / GAME_TICKS;
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';
@@ -708,16 +781,41 @@
var ASTEROID_SCALE_MIN = 0.75;
var ASTEROID_SCALE_VAR = 0.5;
var ASTEROID_TARGET_OFFSET = 500;
var PLAYER_SPEED = 5;
-var PLAYER_PICKUP_DIST = 100;
-var PLAYER_PICKUP_SQRDIST = PLAYER_PICKUP_DIST * PLAYER_PICKUP_DIST;
+var PLAYER_ACTION_INTERVAL = GAME_TICKS / 2;
+var PLAYER_ACTION_DIST = 100;
+var PLAYER_ACTION_SQRDIST = PLAYER_ACTION_DIST * PLAYER_ACTION_DIST;
var PLAYER_BUFFER_DIST = 200;
var PLAYER_BUFFER_SQRDIST = PLAYER_BUFFER_DIST * PLAYER_BUFFER_DIST;
var PLANT_DETAILS = {
plantWeeds: {
+ blueprint: PlantWeeds,
stages: 4,
- blueprint: PlantWeeds
+ fruit: 'fruitWeeds',
+ growthTime: 60 * GAME_TICKS,
+ growthVariance: 10 * GAME_TICKS
+ },
+ plantBush: {
+ blueprint: PlantBush,
+ stages: 5,
+ fruit: 'fruitBush',
+ growthTime: 120 * GAME_TICKS,
+ growthVariance: 30 * GAME_TICKS
+ },
+ plantStalk: {
+ blueprint: PlantStalk,
+ stages: 7,
+ fruit: 'fruitStalk',
+ growthTime: 60 * GAME_TICKS,
+ growthVariance: 20 * GAME_TICKS
+ },
+ plantEyeball: {
+ blueprint: PlantEyeball,
+ stages: 5,
+ fruit: 'fruitEyeball',
+ growthTime: 40 * GAME_TICKS,
+ growthVariance: 10 * GAME_TICKS
}
};
var NAVIGATION = [{
cost: 0,
@@ -853,8 +951,11 @@
game.addChild(planet);
planet.addChild(ship);
ship.x = planet.radius + ROCKET_DIST_REVERSE;
}
+function mod(x, base) {
+ return (x % base + base) % base;
+}
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.