Complete section 5.19 by finishing town portal functionality
This commit is contained in:
parent
485151e37c
commit
41c0ae7eab
@ -3,14 +3,14 @@ use ::specs::prelude::*;
|
|||||||
use crate::components::{
|
use crate::components::{
|
||||||
ApplyMove, ApplyTeleport, BlocksTile, EntityMoved, OtherLevelPosition, Position, Viewshed,
|
ApplyMove, ApplyTeleport, BlocksTile, EntityMoved, OtherLevelPosition, Position, Viewshed,
|
||||||
};
|
};
|
||||||
use crate::{spatial, Map};
|
use crate::{spatial, Map, RunState};
|
||||||
|
|
||||||
pub struct MovementSystem {}
|
pub struct MovementSystem {}
|
||||||
|
|
||||||
impl<'a> System<'a> for MovementSystem {
|
impl<'a> System<'a> for MovementSystem {
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
type SystemData = (
|
type SystemData = (
|
||||||
WriteExpect<'a, Map>,
|
ReadExpect<'a, Map>,
|
||||||
WriteStorage<'a, Position>,
|
WriteStorage<'a, Position>,
|
||||||
ReadStorage<'a, BlocksTile>,
|
ReadStorage<'a, BlocksTile>,
|
||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
@ -20,13 +20,14 @@ impl<'a> System<'a> for MovementSystem {
|
|||||||
WriteStorage<'a, EntityMoved>,
|
WriteStorage<'a, EntityMoved>,
|
||||||
WriteStorage<'a, Viewshed>,
|
WriteStorage<'a, Viewshed>,
|
||||||
ReadExpect<'a, Entity>,
|
ReadExpect<'a, Entity>,
|
||||||
|
WriteExpect<'a, RunState>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn run(&mut self, data: Self::SystemData) {
|
fn run(&mut self, data: Self::SystemData) {
|
||||||
let (
|
let (
|
||||||
mut map,
|
map,
|
||||||
mut position,
|
mut position,
|
||||||
blockers,
|
_blockers,
|
||||||
entities,
|
entities,
|
||||||
mut apply_move,
|
mut apply_move,
|
||||||
mut apply_teleport,
|
mut apply_teleport,
|
||||||
@ -34,6 +35,7 @@ impl<'a> System<'a> for MovementSystem {
|
|||||||
mut moved,
|
mut moved,
|
||||||
mut viewsheds,
|
mut viewsheds,
|
||||||
player_entity,
|
player_entity,
|
||||||
|
mut runstate,
|
||||||
) = data;
|
) = data;
|
||||||
|
|
||||||
// Apply teleports
|
// Apply teleports
|
||||||
@ -49,7 +51,11 @@ impl<'a> System<'a> for MovementSystem {
|
|||||||
.expect("Unable to insert intent to teleport");
|
.expect("Unable to insert intent to teleport");
|
||||||
} else if entity == *player_entity {
|
} else if entity == *player_entity {
|
||||||
// it's the player - we have a mess
|
// it's the player - we have a mess
|
||||||
::rltk::console::log(format!("Not implemented yet."))
|
*runstate = RunState::TeleportingToOtherLevel {
|
||||||
|
x: teleport.dest_x,
|
||||||
|
y: teleport.dest_y,
|
||||||
|
depth: teleport.dest_depth,
|
||||||
|
};
|
||||||
} else if let Some(pos) = position.get(entity) {
|
} else if let Some(pos) = position.get(entity) {
|
||||||
let idx = map.xy_idx(pos.x, pos.y);
|
let idx = map.xy_idx(pos.x, pos.y);
|
||||||
let dest_idx = map.xy_idx(teleport.dest_x, teleport.dest_y);
|
let dest_idx = map.xy_idx(teleport.dest_x, teleport.dest_y);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use ::specs::prelude::*;
|
use ::specs::prelude::*;
|
||||||
|
|
||||||
use crate::components::{
|
use crate::components::{
|
||||||
EntityMoved, EntryTrigger, Hidden, InflictsDamage, Name, Position, SingleActivation,
|
ApplyTeleport, EntityMoved, EntryTrigger, Hidden, InflictsDamage, Name, Position,
|
||||||
SufferDamage,
|
SingleActivation, SufferDamage, TeleportTo,
|
||||||
};
|
};
|
||||||
use crate::game_log::GameLog;
|
use crate::game_log::GameLog;
|
||||||
use crate::particle_system::ParticleBuilder;
|
use crate::particle_system::ParticleBuilder;
|
||||||
@ -25,6 +25,9 @@ impl<'a> System<'a> for TriggerSystem {
|
|||||||
WriteExpect<'a, ParticleBuilder>,
|
WriteExpect<'a, ParticleBuilder>,
|
||||||
WriteStorage<'a, SufferDamage>,
|
WriteStorage<'a, SufferDamage>,
|
||||||
ReadStorage<'a, SingleActivation>,
|
ReadStorage<'a, SingleActivation>,
|
||||||
|
ReadStorage<'a, TeleportTo>,
|
||||||
|
WriteStorage<'a, ApplyTeleport>,
|
||||||
|
ReadExpect<'a, Entity>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn run(&mut self, data: Self::SystemData) {
|
fn run(&mut self, data: Self::SystemData) {
|
||||||
@ -41,6 +44,9 @@ impl<'a> System<'a> for TriggerSystem {
|
|||||||
mut particle_builder,
|
mut particle_builder,
|
||||||
mut inflict_damage,
|
mut inflict_damage,
|
||||||
single_activation,
|
single_activation,
|
||||||
|
teleporters,
|
||||||
|
mut apply_teleport,
|
||||||
|
player_entity,
|
||||||
) = data;
|
) = data;
|
||||||
|
|
||||||
// Iterate the entities that moved and their final position
|
// Iterate the entities that moved and their final position
|
||||||
@ -81,6 +87,24 @@ impl<'a> System<'a> for TriggerSystem {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If it's a teleporter, then do that
|
||||||
|
if let Some(teleport) = teleporters.get(entity_id) {
|
||||||
|
if (teleport.player_only && entity == *player_entity)
|
||||||
|
|| !teleport.player_only
|
||||||
|
{
|
||||||
|
apply_teleport
|
||||||
|
.insert(
|
||||||
|
entity,
|
||||||
|
ApplyTeleport {
|
||||||
|
dest_x: teleport.x,
|
||||||
|
dest_y: teleport.y,
|
||||||
|
dest_depth: teleport.depth,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.expect("Unable to insert intent to teleport");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If it is single activation, it needs to be removed
|
// If it is single activation, it needs to be removed
|
||||||
if single_activation.get(entity_id).is_some() {
|
if single_activation.get(entity_id).is_some() {
|
||||||
remove_entities.push(entity_id);
|
remove_entities.push(entity_id);
|
||||||
|
Loading…
Reference in New Issue
Block a user