fixes cheatmenu, reimpl particle ticker

This commit is contained in:
Llywelwyn 2023-09-24 23:56:29 +01:00
parent 0d4c0c9558
commit 7f9ba34afa
5 changed files with 27 additions and 57 deletions

View file

@ -46,7 +46,7 @@ pub fn show_cheat_menu(_gs: &mut State, ctx: &mut App) -> CheatMenuResult {
pub fn draw_cheat_menu( pub fn draw_cheat_menu(
draw: &mut notan::draw::Draw, draw: &mut notan::draw::Draw,
atlas: &HashMap<String, Texture>, _atlas: &HashMap<String, Texture>,
font: &notan::draw::Font font: &notan::draw::Font
) { ) {
let offsets = crate::camera::get_offset(); let offsets = crate::camera::get_offset();
@ -59,40 +59,7 @@ pub fn draw_cheat_menu(
m - MAGIC MAP REVEAL m - MAGIC MAP REVEAL
g - GOD MODE"#; g - GOD MODE"#;
draw.text(&font, DEBUG_MENU) draw.text(&font, DEBUG_MENU)
.position(1.0 + (offsets.x as f32) * TILESIZE, 1.0 + (offsets.y as f32) * TILESIZE) .position(3.0 + (offsets.x as f32) * TILESIZE, 3.0 + (offsets.y as f32) * TILESIZE)
.color(Color::RED); .color(Color::RED)
/*let (x_offset, y_offset) = (1, 10); .size(TILESIZE);
ctx.print_color(
1 + x_offset,
1 + y_offset,
RGB::named(RED),
RGB::named(BLACK),
"DEBUG MENU! [aA-zZ][Esc.]"
);
let x = 1 + x_offset;
let mut y = 3 + y_offset;
let count = 5;
let width = 19;
ctx.draw_box(x, y, width, (count + 1) as i32, RGB::named(RED), RGB::named(BLACK));
y += 1;
// Asc
ctx.set(x_offset + 2, y, RGB::named(YELLOW), RGB::named(BLACK), to_cp437('a'));
ctx.print(x_offset + 4, y, "ASCEND A FLOOR");
y += 1;
// Desc
ctx.set(x_offset + 2, y, RGB::named(YELLOW), RGB::named(BLACK), to_cp437('d'));
ctx.print(x_offset + 4, y, "DESCEND A FLOOR");
y += 1;
// Heal
ctx.set(x_offset + 2, y, RGB::named(YELLOW), RGB::named(BLACK), to_cp437('h'));
ctx.print(x_offset + 4, y, "HEAL TO FULL");
y += 1;
// Reveal map
ctx.set(x_offset + 2, y, RGB::named(YELLOW), RGB::named(BLACK), to_cp437('m'));
ctx.print(x_offset + 4, y, "MAGIC MAP REVEAL");
y += 1;
// Godmode
ctx.set(x_offset + 2, y, RGB::named(YELLOW), RGB::named(BLACK), to_cp437('g'));
ctx.print(x_offset + 4, y, "GOD MODE");*/
} }

View file

@ -1,6 +1,9 @@
use super::{ State, RunState, tooltip::draw_tooltips, camera::get_offset, VIEWPORT_H, VIEWPORT_W }; use super::{ State, RunState, tooltip::draw_tooltips, camera::get_offset, VIEWPORT_H, VIEWPORT_W };
use bracket_lib::prelude::*; use bracket_lib::prelude::*;
use notan::prelude::*; use notan::prelude::*;
use notan::draw::{ Draw, DrawImages };
use std::collections::HashMap;
use crate::consts::TILESIZE;
#[derive(PartialEq, Copy, Clone)] #[derive(PartialEq, Copy, Clone)]
pub enum FarlookResult { pub enum FarlookResult {
@ -57,3 +60,10 @@ pub fn show_farlook(gs: &mut State, ctx: &mut App) -> FarlookResult {
return FarlookResult::NoResponse { x: ppos.x + offsets.x, y: ppos.x + offsets.y }; return FarlookResult::NoResponse { x: ppos.x + offsets.x, y: ppos.x + offsets.y };
} }
} }
pub fn draw_farlook(x: i32, y: i32, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
draw.image(atlas.get("ui_select_c1").unwrap()).position(
(x as f32) * TILESIZE,
(y as f32) * TILESIZE
);
}

View file

@ -308,13 +308,6 @@ fn render_map_in_view(
} }
} }
fn draw_farlook(x: i32, y: i32, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
draw.image(atlas.get("ui_select_c1").unwrap()).position(
(x as f32) * TILESIZE,
(y as f32) * TILESIZE
);
}
struct BoxDraw { struct BoxDraw {
frame: String, frame: String,
fill: bool, fill: bool,
@ -377,7 +370,7 @@ fn draw_spritebox(panel: BoxDraw, draw: &mut Draw, atlas: &HashMap<String, Textu
} }
use crate::consts::visuals::{ VIEWPORT_H, VIEWPORT_W }; use crate::consts::visuals::{ VIEWPORT_H, VIEWPORT_W };
fn draw_bg(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) { fn draw_bg(_ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
let offset = crate::camera::get_offset(); let offset = crate::camera::get_offset();
let log = BoxDraw { let log = BoxDraw {
frame: "ui_panel_window".to_string(), frame: "ui_panel_window".to_string(),
@ -441,11 +434,10 @@ fn draw(app: &mut App, gfx: &mut Graphics, gs: &mut State) {
} }
match *gs.ecs.fetch::<RunState>() { match *gs.ecs.fetch::<RunState>() {
RunState::Farlook { x, y } => { RunState::Farlook { x, y } => {
draw.text(&gs.font, "RunState::Farlook").position( draw.text(&gs.font, "RunState::Farlook")
((x + 2) as f32) * TILESIZE, .position(((x + 2) as f32) * TILESIZE, (y as f32) * TILESIZE)
(y as f32) * TILESIZE .size(TILESIZE);
); crate::gui::draw_farlook(x, y, &mut draw, &gs.atlas);
draw_farlook(x, y, &mut draw, &gs.atlas);
//draw_tooltips(&gs.ecs, ctx, Some((x, y))); TODO: Put this in draw loop //draw_tooltips(&gs.ecs, ctx, Some((x, y))); TODO: Put this in draw loop
} }
RunState::ShowCheatMenu => { RunState::ShowCheatMenu => {

View file

@ -1,5 +1,6 @@
use super::{ ParticleLifetime, Position, Renderable, BTerm }; use super::{ ParticleLifetime, Position, Renderable, BTerm };
use bracket_lib::prelude::*; use bracket_lib::prelude::*;
use notan::prelude::*;
use specs::prelude::*; use specs::prelude::*;
use crate::consts::visuals::{ DEFAULT_PARTICLE_LIFETIME, SHORT_PARTICLE_LIFETIME }; use crate::consts::visuals::{ DEFAULT_PARTICLE_LIFETIME, SHORT_PARTICLE_LIFETIME };
@ -8,19 +9,19 @@ use crate::consts::visuals::{ DEFAULT_PARTICLE_LIFETIME, SHORT_PARTICLE_LIFETIME
// running through a list and removing the frame_time_ms from the // running through a list and removing the frame_time_ms from the
// delay. When delay is <= 0, make a particle_builder.request for // delay. When delay is <= 0, make a particle_builder.request for
// the particle. // the particle.
pub fn particle_ticker(ecs: &mut World, ctx: &BTerm) { pub fn particle_ticker(ecs: &mut World, ctx: &App) {
cull_dead_particles(ecs, ctx); cull_dead_particles(ecs, ctx);
create_delayed_particles(ecs, ctx); create_delayed_particles(ecs, ctx);
} }
fn cull_dead_particles(ecs: &mut World, ctx: &BTerm) { fn cull_dead_particles(ecs: &mut World, ctx: &App) {
let mut dead_particles: Vec<Entity> = Vec::new(); let mut dead_particles: Vec<Entity> = Vec::new();
{ {
// Age out particles // Age out particles
let mut particles = ecs.write_storage::<ParticleLifetime>(); let mut particles = ecs.write_storage::<ParticleLifetime>();
let entities = ecs.entities(); let entities = ecs.entities();
for (entity, mut particle) in (&entities, &mut particles).join() { for (entity, mut particle) in (&entities, &mut particles).join() {
particle.lifetime_ms -= ctx.frame_time_ms; particle.lifetime_ms -= ctx.timer.delta_f32() * 1000.0;
if particle.lifetime_ms < 0.0 { if particle.lifetime_ms < 0.0 {
dead_particles.push(entity); dead_particles.push(entity);
} }
@ -39,11 +40,11 @@ pub fn check_queue(ecs: &World) -> bool {
return false; return false;
} }
fn create_delayed_particles(ecs: &mut World, ctx: &BTerm) { fn create_delayed_particles(ecs: &mut World, ctx: &App) {
let mut particle_builder = ecs.write_resource::<ParticleBuilder>(); let mut particle_builder = ecs.write_resource::<ParticleBuilder>();
let mut handled_particles: Vec<ParticleRequest> = Vec::new(); let mut handled_particles: Vec<ParticleRequest> = Vec::new();
for delayed_particle in particle_builder.delayed_requests.iter_mut() { for delayed_particle in particle_builder.delayed_requests.iter_mut() {
delayed_particle.delay -= ctx.frame_time_ms; delayed_particle.delay -= ctx.timer.delta_f32() * 1000.0;
if delayed_particle.delay < 0.0 { if delayed_particle.delay < 0.0 {
handled_particles.push(ParticleRequest { handled_particles.push(ParticleRequest {
x: delayed_particle.particle.x, x: delayed_particle.particle.x,

View file

@ -169,7 +169,7 @@ impl State {
let runstate = self.ecs.fetch::<RunState>(); let runstate = self.ecs.fetch::<RunState>();
new_runstate = *runstate; new_runstate = *runstate;
} }
// Particle ticker here particle_system::particle_ticker(&mut self.ecs, ctx);
match new_runstate { match new_runstate {
RunState::PreRun => { RunState::PreRun => {
self.run_systems(); self.run_systems();
@ -377,7 +377,7 @@ impl State {
ctx.cls(); ctx.cls();
ctx.set_active_console(0); ctx.set_active_console(0);
ctx.cls(); ctx.cls();
particle_system::particle_ticker(&mut self.ecs, ctx); //particle_system::particle_ticker(&mut self.ecs, ctx);
match new_runstate { match new_runstate {
RunState::MainMenu { .. } => {} RunState::MainMenu { .. } => {}