Skip to content

Commit

Permalink
add second enemy (rock head with four direction movement)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quillraven committed Mar 31, 2024
1 parent 2ed2155 commit 0273a67
Show file tree
Hide file tree
Showing 27 changed files with 492 additions and 191 deletions.
103 changes: 59 additions & 44 deletions assets/graphics/gameobject.atlas
Original file line number Diff line number Diff line change
Expand Up @@ -3,133 +3,148 @@ size:2048,64
repeat:none
frog/double_jump
index:2
bounds:482,8,32,32
bounds:712,12,32,32
frog/double_jump
index:4
bounds:806,8,32,32
bounds:1036,12,32,32
frog/double_jump
index:1
bounds:986,8,32,32
bounds:1216,12,32,32
frog/double_jump
index:3
bounds:1310,8,32,32
bounds:1540,12,32,32
frog/double_jump
index:0
bounds:1490,8,32,32
bounds:1720,12,32,32
frog/double_jump
index:5
bounds:1598,8,32,32
bounds:1828,12,32,32
frog/fall
index:0
bounds:734,8,32,32
bounds:964,12,32,32
frog/hit
index:4
bounds:518,8,32,32
bounds:748,12,32,32
frog/hit
index:1
bounds:662,8,32,32
bounds:892,12,32,32
frog/hit
index:3
bounds:1022,8,32,32
bounds:1252,12,32,32
frog/hit
index:0
bounds:1202,8,32,32
bounds:1432,12,32,32
frog/hit
index:2
bounds:1526,8,32,32
bounds:1756,12,32,32
frog/idle
index:4
bounds:338,8,32,32
bounds:568,12,32,32
frog/idle
index:9
bounds:446,8,32,32
bounds:676,12,32,32
frog/idle
index:1
bounds:554,8,32,32
bounds:784,12,32,32
frog/idle
index:6
bounds:626,8,32,32
bounds:856,12,32,32
frog/idle
index:3
bounds:842,8,32,32
bounds:1072,12,32,32
frog/idle
index:8
bounds:950,8,32,32
bounds:1180,12,32,32
frog/idle
index:0
bounds:1058,8,32,32
bounds:1288,12,32,32
frog/idle
index:5
bounds:1130,8,32,32
bounds:1360,12,32,32
frog/idle
index:10
bounds:1238,8,32,32
bounds:1468,12,32,32
frog/idle
index:2
bounds:1346,8,32,32
bounds:1576,12,32,32
frog/idle
index:7
bounds:1454,8,32,32
bounds:1684,12,32,32
frog/jump
index:0
bounds:770,8,32,32
bounds:1000,12,32,32
frog/run
index:10
bounds:374,8,32,32
bounds:604,12,32,32
frog/run
index:2
bounds:410,8,32,32
bounds:640,12,32,32
frog/run
index:7
bounds:590,8,32,32
bounds:820,12,32,32
frog/run
index:4
bounds:698,8,32,32
bounds:928,12,32,32
frog/run
index:9
bounds:878,8,32,32
bounds:1108,12,32,32
frog/run
index:1
bounds:914,8,32,32
bounds:1144,12,32,32
frog/run
index:6
bounds:1094,8,32,32
bounds:1324,12,32,32
frog/run
index:11
bounds:1166,8,32,32
bounds:1396,12,32,32
frog/run
index:3
bounds:1274,8,32,32
bounds:1504,12,32,32
frog/run
index:8
bounds:1382,8,32,32
bounds:1612,12,32,32
frog/run
index:0
bounds:1418,8,32,32
bounds:1648,12,32,32
frog/run
index:5
bounds:1562,8,32,32
bounds:1792,12,32,32
rock-head/aggro
index:1
bounds:2,2,42,42
rock-head/aggro
index:0
bounds:94,2,42,42
rock-head/aggro
index:2
bounds:186,2,42,42
rock-head/idle
index:0
bounds:48,2,42,42
rock-head/run
index:0
bounds:140,2,42,42
saw/idle
index:0
bounds:2,2,38,38
bounds:232,6,38,38
saw/idle
index:5
bounds:44,2,38,38
bounds:274,6,38,38
saw/idle
index:2
bounds:86,2,38,38
bounds:316,6,38,38
saw/idle
index:7
bounds:128,2,38,38
bounds:358,6,38,38
saw/idle
index:4
bounds:170,2,38,38
bounds:400,6,38,38
saw/idle
index:1
bounds:212,2,38,38
bounds:442,6,38,38
saw/idle
index:6
bounds:254,2,38,38
bounds:484,6,38,38
saw/idle
index:3
bounds:296,2,38,38
bounds:526,6,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/rock-head.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 38 additions & 1 deletion assets/maps/objects.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.10" tiledversion="1.10.2" name="objects" tilewidth="38" tileheight="38" tilecount="2" columns="0">
<tileset version="1.10" tiledversion="1.10.2" name="objects" tilewidth="42" tileheight="42" tilecount="3" columns="0">
<grid orientation="orthogonal" width="1" height="1"/>
<tile id="0" type="EntityDef">
<properties>
<property name="entityTags" propertytype="EntityTag" value="PLAYER,CAMERA_FOCUS"/>
<property name="gameObject" propertytype="GameObject" value="FROG"/>
<property name="hasAnimation" type="bool" value="true"/>
<property name="hasState" type="bool" value="true"/>
<property name="initialState" value="IDLE"/>
<property name="jumpHeight" type="float" value="3.2"/>
<property name="life" type="int" value="4"/>
<property name="speed" type="float" value="8"/>
Expand Down Expand Up @@ -48,6 +49,7 @@
<property name="gameObject" propertytype="GameObject" value="SAW"/>
<property name="hasAnimation" type="bool" value="true"/>
<property name="hasTrack" type="bool" value="true"/>
<property name="initialState" value=""/>
<property name="speed" type="float" value="3"/>
</properties>
<image width="38" height="38" source="../graphics/object/saw.png"/>
Expand All @@ -63,4 +65,39 @@
</object>
</objectgroup>
</tile>
<tile id="2" type="EntityDef">
<properties>
<property name="bodyType" propertytype="BodyType" value="KinematicBody"/>
<property name="damage" type="int" value="1"/>
<property name="gameObject" propertytype="GameObject" value="ROCK_HEAD"/>
<property name="hasAggro" type="bool" value="true"/>
<property name="hasAnimation" type="bool" value="true"/>
<property name="initialState" value="ROCK_HEAD_IDLE"/>
<property name="speed" type="float" value="12"/>
<property name="timeToMaxSpeed" type="float" value="3"/>
</properties>
<image width="42" height="42" source="../graphics/object/rock-head.png"/>
<objectgroup draworder="index" id="2">
<object id="1" type="FixtureDef" x="6" y="6" width="30" height="30">
<properties>
<property name="density" type="float" value="100"/>
<property name="userData" value="hitbox"/>
</properties>
</object>
<object id="2" type="FixtureDef" x="0" y="-64" width="42" height="170">
<properties>
<property name="isChain" type="bool" value="false"/>
<property name="isSensor" type="bool" value="true"/>
<property name="userData" value="aggroSensor"/>
</properties>
</object>
<object id="3" type="FixtureDef" x="-64" y="0" width="170" height="42">
<properties>
<property name="isChain" type="bool" value="false"/>
<property name="isSensor" type="bool" value="true"/>
<property name="userData" value="aggroSensor"/>
</properties>
</object>
</objectgroup>
</tile>
</tileset>
29 changes: 16 additions & 13 deletions assets/maps/test.tmx
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="30" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="8" nextobjectid="15">
<map version="1.10" tiledversion="1.10.2" orientation="orthogonal" renderorder="right-down" width="40" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="8" nextobjectid="19">
<properties>
<property name="musicAsset" value="TUTORIAL"/>
<property name="name" value="Tutorial"/>
</properties>
<tileset firstgid="1" source="terrain.tsx"/>
<tileset firstgid="243" source="objects.tsx"/>
<objectgroup id="6" name="bgdObjects">
<object id="13" gid="244" x="158" y="63" width="38" height="38">
<object id="13" gid="244" x="318" y="63" width="38" height="38">
<properties>
<property name="entityTags" propertytype="EntityTag" value=""/>
<property name="hasTrack" type="bool" value="false"/>
</properties>
</object>
<object id="4" gid="244" x="333" y="75" width="38" height="38"/>
<object id="4" gid="244" x="493" y="75" width="38" height="38"/>
</objectgroup>
<layer id="1" name="ground" width="30" height="10">
<layer id="1" name="ground" width="40" height="10">
<data encoding="base64" compression="zlib">
eJxjYBgFgwWwAzEHFHMOsFtwgcHuRmT34cKcJKonxjxZIJYjgOWR7CVGPTHmDZS9xkBsQgCbItlLjHpizAMArX8NYQ==
eJxjYBgFo4A4wA7EHFDMOcBuoRQMF78g+4NSzEllc0HmyQKxHJWwPJL7qGGu/BBwnzEQm1AJmyK5jxrmgswDADrHEhE=
</data>
</layer>
<layer id="2" name="decoration" width="30" height="10">
<layer id="2" name="decoration" width="40" height="10">
<data encoding="base64" compression="zlib">
eJxjYBgFIwWwAzEnFnFjIDaBYlMa2CsLxPIUmkFrNw4GoADEilTSi88sUu0hVT0tAQCPawMy
eJxjYBgFo2DgADsQc+DAnHj0YJMzBmITKDalkvtkgVgOB5bHoweXHLGAFn4Z7kABiBXpbAc+O/HJUUP9YAAA8d4EYg==
</data>
</layer>
<objectgroup id="3" name="objects">
<object id="3" gid="243" x="103" y="97" width="32" height="32"/>
<object id="3" gid="243" x="127" y="96" width="32" height="32"/>
<object id="16" gid="245" x="-3" y="69" width="42" height="42"/>
<object id="17" gid="245" x="300" y="100" width="42" height="42"/>
<object id="18" gid="245" x="163" y="31" width="42" height="42"/>
</objectgroup>
<objectgroup id="7" name="fgdObjects">
<object id="11" gid="244" x="269" y="105" width="38" height="38"/>
<object id="11" gid="244" x="429" y="105" width="38" height="38"/>
</objectgroup>
<objectgroup id="5" name="tracks">
<object id="10" x="320" y="57">
<object id="10" x="480" y="57">
<polygon points="0,0 64,-1 80,-25"/>
</object>
<object id="12" x="288" y="96">
<object id="12" x="448" y="96">
<polyline points="0,0 0,-80"/>
</object>
</objectgroup>
<layer id="4" name="foreground" width="30" height="10">
<layer id="4" name="foreground" width="40" height="10">
<data encoding="base64" compression="zlib">
eJxjYBgFo2AUjIKhAQAEsAAB
eJxjYBgFo2AUjIJRMApIBwAGQAAB
</data>
</layer>
</map>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package com.quillraven.github.quillyjumper

enum class GameObject {
FROG,
SAW;
SAW,
ROCK_HEAD;

val atlasKey: String = name.lowercase()
val atlasKey: String = name.lowercase().replace("_", "-")
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.quillraven.github.quillyjumper.ai

import com.badlogic.gdx.graphics.g2d.Animation.PlayMode
import com.badlogic.gdx.math.Vector2
import com.github.quillraven.fleks.Component
import com.github.quillraven.fleks.ComponentType
import com.github.quillraven.fleks.Entity
import com.github.quillraven.fleks.World
import com.quillraven.github.quillyjumper.component.AnimationType
import com.quillraven.github.quillyjumper.component.State
import com.quillraven.github.quillyjumper.component.*
import com.quillraven.github.quillyjumper.util.entityAnimation
import kotlin.math.atan2

data class AiEntity(val entity: Entity, val world: World) {

fun animation(type: AnimationType) {
world.entityAnimation(entity, type)
fun animation(type: AnimationType, playMode: PlayMode = PlayMode.LOOP) {
world.entityAnimation(entity, type, playMode)
}

inline operator fun <reified T : Component<*>> get(type: ComponentType<T>): T = with(world) {
Expand All @@ -22,4 +24,40 @@ data class AiEntity(val entity: Entity, val world: World) {
entity[State].fsm.changeState(state)
}

fun aggroTarget(): Entity? = with(world) {
val (aggroEntities) = entity[Aggro]
if (aggroEntities.isEmpty()) {
return null
}

return aggroEntities.firstOrNull { it has EntityTag.PLAYER }
}

fun notInRange(location: Vector2, tolerance: Float): Boolean = with(world) {
val (_, center) = entity[Graphic]
val diffX = location.x - center.x
val diffY = location.y - center.y

return (diffX * diffX) + (diffY * diffY) > tolerance * tolerance
}

fun inRange(location: Vector2, tolerance: Float): Boolean = with(world) {
val (_, center) = entity[Graphic]
val diffX = location.x - center.x
val diffY = location.y - center.y

return (diffX * diffX) + (diffY * diffY) <= tolerance * tolerance
}

fun inRange(target: Entity, tolerance: Float): Boolean = with(world) {
return inRange(target[Graphic].center, tolerance)
}

fun angleTo(target: Entity): Float = with(world) {
val (_, center) = entity[Graphic]
val (_, targetCenter) = target[Graphic]

return atan2(targetCenter.y - center.y, targetCenter.x - center.x)
}

}
Loading

0 comments on commit 0273a67

Please sign in to comment.