From e5536100dfd02bff7e674625ba9841dce264c782 Mon Sep 17 00:00:00 2001 From: Srikavin Ramkumar Date: Wed, 8 Jan 2020 20:36:03 -0500 Subject: [PATCH] Make game playable --- core/src/me/srikavin/fbla/game/FBLAGame.kt | 2 +- core/src/me/srikavin/fbla/game/Util.kt | 20 ++++- .../game/ecs/component/MinigameComponent.kt | 3 + .../fbla/game/ecs/system/DialogueSystem.kt | 1 - .../fbla/game/ecs/system/InputSystem.kt | 2 +- .../game/ecs/system/MinigameRenderSystem.kt | 5 +- .../fbla/game/ecs/system/PhysicsSystem.kt | 4 +- .../me/srikavin/fbla/game/map/MapLoader.kt | 68 ++++++++++++----- .../srikavin/fbla/game/minigame/Minigame.kt | 71 +++++++++++++++++- .../fbla/game/minigame/MinigameManager.kt | 11 +-- .../dropcatch/DropcatchItemComponent.kt | 12 +++ .../minigame/dropcatch/DropcatchMinigame.kt | 73 +++++++++++++++++++ .../fbla/game/minigame/quiz/QuizMinigame.kt | 4 +- .../game/trigger/InteractiveTriggerHandler.kt | 15 ++-- .../game/trigger/MinigameTriggerHandler.kt | 7 +- .../fbla/game/trigger/TriggerManager.kt | 3 +- 16 files changed, 254 insertions(+), 47 deletions(-) create mode 100644 core/src/me/srikavin/fbla/game/minigame/dropcatch/DropcatchItemComponent.kt create mode 100644 core/src/me/srikavin/fbla/game/minigame/dropcatch/DropcatchMinigame.kt diff --git a/core/src/me/srikavin/fbla/game/FBLAGame.kt b/core/src/me/srikavin/fbla/game/FBLAGame.kt index 2595944..715c4d8 100644 --- a/core/src/me/srikavin/fbla/game/FBLAGame.kt +++ b/core/src/me/srikavin/fbla/game/FBLAGame.kt @@ -53,7 +53,7 @@ class FBLAGame : ApplicationAdapter() { val assetManager = AssetManager() val batch = SpriteBatch() - val physicsWorld = com.badlogic.gdx.physics.box2d.World(Vector2(0f, -16f), true) + val physicsWorld = com.badlogic.gdx.physics.box2d.World(Vector2(0f, -23f), true) val generator = FreeTypeFontGenerator(Gdx.files.internal("assets/fonts/Kenney Pixel.ttf")) val parameter = FreeTypeFontGenerator.FreeTypeFontParameter() diff --git a/core/src/me/srikavin/fbla/game/Util.kt b/core/src/me/srikavin/fbla/game/Util.kt index 667586f..6311c00 100644 --- a/core/src/me/srikavin/fbla/game/Util.kt +++ b/core/src/me/srikavin/fbla/game/Util.kt @@ -1,6 +1,8 @@ package me.srikavin.fbla.game import com.badlogic.gdx.utils.Array +import me.srikavin.fbla.game.minigame.Minigame +import kotlin.reflect.KProperty /** * Type alias to avoid mixing up Kotlin Arrays with Gdx Arrays @@ -10,4 +12,20 @@ typealias GdxArray = Array /** * Type alias to maintain type safety with Artemis-ODB entity identifiers */ -typealias EntityInt = Int \ No newline at end of file +typealias EntityInt = Int + + +/** + * Utility class to allow kotlin classes that delegate to map properties for type safety reasons + */ +class MapTriggerDelegate(val name: String) { + operator fun getValue(mapTriggerProperties: Minigame.MapTriggerProperties, property: KProperty<*>): String { + return mapTriggerProperties.properties.get(name)?.toString() + ?: throw RuntimeException("Minigame trigger without `$name`!") + + } + + operator fun setValue(mapTriggerProperties: Minigame.MapTriggerProperties, property: KProperty<*>, value: String) { + mapTriggerProperties.properties.put(name, value) + } +} diff --git a/core/src/me/srikavin/fbla/game/ecs/component/MinigameComponent.kt b/core/src/me/srikavin/fbla/game/ecs/component/MinigameComponent.kt index b860555..9ebf611 100644 --- a/core/src/me/srikavin/fbla/game/ecs/component/MinigameComponent.kt +++ b/core/src/me/srikavin/fbla/game/ecs/component/MinigameComponent.kt @@ -5,6 +5,9 @@ import me.srikavin.fbla.game.minigame.Minigame /** * Component containing a minigame + * + * @see me.srikavin.fbla.game.ecs.system.MinigameSystem + * @see me.srikavin.fbla.game.ecs.system.MinigameRenderSystem */ class MinigameComponent : Component() { var minigame: Minigame? = null diff --git a/core/src/me/srikavin/fbla/game/ecs/system/DialogueSystem.kt b/core/src/me/srikavin/fbla/game/ecs/system/DialogueSystem.kt index 030c743..f268ed1 100644 --- a/core/src/me/srikavin/fbla/game/ecs/system/DialogueSystem.kt +++ b/core/src/me/srikavin/fbla/game/ecs/system/DialogueSystem.kt @@ -57,7 +57,6 @@ class DialogueSystem : BaseEntitySystem() { if (mapper[e] == dialogueManager.component) { dialogueManager.component = null } - mapper[e].channel.close() } } } diff --git a/core/src/me/srikavin/fbla/game/ecs/system/InputSystem.kt b/core/src/me/srikavin/fbla/game/ecs/system/InputSystem.kt index f4d75b6..0270e6b 100644 --- a/core/src/me/srikavin/fbla/game/ecs/system/InputSystem.kt +++ b/core/src/me/srikavin/fbla/game/ecs/system/InputSystem.kt @@ -20,7 +20,7 @@ import me.srikavin.fbla.game.graphics.player_foot_fixture_id import me.srikavin.fbla.game.physics.ContactListenerManager private const val MAX_HORIZONTAL_VELOCITY = 7f -private val JUMP_IMPULSE = Vector2(0.0f, 25.0f) +private val JUMP_IMPULSE = Vector2(0.0f, 30.0f) private val LEFT_FORCE = Vector2(-50f, 0.0f) private val RIGHT_FORCE = Vector2(50f, 0.0f) diff --git a/core/src/me/srikavin/fbla/game/ecs/system/MinigameRenderSystem.kt b/core/src/me/srikavin/fbla/game/ecs/system/MinigameRenderSystem.kt index c37f461..68138ca 100644 --- a/core/src/me/srikavin/fbla/game/ecs/system/MinigameRenderSystem.kt +++ b/core/src/me/srikavin/fbla/game/ecs/system/MinigameRenderSystem.kt @@ -40,7 +40,7 @@ class MinigameRenderSystem : IteratingSystem() { override fun inserted(entities: IntBag) { for (i in 0 until entities.size()) { val e: EntityInt = entities[i] - minigameMapper[e].minigame?.initalize(skin, stage) + minigameMapper[e].minigame?.initialize(skin, stage) ?: info { "Minigame not initialized upon creation: ${minigameMapper[e]}" } } } @@ -65,6 +65,9 @@ class MinigameRenderSystem : IteratingSystem() { batch.projectionMatrix = camera.combined minigame.render(camera, batch, stage) + + stage.act(Gdx.graphics.deltaTime) + stage.draw() } } diff --git a/core/src/me/srikavin/fbla/game/ecs/system/PhysicsSystem.kt b/core/src/me/srikavin/fbla/game/ecs/system/PhysicsSystem.kt index b33213e..65b4c30 100644 --- a/core/src/me/srikavin/fbla/game/ecs/system/PhysicsSystem.kt +++ b/core/src/me/srikavin/fbla/game/ecs/system/PhysicsSystem.kt @@ -96,9 +96,9 @@ class PhysicsSystem(var physicsWorld: World, private val contactManager: Contact val footBox = FixtureDef().apply { // this.isSensor = true this.shape = PolygonShape().apply { - setAsBox(0.5f, 0.05f, Vector2(0f, -1f), 0f) + setAsBox(0.55f, 0.05f, Vector2(0f, -1f), 0f) } - friction = 1f + friction = .9f } val fixture = physics.body.createFixture(footBox) diff --git a/core/src/me/srikavin/fbla/game/map/MapLoader.kt b/core/src/me/srikavin/fbla/game/map/MapLoader.kt index b6f1013..cb3bc8e 100644 --- a/core/src/me/srikavin/fbla/game/map/MapLoader.kt +++ b/core/src/me/srikavin/fbla/game/map/MapLoader.kt @@ -31,6 +31,8 @@ private const val COLLISION_LAYER_NAME = "Collision" private const val TRIGGER_LAYER_NAME = "Trigger" private const val MAP_SCALE_FACTOR = 1 / 32f +typealias TriggerProcessor = (mapObject: RectangleMapObject, type: String, path: String) -> Unit + /** * Responsible for loading maps and their associated assets as well as spawning players. Tiled Maps that are to be loaded * may contain any of the following layers: @@ -50,7 +52,21 @@ class MapLoader { private val playerAnimations = spritesheetLoader.loadAsespriteSheet("assets/graphics/characters/David.png", "assets/graphics/characters/David.json") private val coinSprite: TextureRegion = TextureRegion(Texture(Gdx.files.internal("assets/graphics/entity/coinGold.png"))) + private val defaultTriggerProcessor: TriggerProcessor = { mapObject, _, path -> + error { throw RuntimeException("Spawn is of type ${mapObject.javaClass.name} instead of RectangleMapObject in $path") } + } + enum class UnloadType { + /** + * Unloads all objects in a level + */ + ALL, + /** + * Unloads all objects without the component [] + */ + NonMinigame, + NONE + } /** * Creates a player entity with the given world and given position @@ -61,14 +77,14 @@ class MapLoader { val e = world.createEntity().edit() .add(PhysicsBody().apply { shape = PolygonShape().apply { - setAsBox(.6f, 1f) + setAsBox(.6f, .9f) } restitution = 0.1f density = 1f friction = 0.1f }) .add(PlayerControlled()) - .add(SpriteOffset(Vector2(-.75f, -1f))) + .add(SpriteOffset(Vector2(-.75f, -1.1f))) .add(Transform().apply { position = pos }) .add(SwitchableAnimation().apply { animations = playerAnimations; currentState = "Stand" }) .add(FixedRotation()) @@ -102,19 +118,28 @@ class MapLoader { * * @param world The world to create entities in * @param path The path to load maps from + * @param unload Whether or not to unload previous maps + * @param customTriggerProcessor A [TriggerProcessor] to handle triggers unknown to this MapLoader * * @return The id of the created [MapComponent] */ - fun loadMap(world: World, path: String): EntityInt { - // Unload previously loaded maps - val entities = world.aspectSubscriptionManager[Aspect.all()].entities - val loadedMapMapper = world.getMapper(MapComponent::class.java) - - for (i in 0 until entities.size()) { - if (loadedMapMapper.has(entities[i])) { - loadedMapMapper[entities[i]].map.disposeSafely() + fun loadMap(world: World, path: String, unload: UnloadType = UnloadType.ALL, + customTriggerProcessor: TriggerProcessor = defaultTriggerProcessor): EntityInt { + if (unload == UnloadType.ALL || unload == UnloadType.NonMinigame) { + // Unload previously loaded maps + val entities = world.aspectSubscriptionManager[Aspect.all()].entities + val loadedMapMapper = world.getMapper(MapComponent::class.java) + val minigameMapper = world.getMapper(MinigameComponent::class.java) + + for (i in 0 until entities.size()) { + if (unload == UnloadType.NonMinigame && minigameMapper.has(entities[i])) { + continue + } + if (loadedMapMapper.has(entities[i])) { + loadedMapMapper[entities[i]].map.disposeSafely() + } + world.delete(entities[i]) } - world.delete(entities[i]) } val map = TmxMapLoader().load(path, TmxMapLoader.Parameters().apply { @@ -142,34 +167,38 @@ class MapLoader { for (mapObject: MapObject in triggerLayer.objects) { if (mapObject is RectangleMapObject) { info { "Processing Trigger at ${mapObject.rectangle.x},${mapObject.rectangle.y} in $path" } - when (mapObject.properties?.get("type")) { - "spawn" -> { + val type = mapObject.properties?.get("type").toString() + when { + type == "spawn" -> { playerPosition.x = mapObject.rectangle.x playerPosition.y = mapObject.rectangle.y spawnTriggerFound = true } - "coin" -> { + type == "coin" -> { val pos = Vector2() createCoin(world, mapObject.rectangle.getPosition(pos).scl(MAP_SCALE_FACTOR)) info { "Making coin at $pos" } } - else -> { + TriggerType.values().any { it.name == type.toUpperCase() } -> { val rect = mapObject.rectangle world.createEntity().edit() - .add(Transform()) + .add(Transform().apply { position = rect.getCenter(recycledVector2).scl(MAP_SCALE_FACTOR).cpy() }) .add(PhysicsBody().apply { shape = PolygonShape().apply { setAsBox(rect.width * MAP_SCALE_FACTOR * .5f, rect.height * MAP_SCALE_FACTOR * .5f, - rect.getCenter(recycledVector2).scl(MAP_SCALE_FACTOR), 0f) + recycledVector2.setZero(), 0f) } - type = BodyDef.BodyType.StaticBody + this.type = BodyDef.BodyType.StaticBody }) .add(MapTrigger().apply { - type = TriggerType.valueOf(mapObject.properties.get("type").toString().toUpperCase()) + this.type = TriggerType.valueOf(type.toUpperCase()) properties = mapObject.properties }) } + else -> { + customTriggerProcessor(mapObject, type, path) + } } } else { error { throw RuntimeException("Spawn is of type ${mapObject.javaClass.name} instead of RectangleMapObject in $path") } @@ -265,7 +294,6 @@ class MapLoader { info { fixtureDefs.toString() } info { collisionLayer.objects.count.toString() } editor.add(PhysicsBody(fixtureDefs, BodyDef.BodyType.StaticBody, 0f, 0.2f, 0f)) - editor.entity return mapEntity } diff --git a/core/src/me/srikavin/fbla/game/minigame/Minigame.kt b/core/src/me/srikavin/fbla/game/minigame/Minigame.kt index 873cfb0..4617aaf 100644 --- a/core/src/me/srikavin/fbla/game/minigame/Minigame.kt +++ b/core/src/me/srikavin/fbla/game/minigame/Minigame.kt @@ -1,27 +1,89 @@ package me.srikavin.fbla.game.minigame +import com.artemis.World +import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.maps.MapProperties import com.badlogic.gdx.scenes.scene2d.Stage import com.badlogic.gdx.scenes.scene2d.ui.Skin +import me.srikavin.fbla.game.MapTriggerDelegate +import me.srikavin.fbla.game.map.MapLoader +/** + * The baseclass that all minigames inherit from. This class handles level transitions and communications with outside + * systems. The field [mapProperties] is available to subclasses as a type-safe version of MapProperties. + */ abstract class Minigame { /** * Stores whether the minigame is currently being played by the user. */ var active: Boolean = false + private set + + private var nextLevel: String = "" + + /** + * If a new map is loaded by a subclass, make sure to set [MapLoader.loadMap] with [MapLoader.UnloadType.NonMinigame] + * to avoid unloading this minigame instance. + */ + protected lateinit var mapLoader: MapLoader /** - * Reset the minigame to its initial conditions. This will always be called before a minigame is made active. + * The entity-component-system world that can be used to create new entities. */ - abstract fun reset(properties: MapProperties) + protected lateinit var world: World + + /** + * A type safe version of the MapProperties provided within the trigger object in the map. + */ + protected lateinit var mapProperties: MapTriggerProperties + + class MapTriggerProperties(val properties: MapProperties) { + val type: String by MapTriggerDelegate("type") + val subtype: String by MapTriggerDelegate("subtype") + val minigameType: String by MapTriggerDelegate("minigame_type") + val nextLevel: String by MapTriggerDelegate("next_level") + } + + /** + * Reset the minigame to its initial conditions. This will always be called before [initialize]. + */ + fun reset(properties: MapProperties, world: World, mapLoader: MapLoader) { + this.mapProperties = MapTriggerProperties(properties) + this.nextLevel = mapProperties.nextLevel + this.mapLoader = mapLoader + this.world = world + + resetMinigame(properties) + } + + /** + * Reset the minigame to its initial conditions. This will be called by [reset] + */ + protected abstract fun resetMinigame(properties: MapProperties) /** * Any inital UI initialization should occur here. The stage will not be modified outside of the minigame while it * is active. */ - abstract fun initalize(skin: Skin, stage: Stage) + fun initialize(skin: Skin, stage: Stage) { + active = true + + initializeMinigame(skin, stage) + } + + /** + * Immediately ends the minigame and transitions to the next level. + */ + fun endMinigame() { + active = false + Gdx.app.postRunnable { + mapLoader.loadMap(world, "assets/maps/$nextLevel") + } + } + + protected abstract fun initializeMinigame(skin: Skin, stage: Stage) /** * The stage will not be modified outside of the minigame while the minigame remains active. No references to the @@ -49,4 +111,5 @@ abstract class Minigame { open fun allowPlayerMovement(): Boolean { return false } -} \ No newline at end of file +} + diff --git a/core/src/me/srikavin/fbla/game/minigame/MinigameManager.kt b/core/src/me/srikavin/fbla/game/minigame/MinigameManager.kt index db92951..d64eb2a 100644 --- a/core/src/me/srikavin/fbla/game/minigame/MinigameManager.kt +++ b/core/src/me/srikavin/fbla/game/minigame/MinigameManager.kt @@ -1,13 +1,14 @@ package me.srikavin.fbla.game.minigame +import me.srikavin.fbla.game.minigame.dropcatch.DropcatchMinigame import me.srikavin.fbla.game.minigame.quiz.QuizMinigame class MinigameManager { - private val minigames = mapOf( - "quiz" to QuizMinigame() -// "dialogue" -// "buttonmash" -// "dropcatch" + private val minigames = mapOf( + "quiz" to QuizMinigame(), + "dropcatch" to DropcatchMinigame(), + "dialogue" to QuizMinigame(), + "buttonmash" to QuizMinigame() ) fun getMinigame(name: String): Minigame { diff --git a/core/src/me/srikavin/fbla/game/minigame/dropcatch/DropcatchItemComponent.kt b/core/src/me/srikavin/fbla/game/minigame/dropcatch/DropcatchItemComponent.kt new file mode 100644 index 0000000..31a9766 --- /dev/null +++ b/core/src/me/srikavin/fbla/game/minigame/dropcatch/DropcatchItemComponent.kt @@ -0,0 +1,12 @@ +package me.srikavin.fbla.game.minigame.dropcatch + +import com.artemis.Component + +enum class DropcatchItemType { + GOOD, + BAD +} + +class DropcatchItemComponent : Component() { + lateinit var type: DropcatchItemType +} \ No newline at end of file diff --git a/core/src/me/srikavin/fbla/game/minigame/dropcatch/DropcatchMinigame.kt b/core/src/me/srikavin/fbla/game/minigame/dropcatch/DropcatchMinigame.kt new file mode 100644 index 0000000..5af9e90 --- /dev/null +++ b/core/src/me/srikavin/fbla/game/minigame/dropcatch/DropcatchMinigame.kt @@ -0,0 +1,73 @@ +package me.srikavin.fbla.game.minigame.dropcatch + +import com.badlogic.gdx.Input +import com.badlogic.gdx.graphics.OrthographicCamera +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import com.badlogic.gdx.maps.MapProperties +import com.badlogic.gdx.maps.objects.RectangleMapObject +import com.badlogic.gdx.math.Vector2 +import com.badlogic.gdx.scenes.scene2d.Stage +import com.badlogic.gdx.scenes.scene2d.ui.Skin +import com.badlogic.gdx.scenes.scene2d.ui.Table +import com.rafaskoberg.gdx.typinglabel.TypingLabel +import me.srikavin.fbla.game.GdxArray +import me.srikavin.fbla.game.ecs.component.Transform +import me.srikavin.fbla.game.map.MapLoader +import me.srikavin.fbla.game.minigame.Minigame + +class DropcatchMinigame : Minigame() { + private val inputs = GdxArray() + + init { + inputs.add(Input.Keys.NUM_1) + inputs.add(Input.Keys.NUM_2) + inputs.add(Input.Keys.NUM_3) + inputs.add(Input.Keys.NUM_4) + inputs.add(Input.Keys.NUM_5) + } + + override fun resetMinigame(properties: MapProperties) { + + } + + override fun initializeMinigame(skin: Skin, stage: Stage) { + stage.root = Table(skin) + stage.root.addActor(TypingLabel("Text", skin)) + val recycled = Vector2() + + mapLoader.loadMap(world, "assets/maps/dropcatch_${this.mapProperties.subtype}.tmx", + MapLoader.UnloadType.NonMinigame) { mapObject: RectangleMapObject, type: String, path: String -> + when (type) { + "gooditem" -> { + world.createEntity().edit() + .add(DropcatchItemComponent().apply { this.type = DropcatchItemType.GOOD }) + .add(Transform().apply { position = mapObject.rectangle.getPosition(recycled) }) +// .add(PhysicsBody().apply { this. }) + } + "baditem" -> { + + } + else -> { + error("Unknown dropcatch minigame type: $type") + } + } + } + } + + override fun render(camera: OrthographicCamera, batch: SpriteBatch, stage: Stage) { + + } + + override fun shouldRenderBackground(): Boolean { + return true + } + + override fun allowPlayerMovement(): Boolean { + return true + } + + override fun process(delta: Float) { + + } + +} \ No newline at end of file diff --git a/core/src/me/srikavin/fbla/game/minigame/quiz/QuizMinigame.kt b/core/src/me/srikavin/fbla/game/minigame/quiz/QuizMinigame.kt index 82f7ab5..fc88886 100644 --- a/core/src/me/srikavin/fbla/game/minigame/quiz/QuizMinigame.kt +++ b/core/src/me/srikavin/fbla/game/minigame/quiz/QuizMinigame.kt @@ -22,11 +22,11 @@ class QuizMinigame : Minigame() { inputs.add(Input.Keys.NUM_5) } - override fun reset(properties: MapProperties) { + override fun resetMinigame(properties: MapProperties) { } - override fun initalize(skin: Skin, stage: Stage) { + override fun initializeMinigame(skin: Skin, stage: Stage) { stage.root = Table(skin) stage.root.addActor(TypingLabel("Text", skin)) } diff --git a/core/src/me/srikavin/fbla/game/trigger/InteractiveTriggerHandler.kt b/core/src/me/srikavin/fbla/game/trigger/InteractiveTriggerHandler.kt index ea7fa85..460b399 100644 --- a/core/src/me/srikavin/fbla/game/trigger/InteractiveTriggerHandler.kt +++ b/core/src/me/srikavin/fbla/game/trigger/InteractiveTriggerHandler.kt @@ -2,11 +2,11 @@ package me.srikavin.fbla.game.trigger import com.artemis.World import com.badlogic.gdx.Gdx +import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.BitmapFont import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator -import com.badlogic.gdx.math.Matrix4 import me.srikavin.fbla.game.EntityInt import me.srikavin.fbla.game.ecs.component.MapTrigger import me.srikavin.fbla.game.ecs.component.Transform @@ -18,7 +18,11 @@ class InteractiveTriggerHandler : TriggerHandler { init { val generator = FreeTypeFontGenerator(Gdx.files.internal("assets/fonts/Kenney Future.ttf")) val parameter = FreeTypeFontGenerator.FreeTypeFontParameter() - parameter.size = 100 + parameter.size = 70 + parameter.spaceX = -10 + parameter.borderColor = Color.BLACK + parameter.borderStraight = false + parameter.borderWidth = 2f font = generator.generateFont(parameter) generator.dispose() } @@ -29,12 +33,11 @@ class InteractiveTriggerHandler : TriggerHandler { camera.update() val batch = world.getRegistered(SpriteBatch::class.java) - val originalMatrix: Matrix4 = camera.combined.cpy() - batch.projectionMatrix = originalMatrix.scale(1 / 45f, 1 / 45f, 1f) + batch.projectionMatrix = camera.combined.cpy().scale(1 / 75f, 1 / 75f, 1f) if (positionMapper.has(triggerEntity)) { - val pos = positionMapper[triggerEntity].position + val pos = positionMapper[triggerEntity].position.cpy().sub(3f, -1f).scl(75f, 75f) if (batch.isDrawing) { font.draw(batch, "Interact [E]", pos.x, pos.y) @@ -45,6 +48,6 @@ class InteractiveTriggerHandler : TriggerHandler { } } - batch.projectionMatrix = originalMatrix //revert projection + batch.projectionMatrix = camera.combined //revert projection } } diff --git a/core/src/me/srikavin/fbla/game/trigger/MinigameTriggerHandler.kt b/core/src/me/srikavin/fbla/game/trigger/MinigameTriggerHandler.kt index caae0ad..1f397d9 100644 --- a/core/src/me/srikavin/fbla/game/trigger/MinigameTriggerHandler.kt +++ b/core/src/me/srikavin/fbla/game/trigger/MinigameTriggerHandler.kt @@ -4,6 +4,7 @@ import com.artemis.World import me.srikavin.fbla.game.EntityInt import me.srikavin.fbla.game.ecs.component.MapTrigger import me.srikavin.fbla.game.ecs.component.MinigameComponent +import me.srikavin.fbla.game.map.MapLoader import me.srikavin.fbla.game.minigame.MinigameManager /** @@ -16,10 +17,12 @@ class MinigameTriggerHandler : TriggerHandler { // Remove entity world.delete(triggerEntity) - val minigame = minigameManager.getMinigame(trigger.properties["name"] as String) - minigame.reset(trigger.properties) + val minigame = minigameManager.getMinigame(trigger.properties["minigame_type"] as String) + minigame.reset(trigger.properties, world, world.getRegistered(MapLoader::class.java)) world.createEntity().edit() .add(MinigameComponent().apply { this.minigame = minigame }) + + minigame.endMinigame() } } \ No newline at end of file diff --git a/core/src/me/srikavin/fbla/game/trigger/TriggerManager.kt b/core/src/me/srikavin/fbla/game/trigger/TriggerManager.kt index 6994091..75212b8 100644 --- a/core/src/me/srikavin/fbla/game/trigger/TriggerManager.kt +++ b/core/src/me/srikavin/fbla/game/trigger/TriggerManager.kt @@ -11,13 +11,14 @@ class TriggerManager { private val coinTriggerHandler = CoinTriggerHandler() private val transitionTriggerHandler = TransitionTriggerHandler() private val interactiveTriggerHandler = InteractiveTriggerHandler() + private val minigameTriggerHandler = MinigameTriggerHandler() fun handle(world: World, player: EntityInt, triggerEntity: EntityInt, trigger: MapTrigger) { when (trigger.type) { TriggerType.COIN -> coinTriggerHandler.run(world, player, triggerEntity, trigger) TriggerType.TRANSITION -> transitionTriggerHandler.run(world, player, triggerEntity, trigger) TriggerType.INTERACTIVE -> interactiveTriggerHandler.run(world, player, triggerEntity, trigger) - TriggerType.MINIGAME -> TODO() + TriggerType.MINIGAME -> minigameTriggerHandler.run(world, player, triggerEntity, trigger) } } } \ No newline at end of file