Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion common/src/components/weapon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ impl Weapon {
self.details.bullet_distance_limit / self.details.bullet_speed
}

pub fn is_magazine_full(&self) -> bool {
self.bullets_left_in_magazine == self.details.magazine_size
}

pub fn is_allowed_to_reload(&self) -> bool {
self.reload_started_at.is_none()
self.reload_started_at.is_none() && !self.is_magazine_full()
}

}

mod weapon_details {
Expand Down
1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod utilities;
pub enum MoveDirection {
Forward,
Backward,
RunForward,
StrafeLeft,
StrafeRight,
}
Expand Down
8 changes: 8 additions & 0 deletions common/src/metric_dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ impl Div<f32> for MeterPerSec {
}
}

impl Mul<f32> for MeterPerSec {
type Output = MeterPerSec;

fn mul(self, rhs: f32) -> Self::Output {
MeterPerSec(self.0 * rhs)
}
}

impl AddAssign<MeterPerSec> for MeterPerSec {
fn add_assign(&mut self, rhs: MeterPerSec) {
self.0.add_assign(rhs.0)
Expand Down
14 changes: 13 additions & 1 deletion server/src/systems/player_movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ pub fn apply_input(mut query: Query<(&GlobalTransform, &mut Transform, &mut Velo
fn move_directions_from_input(input: &Input) -> Vec<MoveDirection> {
let mut directions = Vec::new();
if input.flags.intersects(InputFlags::FORWARD) {
directions.push(MoveDirection::Forward);
if input.flags.intersects(InputFlags::RUN) {
directions.push(MoveDirection::RunForward);
} else {
directions.push(MoveDirection::Forward);
}
}
if input.flags.intersects(InputFlags::BACKWARD) {
directions.push(MoveDirection::Backward);
Expand Down Expand Up @@ -67,6 +71,10 @@ fn as_vector2(move_dir: MoveDirection) -> MeterPerSecVec2 {
x: -PLAYER_MAX_WALK_SPEED / 2.0,
y: MeterPerSec(0.0),
},
MoveDirection::RunForward => MeterPerSecVec2 {
x: MeterPerSec(0.0),
y: PLAYER_MAX_WALK_SPEED * - 2.0,
},
}
}

Expand Down Expand Up @@ -111,6 +119,10 @@ mod test {
fwd_down: FACING_DOWN, vec!{Forward}, (MeterPerSec(0.0), -PLAYER_MAX_WALK_SPEED),
fwd_left: FACING_LEFT, vec!{Forward}, (-PLAYER_MAX_WALK_SPEED, MeterPerSec(0.0)),
fwd_right: FACING_RIGHT, vec!{Forward}, (PLAYER_MAX_WALK_SPEED, MeterPerSec(0.0)),
run_fwd_up: FACING_UP, vec!{RunForward}, (MeterPerSec(0.0), PLAYER_MAX_WALK_SPEED * 2.0),
run_fwd_down: FACING_DOWN, vec!{RunForward}, (MeterPerSec(0.0), -PLAYER_MAX_WALK_SPEED * 2.0),
run_fwd_left: FACING_LEFT, vec!{RunForward}, (-PLAYER_MAX_WALK_SPEED * 2.0, MeterPerSec(0.0)),
run_fwd_right: FACING_RIGHT, vec!{RunForward}, (PLAYER_MAX_WALK_SPEED * 2.0, MeterPerSec(0.0)),
}
}
}