Compare commits
No commits in common. "ef4a98627ea2c32169b6ca33ddf8217510c366e0" and "9e16c22eb5fdf7a55cb20c8df7599b38648fd85c" have entirely different histories.
ef4a98627e
...
9e16c22eb5
@ -20,6 +20,5 @@ fn main() {
|
||||
.add_startup_system(setup.system())
|
||||
.add_startup_system(add_player.system())
|
||||
.add_system(player_movement.system())
|
||||
.add_system(follow_player.system())
|
||||
.run();
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
use crate::prelude::*;
|
||||
use bevy::render::camera::Camera;
|
||||
|
||||
pub fn setup(
|
||||
mut commands: Commands,
|
||||
@ -11,7 +10,7 @@ pub fn setup(
|
||||
|
||||
// Map
|
||||
let grass_material = materials.add(asset_server.load("grass.png").into());
|
||||
let tile_size = Vec2::new(64.0, 64.0);
|
||||
let tile_size = Vec2::new(32.0, 32.0);
|
||||
let sprite = Sprite::new(tile_size);
|
||||
let map_size = Vec2::new(80.0, 50.0);
|
||||
let half_x = (map_size.x / 2.0) as i32;
|
||||
@ -75,26 +74,8 @@ pub fn player_movement(
|
||||
let translation = &mut transform.translation;
|
||||
let delta_seconds = time.delta_seconds();
|
||||
|
||||
translation.x += delta_seconds * direction.x * 300.0;
|
||||
translation.y += delta_seconds * direction.y * 300.0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn follow_player(
|
||||
mut q: QuerySet<(
|
||||
Query<&Transform, With<Player>>,
|
||||
Query<&mut Transform, With<Camera>>,
|
||||
)>,
|
||||
) {
|
||||
if let Ok(player_transform) = q.q0().single() {
|
||||
let player_translation = player_transform.translation;
|
||||
|
||||
if let Ok(mut camera_transform) = q.q1_mut().single_mut() {
|
||||
let camera_translation = &mut camera_transform.translation;
|
||||
|
||||
camera_translation.x = player_translation.x;
|
||||
camera_translation.y = player_translation.y;
|
||||
}
|
||||
translation.x += delta_seconds * direction.x * 100.0;
|
||||
translation.y += delta_seconds * direction.y * 100.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user