tooltips, hud, fixes
This commit is contained in:
parent
367d5f26ae
commit
57bfba8bee
BIN
resources/terminal8x8.png
Normal file
BIN
resources/terminal8x8.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
@ -20,3 +20,12 @@ pub struct WantsToMove {
|
|||||||
pub entity: Entity,
|
pub entity: Entity,
|
||||||
pub destination: Point,
|
pub destination: Point,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
|
pub struct Health {
|
||||||
|
pub current: i32,
|
||||||
|
pub max: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
pub struct Name(pub String);
|
||||||
|
@ -65,7 +65,11 @@ impl GameState for State {
|
|||||||
ctx.cls();
|
ctx.cls();
|
||||||
ctx.set_active_console(1);
|
ctx.set_active_console(1);
|
||||||
ctx.cls();
|
ctx.cls();
|
||||||
|
ctx.set_active_console(2);
|
||||||
|
ctx.cls();
|
||||||
self.resources.insert(ctx.key);
|
self.resources.insert(ctx.key);
|
||||||
|
ctx.set_active_console(0);
|
||||||
|
self.resources.insert(Point::from_tuple(ctx.mouse_pos()));
|
||||||
//self.systems.execute(&mut self.ecs, &mut self.resources);
|
//self.systems.execute(&mut self.ecs, &mut self.resources);
|
||||||
let current_state = self.resources.get::<TurnState>().unwrap().clone();
|
let current_state = self.resources.get::<TurnState>().unwrap().clone();
|
||||||
match current_state {
|
match current_state {
|
||||||
@ -91,8 +95,10 @@ fn main() -> BError {
|
|||||||
.with_tile_dimensions(32, 32)
|
.with_tile_dimensions(32, 32)
|
||||||
.with_resource_path("resources/")
|
.with_resource_path("resources/")
|
||||||
.with_font("dungeonfont.png", 32, 32)
|
.with_font("dungeonfont.png", 32, 32)
|
||||||
|
.with_font("terminal8x8.png", 8, 8)
|
||||||
.with_simple_console(DISPLAY_WIDTH, DISPLAY_HEIGHT, "dungeonfont.png")
|
.with_simple_console(DISPLAY_WIDTH, DISPLAY_HEIGHT, "dungeonfont.png")
|
||||||
.with_simple_console_no_bg(DISPLAY_WIDTH, DISPLAY_HEIGHT, "dungeonfont.png")
|
.with_simple_console_no_bg(DISPLAY_WIDTH, DISPLAY_HEIGHT, "dungeonfont.png")
|
||||||
|
.with_simple_console_no_bg(SCREEN_WIDTH * 2, SCREEN_HEIGHT * 2, "terminal8x8.png")
|
||||||
.build()?;
|
.build()?;
|
||||||
main_loop(context, State::new())
|
main_loop(context, State::new())
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
const NUM_ROOMS: usize = 20;
|
|
||||||
|
|
||||||
|
const NUM_ROOMS: usize = 20;
|
||||||
pub struct MapBuilder {
|
pub struct MapBuilder {
|
||||||
pub map: Map,
|
pub map: Map,
|
||||||
pub rooms: Vec<Rect>,
|
pub rooms: Vec<Rect>,
|
||||||
@ -80,10 +80,10 @@ impl MapBuilder {
|
|||||||
|
|
||||||
if rng.range(0, 2) == 1 {
|
if rng.range(0, 2) == 1 {
|
||||||
self.apply_horizontal_tunnel(prev.x, new.x, prev.y);
|
self.apply_horizontal_tunnel(prev.x, new.x, prev.y);
|
||||||
self.apply_vertical_tunnel(prev.y, new.y, prev.x);
|
self.apply_vertical_tunnel(prev.y, new.y, new.x);
|
||||||
} else {
|
} else {
|
||||||
self.apply_vertical_tunnel(prev.y, new.y, prev.x);
|
self.apply_vertical_tunnel(prev.y, new.y, prev.x);
|
||||||
self.apply_horizontal_tunnel(prev.x, new.x, prev.y);
|
self.apply_horizontal_tunnel(prev.x, new.x, new.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,22 +8,38 @@ pub fn spawn_player(ecs: &mut World, pos: Point) {
|
|||||||
color: ColorPair::new(WHITE, BLACK),
|
color: ColorPair::new(WHITE, BLACK),
|
||||||
glyph: to_cp437('@'),
|
glyph: to_cp437('@'),
|
||||||
},
|
},
|
||||||
|
Health {
|
||||||
|
current: 20,
|
||||||
|
max: 20,
|
||||||
|
},
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_monster(ecs: &mut World, rng: &mut RandomNumberGenerator, pos: Point) {
|
pub fn spawn_monster(ecs: &mut World, rng: &mut RandomNumberGenerator, pos: Point) {
|
||||||
|
let (hp, name, glyph) = match rng.roll_dice(1, 10) {
|
||||||
|
1..=8 => goblin(),
|
||||||
|
_ => orc(),
|
||||||
|
};
|
||||||
|
|
||||||
ecs.push((
|
ecs.push((
|
||||||
Enemy,
|
Enemy,
|
||||||
pos,
|
pos,
|
||||||
Render {
|
Render {
|
||||||
color: ColorPair::new(WHITE, BLACK),
|
color: ColorPair::new(WHITE, BLACK),
|
||||||
glyph: match rng.range(0, 4) {
|
glyph,
|
||||||
0 => to_cp437('E'), // Ettin
|
|
||||||
1 => to_cp437('O'), // Ogre
|
|
||||||
2 => to_cp437('o'), // Orc
|
|
||||||
_ => to_cp437('g'), // goblin
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
MovingRandomly {},
|
MovingRandomly {},
|
||||||
|
Health {
|
||||||
|
current: hp,
|
||||||
|
max: hp,
|
||||||
|
},
|
||||||
|
Name(name),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn goblin() -> (i32, String, FontCharType) {
|
||||||
|
(1, "Goblin".to_string(), to_cp437('g'))
|
||||||
|
}
|
||||||
|
fn orc() -> (i32, String, FontCharType) {
|
||||||
|
(2, "orc".to_string(), to_cp437('o'))
|
||||||
|
}
|
||||||
|
26
src/systems/hud.rs
Normal file
26
src/systems/hud.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
#[system]
|
||||||
|
#[read_component(Health)]
|
||||||
|
#[read_component(Player)]
|
||||||
|
pub fn hud(ecs: &SubWorld) {
|
||||||
|
let mut health_query = <&Health>::query().filter(component::<Player>());
|
||||||
|
let player_health = health_query.iter(ecs).nth(0).unwrap();
|
||||||
|
|
||||||
|
let mut draw_batch = DrawBatch::new();
|
||||||
|
draw_batch.target(2);
|
||||||
|
draw_batch.print_centered(1, "Explore the Dungeon. Cursor keys to move.");
|
||||||
|
draw_batch.bar_horizontal(
|
||||||
|
Point::zero(),
|
||||||
|
SCREEN_WIDTH * 2,
|
||||||
|
player_health.current,
|
||||||
|
player_health.max,
|
||||||
|
ColorPair::new(RED, BLACK),
|
||||||
|
);
|
||||||
|
draw_batch.print_color_centered(
|
||||||
|
0,
|
||||||
|
format!(" Health: {}/{} ", player_health.current, player_health.max,),
|
||||||
|
ColorPair::new(WHITE, RED),
|
||||||
|
);
|
||||||
|
draw_batch.submit(10000).expect("Batch Error");
|
||||||
|
}
|
@ -2,10 +2,12 @@ use crate::prelude::*;
|
|||||||
mod collisions;
|
mod collisions;
|
||||||
mod end_turn;
|
mod end_turn;
|
||||||
mod entity_render;
|
mod entity_render;
|
||||||
|
mod hud;
|
||||||
mod map_render;
|
mod map_render;
|
||||||
mod movement;
|
mod movement;
|
||||||
mod player_input;
|
mod player_input;
|
||||||
mod random_move;
|
mod random_move;
|
||||||
|
mod tooltips;
|
||||||
|
|
||||||
pub fn input_build_scheduler() -> Schedule {
|
pub fn input_build_scheduler() -> Schedule {
|
||||||
Schedule::builder()
|
Schedule::builder()
|
||||||
@ -13,6 +15,8 @@ pub fn input_build_scheduler() -> Schedule {
|
|||||||
.flush()
|
.flush()
|
||||||
.add_system(map_render::map_render_system())
|
.add_system(map_render::map_render_system())
|
||||||
.add_system(entity_render::entity_render_system())
|
.add_system(entity_render::entity_render_system())
|
||||||
|
.add_system(hud::hud_system())
|
||||||
|
.add_system(tooltips::tooltips_system())
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
pub fn player_build_scheduler() -> Schedule {
|
pub fn player_build_scheduler() -> Schedule {
|
||||||
@ -23,6 +27,7 @@ pub fn player_build_scheduler() -> Schedule {
|
|||||||
.flush()
|
.flush()
|
||||||
.add_system(map_render::map_render_system())
|
.add_system(map_render::map_render_system())
|
||||||
.add_system(entity_render::entity_render_system())
|
.add_system(entity_render::entity_render_system())
|
||||||
|
.add_system(hud::hud_system())
|
||||||
.add_system(end_turn::end_turn_system())
|
.add_system(end_turn::end_turn_system())
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
@ -36,6 +41,7 @@ pub fn monster_build_scheduler() -> Schedule {
|
|||||||
.flush()
|
.flush()
|
||||||
.add_system(map_render::map_render_system())
|
.add_system(map_render::map_render_system())
|
||||||
.add_system(entity_render::entity_render_system())
|
.add_system(entity_render::entity_render_system())
|
||||||
|
.add_system(hud::hud_system())
|
||||||
.add_system(end_turn::end_turn_system())
|
.add_system(end_turn::end_turn_system())
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
35
src/systems/tooltips.rs
Normal file
35
src/systems/tooltips.rs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
#[system]
|
||||||
|
#[read_component(Point)]
|
||||||
|
#[read_component(Name)]
|
||||||
|
#[read_component(Health)]
|
||||||
|
pub fn tooltips(
|
||||||
|
ecs: &SubWorld,
|
||||||
|
#[resource] mouse_pos: &Point, // (1)
|
||||||
|
#[resource] camera: &Camera, // (2)
|
||||||
|
) {
|
||||||
|
let mut positions = <(Entity, &Point, &Name)>::query(); // (3)
|
||||||
|
let offset = Point::new(camera.left_x, camera.top_y);
|
||||||
|
let map_pos = *mouse_pos + offset; // (4)
|
||||||
|
let mut draw_batch = DrawBatch::new();
|
||||||
|
draw_batch.target(2);
|
||||||
|
positions
|
||||||
|
.iter(ecs)
|
||||||
|
.filter(|(_, pos, _)| **pos == map_pos) // (5)
|
||||||
|
.for_each(|(entity, _, name)| {
|
||||||
|
let screen_pos = *mouse_pos * 4; // (6)
|
||||||
|
let display = if let Ok(health) = ecs
|
||||||
|
.entry_ref(*entity) // (7)
|
||||||
|
.unwrap()
|
||||||
|
.get_component::<Health>()
|
||||||
|
{
|
||||||
|
format!("{} : {} hp", &name.0, health.current) // (8)
|
||||||
|
} else {
|
||||||
|
// (9)
|
||||||
|
name.0.clone()
|
||||||
|
};
|
||||||
|
draw_batch.print(screen_pos, &display);
|
||||||
|
});
|
||||||
|
draw_batch.submit(10100).expect("Batch error");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user