mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
teleporters
This commit is contained in:
parent
2ce7d91c74
commit
8b8f94ae7f
|
@ -121,6 +121,7 @@ enum Entity {
|
|||
Ice,
|
||||
MovableBlock,
|
||||
Glove,
|
||||
Teleporter,
|
||||
}
|
||||
|
||||
impl FromStr for Entity {
|
||||
|
@ -147,6 +148,7 @@ impl FromStr for Entity {
|
|||
"ICE" => Ice,
|
||||
"BLOCK" => MovableBlock,
|
||||
"GLOVE" => Glove,
|
||||
"TELEPORTER" => Teleporter,
|
||||
_ => return Err(()),
|
||||
})
|
||||
}
|
||||
|
@ -174,6 +176,7 @@ impl quote::ToTokens for Entity {
|
|||
Ice => quote!(Item::Ice),
|
||||
MovableBlock => quote!(Item::MovableBlock),
|
||||
Glove => quote!(Item::Glove),
|
||||
Teleporter => quote!(Item::Teleporter),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,21 @@ impl ActionResult {
|
|||
}
|
||||
}
|
||||
|
||||
fn remove_move_animation_for_entity(
|
||||
animations: &mut Vec<AnimationInstruction>,
|
||||
entity_key: EntityKey,
|
||||
) {
|
||||
if let Some(existing_animation) = animations.iter().position(|x| {
|
||||
if let AnimationInstruction::Move(entity, _, _) = x {
|
||||
*entity == entity_key
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}) {
|
||||
animations.swap_remove(existing_animation);
|
||||
}
|
||||
}
|
||||
|
||||
struct HasMoved(bool);
|
||||
struct WantsToMoveAgain(bool);
|
||||
|
||||
|
@ -338,17 +353,32 @@ impl EntityMap {
|
|||
break;
|
||||
}
|
||||
OverlapResolution::MoveAgain => {
|
||||
if let Some(existing_animation) = animations.iter().position(|x| {
|
||||
if let AnimationInstruction::Move(entity, _, _) = x {
|
||||
*entity == entity_to_update_key
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}) {
|
||||
animations.swap_remove(existing_animation);
|
||||
}
|
||||
remove_move_animation_for_entity(animations, entity_to_update_key);
|
||||
should_move_again = true;
|
||||
}
|
||||
OverlapResolution::Teleport => {
|
||||
// find other teleporter
|
||||
let other_teleporter = self.map.iter().find(|(entity_key, entity)| {
|
||||
*entity_key != other_entity_key
|
||||
&& matches!(entity.entity, EntityType::Teleporter)
|
||||
});
|
||||
|
||||
if let Some((_other_teleporter_key, other_teleporter)) = other_teleporter {
|
||||
let location_to_teleport_to = other_teleporter.location;
|
||||
if self.whats_at(location_to_teleport_to).count() != 0 {
|
||||
//ok, we can teleport
|
||||
remove_move_animation_for_entity(animations, entity_to_update_key);
|
||||
animations.push(AnimationInstruction::Move(
|
||||
entity_to_update_key,
|
||||
location_to_teleport_to,
|
||||
Some(SoundEffect::TeleportEffect),
|
||||
));
|
||||
if let Some(entity) = self.map.get_mut(entity_to_update_key) {
|
||||
entity.location = location_to_teleport_to;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(
|
||||
|
@ -440,6 +470,7 @@ enum OverlapResolution {
|
|||
ToggleSystem(SwitchSystem),
|
||||
Die,
|
||||
MoveAgain,
|
||||
Teleport,
|
||||
}
|
||||
|
||||
fn resolve_spikes(switable: &Switchable) -> OverlapResolution {
|
||||
|
@ -461,6 +492,7 @@ fn resolve_overlap(me: &Entity, other: &Entity) -> OverlapResolution {
|
|||
(_, EntityType::Switch(switch)) => OverlapResolution::ToggleSystem(switch.system),
|
||||
(_, EntityType::Enemy(_) | EntityType::Hero(_)) => OverlapResolution::Die,
|
||||
(_, EntityType::Ice) => OverlapResolution::MoveAgain,
|
||||
(_, EntityType::Teleporter) => OverlapResolution::Teleport,
|
||||
|
||||
_ => OverlapResolution::CoExist,
|
||||
}
|
||||
|
|
|
@ -74,6 +74,7 @@ impl<'a> Sfx<'a> {
|
|||
SoundEffect::SwordDrop => {}
|
||||
SoundEffect::SwitchedDoorToggle => {}
|
||||
SoundEffect::SpikesToggle => {}
|
||||
SoundEffect::TeleportEffect => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,4 +95,5 @@ pub enum SoundEffect {
|
|||
SwitchedDoorToggle,
|
||||
SpikesToggle,
|
||||
WallHit,
|
||||
TeleportEffect,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue