-
Notifications
You must be signed in to change notification settings - Fork 1
Populate game world with procedurally-generated resources #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3eb1733
to
d41bbe0
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Quality Assurance
The game now generates resources for the player to explore:
JIRA Ticket
Development checklist
Changelog
This pull request performs a significant amount of refactoring as I start to establish some personal project conventions:
Prefabs/
ScriptableObjects/
Scripts/
directory with the following categories:_Behaviors/
: components that you place on game entities to make them act a certain way_Data/
: plain ol’ C# classes_Managers/
: MonoBehaviours that manage the lifecycle of some game state_ScriptableObjects/
: configuration definitions that allow for creation of data asset files_Unused/
: files that may be revisited at some point in the future_Utils/
: miscellaneous helpers for coding tasksFeature-wise, this pull request also implements procedural resource generation. The world is now populated with tiles that correspond to a resource (such as
Water
,Coal
, orIron Ore
).How it works
This pull request implements a biome-based procedural generation approach described by Daniel Buckley of Game Dev Academy.
However, I adapted Daniel’s approach to work with biomes that I’d like to create for my own game:
In future pull requests, the player will be able to right-click on a resource to perform manual collection. And since this is a Factorio-style game, the player will be able to refine collected resources, or use them to craft place-able objects.
The biome generation in this pull request is generalize-able across games. It relies on a few pieces:
The
WorldConfig
ScriptableObjectThe world is configurable using a
WorldConfig
ScriptableObject asset.Tweaking the various knobs and sliders will create different patterns of game resources:
The
WorldManager
scriptOnce configured, you can “render” your world by plugging your
WorldConfig
into aWorldManager
:If you’re confused by why your resource map generates in a certain way, you can change the
World Display Mode
and click theRegenerate Resources
button to display the world in various debug states.This enables you to change noise values in your
WorldConfig
, and quickly see your new noise values reflected in the actual generated resources. It’s a great tool for generating your desired resource distribution.Designing noise values for my biomes
Daniel’s biome generation relies on a “minimum value” system. That is, if a combination of 3 noise values exceeds a biome’s minimum threshold, then that biome may potentially be used.
Then of the set of potential biomes, the biome with the smallest difference value is selected:
https://github.com/nucleartide/Baguettorio/blob/d6794d3d28d29a4ea8c744935b307bd6efbc5852/Assets/Scripts/_Data/Query.cs#L25-L50
Since I had 3 noise maps (1 for height, 1 for “moisture”, 1 for “heat") and 9 biomes, I focused on choosing values for 1 noise map at a time, and used the other 2 dimensions of moisture and heat as differentiators within the “bedrock” and “vegetation” biome categories:
You’ll notice that the “land” biome values have the most distance between their threshold values. This is intentional.
The map should be mostly empty and resource-less so the player has land to build upon.