Finish Stand handle() (untested)

This commit is contained in:
Adam Whitehurst 2019-12-20 08:50:54 -08:00
parent e074c7ce1d
commit e40eb2ba20
2 changed files with 59 additions and 18 deletions

View File

@ -1,4 +1,6 @@
use crate::comp::{Body, CharacterState, Controller, ControllerInputs, PhysicsState};
use crate::comp::{
Body, CharacterState, Controller, ControllerInputs, ItemKind, PhysicsState, Stats,
};
use specs::{Component, FlaggedStorage, HashMapStorage};
use specs::{Entities, Join, LazyUpdate, Read, ReadStorage, System};
use sphynx::{Uid, UidAllocator};
@ -10,6 +12,7 @@ pub trait State {
&self,
character: &CharacterState,
inputs: &ControllerInputs,
stats: &Stats,
body: &Body,
physics: &PhysicsState,
) -> CharacterState;
@ -25,6 +28,7 @@ impl State for StandData {
&self,
character: &CharacterState,
inputs: &ControllerInputs,
stats: &Stats,
body: &Body,
physics: &PhysicsState,
) -> CharacterState {
@ -100,26 +104,45 @@ impl State for StandData {
&& !inputs.glide.is_held_down()
&& body.is_humanoid()
{
character.movement = Glide;
continue;
return CharacterState {
action: Idle,
movement: Glide,
};
}
character.movement = Fall;
return CharacterState {
action: character.action,
movement: Fall,
};
}
// Tool Actions
if inputs.toggle_wield.is_just_pressed() {
match action_state {
match character.action {
Wield { .. } | Attack { .. } => {
// Prevent instantaneous reequipping by checking
// for done wielding
if character.action.is_action_finished() {
character.action = Idle;
return CharacterState {
action: Idle,
movement: character.movement,
};
}
continue;
}
Idle => {
character.action = try_wield(stats);
continue;
return CharacterState {
// Try to wield if an item is equipped in main hand
action: if let Some(ItemKind::Tool { kind, .. }) =
stats.equipment.main.as_ref().map(|i| &i.kind)
{
let wield_duration = kind.wield_duration();
Wield {
time_left: wield_duration,
}
} else {
Idle
},
movement: character.movement,
};
}
Charge { .. } | Roll { .. } | Block { .. } => {}
}
@ -129,14 +152,27 @@ impl State for StandData {
} else if inputs.secondary.is_pressed() {
// TODO: SecondaryStart
}
if inputs.move_dir.magnitude_squared() > 0.0 {
return CharacterState {
action: character.action,
movement: Run(RunData),
};
} else {
return CharacterState {
action: character.action,
movement: Stand(StandData),
};
}
return character;
}
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub enum MovementState {
Stand(Stand),
Stand(StandData),
Sit,
Run(Run),
Run(RunData),
Jump,
Fall,
Glide,

View File

@ -1,9 +1,14 @@
use super::movement::ROLL_DURATION;
use crate::{
comp::{
self, item, projectile, ActionState, ActionState::*, Body, CharacterState, ControlEvent,
Controller, ControllerInputs, HealthChange, HealthSource, ItemKind, Mounting,
MovementState, MovementState::*, PhysicsState, Projectile, Stats, Vel,
self, item, projectile, ActionState,
ActionState::*,
Body, CharacterState,
CharacterState::{RunData, StandData},
ControlEvent, Controller, ControllerInputs, HealthChange, HealthSource, ItemKind, Mounting,
MovementState,
MovementState::*,
PhysicsState, Projectile, Stats, Vel,
},
event::{Emitter, EventBus, LocalEvent, ServerEvent},
state::DeltaTime,
@ -88,9 +93,9 @@ impl<'a> System<'a> for Sys {
let get_state_from_move_dir = |move_dir: &Vec2<f32>| -> MovementState {
if move_dir.magnitude_squared() > 0.0 {
Run(_)
Run(RunData)
} else {
Stand(_)
Stand(StandData)
}
};
@ -204,7 +209,7 @@ impl<'a> System<'a> for Sys {
character.movement = Fall;
}
} else {
character.movement = Stand(comp::character_state::Stand);
character.movement = Stand(StandData);
continue;
}
@ -354,7 +359,7 @@ impl<'a> System<'a> for Sys {
// character.movement will be Stand after updating when
// no movement has occurred
if character.movement == Stand(_) {
if character.movement == Stand(StandData) {
character.movement = Sit;
}
if inputs.jump.is_pressed() && !inputs.jump.is_held_down() {