Skip to content
Snippets Groups Projects
Verified Commit e1601d88 authored by Lars Mitsem Selbekk's avatar Lars Mitsem Selbekk Committed by Mathias O. Myklebust
Browse files

Flip converted units horizontally

parent 86f11517
Branches
Tags
1 merge request!55Various spellcasting fixes
......@@ -397,7 +397,6 @@ class BattleController(
private fun applySpell(activeSpell: ActiveSpell<*>) {
activeSpell.apply(battle)
battleMapController.checkForDeadUnits()
battle.getCurrentOutcome()?.let(::resolveGame)
}
}
......@@ -313,10 +313,17 @@ class BattleMapController(
attackUnit(attackingController, targetController)
}
fun checkForDeadUnits() {
unitControllers.values
.filter { it.unitModel.isDead() }
.forEach(::removeUnit)
private fun updateFromModel() {
for (unitController in unitControllers.values.asSequence()) {
val model = unitController.unitModel
if (model.isDead()) {
removeUnit(unitController)
continue
}
if (unitController.converted != (model.allegiance != model.owner)) {
unitController.converted = !unitController.converted
}
}
}
override fun update(dt: Float) {
......@@ -328,6 +335,7 @@ class BattleMapController(
for (uc in unitControllers.values) {
uc.update(dt)
}
updateFromModel()
}
override fun render(sb: SpriteBatch) {
......
......@@ -33,6 +33,11 @@ open class UnitController(
}
var selected: Boolean by unitView::focused
var converted: Boolean = false
set(value) {
field = value
unitView.flipped = converted
}
private var unitHealthBarController = UnitHealthBarController(
unitModel,
......
......@@ -2,5 +2,10 @@ package se.battlegoo.battlegoose.views
enum class FacingDirection {
RIGHT,
LEFT
LEFT;
fun flipped(): FacingDirection = when (this) {
RIGHT -> LEFT
LEFT -> RIGHT
}
}
......@@ -4,7 +4,7 @@ import se.battlegoo.battlegoose.utils.TextureAsset
class UnitView(
unitSprite: UnitSprite,
textureStartFacingDirection: FacingDirection
val textureStartFacingDirection: FacingDirection
) : SpriteViewBase(
when (unitSprite) {
UnitSprite.PRIVATE_PENGUIN -> TextureAsset.UNIT_PRIVATE_PENGUIN
......@@ -21,6 +21,15 @@ class UnitView(
field = value
}
var flipped: Boolean = false
set(value) {
field = value
facingDirection = if (value)
textureStartFacingDirection.flipped()
else
textureStartFacingDirection
}
var focused: Boolean = false
init {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment