add battery-ui (#6)
All checks were successful
Rust / rustfmt (push) Successful in 25s
Rust / clippy (push) Successful in 1m24s
Rust / build (push) Successful in 3m9s

Reviewed-on: #6
Co-authored-by: luckyturtledev <git@lukas1818.de>
Co-committed-by: luckyturtledev <git@lukas1818.de>
This commit is contained in:
luckyturtledev 2024-07-06 20:45:05 +00:00 committed by LuckyTurtleDev
parent 8143a99843
commit b98bc61a02
3 changed files with 52 additions and 1 deletions

View file

@ -5,6 +5,22 @@ use crate::{
use comfy::EngineContext;
use std::ops::Sub;
#[derive(Debug)]
pub struct Ghost {
/// current electric charge of the Ghost
pub charge: f32,
/// max electric charge of the Ghost
pub max_charge: f32
}
impl Default for Ghost {
fn default() -> Self {
Self {
charge: 1000.0,
max_charge: 1000.0
}
}
}
#[repr(i32)]
pub enum ZLayer {
MapMax = -1,
@ -39,4 +55,5 @@ pub fn draw(state: &State, engine: &EngineContext<'_>) {
Activity::House => house::draw(state, engine),
Activity::Overworld => overworld::draw(state, engine)
}
crate::ui::draw(state, engine);
}

View file

@ -8,10 +8,12 @@ mod assets {
mod activities;
mod game;
mod ui;
use self::{
activities::{house::HouseState, overworld::worldgen::Overworld, Activity},
assets::Assets
assets::Assets,
game::Ghost
};
use comfy::{
init_game_config, pollster, run_comfy_main_async, EngineContext, EngineState,
@ -24,6 +26,7 @@ const GAME_NAME: &str = "Powercreep";
struct State {
setup_called: bool,
activity: Activity,
ghost: Ghost,
overworld: Overworld,
house: HouseState
}

31
src/ui.rs Normal file
View file

@ -0,0 +1,31 @@
use crate::State;
use comfy::{
draw_rect, draw_rect_outline, screen_height, screen_to_world, screen_width,
EngineContext, Vec2, BLUE, RED
};
pub fn draw(state: &State, _engine: &EngineContext<'_>) {
// seperate fill state into smaller section for better readability
let section_count = 5;
let mut start_positon = screen_to_world(Vec2::new(screen_width(), screen_height()));
// section size in world codinates
let section_size = Vec2::new(0.5, 0.25);
start_positon.x -= 0.5 * section_size.x + 0.5 * section_size.y;
start_positon.y += 0.5 * section_size.y + 0.5 * section_size.y;
// draw fill level
{
let ghost = &state.ghost;
let percent = ghost.charge / ghost.max_charge;
let mut size = section_size;
size.y = section_size.y * section_count as f32 * percent;
let mut position = start_positon;
position.y += 0.5 * -section_size.y + 0.5 * size.y;
draw_rect(position, size, BLUE, 100);
}
// draw sections
for i in 0 .. section_count {
let mut position = start_positon;
position.y += i as f32 * section_size.y;
draw_rect_outline(position, section_size, 0.1, RED, 100);
}
}