diff --git a/core/assets/assets b/core/assets/assets index 6df36ab..dbfc8fa 160000 --- a/core/assets/assets +++ b/core/assets/assets @@ -1 +1 @@ -Subproject commit 6df36abf3b3123ecf7e413eb0b410c97442a5f32 +Subproject commit dbfc8fae522eb2905cd792debfa2edad0ab6d5b9 diff --git a/core/src/me/srikavin/fbla/game/ecs/component/DisableInput.kt b/core/src/me/srikavin/fbla/game/ecs/component/DisableInput.kt new file mode 100644 index 0000000..027ef4d --- /dev/null +++ b/core/src/me/srikavin/fbla/game/ecs/component/DisableInput.kt @@ -0,0 +1,5 @@ +package me.srikavin.fbla.game.ecs.component + +import com.artemis.Component + +class DisableInput : Component() \ No newline at end of file diff --git a/core/src/me/srikavin/fbla/game/ecs/system/CameraFollowSystem.kt b/core/src/me/srikavin/fbla/game/ecs/system/CameraFollowSystem.kt index 93fff3d..9db7673 100644 --- a/core/src/me/srikavin/fbla/game/ecs/system/CameraFollowSystem.kt +++ b/core/src/me/srikavin/fbla/game/ecs/system/CameraFollowSystem.kt @@ -7,8 +7,8 @@ import com.artemis.managers.TagManager import com.badlogic.gdx.graphics.OrthographicCamera import me.srikavin.fbla.game.ecs.component.Transform -class CameraFollowSystem(val followVertical: Boolean = false, val followHorizontal: Boolean = true) : BaseSystem() { - lateinit var transformMapper: ComponentMapper +class CameraFollowSystem(private val followVertical: Boolean = false, private val followHorizontal: Boolean = true) : BaseSystem() { + private lateinit var transformMapper: ComponentMapper @Wire lateinit var camera: OrthographicCamera 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 da127e0..eac9165 100644 --- a/core/src/me/srikavin/fbla/game/ecs/system/InputSystem.kt +++ b/core/src/me/srikavin/fbla/game/ecs/system/InputSystem.kt @@ -2,6 +2,7 @@ package me.srikavin.fbla.game.ecs.system import com.artemis.ComponentMapper import com.artemis.annotations.All +import com.artemis.annotations.Exclude import com.artemis.annotations.Wire import com.artemis.systems.IteratingSystem import com.badlogic.gdx.Gdx @@ -9,12 +10,12 @@ import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.physics.box2d.* import me.srikavin.fbla.game.Actions +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.graphics.player_foot_fixture_id import me.srikavin.fbla.game.physics.ContactListenerManager -import java.util.function.BiConsumer private const val JUMP_DELAY_SEC = 1.5f private const val MAX_HORIZONTAL_VELOCITY = 7f @@ -23,6 +24,7 @@ private val LEFT_FORCE = Vector2(-50f, 10.0f) private val RIGHT_FORCE = Vector2(50f, 10.0f) @All(PlayerControlled::class, PhysicsBody::class, Transform::class) +@Exclude(DisableInput::class) class InputSystem(private val listenerManager: ContactListenerManager) : IteratingSystem() { private lateinit var playerControlledMapper: ComponentMapper private lateinit var physicsBodyMapper: ComponentMapper @@ -66,16 +68,14 @@ class InputSystem(private val listenerManager: ContactListenerManager) : Iterati override fun process(entityId: Int) { val body = physicsBodyMapper[entityId].body - playerControlledMapper[entityId].bindings.bindings.forEach(BiConsumer { action, keyCode -> + playerControlledMapper[entityId].bindings.bindings.forEach { (action, keyCode) -> if (Gdx.input.isKeyPressed(keyCode)) { when (action) { Actions.JUMP -> { if (allowJump) { allowJump = false - } else { - return@BiConsumer + body.applyLinearImpulse(JUMP_IMPULSE, body.position, true) } - body.applyLinearImpulse(JUMP_IMPULSE, body.position, true) } Actions.MOVE_LEFT -> { if (body.linearVelocity.x > -MAX_HORIZONTAL_VELOCITY) { @@ -90,7 +90,7 @@ class InputSystem(private val listenerManager: ContactListenerManager) : Iterati Actions.USE -> TODO() } } - }) + } } 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 e2960bd..82956af 100644 --- a/core/src/me/srikavin/fbla/game/ecs/system/PhysicsSystem.kt +++ b/core/src/me/srikavin/fbla/game/ecs/system/PhysicsSystem.kt @@ -92,7 +92,7 @@ class PhysicsSystem(var physicsWorld: World, private val contactManager: Contact val footBox = FixtureDef().apply { this.isSensor = true this.shape = PolygonShape().apply { - setAsBox(0.4f, 0.1f, Vector2(0f, -1f), 0f) + setAsBox(0.5f, 0.05f, Vector2(0f, -1f), 0f) } } diff --git a/core/src/me/srikavin/fbla/game/ecs/system/TriggerSystem.kt b/core/src/me/srikavin/fbla/game/ecs/system/TriggerSystem.kt index 3154663..62eea09 100644 --- a/core/src/me/srikavin/fbla/game/ecs/system/TriggerSystem.kt +++ b/core/src/me/srikavin/fbla/game/ecs/system/TriggerSystem.kt @@ -12,6 +12,7 @@ import me.srikavin.fbla.game.EntityInt import me.srikavin.fbla.game.ecs.component.MapTrigger import me.srikavin.fbla.game.ecs.component.PhysicsBody import me.srikavin.fbla.game.physics.ContactListenerManager +import me.srikavin.fbla.game.trigger.TriggerManager @All(MapTrigger::class, PhysicsBody::class) @@ -19,6 +20,8 @@ class TriggerSystem(private val listenerManager: ContactListenerManager) : Itera private lateinit var triggerMapper: ComponentMapper private lateinit var physicsMapper: ComponentMapper + private val triggerManager = TriggerManager() + @Wire lateinit var camera: OrthographicCamera @@ -51,9 +54,9 @@ class TriggerSystem(private val listenerManager: ContactListenerManager) : Itera if (triggerMapper.has(e)) { val trigger = triggerMapper[e] - // Remove body outside of physics simulation + // Handle outside of physics simulation Gdx.app.postRunnable { - world.delete(e) + triggerManager.handle(world, e, other.userData as Int, trigger) } } diff --git a/core/src/me/srikavin/fbla/game/map/MapLoader.kt b/core/src/me/srikavin/fbla/game/map/MapLoader.kt index 5cd0c21..7cf3d34 100644 --- a/core/src/me/srikavin/fbla/game/map/MapLoader.kt +++ b/core/src/me/srikavin/fbla/game/map/MapLoader.kt @@ -176,7 +176,7 @@ class MapLoader(private val assetManager: AssetManager, private val world: World } info { vertices.joinToString { e -> e.toString() } } - if (vertices.size > 8) { + if (vertices.size / 2 >= 8) { info { "Polygon has greater than 8 vertices [${vertices.size / 2}] and will be triangulated" } val triangulator = EarClippingTriangulator() val triangles = triangulator.computeTriangles(vertices)