diff --git a/src/movement_system.rs b/src/movement_system.rs index 4ce7b5c..0eecd32 100644 --- a/src/movement_system.rs +++ b/src/movement_system.rs @@ -3,14 +3,14 @@ use ::specs::prelude::*; use crate::components::{ ApplyMove, ApplyTeleport, BlocksTile, EntityMoved, OtherLevelPosition, Position, Viewshed, }; -use crate::{spatial, Map}; +use crate::{spatial, Map, RunState}; pub struct MovementSystem {} impl<'a> System<'a> for MovementSystem { #[allow(clippy::type_complexity)] type SystemData = ( - WriteExpect<'a, Map>, + ReadExpect<'a, Map>, WriteStorage<'a, Position>, ReadStorage<'a, BlocksTile>, Entities<'a>, @@ -20,13 +20,14 @@ impl<'a> System<'a> for MovementSystem { WriteStorage<'a, EntityMoved>, WriteStorage<'a, Viewshed>, ReadExpect<'a, Entity>, + WriteExpect<'a, RunState>, ); fn run(&mut self, data: Self::SystemData) { let ( - mut map, + map, mut position, - blockers, + _blockers, entities, mut apply_move, mut apply_teleport, @@ -34,6 +35,7 @@ impl<'a> System<'a> for MovementSystem { mut moved, mut viewsheds, player_entity, + mut runstate, ) = data; // Apply teleports @@ -49,7 +51,11 @@ impl<'a> System<'a> for MovementSystem { .expect("Unable to insert intent to teleport"); } else if entity == *player_entity { // 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) { let idx = map.xy_idx(pos.x, pos.y); let dest_idx = map.xy_idx(teleport.dest_x, teleport.dest_y); diff --git a/src/trigger_system.rs b/src/trigger_system.rs index e59074b..6299424 100644 --- a/src/trigger_system.rs +++ b/src/trigger_system.rs @@ -1,8 +1,8 @@ use ::specs::prelude::*; use crate::components::{ - EntityMoved, EntryTrigger, Hidden, InflictsDamage, Name, Position, SingleActivation, - SufferDamage, + ApplyTeleport, EntityMoved, EntryTrigger, Hidden, InflictsDamage, Name, Position, + SingleActivation, SufferDamage, TeleportTo, }; use crate::game_log::GameLog; use crate::particle_system::ParticleBuilder; @@ -25,6 +25,9 @@ impl<'a> System<'a> for TriggerSystem { WriteExpect<'a, ParticleBuilder>, WriteStorage<'a, SufferDamage>, ReadStorage<'a, SingleActivation>, + ReadStorage<'a, TeleportTo>, + WriteStorage<'a, ApplyTeleport>, + ReadExpect<'a, Entity>, ); fn run(&mut self, data: Self::SystemData) { @@ -41,6 +44,9 @@ impl<'a> System<'a> for TriggerSystem { mut particle_builder, mut inflict_damage, single_activation, + teleporters, + mut apply_teleport, + player_entity, ) = data; // 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 single_activation.get(entity_id).is_some() { remove_entities.push(entity_id);