Abandon map_indexing_system
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
1c54755039
commit
e5d820eded
6 changed files with 36 additions and 36 deletions
|
@ -2,7 +2,7 @@ use bracket_lib::prelude::*;
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
use specs_derive::Component;
|
use specs_derive::Component;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component, Clone, Copy)]
|
||||||
pub struct Position {
|
pub struct Position {
|
||||||
pub x: i32,
|
pub x: i32,
|
||||||
pub y: i32,
|
pub y: i32,
|
||||||
|
@ -13,3 +13,21 @@ impl PartialEq<Point> for Position {
|
||||||
self.x == other.x && self.y == other.y
|
self.x == other.x && self.y == other.y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Point> for Position {
|
||||||
|
fn from(point: Point) -> Self {
|
||||||
|
Self {
|
||||||
|
x: point.x,
|
||||||
|
y: point.y,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Position> for Point {
|
||||||
|
fn from(position: Position) -> Self {
|
||||||
|
Self {
|
||||||
|
x: position.x,
|
||||||
|
y: position.y,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -182,6 +182,10 @@ impl Map {
|
||||||
self.tile_content[index] = Some(entity);
|
self.tile_content[index] = Some(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn clear_tile_content(&mut self, index: usize) {
|
||||||
|
self.tile_content[index] = None;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_tiles(&self) -> &Vec<TileType> {
|
pub fn get_tiles(&self) -> &Vec<TileType> {
|
||||||
&self.tiles
|
&self.tiles
|
||||||
}
|
}
|
||||||
|
|
11
src/state.rs
11
src/state.rs
|
@ -117,7 +117,7 @@ impl State {
|
||||||
let mut positions = self.ecs.write_storage::<Position>();
|
let mut positions = self.ecs.write_storage::<Position>();
|
||||||
let mut players = self.ecs.write_storage::<Player>();
|
let mut players = self.ecs.write_storage::<Player>();
|
||||||
let monsters = self.ecs.write_storage::<Monster>();
|
let monsters = self.ecs.write_storage::<Monster>();
|
||||||
let map = self.ecs.read_resource::<Map>();
|
let mut map = self.ecs.write_resource::<Map>();
|
||||||
let mut stats = self.ecs.write_resource::<Stats>();
|
let mut stats = self.ecs.write_resource::<Stats>();
|
||||||
let mut sound_system = self.ecs.write_resource::<SoundOutput>();
|
let mut sound_system = self.ecs.write_resource::<SoundOutput>();
|
||||||
let wants_to_whips = self.ecs.read_storage::<WantsToWhip>();
|
let wants_to_whips = self.ecs.read_storage::<WantsToWhip>();
|
||||||
|
@ -148,6 +148,9 @@ impl State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let index = map.point2d_to_index(Point::from(*pos));
|
||||||
|
map.clear_tile_content(index);
|
||||||
|
|
||||||
pos.x = destination.x;
|
pos.x = destination.x;
|
||||||
pos.y = destination.y;
|
pos.y = destination.y;
|
||||||
|
|
||||||
|
@ -155,6 +158,9 @@ impl State {
|
||||||
player_pos.x = pos.x;
|
player_pos.x = pos.x;
|
||||||
player_pos.y = pos.y;
|
player_pos.y = pos.y;
|
||||||
|
|
||||||
|
let index = map.point2d_to_index(destination);
|
||||||
|
map.set_tile_content(index, player_entity);
|
||||||
|
|
||||||
self.ecs.write_resource::<Clock>().force_tick();
|
self.ecs.write_resource::<Clock>().force_tick();
|
||||||
|
|
||||||
sound_system.play_sound(sound_effects.step.clone());
|
sound_system.play_sound(sound_effects.step.clone());
|
||||||
|
@ -217,9 +223,6 @@ impl State {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_systems(&mut self) {
|
fn run_systems(&mut self) {
|
||||||
let mut map_indexing_system = MapIndexingSystem {};
|
|
||||||
map_indexing_system.run_now(&self.ecs);
|
|
||||||
|
|
||||||
let mut whip_system = WhipSystem {};
|
let mut whip_system = WhipSystem {};
|
||||||
whip_system.run_now(&self.ecs);
|
whip_system.run_now(&self.ecs);
|
||||||
|
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
use bracket_lib::prelude::*;
|
|
||||||
use specs::prelude::*;
|
|
||||||
|
|
||||||
use crate::{components::Position, resources::Map};
|
|
||||||
|
|
||||||
pub struct MapIndexingSystem {}
|
|
||||||
|
|
||||||
impl<'a> System<'a> for MapIndexingSystem {
|
|
||||||
type SystemData = (
|
|
||||||
WriteExpect<'a, Map>,
|
|
||||||
ReadStorage<'a, Position>,
|
|
||||||
Entities<'a>,
|
|
||||||
);
|
|
||||||
|
|
||||||
fn run(&mut self, data: Self::SystemData) {
|
|
||||||
let (mut map, position, entities) = data;
|
|
||||||
|
|
||||||
map.clear_all_tile_content();
|
|
||||||
for (entity, position) in (&entities, &position).join() {
|
|
||||||
let index = map.point2d_to_index(Point {
|
|
||||||
x: position.x,
|
|
||||||
y: position.y,
|
|
||||||
});
|
|
||||||
map.set_tile_content(index, entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,5 @@
|
||||||
pub mod map_indexing_system;
|
|
||||||
pub mod monster_ai_system;
|
pub mod monster_ai_system;
|
||||||
pub mod whip_system;
|
pub mod whip_system;
|
||||||
|
|
||||||
pub use map_indexing_system::MapIndexingSystem;
|
|
||||||
pub use monster_ai_system::MonsterAiSystem;
|
pub use monster_ai_system::MonsterAiSystem;
|
||||||
pub use whip_system::WhipSystem;
|
pub use whip_system::WhipSystem;
|
||||||
|
|
|
@ -17,7 +17,7 @@ impl<'a> System<'a> for MonsterAiSystem {
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
ReadExpect<'a, Clock>,
|
ReadExpect<'a, Clock>,
|
||||||
ReadExpect<'a, Point>,
|
ReadExpect<'a, Point>,
|
||||||
ReadExpect<'a, Map>,
|
WriteExpect<'a, Map>,
|
||||||
WriteExpect<'a, Stats>,
|
WriteExpect<'a, Stats>,
|
||||||
WriteStorage<'a, Monster>,
|
WriteStorage<'a, Monster>,
|
||||||
WriteStorage<'a, Position>,
|
WriteStorage<'a, Position>,
|
||||||
|
@ -31,7 +31,7 @@ impl<'a> System<'a> for MonsterAiSystem {
|
||||||
entities,
|
entities,
|
||||||
clock,
|
clock,
|
||||||
player_pos,
|
player_pos,
|
||||||
map,
|
mut map,
|
||||||
mut stats,
|
mut stats,
|
||||||
mut monsters,
|
mut monsters,
|
||||||
mut positions,
|
mut positions,
|
||||||
|
@ -88,8 +88,12 @@ impl<'a> System<'a> for MonsterAiSystem {
|
||||||
let _ = entities.delete(*entity);
|
let _ = entities.delete(*entity);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
let index = map.point2d_to_index(Point::from(**position));
|
||||||
|
map.clear_tile_content(index);
|
||||||
position.x = destination.x;
|
position.x = destination.x;
|
||||||
position.y = destination.y;
|
position.y = destination.y;
|
||||||
|
let index = map.point2d_to_index(destination);
|
||||||
|
map.set_tile_content(index, *entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue