-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP] Supermath101's work on the player and controls #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| Asset Name,License,Author,Link | ||
| images/player.png,Unknown,clipartstation.com,https://clipartstation.com/human-figure-clipart-4/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,16 @@ | ||
| //! Some UI utility functions and structs. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment doesn't really add anything useful (it's clear what the statement does already), would recommend removing |
||
|
|
||
| use bevy::prelude::*; | ||
|
|
||
| /// Marks a UI element as disabled. | ||
| #[derive(Component)] | ||
| pub struct Disabled; | ||
|
|
||
| pub const NORMAL_COLOR: UiColor = UiColor(Color::rgb(0.15, 0.15, 0.15)); | ||
| pub const HOVERED_COLOR: UiColor = UiColor(Color::rgb(0.25, 0.25, 0.25)); | ||
| pub const PRESSED_COLOR: UiColor = UiColor(Color::rgb(0.35, 0.75, 0.35)); | ||
|
|
||
| /// Creates the [`Style`]s that we add to most buttons. | ||
| pub fn button_style() -> Style { | ||
| Style { | ||
| size: Size::new(Val::Px(150.0), Val::Px(35.0)), | ||
|
|
@@ -17,6 +21,7 @@ pub fn button_style() -> Style { | |
| } | ||
| } | ||
|
|
||
| /// Creates the [`Style`]s that we add to most text. | ||
| pub fn text_style() -> Style { | ||
| Style { | ||
| align_self: AlignSelf::Center, | ||
|
|
@@ -26,6 +31,7 @@ pub fn text_style() -> Style { | |
| } | ||
| } | ||
|
|
||
| /// Creates the [`TextStyle`]s that we add to most text. | ||
| pub fn text_textstyle(asset_server: &AssetServer) -> TextStyle { | ||
| TextStyle { | ||
| font: asset_server.load("fonts/FiraSans-Bold.ttf"), | ||
|
|
@@ -42,6 +48,7 @@ pub fn text_textstyle_disabled(asset_server: &AssetServer) -> TextStyle { | |
| } | ||
| } | ||
|
|
||
| /// Creates the [`TextAlignment`]s that we add to most buttons. | ||
| pub fn button_text_alignment() -> TextAlignment { | ||
| TextAlignment { | ||
| horizontal: HorizontalAlign::Center, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| use bevy::prelude::*; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned before I would move this into singleplayer and rename it to player.rs as it probably won't need its own folder |
||
| use leafwing_input_manager::prelude::*; | ||
|
|
||
| pub fn setup_player(mut commands: Commands, asset_server: Res<AssetServer>) { | ||
| commands | ||
| .spawn_bundle(SpriteBundle { | ||
| texture: asset_server.load("images/player.png"), | ||
| transform: Transform::from_xyz(0., 0., 0.), | ||
| sprite: Sprite { | ||
| custom_size: Some(Vec2::new(32.0, 64.0)), | ||
| ..Default::default() | ||
| }, | ||
| ..Default::default() | ||
| }) | ||
| .insert(Player) | ||
| .insert_bundle(InputManagerBundle::<Action> { | ||
| // Stores "which virtual action buttons are currently pressed" | ||
| action_state: ActionState::default(), | ||
| // Stores how those actions relate to inputs from your player | ||
| input_map: InputMap::new([ | ||
| (Action::MoveLeft, KeyCode::A), | ||
| (Action::MoveRight, KeyCode::D), | ||
| ]), | ||
| }); | ||
| } | ||
|
|
||
| pub fn cleanup_player(mut commands: Commands, query: Query<Entity, With<Player>>) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is probably not necessary - full scene transitions can just despawn everything. In player death scenarios, the systems that detect/cause them would likely despawn the player themselves |
||
| commands.entity(query.single()).despawn(); | ||
| } | ||
|
|
||
| /// The player. | ||
| #[derive(Debug, Component, Clone, Copy)] | ||
| pub struct Player; | ||
|
|
||
| /// The possible keyboard button actions a player can do. | ||
| #[allow(missing_docs)] | ||
| #[derive(Actionlike, PartialEq, Eq, Clone, Copy, Hash, Debug)] | ||
| pub enum Action { | ||
| MoveLeft, | ||
| MoveRight, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| use bevy::prelude::*; | ||
| use bevy_ecs_tilemap::prelude::*; | ||
|
|
||
| use crate::player; | ||
| use crate::GameState; | ||
|
|
||
| pub struct SinglePlayerScene; | ||
|
|
@@ -10,7 +11,12 @@ impl Plugin for SinglePlayerScene { | |
| app.add_plugin(TilemapPlugin) | ||
| .add_system(crate::utils::set_texture_filters_to_nearest) | ||
| .add_system_set( | ||
| SystemSet::on_enter(GameState::Playing).with_system(singleplayer_setup), | ||
| SystemSet::on_enter(GameState::Playing) | ||
| .with_system(singleplayer_setup.label("2d_map_setup")) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This and the next line is a hacky way to integrate the
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is fine. Alternatively you can create a single setup system and from there call the create map and create player fns but then you would need to pass in the system params. |
||
| .with_system(player::setup_player.after("2d_map_setup")), | ||
| ) | ||
| .add_system_set( | ||
| SystemSet::on_exit(GameState::Playing).with_system(player::cleanup_player), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this at least for the time being into the singleplayer crate (it's unlikely we will have multiplayer within the frame of this jam).