Skip to content

Commit

Permalink
make Entity configurable inside Tiled (tile properties)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quillraven committed Mar 24, 2024
1 parent 9e11f85 commit f567d42
Show file tree
Hide file tree
Showing 9 changed files with 398 additions and 294 deletions.
9 changes: 8 additions & 1 deletion assets/maps/objects.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.10.2" name="objects" tilewidth="32" tileheight="32" tilecount="1" columns="0">
<grid orientation="orthogonal" width="1" height="1"/>
<tile id="0">
<tile id="0" type="EntityDef">
<properties>
<property name="GameObject" propertytype="GameObject" value="FROG"/>
<property name="entityTags" propertytype="EntityTag" value="PLAYER,CAMERA_FOCUS"/>
<property name="hasAnimation" type="bool" value="true"/>
<property name="hasState" type="bool" value="true"/>
<property name="jumpHeight" type="float" value="3.2"/>
<property name="life" type="int" value="4"/>
<property name="speed" type="float" value="8"/>
<property name="timeToMaxSpeed" type="float" value="4.5"/>
</properties>
<image width="32" height="32" source="../graphics/object/frog.png"/>
<objectgroup draworder="index" id="2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.badlogic.gdx.utils.ObjectMap
import com.badlogic.gdx.utils.PropertiesUtils
import com.quillraven.github.quillyjumper.audio.AudioService
import com.quillraven.github.quillyjumper.screen.LoadingScreen
import com.quillraven.github.quillyjumper.util.FixtureDefUserData
import com.quillraven.github.quillyjumper.tiled.FixtureDefUserData
import ktx.app.KtxGame
import ktx.app.KtxScreen
import ktx.app.clearScreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.quillraven.github.quillyjumper.event.MapChangeEvent
import com.quillraven.github.quillyjumper.input.KeyboardInputProcessor
import com.quillraven.github.quillyjumper.inputMultiplexer
import com.quillraven.github.quillyjumper.system.*
import com.quillraven.github.quillyjumper.tiled.TiledService
import com.quillraven.github.quillyjumper.ui.GameModel
import com.quillraven.github.quillyjumper.ui.gameView
import ktx.app.KtxScreen
Expand All @@ -42,13 +43,15 @@ class GameScreen(
private val stage = Stage(uiViewport, batch)
private val physicWorld = createWorld(gravity = GRAVITY).apply { autoClearForces = false }
private val world = createEntityWorld(batch, audioService, gameProperties)
private val tiledService = TiledService(world, physicWorld, assets)
private val keyboardProcessor = KeyboardInputProcessor(world)
private val gameModel = GameModel(world)

override fun show() {
Gdx.input.inputMultiplexer.addProcessor(keyboardProcessor)
Gdx.input.inputMultiplexer.addProcessor(stage)

GameEventDispatcher.register(tiledService)
GameEventDispatcher.register(gameModel)
world.systems
.filterIsInstance<GameEventListener>()
Expand All @@ -67,6 +70,7 @@ class GameScreen(
override fun hide() {
Gdx.input.inputMultiplexer.clear()
GameEventDispatcher.unregister(gameModel)
GameEventDispatcher.unregister(tiledService)
world.systems
.filterIsInstance<GameEventListener>()
.forEach { GameEventDispatcher.unregister(it) }
Expand Down Expand Up @@ -139,7 +143,6 @@ class GameScreen(
}

systems {
add(SpawnSystem())
add(MoveSystem())
add(JumpPhysicSystem())
add(PhysicSystem())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.badlogic.gdx.maps.tiled.TiledMap
import com.quillraven.github.quillyjumper.*
import com.quillraven.github.quillyjumper.Quillyjumper.Companion.OBJECT_FIXTURES
import com.quillraven.github.quillyjumper.audio.AudioService
import com.quillraven.github.quillyjumper.util.fixtureDefOf
import com.quillraven.github.quillyjumper.tiled.TiledService.Companion.fixtureDefOf
import ktx.app.KtxScreen
import ktx.app.gdxError
import ktx.assets.disposeSafely
Expand Down

This file was deleted.

Loading

0 comments on commit f567d42

Please sign in to comment.