Skip to content

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
merged 45 commits into from
Mar 9, 2023

Conversation

nucleartide
Copy link
Owner

@nucleartide nucleartide commented Mar 3, 2023

Quality Assurance

Take some screenshots as confirmation of quality assurance.

The game now generates resources for the player to explore:

Screenshot 2023-03-09 at 9 38 05 AM

JIRA Ticket

Sorry folks, this is internal to my Notion workspace!

https://www.notion.so/nucleartide/Mechanics-Populate-land-with-resources-2-days-cbcb0749f764447cbebac6c1cb26a518?pvs=4

Development checklist

Review Files changed and check off the following:

  • Modular: Are you touching the scene file? If so, can you limit your changes to prefab files instead?
  • Editable: Has any configuration been moved into ScriptableObjects, so that modified values persist even after exiting Play mode?
  • Debuggable: Do you have debug views for the prefabs/systems that you are creating?

Changelog

Provide a bulleted list of changes that were made in this pull request.

This pull request performs a significant amount of refactoring as I start to establish some personal project conventions:

  • Update GitHub PR template to follow Ryan Hipple’s 3 Unity engineering pillars
  • Extract more systems into modular Prefabs/
  • Extract more configuration into ScriptableObjects/
  • Organize 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 tasks

Feature-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, or Iron Ore).

How it works

Explain what you did, how you did it, and why you did it. Also any lessons that might be useful to others.

(Note to self: it's easiest to do a stream-of-consciousness writeup of what you did.)

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:

  • Water
  • Land
  • Iron Ore
  • Stone
  • Copper Ore
  • Coal
  • Sugar Cane
  • Wheat
  • Wood

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 ScriptableObject

The world is configurable using a WorldConfig ScriptableObject asset.

Tweaking the various knobs and sliders will create different patterns of game resources:

Screenshot 2023-03-09 at 10 07 39 AM

The WorldManager script

Once configured, you can “render” your world by plugging your WorldConfig into a WorldManager:

Screenshot 2023-03-09 at 10 07 46 AM

If you’re confused by why your resource map generates in a certain way, you can change the World Display Mode and click the Regenerate Resources button to display the world in various debug states.

Screenshot 2023-03-09 at 10 07 51 AM

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:

Untitled Diagram drawio (4)

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.

@nucleartide nucleartide force-pushed the jason/generate-resources branch from 3eb1733 to d41bbe0 Compare March 8, 2023 22:25
@nucleartide nucleartide changed the title Populate game space with low poly resources Populate game world with blocked-out resources Mar 9, 2023
@nucleartide nucleartide changed the title Populate game world with blocked-out resources Implement procedural generation system; populate game world with resource blocks Mar 9, 2023
@nucleartide nucleartide changed the title Implement procedural generation system; populate game world with resource blocks Populate game world with procedurally-generated resources Mar 9, 2023
@nucleartide nucleartide marked this pull request as ready for review March 9, 2023 15:41
@nucleartide nucleartide merged commit b27e5fd into master Mar 9, 2023
@nucleartide nucleartide deleted the jason/generate-resources branch March 9, 2023 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant