summaryrefslogtreecommitdiff
path: root/src/assemblages.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-01-28 22:58:16 +0100
committertroido <troido@protonmail.com>2020-01-28 22:58:16 +0100
commitb3356eabcea09f599ad99c1332450e4d9570161b (patch)
tree3cdb9c9a2092f66a3f3d9dfeade6fcb80294579c /src/assemblages.rs
parent1175f8b436d15c47fb60866755921fc68183dc72 (diff)
refacored systems, components, resources and assemblages into their own files
Diffstat (limited to 'src/assemblages.rs')
-rw-r--r--src/assemblages.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/assemblages.rs b/src/assemblages.rs
new file mode 100644
index 0000000..4705ae4
--- /dev/null
+++ b/src/assemblages.rs
@@ -0,0 +1,61 @@
+
+
+use rand::Rng;
+use specs::{
+ Builder,
+ EntityBuilder
+};
+
+use super::components::{Visible, Controller};
+
+
+
+
+pub trait Assemblage {
+ fn build<'a>(&self, builder: EntityBuilder<'a>) -> EntityBuilder<'a>;
+}
+
+
+
+pub struct Wall;
+
+impl Assemblage for Wall {
+ fn build<'a>(&self, builder: EntityBuilder<'a>) -> EntityBuilder<'a>{
+ builder.with(Visible{sprite: "wall".to_string(), height: 2.0})
+ }
+}
+
+pub struct Grass {
+ sprite: String
+}
+
+impl Grass {
+ pub fn new() -> Grass {
+ Grass {
+ sprite: ["grass1", "grass2", "grass3", "grass1", "grass2", "grass3", "ground"][rand::thread_rng().gen_range(0,7)].to_string()
+ }
+ }
+}
+
+impl Assemblage for Grass {
+ fn build<'a>(&self, builder: EntityBuilder<'a>) -> EntityBuilder<'a>{
+ builder.with(Visible{sprite: self.sprite.to_string(), height: 0.1})
+ }
+}
+
+
+pub struct Player {
+ name: String
+}
+
+impl Player {
+ pub fn new(name: &str) -> Player {
+ Player { name: name.to_string()}
+ }
+}
+
+impl Assemblage for Player {
+ fn build<'a>(&self, builder: EntityBuilder<'a>) -> EntityBuilder<'a>{
+ builder.with(Visible{sprite: "player".to_string(), height: 1.0}).with(Controller(None))
+ }
+}