generated from NiklasEi/bevy_game_template
-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c54fe4
commit e33994f
Showing
10 changed files
with
213 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use bevy::prelude::*; | ||
|
||
pub(super) fn plugin(app: &mut App) { | ||
app.register_type::<PlayerCamera>(); | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Component, Reflect, Default)] | ||
#[reflect(Component)] | ||
pub struct PlayerCamera { | ||
pub follow: Transform, | ||
pub offset: Transform, | ||
pub look_at: Option<Vec3>, | ||
} | ||
|
||
impl PlayerCamera { | ||
pub fn transform(self) -> Transform { | ||
self.follow * self.offset | ||
} | ||
} | ||
|
||
pub fn spawn_player_camera(world: &mut World) { | ||
world.spawn(( | ||
Name::new("Camera"), | ||
Camera3dBundle::default(), | ||
PlayerCamera::default(), | ||
IsDefaultUiCamera, | ||
//create_camera_action_input_manager_bundle(), | ||
)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use bevy::prelude::*; | ||
use leafwing_input_manager::prelude::*; | ||
|
||
pub(super) fn plugin(app: &mut App) { | ||
app.add_plugins(( | ||
InputManagerPlugin::<PlayerAction>::default(), | ||
InputManagerPlugin::<CameraAction>::default(), | ||
)); | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Actionlike, Reflect, Default)] | ||
pub(crate) enum PlayerAction { | ||
#[default] | ||
#[actionlike(DualAxis)] | ||
Move, | ||
Sprint, | ||
Jump, | ||
Interact, | ||
} | ||
|
||
#[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug, Reflect)] | ||
#[actionlike(DualAxis)] | ||
pub enum CameraAction { | ||
RotateCamera, | ||
} | ||
|
||
impl PlayerAction { | ||
pub fn default_input_map() -> InputMap<Self> { | ||
let mut input_map = InputMap::default(); | ||
|
||
// Default gamepad input bindings | ||
input_map.insert(PlayerAction::PedalLeft, GamepadButtonType::LeftTrigger); | ||
input_map.insert(PlayerAction::PedalRight, GamepadButtonType::RightTrigger); | ||
|
||
// Default keyboard input bindings | ||
input_map.insert(PlayerAction::PedalLeft, KeyCode::KeyA); | ||
input_map.insert(PlayerAction::PedalRight, KeyCode::KeyD); | ||
|
||
input_map | ||
} | ||
} | ||
|
||
impl CameraAction { | ||
pub fn default_input_map() -> InputMap<Self> { | ||
let mut input_map = InputMap::default(); | ||
|
||
// Default gamepad input bindings | ||
input_map.insert(CameraAction::RotateCamera, DualAxis::left_stick()); | ||
|
||
// Default keyboard input bindings | ||
input_map.insert(CameraAction::RotateCamera, DualAxis::mouse_motion()); | ||
|
||
input_map | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.