DEADSOFTWARE

Add RenderModule code generation
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / render / BackgroundBlocksRenderer.kt
1 package ru.deadsoftware.cavedroid.game.render
3 import com.badlogic.gdx.Gdx
4 import com.badlogic.gdx.graphics.GL20
5 import com.badlogic.gdx.graphics.g2d.SpriteBatch
6 import com.badlogic.gdx.graphics.glutils.ShapeRenderer
7 import com.badlogic.gdx.math.Rectangle
8 import ru.deadsoftware.cavedroid.game.GameScope
9 import ru.deadsoftware.cavedroid.game.mobs.MobsController
10 import ru.deadsoftware.cavedroid.game.world.GameWorld
11 import ru.deadsoftware.cavedroid.misc.utils.forEachBlockInArea
12 import javax.inject.Inject
14 @GameScope
15 @GameRenderer
16 class BackgroundBlocksRenderer @Inject constructor(
17 gameWorld: GameWorld,
18 mobsController: MobsController
19 ) : BlocksRenderer(gameWorld, mobsController) {
21 override val renderLayer get() = RENDER_LAYER
23 override val background = true
25 override fun draw(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle, delta: Float) {
26 forEachBlockInArea(viewport) { x, y ->
27 drawBackMap(spriteBatch, viewport, x, y)
28 }
30 drawBlockDamage(spriteBatch, viewport)
32 spriteBatch.end()
33 Gdx.gl.glEnable(GL20.GL_BLEND)
34 Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
35 shapeRenderer.begin(ShapeRenderer.ShapeType.Filled)
36 shapeRenderer.setColor(0f, 0f, 0f, .5f)
38 forEachBlockInArea(viewport) { x, y ->
39 shadeBackMap(shapeRenderer, viewport, x, y)
40 }
42 shapeRenderer.end()
43 Gdx.gl.glDisable(GL20.GL_BLEND)
44 spriteBatch.begin()
46 forEachBlockInArea(viewport) { x, y ->
47 drawForeMap(spriteBatch, viewport, x, y)
48 }
49 }
51 companion object {
52 private const val RENDER_LAYER = 100000
53 }
54 }