Skip to content

Commit

Permalink
add new saw enemy and track system support
Browse files Browse the repository at this point in the history
  • Loading branch information
Quillraven committed Mar 24, 2024
1 parent f567d42 commit 050043b
Show file tree
Hide file tree
Showing 28 changed files with 346 additions and 69 deletions.
3 changes: 2 additions & 1 deletion assets/game.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
soundVolume=0.5
musicVolume=0.01
debugPhysic=false
enableProfiling=false
enableProfiling=true
debugTrack=false
# NONE = 0 / DEBUG = 3 / INFO = 2 / ERROR = 1
logLevel=3
98 changes: 61 additions & 37 deletions assets/graphics/gameobject.atlas
Original file line number Diff line number Diff line change
@@ -1,111 +1,135 @@
gameobject.png
size:256,256
size:2048,64
repeat:none
frog/double_jump
index:2
bounds:38,182,32,32
bounds:482,8,32,32
frog/double_jump
index:4
bounds:110,182,32,32
bounds:806,8,32,32
frog/double_jump
index:1
bounds:110,146,32,32
bounds:986,8,32,32
frog/double_jump
index:3
bounds:218,218,32,32
bounds:1310,8,32,32
frog/double_jump
index:0
bounds:182,146,32,32
bounds:1490,8,32,32
frog/double_jump
index:5
bounds:110,38,32,32
bounds:1598,8,32,32
frog/fall
index:0
bounds:38,110,32,32
bounds:734,8,32,32
frog/hit
index:4
bounds:74,218,32,32
bounds:518,8,32,32
frog/hit
index:1
bounds:110,218,32,32
bounds:662,8,32,32
frog/hit
index:3
bounds:146,182,32,32
bounds:1022,8,32,32
frog/hit
index:0
bounds:110,110,32,32
bounds:1202,8,32,32
frog/hit
index:2
bounds:218,182,32,32
bounds:1526,8,32,32
frog/idle
index:4
bounds:2,218,32,32
bounds:338,8,32,32
frog/idle
index:9
bounds:2,146,32,32
bounds:446,8,32,32
frog/idle
index:1
bounds:2,110,32,32
bounds:554,8,32,32
frog/idle
index:6
bounds:74,182,32,32
bounds:626,8,32,32
frog/idle
index:3
bounds:146,218,32,32
bounds:842,8,32,32
frog/idle
index:8
bounds:74,110,32,32
bounds:950,8,32,32
frog/idle
index:0
bounds:182,218,32,32
bounds:1058,8,32,32
frog/idle
index:5
bounds:38,38,32,32
bounds:1130,8,32,32
frog/idle
index:10
bounds:146,146,32,32
bounds:1238,8,32,32
frog/idle
index:2
bounds:38,2,32,32
bounds:1346,8,32,32
frog/idle
index:7
bounds:146,110,32,32
bounds:1454,8,32,32
frog/jump
index:0
bounds:74,146,32,32
bounds:770,8,32,32
frog/run
index:10
bounds:2,182,32,32
bounds:374,8,32,32
frog/run
index:2
bounds:38,218,32,32
bounds:410,8,32,32
frog/run
index:7
bounds:38,146,32,32
bounds:590,8,32,32
frog/run
index:4
bounds:2,74,32,32
bounds:698,8,32,32
frog/run
index:9
bounds:2,38,32,32
bounds:878,8,32,32
frog/run
index:1
bounds:38,74,32,32
bounds:914,8,32,32
frog/run
index:6
bounds:2,2,32,32
bounds:1094,8,32,32
frog/run
index:11
bounds:74,74,32,32
bounds:1166,8,32,32
frog/run
index:3
bounds:182,182,32,32
bounds:1274,8,32,32
frog/run
index:8
bounds:74,38,32,32
bounds:1382,8,32,32
frog/run
index:0
bounds:110,74,32,32
bounds:1418,8,32,32
frog/run
index:5
bounds:74,2,32,32
bounds:1562,8,32,32
saw/idle
index:0
bounds:2,2,38,38
saw/idle
index:5
bounds:44,2,38,38
saw/idle
index:2
bounds:86,2,38,38
saw/idle
index:7
bounds:128,2,38,38
saw/idle
index:4
bounds:170,2,38,38
saw/idle
index:1
bounds:212,2,38,38
saw/idle
index:6
bounds:254,2,38,38
saw/idle
index:3
bounds:296,2,38,38
Binary file modified assets/graphics/gameobject.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/graphics/object/saw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 21 additions & 1 deletion assets/maps/objects.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?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">
<tileset version="1.10" tiledversion="1.10.2" name="objects" tilewidth="38" tileheight="38" tilecount="2" columns="0">
<grid orientation="orthogonal" width="1" height="1"/>
<tile id="0" type="EntityDef">
<properties>
Expand Down Expand Up @@ -40,4 +40,24 @@
</object>
</objectgroup>
</tile>
<tile id="1" type="EntityDef">
<properties>
<property name="GameObject" propertytype="GameObject" value="SAW"/>
<property name="bodyType" propertytype="BodyType" value="KinematicBody"/>
<property name="entityTags" propertytype="EntityTag" value="FOLLOW_TRACK"/>
<property name="hasAnimation" type="bool" value="true"/>
<property name="speed" type="float" value="3"/>
</properties>
<image width="38" height="38" source="../graphics/object/saw.png"/>
<objectgroup draworder="index" id="2">
<object id="1" type="FixtureDef" x="3" y="3" width="32" height="32">
<properties>
<property name="density" type="float" value="100"/>
<property name="isChain" type="bool" value="true"/>
<property name="userData" value="hitbox"/>
</properties>
<ellipse/>
</object>
</objectgroup>
</tile>
</tileset>
26 changes: 18 additions & 8 deletions assets/maps/test.tmx
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="20" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="5" nextobjectid="4">
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="30" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="13">
<properties>
<property name="musicAsset" value="TUTORIAL"/>
<property name="name" value="Tutorial"/>
</properties>
<tileset firstgid="1" source="terrain.tsx"/>
<tileset firstgid="243" source="objects.tsx"/>
<layer id="1" name="ground" width="20" height="10">
<layer id="1" name="ground" width="30" height="10">
<data encoding="base64" compression="zlib">
eJxjYBgF6IAdiDmgmHOA3UIpQPYLLsxJpHqQOlkgliOA5ZHMw6dengbmGQOxCQFsimQePvUgdQAqcAiR
eJxjYBgFgwWwAzEHFHMOsFtwgcHuRmT34cKcJKonxjxZIJYjgOWR7CVGPTHmDZS9xkBsQgCbItlLjHpizAMArX8NYQ==
</data>
</layer>
<layer id="2" name="decoration" width="20" height="10">
<layer id="2" name="decoration" width="30" height="10">
<data encoding="base64" compression="zlib">
eJxjYBgF1ALsQMyJRdwYiE2g2JQE82SBWJ4K7hpsQAGIFQmIYVNDjBy1AQBsygIh
eJxjYBgFIwWwAzEnFnFjIDaBYlMa2CsLxPIUmkFrNw4GoADEilTSi88sUu0hVT0tAQCPawMy
</data>
</layer>
<objectgroup id="3" name="objects">
<object id="3" gid="243" x="-6" y="96" width="32" height="32"/>
<object id="3" gid="243" x="209" y="94" width="32" height="32"/>
<object id="4" gid="244" x="333" y="75" width="38" height="38"/>
<object id="11" gid="244" x="269" y="105" width="38" height="38"/>
</objectgroup>
<layer id="4" name="foreground" width="20" height="10">
<objectgroup id="5" name="tracks">
<object id="10" x="320" y="57">
<polygon points="0,0 64,-1 80,-25"/>
</object>
<object id="12" x="288" y="96">
<polyline points="0,0 0,-80"/>
</object>
</objectgroup>
<layer id="4" name="foreground" width="30" height="10">
<data encoding="base64" compression="zlib">
eJxjYBgFo2AU4AIAAyAAAQ==
eJxjYBgFo2AUjIKhAQAEsAAB
</data>
</layer>
</map>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.quillraven.github.quillyjumper

enum class GameObject {
FROG;
FROG,
SAW;

val atlasKey: String = name.lowercase()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data class GameProperties(
val musicVolume: Float,
val debugPhysic: Boolean,
val enableProfiling: Boolean,
val debugTrack: Boolean,
val logLevel: Int,
)

Expand All @@ -16,6 +17,7 @@ fun ObjectMap<String, String>.toGameProperties() = GameProperties(
musicVolume = getOrDefault("musicVolume", 1f),
debugPhysic = getOrDefault("debugPhysic", false),
enableProfiling = getOrDefault("enableProfiling", false),
debugTrack = getOrDefault("debugTrack", false),
logLevel = getOrDefault("logLevel", Application.LOG_INFO),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import com.github.quillraven.fleks.EntityTags
import com.github.quillraven.fleks.entityTagOf

enum class EntityTag : EntityTags by entityTagOf() {
PLAYER, CAMERA_FOCUS
PLAYER, CAMERA_FOCUS, FOLLOW_TRACK
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.quillraven.github.quillyjumper.component

import com.badlogic.gdx.math.Rectangle
import com.github.quillraven.fleks.Component
import com.github.quillraven.fleks.ComponentType
import com.quillraven.github.quillyjumper.GameObject

data class Tiled(
val gameObject: GameObject,
val mapObjectID: Int
val mapObjectID: Int,
val mapObjectBoundary: Rectangle, // units are in Tiled units (=pixels instead of world units)
) : Component<Tiled> {
override fun type() = Tiled

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.quillraven.github.quillyjumper.component

import com.badlogic.gdx.math.Vector2
import com.github.quillraven.fleks.Component
import com.github.quillraven.fleks.ComponentType

data class Track(
val trackPoints: List<Vector2>,
val closedTrack: Boolean,
var currentIdx: Int = -1,
var moveX: Float = 0f,
var moveY: Float = 0f,
var angleRad: Float = 0f,
) : Component<Track> {
override fun type() = Track

companion object : ComponentType<Track>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class GameScreen(
world.systems
.filterIsInstance<GameEventListener>()
.forEach { GameEventDispatcher.register(it) }
physicWorld.setContactListener(world.system<PhysicSystem>())

// setup UI
stage.actors {
Expand Down Expand Up @@ -144,6 +145,7 @@ class GameScreen(

systems {
add(MoveSystem())
add(TrackSystem())
add(JumpPhysicSystem())
add(PhysicSystem())
add(StateSystem())
Expand All @@ -156,6 +158,9 @@ class GameScreen(
if (gameProperties.enableProfiling) {
add(GlProfilerSystem())
}
if (gameProperties.debugTrack) {
add(TrackDebugSystem())
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GlProfilerSystem : IntervalSystem() {
private val profiler = GLProfiler(Gdx.graphics).apply { enable() }

override fun onTick() {
Gdx.graphics.setTitle("bindings: ${profiler.textureBindings}, drawCalls: ${profiler.drawCalls}, calls: ${profiler.calls}")
Gdx.graphics.setTitle("bindings: ${profiler.textureBindings}, drawCalls: ${profiler.drawCalls}, calls: ${profiler.calls} fps: ${Gdx.app.graphics.framesPerSecond}")

profiler.reset()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import com.github.quillraven.fleks.World.Companion.family
import com.quillraven.github.quillyjumper.component.Graphic
import com.quillraven.github.quillyjumper.component.Move
import com.quillraven.github.quillyjumper.component.MoveDirection
import com.quillraven.github.quillyjumper.component.Track

class MoveSystem : IteratingSystem(family { all(Move) }) {
class MoveSystem : IteratingSystem(family { all(Move).none(Track) }) {

override fun onTickEntity(entity: Entity) {
val moveCmp = entity[Move]
Expand All @@ -29,7 +30,7 @@ class MoveSystem : IteratingSystem(family { all(Move) }) {
}

moveCmp.timer = (timer + (deltaTime * (1f / timeToMax))).coerceAtMost(1f)
moveCmp.current = Interpolation.pow5Out.apply(MIN_SPEED, max, moveCmp.timer) * direction.value
moveCmp.current = MOVE_INTERPOLATION.apply(MIN_SPEED, max, moveCmp.timer) * direction.value
return
}

Expand All @@ -39,7 +40,8 @@ class MoveSystem : IteratingSystem(family { all(Move) }) {
}

companion object {
private const val MIN_SPEED = 1f
const val MIN_SPEED = 1f
val MOVE_INTERPOLATION = Interpolation.pow5Out
}

}
Loading

0 comments on commit 050043b

Please sign in to comment.