Add a bunch of missing files
This commit is contained in:
parent
b4796f40ea
commit
cf599dd2be
BIN
resources/terminal8x8.png
Normal file
BIN
resources/terminal8x8.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
17
src/systems/collisions.rs
Normal file
17
src/systems/collisions.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
#[system]
|
||||
#[read_component(Point)]
|
||||
#[read_component(Player)]
|
||||
#[read_component(Enemy)]
|
||||
pub fn collisions(ecs: &mut SubWorld, commands: &mut CommandBuffer) {
|
||||
let mut player_pos = Point::zero();
|
||||
let mut players = <&Point>::query().filter(component::<Player>());
|
||||
players.iter(ecs).for_each(|pos| player_pos = *pos);
|
||||
|
||||
let mut enemies = <(Entity, &Point)>::query().filter(component::<Enemy>());
|
||||
enemies
|
||||
.iter(ecs)
|
||||
.filter(|(_, pos)| **pos == player_pos)
|
||||
.for_each(|(entity, _)| commands.remove(*entity));
|
||||
}
|
12
src/systems/end_turn.rs
Normal file
12
src/systems/end_turn.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
#[system]
|
||||
pub fn end_turn(#[resource] turn_state: &mut TurnState) {
|
||||
let new_state = match turn_state {
|
||||
TurnState::AwaitingInput => return,
|
||||
TurnState::PlayerTurn => TurnState::MonsterTurn,
|
||||
TurnState::MonsterTurn => TurnState::AwaitingInput,
|
||||
};
|
||||
|
||||
*turn_state = new_state;
|
||||
}
|
28
src/systems/hud.rs
Normal file
28
src/systems/hud.rs
Normal file
@ -0,0 +1,28 @@
|
||||
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).next().unwrap();
|
||||
let mut draw_batch = DrawBatch::new();
|
||||
draw_batch.target(2);
|
||||
draw_batch.print_centered(1, "Explore the Dungeon. Cursor keys or ASWD 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");
|
||||
}
|
26
src/systems/movement.rs
Normal file
26
src/systems/movement.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
#[system(for_each)]
|
||||
#[read_component(Player)]
|
||||
pub fn movement(
|
||||
entity: &Entity,
|
||||
want_move: &WantsToMove,
|
||||
#[resource] map: &Map,
|
||||
#[resource] camera: &mut Camera,
|
||||
ecs: &mut SubWorld,
|
||||
commands: &mut CommandBuffer,
|
||||
) {
|
||||
if map.can_enter_tile(want_move.destination) {
|
||||
commands.add_component(want_move.entity, want_move.destination);
|
||||
|
||||
if ecs
|
||||
.entry_ref(want_move.entity)
|
||||
.unwrap()
|
||||
.get_component::<Player>()
|
||||
.is_ok()
|
||||
{
|
||||
camera.on_player_move(want_move.destination)
|
||||
}
|
||||
}
|
||||
commands.remove(*entity);
|
||||
}
|
25
src/systems/random_move.rs
Normal file
25
src/systems/random_move.rs
Normal file
@ -0,0 +1,25 @@
|
||||
use crate::prelude::*;
|
||||
|
||||
#[system]
|
||||
#[read_component(Point)]
|
||||
#[read_component(MovingRandomly)]
|
||||
pub fn random_move(ecs: &mut SubWorld, commands: &mut CommandBuffer) {
|
||||
let mut movers = <(Entity, &Point, &MovingRandomly)>::query();
|
||||
movers.iter_mut(ecs).for_each(|(entity, pos, _)| {
|
||||
let mut rng = RandomNumberGenerator::new();
|
||||
let destination = match rng.range(0, 4) {
|
||||
0 => Point::new(-1, 0),
|
||||
1 => Point::new(1, 0),
|
||||
2 => Point::new(0, -1),
|
||||
_ => Point::new(0, 1),
|
||||
} + *pos;
|
||||
|
||||
commands.push((
|
||||
(),
|
||||
WantsToMove {
|
||||
entity: *entity,
|
||||
destination,
|
||||
},
|
||||
));
|
||||
});
|
||||
}
|
6
src/turn_state.rs
Normal file
6
src/turn_state.rs
Normal file
@ -0,0 +1,6 @@
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub enum TurnState {
|
||||
AwaitingInput,
|
||||
PlayerTurn,
|
||||
MonsterTurn,
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user