-
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 flash shader when player is hurt
- Loading branch information
1 parent
a68d255
commit 7c29ad3
Showing
6 changed files
with
90 additions
and
6 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
core/src/main/kotlin/com/quillraven/github/quillyjumper/component/Flash.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,18 @@ | ||
package com.quillraven.github.quillyjumper.component | ||
|
||
import com.badlogic.gdx.graphics.Color | ||
import com.github.quillraven.fleks.Component | ||
import com.github.quillraven.fleks.ComponentType | ||
|
||
data class Flash( | ||
val color: Color, | ||
var weight: Float, | ||
var amount: Int, | ||
val delay: Float, | ||
var delayTimer: Float = delay, | ||
var doFlash: Boolean = true, | ||
) : Component<Flash> { | ||
override fun type() = Flash | ||
|
||
companion object : ComponentType<Flash>() | ||
} |
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
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/FlashSystem.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.Flash | ||
import com.quillraven.github.quillyjumper.component.Graphic | ||
|
||
class FlashSystem : IteratingSystem(family { all(Flash, Graphic) }) { | ||
|
||
override fun onTickEntity(entity: Entity) { | ||
val flashCmp = entity[Flash] | ||
val (_, _, amount, delay, delayTimer) = flashCmp | ||
|
||
if (amount <= 0) { | ||
// flash is done -> remove it | ||
entity.configure { it -= Flash } | ||
return | ||
} | ||
|
||
if (delayTimer <= 0f) { | ||
if (flashCmp.doFlash) { | ||
flashCmp.amount-- | ||
} | ||
flashCmp.delayTimer = delay | ||
flashCmp.doFlash = !flashCmp.doFlash | ||
} | ||
flashCmp.delayTimer -= deltaTime | ||
} | ||
|
||
} |
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
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