add battery-ui #6
3 changed files with 52 additions and 1 deletions
17
src/game.rs
17
src/game.rs
|
@ -5,6 +5,22 @@ use crate::{
|
||||||
use comfy::EngineContext;
|
use comfy::EngineContext;
|
||||||
use std::ops::Sub;
|
use std::ops::Sub;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Ghost {
|
||||||
LuckyTurtleDev marked this conversation as resolved
Outdated
|
|||||||
|
/// 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)]
|
#[repr(i32)]
|
||||||
pub enum ZLayer {
|
pub enum ZLayer {
|
||||||
MapMax = -1,
|
MapMax = -1,
|
||||||
|
@ -39,4 +55,5 @@ pub fn draw(state: &State, engine: &EngineContext<'_>) {
|
||||||
Activity::House => house::draw(state, engine),
|
Activity::House => house::draw(state, engine),
|
||||||
Activity::Overworld => overworld::draw(state, engine)
|
Activity::Overworld => overworld::draw(state, engine)
|
||||||
}
|
}
|
||||||
|
crate::ui::draw(state, engine);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,12 @@ mod assets {
|
||||||
|
|
||||||
mod activities;
|
mod activities;
|
||||||
mod game;
|
mod game;
|
||||||
|
mod ui;
|
||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
activities::{house::HouseState, overworld::worldgen::Overworld, Activity},
|
activities::{house::HouseState, overworld::worldgen::Overworld, Activity},
|
||||||
assets::Assets
|
assets::Assets,
|
||||||
|
game::Ghost
|
||||||
};
|
};
|
||||||
use comfy::{
|
use comfy::{
|
||||||
init_game_config, pollster, run_comfy_main_async, EngineContext, EngineState,
|
init_game_config, pollster, run_comfy_main_async, EngineContext, EngineState,
|
||||||
|
@ -24,6 +26,7 @@ const GAME_NAME: &str = "Powercreep";
|
||||||
struct State {
|
struct State {
|
||||||
setup_called: bool,
|
setup_called: bool,
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
|
ghost: Ghost,
|
||||||
overworld: Overworld,
|
overworld: Overworld,
|
||||||
house: HouseState
|
house: HouseState
|
||||||
}
|
}
|
||||||
|
|
31
src/ui.rs
Normal file
31
src/ui.rs
Normal 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;
|
||||||
LuckyTurtleDev marked this conversation as resolved
Outdated
msrd0
commented
GHOST!!! GHOST!!!
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue
Ghost