summaryrefslogtreecommitdiff
path: root/dungeon/src/enemy.rs
blob: 4742bef6690460db4c700ab12feee4faee06acf0 (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
use crate::{Direction, Entity, EntityMoveSpeed, FPos, Pos};

pub const ZOMBIE_HEALTH: u32 = 50;

#[derive(Clone, Debug, PartialEq)]
pub enum EnemyAttackType {
	Melee,
	Ranged,
}

#[derive(Clone, Debug, PartialEq)]
pub enum EnemyType {
	Zombie,
}

#[derive(Clone, Debug, PartialEq)]
pub struct Enemy {
	pub entity: Entity,
	pub enemy_type: EnemyType,
	pub attack_type: EnemyAttackType,
	time_acc: f32,
}

impl Enemy {
	pub fn new(enemy_type: EnemyType, pos: Pos) -> Self {
		match enemy_type {
			EnemyType::Zombie => Self::zombie(pos),
		}
	}

	fn _new(
		pos: Pos,
		health: u32,
		move_speed: EntityMoveSpeed,
		enemy_type: EnemyType,
		attack_type: EnemyAttackType,
	) -> Self {
		let entity = Entity::enemy(pos, move_speed, health);
		Self {
			entity,
			enemy_type,
			attack_type,
			time_acc: 0.,
		}
	}

	fn zombie(pos: Pos) -> Self {
		Self::_new(
			pos,
			ZOMBIE_HEALTH,
			EntityMoveSpeed::Slow,
			EnemyType::Zombie,
			EnemyAttackType::Melee,
		)
	}
}