Change collider when growing or shrinking.
This commit is contained in:
parent
c8364fe4b8
commit
9d5b6af8d2
1 changed files with 14 additions and 2 deletions
|
@ -71,7 +71,13 @@ impl Hero {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn grow(&mut self, scene: &mut Scene<Texture<Resources>>, dt: f64) {
|
pub fn grow(&mut self, scene: &mut Scene<Texture<Resources>>, dt: f64) {
|
||||||
self.size += 1;
|
if let Some(sprite) = scene.child(self.sprite_id) {
|
||||||
|
self.size += 60;
|
||||||
|
let bounds = sprite.bounding_box();
|
||||||
|
self.w = bounds[2];
|
||||||
|
self.h = bounds[3];
|
||||||
|
self.collider = Cuboid2::new(Vector2::new(bounds[2], bounds[3]));
|
||||||
|
}
|
||||||
scene.run(self.sprite_id,
|
scene.run(self.sprite_id,
|
||||||
&Action(Ease(EaseFunction::ElasticInOut,
|
&Action(Ease(EaseFunction::ElasticInOut,
|
||||||
Box::new(ScaleBy(dt * 5.0, 0.3, 0.3)))));
|
Box::new(ScaleBy(dt * 5.0, 0.3, 0.3)))));
|
||||||
|
@ -79,7 +85,13 @@ impl Hero {
|
||||||
|
|
||||||
pub fn shrink(&mut self, scene: &mut Scene<Texture<Resources>>, dt: f64) {
|
pub fn shrink(&mut self, scene: &mut Scene<Texture<Resources>>, dt: f64) {
|
||||||
if self.size > 0 {
|
if self.size > 0 {
|
||||||
|
if let Some(sprite) = scene.child(self.sprite_id) {
|
||||||
self.size -= 1;
|
self.size -= 1;
|
||||||
|
let bounds = sprite.bounding_box();
|
||||||
|
self.w = bounds[2];
|
||||||
|
self.h = bounds[3];
|
||||||
|
self.collider = Cuboid2::new(Vector2::new(bounds[2], bounds[3]));
|
||||||
|
}
|
||||||
scene.run(self.sprite_id,
|
scene.run(self.sprite_id,
|
||||||
&Action(Ease(EaseFunction::ElasticInOut,
|
&Action(Ease(EaseFunction::ElasticInOut,
|
||||||
Box::new(ScaleBy(dt * 5.0, -0.005, -0.005)))));
|
Box::new(ScaleBy(dt * 5.0, -0.005, -0.005)))));
|
||||||
|
|
Loading…
Reference in a new issue