Initial tile push with item cycle
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy::input::keyboard::KeyCode;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct PanningCamera {
|
||||
pub pan_speed: f32,
|
||||
}
|
||||
|
||||
pub fn camera_movement(
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
mut query: Query<(&PanningCamera, &mut Transform), With<Camera>>,
|
||||
) {
|
||||
for (camera, mut transform) in query.iter_mut() {
|
||||
let mut direction = Vec2::ZERO;
|
||||
|
||||
if keyboard_input.pressed(KeyCode::ArrowUp) {
|
||||
direction.y += 1.0;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::ArrowDown) {
|
||||
direction.y -= 1.0;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::ArrowLeft) {
|
||||
direction.x -= 1.0;
|
||||
}
|
||||
if keyboard_input.pressed(KeyCode::ArrowRight) {
|
||||
direction.x += 1.0;
|
||||
}
|
||||
|
||||
if direction.length() > 0.0 {
|
||||
direction = direction.normalize();
|
||||
|
||||
let movement = direction * camera.pan_speed;
|
||||
transform.translation.x += movement.x;
|
||||
transform.translation.y += movement.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_panning_camera(mut commands: Commands) {
|
||||
commands.spawn((
|
||||
Camera2d::default(),
|
||||
PanningCamera { pan_speed: 5.0 }
|
||||
));
|
||||
}
|
||||
Reference in New Issue
Block a user