Complete section 5.19 by finishing town portal functionality

This commit is contained in:
Timothy Warren 2022-01-18 11:43:36 -05:00
parent 485151e37c
commit 41c0ae7eab
2 changed files with 37 additions and 7 deletions

View File

@ -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);

View File

@ -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);