summaryrefslogtreecommitdiff
path: root/src/assemblages.rs
blob: d56e0f3fc38dcd3a92a1e3cf7465dc813941bc34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61


use rand::Rng;
use specs::{
	Builder,
	EntityBuilder
};

use super::components::{Visible, Blocking};




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}).with(Blocking)
	}
}

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})
	}
}