diff --git a/core/src/me/srikavin/fbla/game/ecs/system/PhysicsDebugSystem.kt b/core/src/me/srikavin/fbla/game/ecs/system/PhysicsDebugSystem.kt index ac5887d..92bd2b3 100644 --- a/core/src/me/srikavin/fbla/game/ecs/system/PhysicsDebugSystem.kt +++ b/core/src/me/srikavin/fbla/game/ecs/system/PhysicsDebugSystem.kt @@ -7,13 +7,18 @@ import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer import com.badlogic.gdx.physics.box2d.World -class PhysicsDebugSystem(var physicsWorld: World) : BaseSystem() { +/** + * Responsible for drawing overlays over box2d physics objects + */ +class PhysicsDebugSystem(var physicsWorld: World, var debug: Boolean = true) : BaseSystem() { private var debugRenderer = Box2DDebugRenderer() @Wire lateinit var camera: OrthographicCamera override fun processSystem() { - debugRenderer.render(physicsWorld, camera.combined) + if (debug) { + debugRenderer.render(physicsWorld, camera.combined) + } } } \ No newline at end of file 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 369a7bf..e7c2141 100644 --- a/core/src/me/srikavin/fbla/game/ecs/system/PhysicsSystem.kt +++ b/core/src/me/srikavin/fbla/game/ecs/system/PhysicsSystem.kt @@ -3,11 +3,9 @@ package me.srikavin.fbla.game.ecs.system import com.artemis.ComponentMapper import com.artemis.EntitySubscription import com.artemis.annotations.All -import com.artemis.annotations.Wire import com.artemis.managers.TagManager import com.artemis.systems.IteratingSystem import com.artemis.utils.IntBag -import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.physics.box2d.* import ktx.collections.GdxArray @@ -18,7 +16,10 @@ 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 - +/** + * Responsible for communicating and keeping entities in sync with Box2D. The physics engine uses a fixed timestep of + * 60 steps a second. + */ @All(Transform::class, PhysicsBody::class) class PhysicsSystem(var physicsWorld: World, private val contactManager: ContactListenerManager) : IteratingSystem() { lateinit var transformMapper: ComponentMapper @@ -90,7 +91,7 @@ class PhysicsSystem(var physicsWorld: World, private val contactManager: Contact if (e == world.getSystem(TagManager::class.java).getEntityId("PLAYER")) { val footBox = FixtureDef().apply { -// this.isSensor = true + // this.isSensor = true this.shape = PolygonShape().apply { setAsBox(0.5f, 0.05f, Vector2(0f, -1f), 0f) } @@ -116,15 +117,12 @@ class PhysicsSystem(var physicsWorld: World, private val contactManager: Contact } } - - @Wire - lateinit var camera: OrthographicCamera - override fun begin() { physicsWorld.step(1 / 60f, 6, 6) } override fun process(entityId: Int) { + // Update positions of physics entities transformMapper[entityId].position.set(physicsMapper[entityId].body.position) } } \ No newline at end of file diff --git a/core/src/me/srikavin/fbla/game/ecs/system/PlayerAnimationSystem.kt b/core/src/me/srikavin/fbla/game/ecs/system/PlayerAnimationSystem.kt index dce81e2..afb1b0a 100644 --- a/core/src/me/srikavin/fbla/game/ecs/system/PlayerAnimationSystem.kt +++ b/core/src/me/srikavin/fbla/game/ecs/system/PlayerAnimationSystem.kt @@ -4,20 +4,27 @@ import com.artemis.BaseSystem 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.PhysicsBody import me.srikavin.fbla.game.ecs.component.SwitchableAnimation +/** + * The value for the player jump animation within the graphics system + */ const val JUMP_ANIMATION = "Jump" -const val Walk_ANIMATION = "Walk" +/** + * The value for the player walk animation within the graphics system + */ +const val WALK_ANIMATION = "Walk" +/** + * The value for the player standing animation within the graphics system + */ const val STAND_ANIMATION = "Stand" -class PlayerAnimationSystem(val followVertical: Boolean = false, val followHorizontal: Boolean = true) : BaseSystem() { - lateinit var physicsBodyMapper: ComponentMapper - lateinit var switchableAnimationMapper: ComponentMapper - +class PlayerAnimationSystem : BaseSystem() { + @Wire + private lateinit var physicsBodyMapper: ComponentMapper @Wire - lateinit var camera: OrthographicCamera + private lateinit var switchableAnimationMapper: ComponentMapper override fun processSystem() { val player = world.getSystem(TagManager::class.java).getEntityId("PLAYER") @@ -27,21 +34,25 @@ class PlayerAnimationSystem(val followVertical: Boolean = false, val followHoriz val switchableAnimation = switchableAnimationMapper[player] val vel = physicsBodyComponent.body.linearVelocity - if (vel.x < -1f) { - switchableAnimation.currentState = "Walk" - switchableAnimation.mirror = true - switchableAnimation.looping = true - } else if (vel.x > 1f) { - switchableAnimation.currentState = "Walk" - switchableAnimation.mirror = false - switchableAnimation.looping = true - } else { - switchableAnimation.currentState = "Stand" - switchableAnimation.looping = true + when { + vel.x < -1f -> { + switchableAnimation.currentState = WALK_ANIMATION + switchableAnimation.mirror = true + switchableAnimation.looping = true + } + vel.x > 1f -> { + switchableAnimation.currentState = WALK_ANIMATION + switchableAnimation.mirror = false + switchableAnimation.looping = true + } + else -> { + switchableAnimation.currentState = STAND_ANIMATION + switchableAnimation.looping = true + } } if (vel.y > 1f) { - switchableAnimation.currentState = "Jump" + switchableAnimation.currentState = JUMP_ANIMATION switchableAnimation.looping = false } }