-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add blink effect when player takes damage
- Loading branch information
1 parent
0273a67
commit 28246aa
Showing
4 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
core/src/main/kotlin/com/quillraven/github/quillyjumper/component/Blink.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.quillraven.github.quillyjumper.component | ||
|
||
import com.github.quillraven.fleks.Component | ||
import com.github.quillraven.fleks.ComponentType | ||
|
||
data class Blink( | ||
var maxTime: Float, | ||
val blinkRatio: Float, // amount in seconds after a blink is happening | ||
var timer: Float = 0f, | ||
) : Component<Blink> { | ||
override fun type() = Blink | ||
|
||
companion object : ComponentType<Blink>() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
core/src/main/kotlin/com/quillraven/github/quillyjumper/system/BlinkSystem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.quillraven.github.quillyjumper.system | ||
|
||
import com.github.quillraven.fleks.Entity | ||
import com.github.quillraven.fleks.IteratingSystem | ||
import com.github.quillraven.fleks.World.Companion.family | ||
import com.quillraven.github.quillyjumper.component.Blink | ||
import com.quillraven.github.quillyjumper.component.Graphic | ||
|
||
class BlinkSystem : IteratingSystem(family { all(Blink, Graphic) }) { | ||
|
||
override fun onTickEntity(entity: Entity) { | ||
val blinkCmp = entity[Blink] | ||
val (maxTime, blinkRatio) = blinkCmp | ||
val (sprite) = entity[Graphic] | ||
|
||
if (maxTime <= 0f) { | ||
// blinking is done -> remove it | ||
sprite.setAlpha(1f) | ||
entity.configure { it -= Blink } | ||
return | ||
} | ||
|
||
blinkCmp.maxTime -= deltaTime | ||
blinkCmp.timer += deltaTime | ||
if (blinkCmp.timer >= blinkRatio) { | ||
blinkCmp.timer = 0f | ||
sprite.setAlpha(if (sprite.color.a == 0f) 1f else 0f) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters