Through stage 4
This commit is contained in:
parent
d1700f186b
commit
37691d64ba
Binary file not shown.
Before Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.1 KiB |
20
android/assets/images/game.atlas
Normal file
20
android/assets/images/game.atlas
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
game.png
|
||||
size: 256,128
|
||||
format: RGBA8888
|
||||
filter: Nearest,Nearest
|
||||
repeat: none
|
||||
bucket
|
||||
rotate: false
|
||||
xy: 2, 2
|
||||
size: 64, 64
|
||||
orig: 64, 64
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
drop
|
||||
rotate: false
|
||||
xy: 70, 2
|
||||
size: 64, 64
|
||||
orig: 64, 64
|
||||
offset: 0, 0
|
||||
index: -1
|
BIN
android/assets/images/game.png
Normal file
BIN
android/assets/images/game.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
@ -104,7 +104,9 @@ project(":core") {
|
||||
api "com.badlogicgames.ashley:ashley:$ashleyVersion"
|
||||
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
||||
api "io.github.libktx:ktx-app:$ktxVersion"
|
||||
api "io.github.libktx:ktx-assets:$ktxVersion"
|
||||
api "io.github.libktx:ktx-collections:$ktxVersion"
|
||||
api "io.github.libktx:ktx-graphics:$ktxVersion"
|
||||
api "io.github.libktx:ktx-log:$ktxVersion"
|
||||
}
|
||||
}
|
||||
|
32
core/src/me/msoucy/ptures/EAssets.kt
Normal file
32
core/src/me/msoucy/ptures/EAssets.kt
Normal file
@ -0,0 +1,32 @@
|
||||
package me.msoucy.ptures
|
||||
|
||||
import com.badlogic.gdx.assets.AssetManager
|
||||
import com.badlogic.gdx.audio.Music
|
||||
import com.badlogic.gdx.audio.Sound
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas
|
||||
import ktx.assets.getAsset
|
||||
import ktx.assets.load
|
||||
|
||||
// sounds
|
||||
enum class SoundAssets(val path: String) {
|
||||
Drop("sounds/drop.wav")
|
||||
}
|
||||
|
||||
inline fun AssetManager.load(asset: SoundAssets) = load<Sound>(asset.path)
|
||||
inline operator fun AssetManager.get(asset: SoundAssets) = getAsset<Sound>(asset.path)
|
||||
|
||||
// music
|
||||
enum class MusicAssets(val path: String) {
|
||||
Rain("music/rain.mp3")
|
||||
}
|
||||
|
||||
inline fun AssetManager.load(asset: MusicAssets) = load<Music>(asset.path)
|
||||
inline operator fun AssetManager.get(asset: MusicAssets) = getAsset<Music>(asset.path)
|
||||
|
||||
// texture atlas
|
||||
enum class TextureAtlasAssets(val path: String) {
|
||||
Game("images/game.atlas")
|
||||
}
|
||||
|
||||
inline fun AssetManager.load(asset: TextureAtlasAssets) = load<TextureAtlas>(asset.path)
|
||||
inline operator fun AssetManager.get(asset: TextureAtlasAssets) = getAsset<TextureAtlas>(asset.path)
|
@ -1,25 +1,27 @@
|
||||
package me.msoucy.ptures
|
||||
|
||||
import com.badlogic.gdx.assets.AssetManager
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import ktx.app.KtxGame
|
||||
import ktx.app.KtxScreen
|
||||
import me.msoucy.ptures.screens.MainMenuScreen
|
||||
import me.msoucy.ptures.screens.LoadingScreen
|
||||
|
||||
class PTures : KtxGame<KtxScreen>() {
|
||||
val batch by lazy { SpriteBatch() }
|
||||
// use LibGDX's default Arial font
|
||||
val font by lazy { BitmapFont() }
|
||||
val assets = AssetManager()
|
||||
|
||||
override fun create() {
|
||||
addScreen(MainMenuScreen(this))
|
||||
setScreen<MainMenuScreen>()
|
||||
addScreen(LoadingScreen(this))
|
||||
setScreen<LoadingScreen>()
|
||||
super.create()
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
batch.dispose()
|
||||
font.dispose()
|
||||
assets.dispose()
|
||||
super.dispose()
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package me.msoucy.ptures.screens
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.math.MathUtils
|
||||
import com.badlogic.gdx.math.Rectangle
|
||||
import com.badlogic.gdx.math.Vector3
|
||||
@ -12,14 +11,18 @@ import com.badlogic.gdx.utils.TimeUtils
|
||||
import ktx.app.KtxScreen
|
||||
import ktx.collections.iterate
|
||||
import ktx.graphics.use
|
||||
import me.msoucy.ptures.PTures
|
||||
import ktx.log.logger
|
||||
import me.msoucy.ptures.*
|
||||
|
||||
private val log = logger<GameScreen>()
|
||||
|
||||
class GameScreen(val game: PTures) : KtxScreen {
|
||||
|
||||
private val dropImage = Texture(Gdx.files.internal("images/drop.png"))
|
||||
private val bucketImage = Texture(Gdx.files.internal("images/bucket.png"))
|
||||
private val dropSound = Gdx.audio.newSound(Gdx.files.internal("sounds/drop.wav"))
|
||||
private val rainMusic = Gdx.audio.newMusic(Gdx.files.internal("music/rain.mp3")).apply { isLooping = true }
|
||||
private val dropImage = game.assets[TextureAtlasAssets.Game].findRegion("drop")
|
||||
private val bucketImage = game.assets[TextureAtlasAssets.Game].findRegion("bucket")
|
||||
private val dropSound = game.assets[SoundAssets.Drop]
|
||||
private val rainMusic = game.assets[MusicAssets.Rain].apply { isLooping = true }
|
||||
|
||||
// The camera ensures we can render using our target resolution of 800x480
|
||||
// pixels no matter what the screen resolution is.
|
||||
private val camera = OrthographicCamera().apply { setToOrtho(false, 800f, 480f) }
|
||||
@ -75,8 +78,10 @@ class GameScreen(val game: PTures) : KtxScreen {
|
||||
// effect also
|
||||
raindrops.iterate { raindrop, iterator ->
|
||||
raindrop.y -= 200 * delta
|
||||
if (raindrop.y + 64 < 0)
|
||||
if (raindrop.y + 64 < 0) {
|
||||
iterator.remove()
|
||||
log.debug { "Missed a raindrop!" }
|
||||
}
|
||||
|
||||
if (raindrop.overlaps(bucket)) {
|
||||
dropsGathered++
|
||||
@ -91,11 +96,4 @@ class GameScreen(val game: PTures) : KtxScreen {
|
||||
rainMusic.play()
|
||||
spawnRaindrop()
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
dropImage.dispose()
|
||||
bucketImage.dispose()
|
||||
dropSound.dispose()
|
||||
rainMusic.dispose()
|
||||
}
|
||||
}
|
43
core/src/me/msoucy/ptures/screens/LoadingScreen.kt
Normal file
43
core/src/me/msoucy/ptures/screens/LoadingScreen.kt
Normal file
@ -0,0 +1,43 @@
|
||||
package me.msoucy.ptures.screens
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import ktx.app.KtxScreen
|
||||
import ktx.graphics.use
|
||||
import me.msoucy.ptures.*
|
||||
|
||||
class LoadingScreen(val game: PTures) : KtxScreen {
|
||||
private val camera = OrthographicCamera().apply {
|
||||
setToOrtho(false, 800f, 480f)
|
||||
}
|
||||
|
||||
override fun render(delta: Float) {
|
||||
// Continue loading assets
|
||||
game.assets.update()
|
||||
|
||||
camera.update()
|
||||
game.batch.projectionMatrix = camera.combined
|
||||
|
||||
game.batch.use {
|
||||
game.font.draw(it, "Welcome to Drop!!! ", 100f, 150f)
|
||||
if (game.assets.isFinished) {
|
||||
game.font.draw(it, "Tap anywhere to begin!", 100f, 100f)
|
||||
} else {
|
||||
game.font.draw(it, "Loading assets...", 100f, 100f)
|
||||
}
|
||||
}
|
||||
|
||||
if (Gdx.input.isTouched && game.assets.isFinished) {
|
||||
game.addScreen(GameScreen(game))
|
||||
game.setScreen<GameScreen>()
|
||||
game.removeScreen<LoadingScreen>()
|
||||
dispose()
|
||||
}
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
MusicAssets.values().forEach { game.assets.load(it) }
|
||||
SoundAssets.values().forEach { game.assets.load(it) }
|
||||
TextureAtlasAssets.values().forEach { game.assets.load(it) }
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package me.msoucy.ptures.screens
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import ktx.app.KtxScreen
|
||||
import ktx.graphics.use
|
||||
import me.msoucy.ptures.PTures
|
||||
|
||||
class MainMenuScreen(val game: PTures) : KtxScreen {
|
||||
private val camera = OrthographicCamera().apply {
|
||||
setToOrtho(false, 800f, 480f)
|
||||
}
|
||||
|
||||
override fun render(delta: Float) {
|
||||
camera.update()
|
||||
game.batch.projectionMatrix = camera.combined
|
||||
|
||||
game.batch.use {
|
||||
game.font.draw(it, "Welcome to Drop!!! ", 100f, 150f)
|
||||
game.font.draw(it, "Tap anywhere to begin!", 100f, 100f)
|
||||
}
|
||||
|
||||
if (Gdx.input.isTouched) {
|
||||
game.addScreen(GameScreen(game))
|
||||
game.setScreen<GameScreen>()
|
||||
game.removeScreen<MainMenuScreen>()
|
||||
dispose()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package me.msoucy.ptures.desktop
|
||||
|
||||
import com.badlogic.gdx.Application
|
||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication
|
||||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
|
||||
import me.msoucy.ptures.PTures
|
||||
@ -7,7 +8,11 @@ import me.msoucy.ptures.PTures
|
||||
object DesktopLauncher {
|
||||
@JvmStatic
|
||||
fun main(arg: Array<String>) {
|
||||
val config = LwjglApplicationConfiguration()
|
||||
LwjglApplication(PTures(), config)
|
||||
val config = LwjglApplicationConfiguration().apply {
|
||||
title = "Drop"
|
||||
width = 800
|
||||
height = 480
|
||||
}
|
||||
LwjglApplication(PTures(), config).logLevel = Application.LOG_DEBUG
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user