finish
Some checks failed
Rust / rustfmt (pull_request) Successful in 19s
Rust / clippy (pull_request) Failing after 39s
Rust / build (pull_request) Successful in 2m3s

This commit is contained in:
luckyturtledev 2024-07-06 22:23:31 +02:00
parent 49d565e73b
commit 255df67d7b
3 changed files with 36 additions and 19 deletions

View file

@ -8,14 +8,17 @@ use crate::{
#[derive(Debug)] #[derive(Debug)]
pub struct Gost { pub struct Gost {
/// current electric charge of the Ghost /// current electric charge of the Ghost
charge: u32, pub charge: f32,
/// max electric charge of the Ghost /// max electric charge of the Ghost
max_charge: u32, pub max_charge: f32
} }
impl Default for Gost { impl Default for Gost {
fn default() -> Self { fn default() -> Self {
Self { charge: 100, max_charge: 100 } Self {
charge: 1000.0,
max_charge: 1000.0
}
} }
} }

View file

@ -11,14 +11,14 @@ const GAME_NAME: &str = "Powercreep";
#[derive(Debug)] #[derive(Debug)]
struct State { struct State {
activity: Activity, activity: Activity,
gohst: Gost, gohst: Gost
} }
impl Default for State { impl Default for State {
fn default() -> Self { fn default() -> Self {
Self { Self {
activity: Activity::House, activity: Activity::House,
gohst: Default::default(), gohst: Default::default()
} }
} }
} }

View file

@ -1,17 +1,31 @@
use comfy::egui::Pos2;
use comfy::egui::Rect;
use comfy::EngineContext;
use comfy::egui;
use comfy::GREEN;
use comfy::RED;
use crate::State; 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) { pub fn draw(state: &State, engine: &EngineContext) {
egui::Area::new("batterie_show") // seperate fill state into smaller section for better readability
.anchor(egui::Align2::RIGHT_BOTTOM, egui::vec2(0.0, 0.0)) let section_count = 5;
.show(egui(), |ui| { let mut start_positon = screen_to_world(Vec2::new(screen_width(), screen_height()));
let painter = ui.painter(); // section size in world codinates
painter.rect(Rect{min: Pos2::new(0.0, 0.0), max: Pos2::new(32.0, 32.0)}, 0.0, RED, (4.0, GREEN)); 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 gohst = &state.gohst;
let percent = gohst.charge / gohst.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);
}
}