diff --git a/assets/ability/effects/fow/fow.png b/assets/ability/effects/fow/fow.png deleted file mode 100644 index 8b899db6..00000000 Binary files a/assets/ability/effects/fow/fow.png and /dev/null differ diff --git a/assets/board/fow.png b/assets/board/fow.png new file mode 100644 index 00000000..0b4651e3 Binary files /dev/null and b/assets/board/fow.png differ diff --git a/chessevolved_model/src/main/kotlin/io/github/chessevolved/components/FowComponent.kt b/chessevolved_model/src/main/kotlin/io/github/chessevolved/components/FowComponent.kt new file mode 100644 index 00000000..e04fb11b --- /dev/null +++ b/chessevolved_model/src/main/kotlin/io/github/chessevolved/components/FowComponent.kt @@ -0,0 +1,13 @@ +package io.github.chessevolved.components + +import com.badlogic.ashley.core.Component +import com.badlogic.ashley.core.ComponentMapper + +class FowComponent( + var showFog: Boolean, +) : Component { + companion object { + val mapper: ComponentMapper = + ComponentMapper.getFor(FowComponent::class.java) + } +} diff --git a/chessevolved_model/src/main/kotlin/io/github/chessevolved/entities/BoardSquareFactory.kt b/chessevolved_model/src/main/kotlin/io/github/chessevolved/entities/BoardSquareFactory.kt index 18bfd3c9..e82c3cb9 100644 --- a/chessevolved_model/src/main/kotlin/io/github/chessevolved/entities/BoardSquareFactory.kt +++ b/chessevolved_model/src/main/kotlin/io/github/chessevolved/entities/BoardSquareFactory.kt @@ -9,6 +9,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.scenes.scene2d.Stage import com.badlogic.gdx.scenes.scene2d.ui.Image import io.github.chessevolved.components.ActorComponent +import io.github.chessevolved.components.FowComponent import io.github.chessevolved.components.HighlightComponent import io.github.chessevolved.components.PlayerColorComponent import io.github.chessevolved.components.PositionComponent @@ -17,6 +18,7 @@ import io.github.chessevolved.components.WeatherEventComponent import io.github.chessevolved.data.Position import io.github.chessevolved.enums.PlayerColor import io.github.chessevolved.enums.WeatherEvent +import io.github.chessevolved.singletons.GameSettings import io.github.chessevolved.systems.InputService import ktx.actors.onClick @@ -25,6 +27,7 @@ class BoardSquareFactory( private val assetManager: AssetManager, ) { private val inputService: InputService = InputService() + private val isFowEnabled = GameSettings.isFOWEnabled() private fun getBoardSquareTextureRegion(playerColor: PlayerColor): TextureRegion { val colorStr = playerColor.name.lowercase() @@ -65,6 +68,7 @@ class BoardSquareFactory( add(PlayerColorComponent(playerColor)) add(TextureRegionComponent(getBoardSquareTextureRegion(playerColor))) add(HighlightComponent(Color.WHITE)) + add(FowComponent(isFowEnabled)) add( ActorComponent( getBoardActor(position, stage) { clickedPosition -> inputService.clickBoardSquareAtPosition(clickedPosition) }, diff --git a/chessevolved_model/src/main/kotlin/io/github/chessevolved/systems/FowRenderingSystem.kt b/chessevolved_model/src/main/kotlin/io/github/chessevolved/systems/FowRenderingSystem.kt new file mode 100644 index 00000000..32b6e764 --- /dev/null +++ b/chessevolved_model/src/main/kotlin/io/github/chessevolved/systems/FowRenderingSystem.kt @@ -0,0 +1,43 @@ +package io.github.chessevolved.systems + +import com.badlogic.ashley.core.Entity +import com.badlogic.ashley.core.Family +import com.badlogic.ashley.systems.IteratingSystem +import com.badlogic.gdx.assets.AssetManager +import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import io.github.chessevolved.components.FowComponent +import io.github.chessevolved.components.PositionComponent +import io.github.chessevolved.singletons.GameSettings + +class FowRenderingSystem( + private val batch: SpriteBatch, + private val assetManager: AssetManager, +) : IteratingSystem( + Family.all(PositionComponent::class.java, FowComponent::class.java).get(), + ) { + private val isFowEnabled = GameSettings.isFOWEnabled() + private val fowTexture = assetManager.get("board/fow.png", Texture::class.java) + + override fun processEntity( + entity: Entity, + deltaTime: Float, + ) { + if (!isFowEnabled) return + + val position = PositionComponent.mapper.get(entity) + val fow = FowComponent.mapper.get(entity) + + if (position != null && fow != null) { + if (fow.showFog && (position.position.y >= (GameSettings.getBoardSize() + 1) / 2)) { + batch.draw( + fowTexture, + position.position.x.toFloat(), + position.position.y.toFloat(), + 1f, + 1f, + ) + } + } + } +} diff --git a/chessevolved_model/src/main/kotlin/io/github/chessevolved/systems/MovementSystem.kt b/chessevolved_model/src/main/kotlin/io/github/chessevolved/systems/MovementSystem.kt index c59b4c78..1613a1e8 100644 --- a/chessevolved_model/src/main/kotlin/io/github/chessevolved/systems/MovementSystem.kt +++ b/chessevolved_model/src/main/kotlin/io/github/chessevolved/systems/MovementSystem.kt @@ -4,11 +4,14 @@ import com.badlogic.ashley.core.Entity import com.badlogic.ashley.core.Family import com.badlogic.ashley.systems.IteratingSystem import io.github.chessevolved.components.ActorComponent +import io.github.chessevolved.components.FowComponent import io.github.chessevolved.components.MovementIntentComponent import io.github.chessevolved.components.MovementRuleComponent import io.github.chessevolved.components.PositionComponent import io.github.chessevolved.components.SelectionComponent import io.github.chessevolved.components.ValidMovesComponent +import io.github.chessevolved.data.Position +import io.github.chessevolved.singletons.EcsEngine class MovementSystem( private val onTurnComplete: () -> Unit, @@ -20,6 +23,8 @@ class MovementSystem( MovementIntentComponent::class.java, ).get(), ) { + private val boardFamily = Family.all(PositionComponent::class.java, FowComponent::class.java).get() + override fun processEntity( entity: Entity?, deltaTime: Float, @@ -49,10 +54,30 @@ class MovementSystem( } } + clearFow(targetPosition) + entity?.remove(SelectionComponent::class.java) entity?.remove(ValidMovesComponent::class.java) entity?.remove(MovementIntentComponent::class.java) onTurnComplete() } + + private fun clearFow(center: Position) { + for (x in -1..1) { + for (y in -1..1) { + val currentPosition = Position(center.x + x, center.y + y) + + val boardSquare = + EcsEngine.getEntitiesFor(boardFamily).firstOrNull { + PositionComponent.mapper.get(it).position == currentPosition + } + + boardSquare?.let { + val fow = FowComponent.mapper.get(it) + if (fow.showFog) fow.showFog = false + } + } + } + } } diff --git a/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/GamePresenter.kt b/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/GamePresenter.kt index 363e41c9..519fd27d 100644 --- a/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/GamePresenter.kt +++ b/chessevolved_presenter/src/main/kotlin/io/github/chessevolved/presenters/GamePresenter.kt @@ -23,9 +23,11 @@ import io.github.chessevolved.singletons.EcsEntityMapper import io.github.chessevolved.singletons.Game import io.github.chessevolved.singletons.Game.subscribeToGameUpdates import io.github.chessevolved.singletons.Game.unsubscribeFromGameUpdates +import io.github.chessevolved.singletons.GameSettings import io.github.chessevolved.singletons.Lobby import io.github.chessevolved.systems.AbilitySystem import io.github.chessevolved.systems.CaptureSystem +import io.github.chessevolved.systems.FowRenderingSystem import io.github.chessevolved.systems.InputSystem import io.github.chessevolved.systems.MovementSystem import io.github.chessevolved.systems.RenderingSystem @@ -57,6 +59,7 @@ class GamePresenter( private val movementSystem: MovementSystem private val renderingSystem: RenderingSystem + private val fowRenderingSystem: FowRenderingSystem private val selectionListener: SelectionEntityListener private val captureSystem: CaptureSystem private val inputSystem: InputSystem @@ -64,6 +67,7 @@ class GamePresenter( private val visualEffectSystem: VisualEffectSystem private var navigatingToEndGame = false + private val isFowEnabled = GameSettings.isFOWEnabled() init { setupGameView() @@ -92,6 +96,9 @@ class GamePresenter( loadRequiredAssets() assetManager.finishLoading() + fowRenderingSystem = FowRenderingSystem(gameBatch, assetManager) + engine.addSystem(fowRenderingSystem) + visualEffectSystem.initializeAnimations() setupBoard() @@ -103,6 +110,7 @@ class GamePresenter( private fun loadRequiredAssets() { assetManager.load("board/black-tile.png", Texture::class.java) assetManager.load("board/white-tile.png", Texture::class.java) + assetManager.load("board/fow.png", Texture::class.java) PlayerColor.entries.forEach { color -> PieceType.entries.forEach { type ->