Skip to content

Commit

Permalink
Slowed down how fast our player moves around the road.
Browse files Browse the repository at this point in the history
  • Loading branch information
StarArawn authored and StarArawn committed Apr 13, 2021
1 parent 0b6ab33 commit f4476e1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/game/gameplay/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod player;
4 changes: 2 additions & 2 deletions src/game/player/mod.rs → src/game/gameplay/player/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use bevy::{prelude::*, render::texture};
use bevy::prelude::*;

mod movement;
mod player;
pub use player::{Player};
pub use player::Player;

pub use movement::movement;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
use std::thread::current;

use bevy::prelude::*;
use crate::game::map::Map;
use crate::game::{map::Map, timing::Timing};

use super::Player;

pub fn movement(
mut timing: ResMut<Timing>,
map: Res<Map>,
mut player_query: Query<(&mut Player, &mut Transform)>,
) {
if !timing.should_update {
return;
}

timing.should_update = false;

if map.road_path.len() > 0 {
for (mut player, mut transform) in player_query.iter_mut() {
player.current_position += 1;
Expand All @@ -17,7 +22,7 @@ pub fn movement(
}

let current_road_position = map.road_path[player.current_position];
transform.translation = Vec3::new(current_road_position.0 as f32 * 16.0, current_road_position.1 as f32 * 16.0, 10.0);
transform.translation = Vec3::new((current_road_position.0 as f32 * 16.0) + 8.0, (current_road_position.1 as f32 * 16.0) + 8.0, 10.0);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use bevy::prelude::*;

#[derive(Default, Clone, Debug)]
pub struct Player {
pub current_position: usize,
Expand Down
24 changes: 19 additions & 5 deletions src/game/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use bevy::prelude::*;

mod camera;
mod game_state;
mod map;
mod player;
mod gameplay;
mod loading;
mod map;
mod timing;

pub use game_state::GameState;

Expand All @@ -14,6 +15,8 @@ impl Plugin for GamePlugin {
fn build(&self, app: &mut AppBuilder) {
app
.add_state(GameState::default())
.init_resource::<timing::Timing>()
.add_system(timing::update.system())
.add_system_set(
SystemSet::on_update(GameState::Loading)
.with_system(loading::loading.system())
Expand All @@ -27,11 +30,22 @@ impl Plugin for GamePlugin {
SystemSet::on_update(GameState::Generating)
.with_system(map::generate_map.system())
.after("spawn_map")
.with_system(player::spawn_player.system())
.with_system(gameplay::player::spawn_player.system())
.after("spawn_map")
)
.add_system(camera::camera_movement.system())
.add_system(player::movement.system())
.add_system_set(
// Gameplay update
SystemSet::on_update(GameState::Playing)
.label("gameplay_update")
.with_system(gameplay::player::movement.system())
)
.add_system_set(
// Realtime update
// Used for non-gameplay items that should update every frame.
SystemSet::on_update(GameState::Playing)
.label("realtime_update")
.with_system(camera::camera_movement.system())
)
.add_plugin(map::MapPlugin);
}
}
19 changes: 19 additions & 0 deletions src/game/timing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use bevy::prelude::*;

#[derive(Default)]
pub struct Timing {
pub last_time: f64,
pub should_update: bool,
}

pub fn update(
time: Res<Time>,
mut timing: ResMut<Timing>,
) {

let current = time.seconds_since_startup();
if (current - timing.last_time) > 0.500 {
timing.last_time = current;
timing.should_update = true;
}
}

0 comments on commit f4476e1

Please sign in to comment.