energie lost overworld
Some checks failed
Rust / rustfmt (push) Failing after 24s
Rust / clippy (push) Failing after 1m26s
Rust / build (push) Successful in 3m3s

This commit is contained in:
luckyturtledev 2024-07-07 16:39:54 +02:00
parent b9e065058f
commit 2354e34142
3 changed files with 37 additions and 11 deletions

View file

@ -1,6 +1,6 @@
use crate::{activities::Activity, game::ZLayer, State}; use crate::{activities::Activity, game::ZLayer, State};
use comfy::{ use comfy::{
draw_circle, draw_rect_outline, draw_sprite, error, info, is_key_down, delta, draw_circle, draw_rect_outline, draw_sprite, error, info, is_key_down,
main_camera_mut, EngineContext, IVec2, KeyCode, Vec2, RED, WHITE main_camera_mut, EngineContext, IVec2, KeyCode, Vec2, RED, WHITE
}; };
use std::time::Instant; use std::time::Instant;
@ -27,7 +27,7 @@ pub fn draw(state: &crate::State, _engine: &comfy::EngineContext<'_>) {
draw_circle(state.ghost.overworld_pos, 0.5, RED, ZLayer::Ghost.into()); draw_circle(state.ghost.overworld_pos, 0.5, RED, ZLayer::Ghost.into());
} }
fn update_move_player(state: &mut State, ctx: &mut EngineContext<'_>) { fn update_move_player(state: &mut State, _ctx: &mut EngineContext<'_>) {
let now = Instant::now(); let now = Instant::now();
// Are there any pending position updates? If so, we ignore all user input and execute // Are there any pending position updates? If so, we ignore all user input and execute
@ -174,6 +174,15 @@ pub fn update(state: &mut State, ctx: &mut EngineContext<'_>) {
} }
} }
// energie lost
{
let ghost = &mut state.ghost;
ghost.charge -= 70.0 * ctx.delta;
if ghost.overworld_movement_pending != Vec2::ZERO {
ghost.charge -= 70.0 * ctx.delta;
}
}
// generate more chunks if needed // generate more chunks if needed
{ {
let half_viewport = (camera.world_viewport() * 0.5 + 3.0).as_ivec2(); let half_viewport = (camera.world_viewport() * 0.5 + 3.0).as_ivec2();

View file

@ -4,7 +4,10 @@ use crate::{
State State
}; };
use comfy::{EngineContext, Vec2}; use comfy::{EngineContext, Vec2};
use std::{ops::Sub, time::Instant}; use std::{
ops::{Add, Sub},
time::Instant
};
#[derive(Debug)] #[derive(Debug)]
pub struct Ghost { pub struct Ghost {
@ -71,7 +74,8 @@ pub enum ZLayer {
ElectricLayer = -2, ElectricLayer = -2,
MapMax = -1, MapMax = -1,
Human = 0, Human = 0,
Ghost = 1 Ghost = 1,
UI = 100
} }
impl From<ZLayer> for i32 { impl From<ZLayer> for i32 {
@ -89,7 +93,15 @@ impl Sub<i32> for ZLayer {
} }
} }
pub fn setup(state: &mut State, ctx: &mut EngineContext<'_>) { impl Add<i32> for ZLayer {
type Output = i32;
fn add(self, other: i32) -> Self::Output {
i32::from(self) + other
}
}
pub fn setup(_state: &mut State, ctx: &mut EngineContext<'_>) {
Assets::load(ctx); Assets::load(ctx);
//house::setup(state, ctx); //house::setup(state, ctx);
@ -101,6 +113,7 @@ pub fn update(state: &mut State, engine: &mut EngineContext<'_>) {
Activity::House(_) => house::update(state, engine), Activity::House(_) => house::update(state, engine),
Activity::Overworld => overworld::update(state, engine) Activity::Overworld => overworld::update(state, engine)
} }
state.ghost.charge = state.ghost.charge.max(0.0);
} }
pub fn draw(state: &State, engine: &EngineContext<'_>) { pub fn draw(state: &State, engine: &EngineContext<'_>) {

View file

@ -1,7 +1,7 @@
use crate::State; use crate::{game::ZLayer, State};
use comfy::{ use comfy::{
draw_rect, draw_rect_outline, egui, screen_height, screen_to_world, screen_width, draw_rect, draw_rect_outline, egui, screen_height, screen_to_world, screen_width,
EngineContext, Vec2, BLUE, RED, WHITE EngineContext, Vec2, BLACK, BLUE, RED, WHITE
}; };
use egui::widget_text::RichText; use egui::widget_text::RichText;
@ -18,16 +18,20 @@ pub fn draw_batterie(state: &State, _engine: &EngineContext<'_>) {
let ghost = &state.ghost; let ghost = &state.ghost;
let percent = ghost.charge / ghost.max_charge; let percent = ghost.charge / ghost.max_charge;
let mut size = section_size; let mut size = section_size;
size.y = section_size.y * section_count as f32 * percent; size.y = section_size.y * section_count as f32;
let mut position = start_positon; let mut position = start_positon;
position.y += 0.5 * -section_size.y + 0.5 * size.y; position.y += 0.5 * -section_size.y + 0.5 * size.y;
draw_rect(position, size, BLUE, 100); draw_rect(position, size, BLACK, ZLayer::UI.into());
size.y *= percent;
let mut position = start_positon;
position.y += 0.5 * -section_size.y + 0.5 * size.y;
draw_rect(position, size, BLUE, ZLayer::UI + 1);
} }
// draw sections // draw sections
for i in 0 .. section_count { for i in 0 .. section_count {
let mut position = start_positon; let mut position = start_positon;
position.y += i as f32 * section_size.y; position.y += i as f32 * section_size.y;
draw_rect_outline(position, section_size, 0.1, RED, 100); draw_rect_outline(position, section_size, 0.1, RED, ZLayer::UI + 2);
} }
} }
@ -36,7 +40,7 @@ pub fn draw_highscore(state: &State, _engine: &EngineContext<'_>) {
.anchor(egui::Align2::RIGHT_TOP, egui::vec2(0.0, 0.0)) .anchor(egui::Align2::RIGHT_TOP, egui::vec2(0.0, 0.0))
.show(egui(), |ui| { .show(egui(), |ui| {
ui.label( ui.label(
RichText::new(format!("{:.0}", state.score)) RichText::new(format!("{:.0} ", state.score))
.color(WHITE) .color(WHITE)
.monospace() .monospace()
.size(16.0) .size(16.0)