mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-14 17:59:11 +07:00
Units sprites move towards the enemy they're attacking
This commit is contained in:
@ -78,7 +78,7 @@ object BattleHelper {
|
||||
reachableTile,
|
||||
tile,
|
||||
movementLeft,
|
||||
Battle.getMapCombatantOfTile(tile)!!
|
||||
Battle.getMapCombatantOfTile(tile)
|
||||
)
|
||||
else if (tile in tilesWithoutEnemies) continue // avoid checking the same empty tile multiple times
|
||||
else if (tileContainsAttackableEnemy(unit, tile, tilesToCheck)) {
|
||||
@ -104,7 +104,6 @@ object BattleHelper {
|
||||
if (tile !in (tilesToCheck ?: unit.civ.viewableTiles)) return false
|
||||
val mapCombatant = Battle.getMapCombatantOfTile(tile)
|
||||
|
||||
|
||||
return (!unit.baseUnit.isMelee() || mapCombatant !is MapUnitCombatant || !mapCombatant.unit.isCivilian() || unit.movement.canPassThrough(tile))
|
||||
}
|
||||
|
||||
|
@ -6,11 +6,13 @@ import com.badlogic.gdx.scenes.scene2d.Actor
|
||||
import com.badlogic.gdx.scenes.scene2d.Group
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.FloatAction
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.RelativeTemporalAction
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.logic.battle.ICombatant
|
||||
import com.unciv.logic.map.HexMath
|
||||
import com.unciv.ui.images.ImageGetter
|
||||
import com.unciv.ui.screens.worldscreen.WorldScreen
|
||||
|
||||
@ -47,7 +49,38 @@ object BattleTableHelpers {
|
||||
actor.color = color.cpy().lerp(Color.RED, percent)
|
||||
}
|
||||
|
||||
val actorsToMove = getMapActorsForCombatant(attacker).toList()
|
||||
|
||||
val attackVectorHexCoords = defender.getTile().position.cpy().sub(attacker.getTile().position)
|
||||
val attackVectorWorldCoords = HexMath.hex2WorldCoords(attackVectorHexCoords)
|
||||
.nor() // normalize vector to length of "1"
|
||||
.scl(10f) // we want 10 pixel movement
|
||||
|
||||
stage.addAction(
|
||||
Actions.sequence(
|
||||
object : RelativeTemporalAction(){
|
||||
init {
|
||||
duration = 0.5f
|
||||
interpolation = Interpolation.sine
|
||||
}
|
||||
override fun updateRelative(percentDelta: Float) {
|
||||
for (actor in actorsToMove){
|
||||
actor.moveBy(attackVectorWorldCoords.x * percentDelta, attackVectorWorldCoords.y * percentDelta)
|
||||
}
|
||||
}
|
||||
},
|
||||
Actions.parallel( // While the unit is moving back to its normal position, we flash the damages on both units
|
||||
object : RelativeTemporalAction(){
|
||||
init {
|
||||
duration = 0.5f
|
||||
interpolation = Interpolation.sine
|
||||
}
|
||||
override fun updateRelative(percentDelta: Float) {
|
||||
for (actor in actorsToMove){
|
||||
actor.moveBy(attackVectorWorldCoords.x * -percentDelta, attackVectorWorldCoords.y * -percentDelta)
|
||||
}
|
||||
}
|
||||
},
|
||||
Actions.sequence(
|
||||
object : FloatAction(0f, 1f, 0.3f, Interpolation.sine) {
|
||||
override fun update(percent: Float) = updateRedPercent(percent)
|
||||
@ -55,7 +88,11 @@ object BattleTableHelpers {
|
||||
object : FloatAction(0f, 1f, 0.3f, Interpolation.sine) {
|
||||
override fun update(percent: Float) = updateRedPercent(1 - percent)
|
||||
}
|
||||
)
|
||||
)
|
||||
))
|
||||
|
||||
|
||||
}
|
||||
|
||||
fun getHealthBar(maxHealth: Int, currentHealth: Int, maxRemainingHealth: Int, minRemainingHealth: Int): Table {
|
||||
|
Reference in New Issue
Block a user