Skip to content

Commit

Permalink
Update GameUI
Browse files Browse the repository at this point in the history
Add awards (to some extent)
Add death animation and text
Fix minor issue with collisions
  • Loading branch information
srikavin committed Feb 11, 2020
1 parent a6bb8d2 commit 1aaf739
Show file tree
Hide file tree
Showing 46 changed files with 707 additions and 166 deletions.
30 changes: 16 additions & 14 deletions core/src/me/srikavin/fbla/game/FBLAGame.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ import com.strongjoshua.console.GUIConsole
import ktx.assets.disposeSafely
import me.srikavin.fbla.game.Scene.PLAYING
import me.srikavin.fbla.game.Scene.TITLE
import me.srikavin.fbla.game.award.Awards
import me.srikavin.fbla.game.ecs.component.MinigameComponent
import me.srikavin.fbla.game.ecs.system.*
import me.srikavin.fbla.game.map.MapLoader
import me.srikavin.fbla.game.minigame.dropcatch.DropcatchMinigame
import me.srikavin.fbla.game.physics.ContactListenerManager
import me.srikavin.fbla.game.state.GameState
import me.srikavin.fbla.game.ui.MainMenu
import me.srikavin.fbla.game.util.GameFonts

const val cameraScale = 45f

Expand Down Expand Up @@ -138,7 +141,14 @@ class FBLAGame : ApplicationAdapter() {
reset(MapProperties().apply { put("subtype", stage); put("next_level", "level1.tmx") }, world, mapLoader)
}
})
}

fun addAward(name: String) {
gameState.addAward(name)
}

fun removeAward(name: String) {
gameState.removeAward(name)
}

fun debug(boolean: Boolean) {
Expand All @@ -162,6 +172,8 @@ class FBLAGame : ApplicationAdapter() {
assetManager.setLoader(FreeTypeFontGenerator::class.java, FreeTypeFontGeneratorLoader(resolver))
assetManager.setLoader(BitmapFont::class.java, ".ttf", FreetypeFontLoader(resolver))

GameFonts.loadFonts(assetManager, "assets/fonts/font.ttf")
Awards.init(assetManager)

fun newCursor(name: String): Cursor {
val p = Pixmap(Gdx.files.internal("assets/cursors/$name.png"))
Expand All @@ -170,21 +182,9 @@ class FBLAGame : ApplicationAdapter() {

Gdx.graphics.setCursor(newCursor("cursor"))

val parameter = FreetypeFontLoader.FreeTypeFontLoaderParameter().apply {
fontParameters.apply {
size = 22
fontFileName = "assets/fonts/font.ttf"
gamma = .8f
}
}
assetManager.load("defaultFont.ttf", BitmapFont::class.java, parameter)
val font = assetManager.finishLoadingAsset<BitmapFont>("defaultFont.ttf")
font.data.apply {
markupEnabled = true
}

val fontMap = ObjectMap<String, Any>()
fontMap.put("defaultFont", font)
fontMap.put("defaultFont", GameFonts.DEFAULT)
fontMap.put("menuFont", GameFonts.MENU)

assetManager.load("assets/skin/skin.json", Skin::class.java, SkinLoader.SkinParameter(fontMap))
}
Expand All @@ -198,6 +198,8 @@ class FBLAGame : ApplicationAdapter() {
}
mainMenuUI.build()
scene = TITLE
startGame()
scene = PLAYING
}

override fun render() {
Expand Down
3 changes: 0 additions & 3 deletions core/src/me/srikavin/fbla/game/GameState.kt

This file was deleted.

13 changes: 13 additions & 0 deletions core/src/me/srikavin/fbla/game/award/America.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.srikavin.fbla.game.award

import me.srikavin.fbla.game.state.GameRules

class America : Award() {
override fun apply(gameRules: GameRules) {
gameRules.enemiesToGold = true
}

override fun getName(): String {
return "america"
}
}
30 changes: 30 additions & 0 deletions core/src/me/srikavin/fbla/game/award/Award.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.srikavin.fbla.game.award

import com.badlogic.gdx.assets.AssetManager
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
import me.srikavin.fbla.game.state.GameRules

abstract class Award {
private lateinit var texture: Texture
private lateinit var drawable: TextureRegionDrawable

abstract fun apply(gameRules: GameRules)

protected abstract fun getName(): String

fun loadDrawable(assetManager: AssetManager) {
val path = "assets/graphics/awards/${getName()}.png"
assetManager.load(path, Texture::class.java)
texture = assetManager.finishLoadingAsset(path)
drawable = TextureRegionDrawable(texture)
}

fun getTexture(): Texture {
return texture
}

fun getDrawable(): TextureRegionDrawable {
return drawable
}
}
28 changes: 28 additions & 0 deletions core/src/me/srikavin/fbla/game/award/Awards.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package me.srikavin.fbla.game.award

import com.badlogic.gdx.assets.AssetManager

object Awards {
val future: Future = Future()
val business: Business = Business()
val leader: Leader = Leader()
val america: America = America()

private val nameMap = mapOf(
"future" to future,
"business" to business,
"leader" to leader,
"america" to america
)

fun init(assetManager: AssetManager) {
future.loadDrawable(assetManager)
business.loadDrawable(assetManager)
leader.loadDrawable(assetManager)
america.loadDrawable(assetManager)
}

fun getAward(name: String): Award {
return nameMap.getValue(name)
}
}
13 changes: 13 additions & 0 deletions core/src/me/srikavin/fbla/game/award/Business.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.srikavin.fbla.game.award

import me.srikavin.fbla.game.state.GameRules

class Business : Award() {
override fun apply(gameRules: GameRules) {
gameRules.coinMultiplier = 2
}

override fun getName(): String {
return "business"
}
}
13 changes: 13 additions & 0 deletions core/src/me/srikavin/fbla/game/award/Future.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.srikavin.fbla.game.award

import me.srikavin.fbla.game.state.GameRules

class Future : Award() {
override fun apply(gameRules: GameRules) {
gameRules.livesGainedPerLevel = 1
}

override fun getName(): String {
return "future"
}
}
13 changes: 13 additions & 0 deletions core/src/me/srikavin/fbla/game/award/Leader.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.srikavin.fbla.game.award

import me.srikavin.fbla.game.state.GameRules

class Leader : Award() {
override fun apply(gameRules: GameRules) {
gameRules.enemiesToGold = true
}

override fun getName(): String {
return "leader"
}
}
2 changes: 1 addition & 1 deletion core/src/me/srikavin/fbla/game/dialogue/DialogueManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DialogueManager(private val stage: Stage, skin: Skin) {

private val dialogues = mapOf(
"meeting" to DialogueMeeting(),
"make_chapter" to DialogueMakeChapter(),
"recruit" to DialogueMakeChapter(),
"job_interview" to DialogueJobInterview(),
"office" to DialogueSpeech(),
"letter_rec" to DialogueLetterRec(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package me.srikavin.fbla.game.ecs.component

import com.artemis.Component
import com.artemis.annotations.EntityId
import me.srikavin.fbla.game.EntityInt
import me.srikavin.fbla.game.util.EntityInt

/**
* Component indicating that an entity was the result of loading a map
Expand Down
7 changes: 7 additions & 0 deletions core/src/me/srikavin/fbla/game/ecs/component/Dead.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package me.srikavin.fbla.game.ecs.component

import com.artemis.Component

class Dead : Component() {
var respawnRunnable: () -> Unit = {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package me.srikavin.fbla.game.ecs.component

import com.artemis.Component
import com.badlogic.gdx.physics.box2d.*
import me.srikavin.fbla.game.GdxArray
import me.srikavin.fbla.game.util.GdxArray

/**
* A component containing the necessary properties to represent an entity as a physics object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,31 @@ import ktx.collections.GdxMap
*/
class SwitchableAnimation : Component() {
lateinit var animations: GdxMap<String, Animation<TextureRegion>>
lateinit var currentState: String
private lateinit var _currentState: String
var currentState: String
get() = _currentState
set(value) {
if (locked <= 0) {
_currentState = value
}
}
var mirror: Boolean = false
var looping: Boolean = false
private var locked: Float = 0f

/**
* Lock this animation component to the given animation. Multiple calls to [lock] will override the previous ones.
*
* @param animationName The name of the animation to lock to.
*/
fun lock(animationName: String) {
locked = animations[animationName].animationDuration
_currentState = animationName
}

fun getCurrentAndUpdate(delta: Float): Animation<TextureRegion> {
locked -= delta
return animations[currentState]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.artemis.ComponentMapper
import com.artemis.annotations.Wire
import com.artemis.managers.TagManager
import com.badlogic.gdx.graphics.OrthographicCamera
import me.srikavin.fbla.game.ecs.component.Dead
import me.srikavin.fbla.game.ecs.component.Transform

/**
Expand All @@ -16,12 +17,18 @@ import me.srikavin.fbla.game.ecs.component.Transform
class CameraFollowSystem(var followVertical: Boolean = true, var followHorizontal: Boolean = true) : BaseSystem() {
@Wire
private lateinit var transformMapper: ComponentMapper<Transform>
private lateinit var deadMapper: ComponentMapper<Dead>

@Wire
internal lateinit var camera: OrthographicCamera

override fun processSystem() {
val player = world.getSystem(TagManager::class.java).getEntityId("PLAYER")

if (deadMapper.has(player)) {
return
}

if (player != -1 && transformMapper.has(player)) {
val pos = transformMapper[player].position
if (followHorizontal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class EntityRenderSystem : IteratingSystem() {
switchableAnimationMapper.has(entityId) -> {
val animated = switchableAnimationMapper[entityId]
mirrored = animated.mirror
animated.animations[animated.currentState].getKeyFrame(stateTime, animated.looping)
animated.getCurrentAndUpdate(world.delta).getKeyFrame(stateTime, animated.looping)
}
animatedMapper.has(entityId) -> {
val animated = animatedMapper[entityId]
Expand Down
12 changes: 8 additions & 4 deletions core/src/me/srikavin/fbla/game/ecs/system/InputSystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import com.badlogic.gdx.physics.box2d.ContactImpulse
import com.badlogic.gdx.physics.box2d.ContactListener
import com.badlogic.gdx.physics.box2d.Manifold
import me.srikavin.fbla.game.GameActions
import me.srikavin.fbla.game.ecs.component.DisableInput
import me.srikavin.fbla.game.ecs.component.PhysicsBody
import me.srikavin.fbla.game.ecs.component.PlayerControlled
import me.srikavin.fbla.game.ecs.component.Transform
import me.srikavin.fbla.game.ecs.component.*
import me.srikavin.fbla.game.graphics.player_foot_fixture_id
import me.srikavin.fbla.game.physics.ContactListenerManager

Expand All @@ -37,6 +34,9 @@ class InputSystem(private val listenerManager: ContactListenerManager) : Iterati
@Wire
private lateinit var physicsBodyMapper: ComponentMapper<PhysicsBody>

@Wire
private lateinit var deadMapper: ComponentMapper<Dead>

private var allowJump: Int = 0

inner class FootContactListener : ContactListener {
Expand Down Expand Up @@ -71,6 +71,10 @@ class InputSystem(private val listenerManager: ContactListenerManager) : Iterati


override fun process(entityId: Int) {
if (deadMapper.has(entityId)) {
return
}

val body = physicsBodyMapper[entityId].body

if (allowJump == 0 && body.linearVelocity.y < -1f && body.linearVelocity.y > -15f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.utils.viewport.ExtendViewport
import ktx.log.info
import me.srikavin.fbla.game.EntityInt
import me.srikavin.fbla.game.ecs.component.MinigameComponent
import me.srikavin.fbla.game.registerInputHandler
import me.srikavin.fbla.game.util.EntityInt
import me.srikavin.fbla.game.util.registerInputHandler

/**
* Handles rendering active minigames
Expand Down
27 changes: 27 additions & 0 deletions core/src/me/srikavin/fbla/game/ecs/system/PhysicsSystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,26 @@ class PhysicsSystem(var physicsWorld: World, private val contactManager: Contact
}
}

val filter = Filter()
filter.groupIndex = -1
fixtures.forEach {
it.filterData = filter
}


if (e == world.getSystem(TagManager::class.java).getEntityId("PLAYER")) {
// Increased friction when touching ground without affecting wall sliding
val feet = FixtureDef().apply {
// this.isSensor = true
this.shape = PolygonShape().apply {
setAsBox(0.6f, 0.05f, Vector2(0f, -1f), 0f)
}
friction = .9f
}

fixtures.add(physics.body.createFixture(feet))

// Used to detect when the player is on the ground
val footBox = FixtureDef().apply {
// this.isSensor = true
this.shape = PolygonShape().apply {
Expand All @@ -103,9 +121,18 @@ class PhysicsSystem(var physicsWorld: World, private val contactManager: Contact

val fixture = physics.body.createFixture(footBox)
fixture.userData = player_foot_fixture_id
fixture.isSensor = true
fixtures.add(fixture)


// Apply a filter to allow for the death animation
filter.groupIndex = 1
fixtures.forEach {
it.filterData = filter
}
}


physics.fixtures = fixtures
}
}
Expand Down
Loading

0 comments on commit 1aaf739

Please sign in to comment.