Commit 074288a committed Jul 25, 2024 · 4 / 4
1 parent f1bdcd1 commit 074288a Copy full SHA for 074288a
File tree 1 file changed +27
-6
lines changed
1 file changed +27
-6
lines changed Original file line number Diff line number Diff line change
1
+ use std:: time:: Duration ;
2
+
1
3
use avian2d:: prelude:: * ;
2
4
use bevy:: ecs:: system:: EntityCommand ;
3
5
use bevy:: prelude:: * ;
4
6
use bevy:: utils:: HashMap ;
7
+ use bevy_tweening:: * ;
5
8
use serde:: Deserialize ;
6
9
use serde:: Serialize ;
7
10
@@ -54,14 +57,17 @@ pub struct Projectile {
54
57
#[ serde( skip) ]
55
58
pub texture : Handle < Image > ,
56
59
57
- /// In seconds, not beats.
60
+ /// Lifetime in seconds, not beats.
58
61
pub lifetime : f32 ,
62
+ /// Hitbox radius.
59
63
pub radius : f32 ,
60
64
pub speed : f32 ,
61
65
pub damage : f32 ,
62
66
pub knockback : f32 ,
63
67
}
64
68
69
+ const FADE_SECS : f32 = 0.2 ;
70
+
65
71
pub fn projectile (
66
72
key : impl Into < String > ,
67
73
power : f32 ,
@@ -84,11 +90,26 @@ pub fn projectile(
84
90
. insert ( (
85
91
Name :: new ( projectile. name . replace ( ' ' , "" ) ) ,
86
92
// Appearance:
87
- SpriteBundle {
88
- sprite : Sprite { color, ..default ( ) } ,
89
- texture : projectile. texture . clone ( ) ,
90
- ..default ( )
91
- } ,
93
+ (
94
+ SpriteBundle {
95
+ sprite : Sprite { color, ..default ( ) } ,
96
+ texture : projectile. texture . clone ( ) ,
97
+ ..default ( )
98
+ } ,
99
+ Animator :: new (
100
+ Delay :: new ( Duration :: from_secs_f32 (
101
+ ( projectile. lifetime - FADE_SECS ) . max ( 0.001 ) ,
102
+ ) )
103
+ . then ( Tween :: new (
104
+ EaseMethod :: Linear ,
105
+ Duration :: from_secs_f32 ( projectile. lifetime . clamp ( 0.001 , FADE_SECS ) ) ,
106
+ lens:: SpriteColorLens {
107
+ start : color,
108
+ end : Color :: NONE ,
109
+ } ,
110
+ ) ) ,
111
+ ) ,
112
+ ) ,
92
113
// Physics:
93
114
(
94
115
RigidBody :: Kinematic ,
You can’t perform that action at this time.
0 commit comments