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,
|
Ice,
|
||||||
MovableBlock,
|
MovableBlock,
|
||||||
Glove,
|
Glove,
|
||||||
|
Teleporter,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for Entity {
|
impl FromStr for Entity {
|
||||||
|
@ -147,6 +148,7 @@ impl FromStr for Entity {
|
||||||
"ICE" => Ice,
|
"ICE" => Ice,
|
||||||
"BLOCK" => MovableBlock,
|
"BLOCK" => MovableBlock,
|
||||||
"GLOVE" => Glove,
|
"GLOVE" => Glove,
|
||||||
|
"TELEPORTER" => Teleporter,
|
||||||
_ => return Err(()),
|
_ => return Err(()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -174,6 +176,7 @@ impl quote::ToTokens for Entity {
|
||||||
Ice => quote!(Item::Ice),
|
Ice => quote!(Item::Ice),
|
||||||
MovableBlock => quote!(Item::MovableBlock),
|
MovableBlock => quote!(Item::MovableBlock),
|
||||||
Glove => quote!(Item::Glove),
|
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 HasMoved(bool);
|
||||||
struct WantsToMoveAgain(bool);
|
struct WantsToMoveAgain(bool);
|
||||||
|
|
||||||
|
@ -338,17 +353,32 @@ impl EntityMap {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
OverlapResolution::MoveAgain => {
|
OverlapResolution::MoveAgain => {
|
||||||
if let Some(existing_animation) = animations.iter().position(|x| {
|
remove_move_animation_for_entity(animations, entity_to_update_key);
|
||||||
if let AnimationInstruction::Move(entity, _, _) = x {
|
|
||||||
*entity == entity_to_update_key
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
animations.swap_remove(existing_animation);
|
|
||||||
}
|
|
||||||
should_move_again = true;
|
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),
|
ToggleSystem(SwitchSystem),
|
||||||
Die,
|
Die,
|
||||||
MoveAgain,
|
MoveAgain,
|
||||||
|
Teleport,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_spikes(switable: &Switchable) -> OverlapResolution {
|
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::Switch(switch)) => OverlapResolution::ToggleSystem(switch.system),
|
||||||
(_, EntityType::Enemy(_) | EntityType::Hero(_)) => OverlapResolution::Die,
|
(_, EntityType::Enemy(_) | EntityType::Hero(_)) => OverlapResolution::Die,
|
||||||
(_, EntityType::Ice) => OverlapResolution::MoveAgain,
|
(_, EntityType::Ice) => OverlapResolution::MoveAgain,
|
||||||
|
(_, EntityType::Teleporter) => OverlapResolution::Teleport,
|
||||||
|
|
||||||
_ => OverlapResolution::CoExist,
|
_ => OverlapResolution::CoExist,
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,7 @@ impl<'a> Sfx<'a> {
|
||||||
SoundEffect::SwordDrop => {}
|
SoundEffect::SwordDrop => {}
|
||||||
SoundEffect::SwitchedDoorToggle => {}
|
SoundEffect::SwitchedDoorToggle => {}
|
||||||
SoundEffect::SpikesToggle => {}
|
SoundEffect::SpikesToggle => {}
|
||||||
|
SoundEffect::TeleportEffect => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,4 +95,5 @@ pub enum SoundEffect {
|
||||||
SwitchedDoorToggle,
|
SwitchedDoorToggle,
|
||||||
SpikesToggle,
|
SpikesToggle,
|
||||||
WallHit,
|
WallHit,
|
||||||
|
TeleportEffect,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue