Through stage 6
This commit is contained in:
parent
ec58d8638e
commit
645dd2e90c
@ -107,6 +107,7 @@ project(":core") {
|
|||||||
api "io.github.libktx:ktx-assets:$ktxVersion"
|
api "io.github.libktx:ktx-assets:$ktxVersion"
|
||||||
api "io.github.libktx:ktx-collections:$ktxVersion"
|
api "io.github.libktx:ktx-collections:$ktxVersion"
|
||||||
api "io.github.libktx:ktx-graphics:$ktxVersion"
|
api "io.github.libktx:ktx-graphics:$ktxVersion"
|
||||||
|
api "io.github.libktx:ktx-inject:$ktxVersion"
|
||||||
api "io.github.libktx:ktx-log:$ktxVersion"
|
api "io.github.libktx:ktx-log:$ktxVersion"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,33 @@
|
|||||||
package me.msoucy.ptures
|
package me.msoucy.ptures
|
||||||
|
|
||||||
import com.badlogic.gdx.assets.AssetManager
|
import com.badlogic.gdx.assets.AssetManager
|
||||||
|
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Batch
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import ktx.app.KtxGame
|
import ktx.app.KtxGame
|
||||||
import ktx.app.KtxScreen
|
import ktx.app.KtxScreen
|
||||||
|
import ktx.inject.Context
|
||||||
import me.msoucy.ptures.screens.LoadingScreen
|
import me.msoucy.ptures.screens.LoadingScreen
|
||||||
|
|
||||||
class PTures : KtxGame<KtxScreen>() {
|
class PTures : KtxGame<KtxScreen>() {
|
||||||
val batch by lazy { SpriteBatch() }
|
private val context = Context()
|
||||||
val font by lazy { BitmapFont() }
|
|
||||||
val assets = AssetManager()
|
|
||||||
|
|
||||||
override fun create() {
|
override fun create() {
|
||||||
addScreen(LoadingScreen(this))
|
context.register {
|
||||||
|
bindSingleton(this@PTures)
|
||||||
|
bindSingleton<Batch>(SpriteBatch())
|
||||||
|
bindSingleton(BitmapFont())
|
||||||
|
bindSingleton(AssetManager())
|
||||||
|
bindSingleton(OrthographicCamera().apply { setToOrtho(false, 800f, 480f) })
|
||||||
|
addScreen(LoadingScreen(inject(), inject(), inject(), inject(), inject()))
|
||||||
|
}
|
||||||
setScreen<LoadingScreen>()
|
setScreen<LoadingScreen>()
|
||||||
super.create()
|
super.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
batch.dispose()
|
context.dispose()
|
||||||
font.dispose()
|
|
||||||
assets.dispose()
|
|
||||||
super.dispose()
|
super.dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,10 @@ package me.msoucy.ptures.screens
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.Input
|
import com.badlogic.gdx.Input
|
||||||
|
import com.badlogic.gdx.assets.AssetManager
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Batch
|
||||||
|
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
||||||
import com.badlogic.gdx.math.MathUtils
|
import com.badlogic.gdx.math.MathUtils
|
||||||
import com.badlogic.gdx.math.Rectangle
|
import com.badlogic.gdx.math.Rectangle
|
||||||
import com.badlogic.gdx.math.Vector3
|
import com.badlogic.gdx.math.Vector3
|
||||||
@ -18,16 +21,18 @@ import me.msoucy.ptures.*
|
|||||||
|
|
||||||
private val log = logger<GameScreen>()
|
private val log = logger<GameScreen>()
|
||||||
|
|
||||||
class GameScreen(val game: PTures) : KtxScreen {
|
class GameScreen(private val batch: Batch,
|
||||||
|
private val font: BitmapFont,
|
||||||
|
assets: AssetManager,
|
||||||
|
private val camera: OrthographicCamera) : KtxScreen {
|
||||||
|
|
||||||
private val dropImage = game.assets[TextureAtlasAssets.Game].findRegion("drop")
|
private val dropImage = assets[TextureAtlasAssets.Game].findRegion("drop")
|
||||||
private val bucketImage = game.assets[TextureAtlasAssets.Game].findRegion("bucket")
|
private val bucketImage = assets[TextureAtlasAssets.Game].findRegion("bucket")
|
||||||
private val dropSound = game.assets[SoundAssets.Drop]
|
private val dropSound = assets[SoundAssets.Drop]
|
||||||
private val rainMusic = game.assets[MusicAssets.Rain].apply { isLooping = true }
|
private val rainMusic = assets[MusicAssets.Rain].apply { isLooping = true }
|
||||||
|
|
||||||
// The camera ensures we can render using our target resolution of 800x480
|
// The camera ensures we can render using our target resolution of 800x480
|
||||||
// pixels no matter what the screen resolution is.
|
// pixels no matter what the screen resolution is.
|
||||||
private val camera = OrthographicCamera().apply { setToOrtho(false, 800f, 480f) }
|
|
||||||
private val bucket = Rectangle(800f / 2f - 64f / 2f, 20f, 64f, 64f)
|
private val bucket = Rectangle(800f / 2f - 64f / 2f, 20f, 64f, 64f)
|
||||||
private val touchPos = Vector3()
|
private val touchPos = Vector3()
|
||||||
private val raindropsPool = pool { Rectangle() }
|
private val raindropsPool = pool { Rectangle() }
|
||||||
@ -45,11 +50,11 @@ class GameScreen(val game: PTures) : KtxScreen {
|
|||||||
camera.update()
|
camera.update()
|
||||||
|
|
||||||
// tell the SpriteBatch to render in the coordinate system specified by the camera.
|
// tell the SpriteBatch to render in the coordinate system specified by the camera.
|
||||||
game.batch.projectionMatrix = camera.combined
|
batch.projectionMatrix = camera.combined
|
||||||
|
|
||||||
// begin a new batch and draw the bucket and all drops
|
// begin a new batch and draw the bucket and all drops
|
||||||
game.batch.use { batch ->
|
batch.use { batch ->
|
||||||
game.font.draw(batch, "Drops Collected: " + dropsGathered, 0f, 480f)
|
font.draw(batch, "Drops Collected: " + dropsGathered, 0f, 480f)
|
||||||
batch.draw(bucketImage, bucket.x, bucket.y, bucket.width, bucket.height)
|
batch.draw(bucketImage, bucket.x, bucket.y, bucket.width, bucket.height)
|
||||||
activeRaindrops.forEach { r -> batch.draw(dropImage, r.x, r.y) }
|
activeRaindrops.forEach { r -> batch.draw(dropImage, r.x, r.y) }
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,37 @@
|
|||||||
package me.msoucy.ptures.screens
|
package me.msoucy.ptures.screens
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
|
import com.badlogic.gdx.assets.AssetManager
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Batch
|
||||||
|
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
||||||
import ktx.app.KtxScreen
|
import ktx.app.KtxScreen
|
||||||
import ktx.graphics.use
|
import ktx.graphics.use
|
||||||
import me.msoucy.ptures.*
|
import me.msoucy.ptures.*
|
||||||
|
|
||||||
class LoadingScreen(val game: PTures) : KtxScreen {
|
class LoadingScreen(private val game: PTures,
|
||||||
private val camera = OrthographicCamera().apply {
|
private val batch: Batch,
|
||||||
setToOrtho(false, 800f, 480f)
|
private val font: BitmapFont,
|
||||||
}
|
private val assets: AssetManager,
|
||||||
|
private val camera: OrthographicCamera) : KtxScreen {
|
||||||
override fun render(delta: Float) {
|
override fun render(delta: Float) {
|
||||||
// Continue loading assets
|
// Continue loading assets
|
||||||
game.assets.update()
|
assets.update()
|
||||||
|
|
||||||
camera.update()
|
camera.update()
|
||||||
game.batch.projectionMatrix = camera.combined
|
batch.projectionMatrix = camera.combined
|
||||||
|
|
||||||
game.batch.use {
|
batch.use {
|
||||||
game.font.draw(it, "Welcome to Drop!!! ", 100f, 150f)
|
font.draw(it, "Welcome to Drop!!! ", 100f, 150f)
|
||||||
if (game.assets.isFinished) {
|
if (assets.isFinished) {
|
||||||
game.font.draw(it, "Tap anywhere to begin!", 100f, 100f)
|
font.draw(it, "Tap anywhere to begin!", 100f, 100f)
|
||||||
} else {
|
} else {
|
||||||
game.font.draw(it, "Loading assets...", 100f, 100f)
|
font.draw(it, "Loading assets...", 100f, 100f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Gdx.input.isTouched && game.assets.isFinished) {
|
if (Gdx.input.isTouched && assets.isFinished) {
|
||||||
game.addScreen(GameScreen(game))
|
game.addScreen(GameScreen(batch, font, assets, camera))
|
||||||
game.setScreen<GameScreen>()
|
game.setScreen<GameScreen>()
|
||||||
game.removeScreen<LoadingScreen>()
|
game.removeScreen<LoadingScreen>()
|
||||||
dispose()
|
dispose()
|
||||||
@ -36,8 +39,8 @@ class LoadingScreen(val game: PTures) : KtxScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun show() {
|
override fun show() {
|
||||||
MusicAssets.values().forEach { game.assets.load(it) }
|
MusicAssets.values().forEach { assets.load(it) }
|
||||||
SoundAssets.values().forEach { game.assets.load(it) }
|
SoundAssets.values().forEach { assets.load(it) }
|
||||||
TextureAtlasAssets.values().forEach { game.assets.load(it) }
|
TextureAtlasAssets.values().forEach { assets.load(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user