forked from amethyst/evoli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a basic implementation of the Topplegrass creature
Refer to issue amethyst#61 Topplegrass is explained here: https://community.amethyst.rs/t/evoli-creature-designs/814/10 Any entity with the Movement component intelligently avoids obstacles. However, not all entities that can move can steer; for example, Topplegrass is moved only by the wind. Therefore, add a new component tag AvoidObstaclesTag to all entities that are supposed to steer. Add new resource Wind. Implement debug keyboard inputs to change wind direction and speed. Load initial wind vector from a config file. In order to load from file, pass the assets directory path to the loading state. Add gravity system that affects entities with the FallingTag. Add system that deletes Topplegrass entities when they leave the world bounds.
- Loading branch information
Showing
23 changed files
with
504 additions
and
6 deletions.
There are no files selected for viewing
Git LFS file not shown
Git LFS file not shown
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ Prefab ( | |
), | ||
), | ||
intelligence_tag: (), | ||
avoid_obstacles_tag: (), | ||
perception: ( | ||
range: 3.0, | ||
), | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ Prefab ( | |
), | ||
), | ||
intelligence_tag: (), | ||
avoid_obstacles_tag: (), | ||
perception: ( | ||
range: 2.5, | ||
), | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![enable(implicit_some)] | ||
Prefab ( | ||
entities: [ | ||
( | ||
data: ( | ||
name: ( | ||
name: "Topplegrass" | ||
), | ||
gltf: File("assets/Topplegrass.gltf", ()), | ||
movement: ( | ||
velocity: [0.0, 0.0, 0.0], | ||
max_movement_speed: 10.0, | ||
), | ||
despawn_when_out_of_bounds_tag: (), | ||
topplegrass_tag: (), | ||
), | ||
), | ||
], | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
( | ||
// Initial wind speed. | ||
// Speed can be altered during game using the debug controls. | ||
// Values between about 1.5 and 5 seem to result in a nice, semi-realistic looking effect. | ||
wind: [2.0, 0.0], | ||
) |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod spatial_grid; | ||
pub mod wind; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use amethyst::core::math::Vector2; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Keeps track of the wind conditions in the world. | ||
/// Currently, wind is represented by a 2D vector. | ||
#[derive(Deserialize, Serialize)] | ||
#[serde(default)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct Wind { | ||
pub wind: Vector2<f32>, | ||
} | ||
|
||
impl Wind { | ||
pub fn new(x: f32, y: f32) -> Wind { | ||
Wind { | ||
wind: Vector2::new(x, y), | ||
} | ||
} | ||
} | ||
|
||
impl Default for Wind { | ||
fn default() -> Self { | ||
Wind::new(0.0, 0.0) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use amethyst::{core::timing::Time, ecs::*}; | ||
|
||
use crate::{components::creatures::FallingTag, components::creatures::Movement}; | ||
|
||
/// Acceleration due to gravity. | ||
const GRAVITY: f32 = 4.0; | ||
|
||
/// Applies the force of gravity on all entities with the FallingTag. | ||
/// Will remove the tag if an entity has reached the ground again. | ||
#[derive(Default)] | ||
pub struct GravitySystem; | ||
|
||
impl<'s> System<'s> for GravitySystem { | ||
type SystemData = ( | ||
WriteStorage<'s, Movement>, | ||
ReadStorage<'s, FallingTag>, | ||
Read<'s, Time>, | ||
); | ||
|
||
fn run(&mut self, (mut movements, falling_tags, time): Self::SystemData) { | ||
for (movement, _) in (&mut movements, &falling_tags).join() { | ||
//TODO: Add terminal velocity cap on falling speed. | ||
movement.velocity.z = movement.velocity.z - GRAVITY * time.delta_seconds(); | ||
} | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
pub mod out_of_bounds; | ||
pub mod perception; | ||
pub mod topplegrass; | ||
pub mod wind_control; | ||
pub mod gravity; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::resources::world_bounds::WorldBounds; | ||
use amethyst::{core::transform::components::Transform, ecs::*}; | ||
|
||
use crate::components::creatures::DespawnWhenOutOfBoundsTag; | ||
|
||
/// Deletes any entity tagged with DespawnWhenOutOfBoundsTag if they are detected to be outside | ||
/// the world bounds. | ||
#[derive(Default)] | ||
pub struct OutOfBoundsDespawnSystem; | ||
|
||
impl<'s> System<'s> for OutOfBoundsDespawnSystem { | ||
type SystemData = ( | ||
Entities<'s>, | ||
ReadStorage<'s, Transform>, | ||
ReadStorage<'s, DespawnWhenOutOfBoundsTag>, | ||
ReadExpect<'s, WorldBounds>, | ||
); | ||
|
||
fn run(&mut self, (entities, locals, tags, bounds): Self::SystemData) { | ||
for (entity, local, _) in (&*entities, &locals, &tags).join() { | ||
let pos = local.translation(); | ||
if pos.x > bounds.right | ||
|| pos.x < bounds.left | ||
|| pos.y > bounds.top | ||
|| pos.y < bounds.bottom | ||
{ | ||
let _ = entities.delete(entity); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.