1 package ru.deadsoftware.cavedroid.game.render
3 import com.badlogic.gdx.graphics.g2d.SpriteBatch
4 import com.badlogic.gdx.graphics.glutils.ShapeRenderer
5 import com.badlogic.gdx.math.Rectangle
6 import ru.deadsoftware.cavedroid.game.GameScope
7 import ru.deadsoftware.cavedroid.game.objects.drop.DropController
8 import ru.deadsoftware.cavedroid.game.world.GameWorld
9 import ru.deadsoftware.cavedroid.misc.utils.cycledInsideWorld
10 import ru.deadsoftware.cavedroid.misc.utils.drawSprite
11 import ru.deadsoftware.cavedroid.misc.utils.px
12 import javax.inject.Inject
14 @GameScope
15 @GameRenderer
16 class DropsRenderer @Inject constructor(
17 private val dropController: DropController,
18 private val gameWorld: GameWorld,
19 ) : IGameRenderer {
21 override val renderLayer = RENDER_LAYER
23 override fun draw(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle, delta: Float) {
24 dropController.forEach { drop ->
25 drop.cycledInsideWorld(viewport, gameWorld.width.px)?.let { dropRect ->
26 spriteBatch.drawSprite(
27 sprite = drop.item.sprite,
28 x = dropRect.x - viewport.x,
29 y = dropRect.y - viewport.y,
30 width = dropRect.width,
31 height = dropRect.height,
32 )
33 }
34 }
35 }
37 companion object {
38 private const val RENDER_LAYER = 100200
39 }
41 }