-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ui setup * health component * issues with ui texture atlas * working health indicator * player lose health
- Loading branch information
1 parent
ea1ee94
commit 9c188a4
Showing
18 changed files
with
215 additions
and
12 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,58 @@ | ||
use std::thread::current; | ||
|
||
use autodefault::*; | ||
use bevy::prelude::*; | ||
use bevy_bobs::component::health::Health; | ||
|
||
use crate::{ | ||
assets::SpriteSheet, player::Player, screens::utils::FONT_PATH, | ||
spritesheet_constants::SpriteIndex, utils::ok_or_return, | ||
}; | ||
|
||
#[derive(Component)] | ||
struct HealthNode; | ||
|
||
pub struct HealthPlugin; | ||
|
||
impl Plugin for HealthPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_system(update); | ||
} | ||
} | ||
|
||
#[autodefault] | ||
#[allow(non_snake_case)] | ||
pub fn HealthBar(cmd: &mut ChildBuilder) -> Entity { | ||
cmd.spawn() | ||
.insert(HealthNode) | ||
.insert_bundle(NodeBundle { | ||
style: Style { | ||
display: Display::Flex, | ||
}, | ||
}) | ||
.id() | ||
} | ||
|
||
#[autodefault] | ||
fn update( | ||
mut cmd: Commands, | ||
mut player_query: Query<&Health, With<Player>>, | ||
mut ui_query: Query<(Entity, &mut HealthNode), Without<Player>>, | ||
asset_server: Res<AssetServer>, | ||
) { | ||
let health = ok_or_return!(player_query.get_single()); | ||
|
||
// TODO kinda inefficnet to despawn all health nodes and respawn every frame | ||
for (entity, mut health_node) in ui_query.iter_mut() { | ||
cmd.entity(entity).despawn_descendants(); | ||
|
||
for i in 0..health.current() { | ||
cmd.entity(entity).with_children(|parent| { | ||
parent.spawn().insert_bundle(ImageBundle { | ||
image: UiImage(asset_server.load("tilesheet/heart.png")), | ||
style: Style {}, | ||
}); | ||
}); | ||
} | ||
} | ||
} |
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,7 @@ | ||
use bevy::prelude::*; | ||
|
||
pub struct InventoryPlugin; | ||
|
||
impl Plugin for InventoryPlugin { | ||
fn build(&self, app: &mut App) {} | ||
} |
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,14 @@ | ||
pub mod health; | ||
pub mod inventory; | ||
|
||
use bevy::prelude::*; | ||
|
||
use self::{health::HealthPlugin, inventory::InventoryPlugin}; | ||
|
||
pub struct ComponentPlugin; | ||
|
||
impl Plugin for ComponentPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_plugin(InventoryPlugin).add_plugin(HealthPlugin); | ||
} | ||
} |
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,35 @@ | ||
use autodefault::*; | ||
use bevy::prelude::*; | ||
use iyes_loopless::prelude::*; | ||
|
||
use super::{ | ||
components::health::HealthBar, | ||
state::ScreenState, | ||
utils::{destroy_ui, UIRoot}, | ||
}; | ||
use crate::{assets::SpriteSheet, spritesheet_constants::SpriteIndex}; | ||
|
||
pub struct IngamePlugin; | ||
|
||
impl Plugin for IngamePlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_enter_system(ScreenState::Ingame, render_ui) | ||
.add_exit_system(ScreenState::Ingame, destroy_ui); | ||
} | ||
} | ||
|
||
#[autodefault] | ||
fn render_ui(mut cmd: Commands) { | ||
cmd.spawn() | ||
.insert(UIRoot) | ||
.insert_bundle(NodeBundle { | ||
color: UiColor(Color::NONE), | ||
style: Style { | ||
align_self: AlignSelf::FlexEnd, | ||
// justify_content: JustifyContent::Center, | ||
}, | ||
}) | ||
.with_children(|mut parent| { | ||
HealthBar(&mut parent); | ||
}); | ||
} |
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,28 @@ | ||
mod components; | ||
mod ingame; | ||
mod state; | ||
mod utils; | ||
|
||
use bevy::prelude::*; | ||
use iyes_loopless::state::NextState; | ||
|
||
use self::{ | ||
components::ComponentPlugin, | ||
ingame::IngamePlugin, | ||
state::{ScreenState, StatePlugin}, | ||
}; | ||
|
||
pub struct ScreensPlugin; | ||
|
||
impl Plugin for ScreensPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_plugin(StatePlugin) | ||
.add_plugin(IngamePlugin) | ||
.add_plugin(ComponentPlugin) | ||
.add_startup_system(debug); | ||
} | ||
} | ||
|
||
fn debug(mut cmd: Commands) { | ||
cmd.insert_resource(NextState(ScreenState::Ingame)); | ||
} |
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,18 @@ | ||
use bevy::prelude::*; | ||
use iyes_loopless::prelude::*; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub enum ScreenState { | ||
MainMenu, | ||
Settings, | ||
LevelSelect, | ||
Ingame, | ||
} | ||
|
||
pub struct StatePlugin; | ||
|
||
impl Plugin for StatePlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_loopless_state(ScreenState::MainMenu); | ||
} | ||
} |
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,13 @@ | ||
use bevy::prelude::*; | ||
|
||
pub const FONT_PATH: &str = "fonts/arcadeclassic.ttf"; | ||
|
||
/// Marker component for the root node of each screen | ||
#[derive(Component)] | ||
pub struct UIRoot; | ||
|
||
/// Clean up UI when switching screens | ||
pub fn destroy_ui(mut cmd: Commands, query: Query<Entity, With<UIRoot>>) { | ||
let e = query.single(); | ||
cmd.entity(e).despawn_recursive(); | ||
} |
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