-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_utils.rs
134 lines (115 loc) · 2.67 KB
/
game_utils.rs
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
use bevy::prelude::*;
use std::fmt;
#[derive(Default, Event)]
pub struct ResetGameEvent {}
#[derive(Default, Event)]
pub struct PlayerHitEvent {}
#[derive(Default, Event)]
pub struct PlayerShootEvent {}
#[derive(Default, Event)]
pub struct PlayerPowerUpEvent {}
#[derive(Default, Event)]
pub struct UpdateUIEvent {
pub player_number: usize,
}
#[derive(Default, Event)]
pub struct PlayerDeadEvent {}
#[derive(Component, Clone)]
pub enum Direction {
Up,
Down,
Right,
Left,
None,
}
impl Direction {
pub fn opposite(&self) -> Direction {
match self {
Direction::Up => Direction::Down,
Direction::Down => Direction::Up,
Direction::Right => Direction::Left,
Direction::Left => Direction::Right,
Direction::None => Direction::None,
}
}
}
#[derive(Component, Clone)]
pub struct DirectionHelper {
pub direction_y: Direction,
pub direction_x: Direction,
}
#[derive(Component, Clone)]
pub struct DirectionBlock {
pub up: bool,
pub down: bool,
pub right: bool,
pub left: bool,
}
#[derive(Component, Clone)]
pub enum BulletType {
NormalBullet,
IceBullet,
ExplosiveBullet,
BouncyBullet,
}
#[derive(Component, Clone)]
pub enum TimerType {
Invulnerable,
Stun,
Shoot,
}
#[derive(Component)]
pub struct Name(String);
impl Name {
pub fn new(name: String) -> Self {
Self(name)
}
}
#[derive(Component)]
pub struct Collider;
#[derive(Component)]
pub struct HitCooldownTimer {
pub timer: Timer,
pub associated_player: String,
pub timer_type: TimerType,
}
#[derive(Component)]
pub struct AnimationTimer {
pub timer: Timer,
pub counter: i32,
}
#[derive(Component)]
pub struct InvulnerableBlinkTimer {
pub timer: Timer,
pub color: bool,
pub associated_player: String,
}
#[derive(Component)]
pub struct Bindings {
pub shoot: KeyCode,
pub shoot_special: KeyCode,
pub up: KeyCode,
pub down: KeyCode,
pub right: KeyCode,
pub left: KeyCode,
}
impl BulletType {
pub fn convert_int(number: i32) -> Option<BulletType> {
match number {
0 => Some(BulletType::IceBullet),
1 => Some(BulletType::ExplosiveBullet),
2 => Some(BulletType::BouncyBullet),
_ => None,
}
}
}
impl fmt::Display for BulletType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
BulletType::IceBullet => write!(f, "Ice"),
BulletType::NormalBullet => write!(f, "None"),
BulletType::ExplosiveBullet => write!(f, "Grenade"),
BulletType::BouncyBullet => write!(f, "Bouncy"),
}
}
}