An open API service indexing awesome lists of open source software.

https://github.com/openchanter/ecosystems

A simple 3D ecosystem simulation made in C#
https://github.com/openchanter/ecosystems

3d ecosystems game simulation

Last synced: 4 months ago
JSON representation

A simple 3D ecosystem simulation made in C#

Awesome Lists containing this project

README

          

# Ecosystem Simulation 🐇
This is a basic ecosystem simulation game made with a Raylib port (Vinculum) in C#. It features different organisms that interact with eachother (ex. fox, rabbit, bush) as well as a random island generator for the play area and various features for understanding the simulation and logging results.
## Repository Stats 📊
[![Build & Publish](https://github.com/OpEnchanter/ecosystems/actions/workflows/build.yml/badge.svg)](https://github.com/OpEnchanter/ecosystems/actions/workflows/build.yml)
[![wakatime](https://wakatime.com/badge/user/98f6777a-987b-4ee6-8815-04a0d8ae8626/project/2e3ef99d-2602-4d64-9470-7c536294cd83.svg)](https://wakatime.com/badge/user/98f6777a-987b-4ee6-8815-04a0d8ae8626/project/2e3ef99d-2602-4d64-9470-7c536294cd83)

## Controls đŸ•šī¸
### **Movement**
- **Forward** : `W`
- **Backward** : `S`
- **Left** : `A`
- **Right** : `D`
- **Down** : `Left Control`
- **Up** : `Space`
- **Sprint** : `Shift`
- **Interact**: `Left Click`
### **Menus**
- **Open menu** : `Tab`
- **Use the menu**: The menu has options for logging data, quitting the game, turning on debug mode and turning on cheats.
- **Open god menu**: `Left click on organism`
- **Use god meny**: The god menu allows you to interact with organisms such as killing them feeding them and hydrating them.

## Logging Display 📈
The python file in `plot/python` can be used to visualize the logs generated by the program.

**Prerequisites**
- `pandas`
- `matplotlib`

These prerequisites can be installed with
```pwsh
pip install pandas matplotlib
```

The graph can be loaded and run with
```pwsh
python ./plot/main.py
```

## Debug mode ❗
Debug mode gives an ingame look into the inner workings of the simulation.

**Features**
- Displays stats about organisms above them (ex. traits and stats)
- Displays organism's pathing target

## Examples 📃
These are some examples of environments that have been generated within the simulation.
![Island](readme-resources/Island1.png)
![Island](readme-resources/Island2.png)

## Getting Started 🚀
1. Download the `.zip` from the releases on this page.
2. Unzip the file.
3. Run the `.exe` (if prompted asking if you want to run the file click more options, then run anyway).

> **Note**: Currently, if you want to use this on Linux or MacOS you will have to compile from source yourself.

## Compile from source 💾

### Prerequisites
- **.NET**: Ensure that you have the .NET SDK installed on your computer.

### Run the simulation
1. Clone the repository
```pwsh
git clone https://github.com/OpEnchanter/ecosystems.git
```
2. Navigate to the project's directory
```pwsh
cd ecosystems
```
3. Build and run
```pwsh
dotnet run
```

## Code examples
If you want to modify the simulation to add your own personal organisms you can create the organism and make it spawn by modifying `Program.cs`.

> **Note**: You should have a decent understanding of `C#` before attempting to modify the code.

### Load the model
Load the organism's model and texture and use them.
```cs
Image image = Raylib.LoadImage("texture.png"); // Load the texture as an Image
Texture texture = Raylib.LoadTextureFromImage(image); // Load Texture from image

Model model = Raylib.LoadModelFromMesh("model.obj"); // Load model
model.materials[0].maps[(int)MaterialMapIndex.MATERIAL_MAP_ALBEDO].texture = texture; // Apply texture to model
model.materials[0].shader = lit; // Apply lit shader to model
```

### Create the organism
Create a new organism and give it a model and position, then modify it's traits (note that it will evolve and the traits will change).
```cs
Organism organism = new Organism() {
model = model;
organismPosition = new Vector3(0,0,0);
} // Create and organism with a model and position
// Modify organism traits
organism.traits.eyesight = 10.0f;
organism.traits.speed = 1.0f;
organism.traits.oType = organismType.CustomOrganism; // A new organism type must be added to the organismType enum
organism.traits.foodSources = new organismType[] { organismType.Bush }; // What the organism can eat
organism.traits.hydrationSources = new fluidType[] { fluidType.Water }; // How the organism can get hydration
```

### Make the organism spawn
Modify the function call beginning on line 601 to include a number and reference to your organism.
```cs
placeFeatures(new Dictionary
{
{ bush, 150 },
{ fox, 120 },
{ rabbit, 120 },
{ organism, 400} // This will spawn 400 of organism on the island
}, *groundHeightmap, terrainThreshold);
```

## Code line count 🧮
If you want to check how many lines of code there are in the project (either if you are curious or you made an addition) you can run the command
```pwsh
cloc ./ --include-lang=C#,Python
```
This is assuming you have `cloc.exe` somewhere on your computer and it is added to your `PATH`