-
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.
- Loading branch information
1 parent
050043b
commit f43a2ad
Showing
15 changed files
with
183 additions
and
64 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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
10 changes: 10 additions & 0 deletions
10
core/src/main/kotlin/com/quillraven/github/quillyjumper/component/Damage.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,10 @@ | ||
package com.quillraven.github.quillyjumper.component | ||
|
||
import com.github.quillraven.fleks.Component | ||
import com.github.quillraven.fleks.ComponentType | ||
|
||
data class Damage(var amount: Int) : Component<Damage> { | ||
override fun type() = Damage | ||
|
||
companion object : ComponentType<Damage>() | ||
} |
10 changes: 10 additions & 0 deletions
10
core/src/main/kotlin/com/quillraven/github/quillyjumper/component/DamageTaken.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,10 @@ | ||
package com.quillraven.github.quillyjumper.component | ||
|
||
import com.github.quillraven.fleks.Component | ||
import com.github.quillraven.fleks.ComponentType | ||
|
||
data class DamageTaken(var amount: Int) : Component<DamageTaken> { | ||
override fun type() = DamageTaken | ||
|
||
companion object : ComponentType<DamageTaken>() | ||
} |
10 changes: 10 additions & 0 deletions
10
core/src/main/kotlin/com/quillraven/github/quillyjumper/component/Invulnerable.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,10 @@ | ||
package com.quillraven.github.quillyjumper.component | ||
|
||
import com.github.quillraven.fleks.Component | ||
import com.github.quillraven.fleks.ComponentType | ||
|
||
data class Invulnerable(var time: Float) : Component<Invulnerable> { | ||
override fun type() = Invulnerable | ||
|
||
companion object : ComponentType<Invulnerable>() | ||
} |
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
39 changes: 39 additions & 0 deletions
39
core/src/main/kotlin/com/quillraven/github/quillyjumper/system/DamageSystem.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,39 @@ | ||
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.github.quillraven.fleks.World.Companion.inject | ||
import com.quillraven.github.quillyjumper.SoundAsset | ||
import com.quillraven.github.quillyjumper.audio.AudioService | ||
import com.quillraven.github.quillyjumper.component.DamageTaken | ||
import com.quillraven.github.quillyjumper.component.EntityTag | ||
import com.quillraven.github.quillyjumper.component.Invulnerable | ||
import com.quillraven.github.quillyjumper.component.Life | ||
import com.quillraven.github.quillyjumper.event.EntityDamageEvent | ||
import com.quillraven.github.quillyjumper.event.GameEventDispatcher | ||
import ktx.log.logger | ||
|
||
class DamageSystem( | ||
private val audioService: AudioService = inject(), | ||
) : IteratingSystem(family { all(DamageTaken, Life).none(Invulnerable) }) { | ||
|
||
override fun onTickEntity(entity: Entity) { | ||
val (damageAmount) = entity[DamageTaken] | ||
val lifeCmp = entity[Life] | ||
lifeCmp.current = (lifeCmp.current - damageAmount).coerceAtLeast(0f) | ||
log.debug { "Entity $entity takes $damageAmount damage. New life=${lifeCmp.current}" } | ||
audioService.play(SoundAsset.HURT) | ||
GameEventDispatcher.fire(EntityDamageEvent(entity, lifeCmp)) | ||
|
||
if (entity has EntityTag.PLAYER) { | ||
// player becomes invulnerable after taking damage | ||
entity.configure { it += Invulnerable(1.5f) } | ||
} | ||
} | ||
|
||
companion object { | ||
private val log = logger<DamageSystem>() | ||
} | ||
|
||
} |
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
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