Add lights and gravity again

This commit is contained in:
timokoesters 2020-03-24 20:31:54 +01:00
parent 58585e0810
commit f0ce088810
3 changed files with 38 additions and 7 deletions

View File

@ -1,5 +1,7 @@
use crate::{
comp::{Body, CharacterState, EnergySource, Item, Projectile, StateUpdate},
comp::{
Body, CharacterState, EnergySource, Gravity, Item, LightEmitter, Projectile, StateUpdate,
},
states::*,
sys::character_behavior::JoinData,
};
@ -22,6 +24,8 @@ pub enum CharacterAbility {
recover_duration: Duration,
projectile: Projectile,
projectile_body: Body,
projectile_light: Option<LightEmitter>,
projectile_gravity: Option<Gravity>,
},
Boost {
duration: Duration,
@ -122,6 +126,8 @@ impl From<&CharacterAbility> for CharacterState {
recover_duration,
projectile,
projectile_body,
projectile_light,
projectile_gravity,
energy_cost: _,
} => CharacterState::BasicRanged(basic_ranged::Data {
exhausted: false,
@ -130,6 +136,8 @@ impl From<&CharacterAbility> for CharacterState {
recover_duration: *recover_duration,
projectile: projectile.clone(),
projectile_body: *projectile_body,
projectile_light: *projectile_light,
projectile_gravity: *projectile_gravity,
}),
CharacterAbility::Boost { duration, only_up } => CharacterState::Boost(boost::Data {
duration: *duration,

View File

@ -2,7 +2,8 @@ use crate::{
assets::{self, Asset},
comp::{
body::{humanoid, object},
projectile, Body, CharacterAbility, HealthChange, HealthSource, Projectile,
projectile, Body, CharacterAbility, Gravity, HealthChange, HealthSource, LightEmitter,
Projectile,
},
effect::Effect,
terrain::{Block, BlockKind},
@ -107,6 +108,8 @@ impl ToolData {
owner: None,
},
projectile_body: Body::Object(object::Body::Arrow),
projectile_light: None,
projectile_gravity: Some(Gravity(0.1)),
}],
Dagger(_) => vec![BasicMelee {
buildup_duration: Duration::from_millis(100),
@ -146,6 +149,12 @@ impl ToolData {
owner: None,
},
projectile_body: Body::Object(object::Body::BoltFire),
projectile_light: Some(LightEmitter {
col: (0.72, 0.11, 0.11).into(),
..Default::default()
}),
projectile_gravity: None,
},
BasicRanged {
energy_cost: 400,
@ -168,6 +177,12 @@ impl ToolData {
owner: None,
},
projectile_body: Body::Object(object::Body::BoltFire),
projectile_light: Some(LightEmitter {
col: (0.72, 0.11, 0.11).into(),
..Default::default()
}),
projectile_gravity: None,
},
],
Shield(_) => vec![BasicBlock],
@ -194,6 +209,8 @@ impl ToolData {
owner: None,
},
projectile_body: Body::Object(object::Body::ArrowSnake),
projectile_light: None,
projectile_gravity: None,
}],
},
Empty => vec![],

View File

@ -1,5 +1,5 @@
use crate::{
comp::{Body, CharacterState, Gravity, Projectile, StateUpdate},
comp::{Body, CharacterState, Gravity, LightEmitter, Projectile, StateUpdate},
event::ServerEvent,
states::utils::*,
sys::character_behavior::*,
@ -14,10 +14,10 @@ pub struct Data {
pub prepare_timer: Duration,
/// How long the state has until exiting
pub recover_duration: Duration,
/// Projectile
pub projectile: Projectile,
/// Projectile
pub projectile_body: Body,
pub projectile_light: Option<LightEmitter>,
pub projectile_gravity: Option<Gravity>,
/// Whether the attack fired already
pub exhausted: bool,
}
@ -39,6 +39,8 @@ impl CharacterBehavior for Data {
recover_duration: self.recover_duration,
projectile: self.projectile.clone(),
projectile_body: self.projectile_body,
projectile_light: self.projectile_light,
projectile_gravity: self.projectile_gravity,
exhausted: false,
});
} else if !self.exhausted {
@ -49,9 +51,9 @@ impl CharacterBehavior for Data {
entity: data.entity,
dir: data.inputs.look_dir,
body: self.projectile_body,
light: None,
projectile,
gravity: Some(Gravity(0.1)),
light: self.projectile_light,
gravity: self.projectile_gravity,
});
update.character = CharacterState::BasicRanged(Data {
@ -60,6 +62,8 @@ impl CharacterBehavior for Data {
recover_duration: self.recover_duration,
projectile: self.projectile.clone(),
projectile_body: self.projectile_body,
projectile_light: self.projectile_light,
projectile_gravity: self.projectile_gravity,
exhausted: true,
});
} else if self.recover_duration != Duration::default() {
@ -73,6 +77,8 @@ impl CharacterBehavior for Data {
.unwrap_or_default(),
projectile: self.projectile.clone(),
projectile_body: self.projectile_body,
projectile_light: self.projectile_light,
projectile_gravity: self.projectile_gravity,
exhausted: true,
});
return update;