parent
673bc06cc1
commit
911b636530
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
@ -0,0 +1,106 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<TextureAtlas imagePath="sprites.png">
|
||||
<!--
|
||||
Created with ShoeBox
|
||||
http://renderhjs.net/shoebox/
|
||||
-->
|
||||
<SubTexture name="hitman1_gun.png" x="210" y="440" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="hitman1_hold.png" x="332" y="308" width="35" height="43" frameX="-0" frameY="-0" frameWidth="35" frameHeight="43"/>
|
||||
<SubTexture name="hitman1_machine.png" x="160" y="440" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="hitman1_reload.png" x="213" y="220" width="39" height="43" frameX="-0" frameY="-0" frameWidth="39" frameHeight="43"/>
|
||||
<SubTexture name="hitman1_silencer.png" x="55" y="440" width="54" height="43" frameX="-0" frameY="-0" frameWidth="54" frameHeight="43"/>
|
||||
<SubTexture name="hitman1_stand.png" x="337" y="0" width="33" height="43" frameX="-0" frameY="-0" frameWidth="33" frameHeight="43"/>
|
||||
<SubTexture name="hitman2_gun.png" x="111" y="88" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="hitman2_hold.png" x="332" y="352" width="35" height="43" frameX="-0" frameY="-0" frameWidth="35" frameHeight="43"/>
|
||||
<SubTexture name="hitman2_machine.png" x="110" y="440" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="hitman2_reload.png" x="255" y="308" width="39" height="43" frameX="-0" frameY="-0" frameWidth="39" frameHeight="43"/>
|
||||
<SubTexture name="hitman2_silencer.png" x="0" y="396" width="54" height="43" frameX="-0" frameY="-0" frameWidth="54" frameHeight="43"/>
|
||||
<SubTexture name="hitman2_stand.png" x="368" y="352" width="33" height="43" frameX="-0" frameY="-0" frameWidth="33" frameHeight="43"/>
|
||||
<SubTexture name="manBlue_gun.png" x="111" y="0" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="manBlue_hold.png" x="332" y="176" width="35" height="43" frameX="-0" frameY="-0" frameWidth="35" frameHeight="43"/>
|
||||
<SubTexture name="manBlue_machine.png" x="111" y="44" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="manBlue_reload.png" x="253" y="220" width="39" height="43" frameX="-0" frameY="-0" frameWidth="39" frameHeight="43"/>
|
||||
<SubTexture name="manBlue_silencer.png" x="55" y="396" width="54" height="43" frameX="-0" frameY="-0" frameWidth="54" frameHeight="43"/>
|
||||
<SubTexture name="manBlue_stand.png" x="369" y="264" width="33" height="43" frameX="-0" frameY="-0" frameWidth="33" frameHeight="43"/>
|
||||
<SubTexture name="manBrown_gun.png" x="111" y="132" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="manBrown_hold.png" x="336" y="88" width="35" height="43" frameX="-0" frameY="-0" frameWidth="35" frameHeight="43"/>
|
||||
<SubTexture name="manBrown_machine.png" x="161" y="132" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="manBrown_reload.png" x="260" y="440" width="39" height="43" frameX="-0" frameY="-0" frameWidth="39" frameHeight="43"/>
|
||||
<SubTexture name="manBrown_silencer.png" x="55" y="352" width="54" height="43" frameX="-0" frameY="-0" frameWidth="54" frameHeight="43"/>
|
||||
<SubTexture name="manBrown_stand.png" x="368" y="132" width="33" height="43" frameX="-0" frameY="-0" frameWidth="33" frameHeight="43"/>
|
||||
<SubTexture name="manOld_gun.png" x="162" y="352" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="manOld_hold.png" x="333" y="396" width="35" height="43" frameX="-0" frameY="-0" frameWidth="35" frameHeight="43"/>
|
||||
<SubTexture name="manOld_machine.png" x="161" y="0" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="manOld_reload.png" x="255" y="264" width="39" height="43" frameX="-0" frameY="-0" frameWidth="39" frameHeight="43"/>
|
||||
<SubTexture name="manOld_silencer.png" x="0" y="308" width="54" height="43" frameX="-0" frameY="-0" frameWidth="54" frameHeight="43"/>
|
||||
<SubTexture name="manOld_stand.png" x="368" y="308" width="33" height="43" frameX="-0" frameY="-0" frameWidth="33" frameHeight="43"/>
|
||||
<SubTexture name="manRed_gun.png" x="161" y="88" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="manRed_hold.png" x="336" y="44" width="35" height="43" frameX="-0" frameY="-0" frameWidth="35" frameHeight="43"/>
|
||||
<SubTexture name="manRed_machine.png" x="163" y="176" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="manRed_reload.png" x="261" y="0" width="39" height="43" frameX="-0" frameY="-0" frameWidth="39" frameHeight="43"/>
|
||||
<SubTexture name="manRed_silencer.png" x="0" y="264" width="54" height="43" frameX="-0" frameY="-0" frameWidth="54" frameHeight="43"/>
|
||||
<SubTexture name="manRed_stand.png" x="369" y="396" width="33" height="43" frameX="-0" frameY="-0" frameWidth="33" frameHeight="43"/>
|
||||
<SubTexture name="robot1_gun.png" x="211" y="44" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="robot1_hold.png" x="332" y="220" width="35" height="43" frameX="-0" frameY="-0" frameWidth="35" frameHeight="43"/>
|
||||
<SubTexture name="robot1_machine.png" x="163" y="220" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="robot1_reload.png" x="255" y="352" width="39" height="43" frameX="-0" frameY="-0" frameWidth="39" frameHeight="43"/>
|
||||
<SubTexture name="robot1_silencer.png" x="0" y="440" width="54" height="43" frameX="-0" frameY="-0" frameWidth="54" frameHeight="43"/>
|
||||
<SubTexture name="robot1_stand.png" x="368" y="176" width="33" height="43" frameX="-0" frameY="-0" frameWidth="33" frameHeight="43"/>
|
||||
<SubTexture name="robot2_gun.png" x="162" y="264" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="robot2_hold.png" x="333" y="264" width="35" height="43" frameX="-0" frameY="-0" frameWidth="35" frameHeight="43"/>
|
||||
<SubTexture name="robot2_machine.png" x="161" y="44" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="robot2_reload.png" x="253" y="176" width="39" height="43" frameX="-0" frameY="-0" frameWidth="39" frameHeight="43"/>
|
||||
<SubTexture name="robot2_silencer.png" x="0" y="352" width="54" height="43" frameX="-0" frameY="-0" frameWidth="54" frameHeight="43"/>
|
||||
<SubTexture name="robot2_stand.png" x="337" y="440" width="33" height="43" frameX="-0" frameY="-0" frameWidth="33" frameHeight="43"/>
|
||||
<SubTexture name="soldier1_gun.png" x="110" y="220" width="52" height="43" frameX="-0" frameY="-0" frameWidth="52" frameHeight="43"/>
|
||||
<SubTexture name="soldier1_hold.png" x="261" y="44" width="38" height="43" frameX="-0" frameY="-0" frameWidth="38" frameHeight="43"/>
|
||||
<SubTexture name="soldier1_machine.png" x="58" y="132" width="52" height="43" frameX="-0" frameY="-0" frameWidth="52" frameHeight="43"/>
|
||||
<SubTexture name="soldier1_reload.png" x="212" y="264" width="42" height="43" frameX="-0" frameY="-0" frameWidth="42" frameHeight="43"/>
|
||||
<SubTexture name="soldier1_silencer.png" x="0" y="88" width="57" height="43" frameX="-0" frameY="-0" frameWidth="57" frameHeight="43"/>
|
||||
<SubTexture name="soldier1_stand.png" x="300" y="440" width="36" height="43" frameX="-0" frameY="-0" frameWidth="36" frameHeight="43"/>
|
||||
<SubTexture name="soldier2_gun.png" x="58" y="0" width="52" height="43" frameX="-0" frameY="-0" frameWidth="52" frameHeight="43"/>
|
||||
<SubTexture name="soldier2_hold.png" x="293" y="176" width="38" height="43" frameX="-0" frameY="-0" frameWidth="38" frameHeight="43"/>
|
||||
<SubTexture name="soldier2_machine.png" x="57" y="220" width="52" height="43" frameX="-0" frameY="-0" frameWidth="52" frameHeight="43"/>
|
||||
<SubTexture name="soldier2_reload.png" x="211" y="132" width="42" height="43" frameX="-0" frameY="-0" frameWidth="42" frameHeight="43"/>
|
||||
<SubTexture name="soldier2_silencer.png" x="0" y="132" width="57" height="43" frameX="-0" frameY="-0" frameWidth="57" frameHeight="43"/>
|
||||
<SubTexture name="soldier2_stand.png" x="296" y="396" width="36" height="43" frameX="-0" frameY="-0" frameWidth="36" frameHeight="43"/>
|
||||
<SubTexture name="survivor1_gun.png" x="110" y="352" width="51" height="43" frameX="-0" frameY="-0" frameWidth="51" frameHeight="43"/>
|
||||
<SubTexture name="survivor1_hold.png" x="295" y="264" width="37" height="43" frameX="-0" frameY="-0" frameWidth="37" frameHeight="43"/>
|
||||
<SubTexture name="survivor1_machine.png" x="110" y="396" width="51" height="43" frameX="-0" frameY="-0" frameWidth="51" frameHeight="43"/>
|
||||
<SubTexture name="survivor1_reload.png" x="254" y="396" width="41" height="43" frameX="-0" frameY="-0" frameWidth="41" frameHeight="43"/>
|
||||
<SubTexture name="survivor1_silencer.png" x="0" y="220" width="56" height="43" frameX="-0" frameY="-0" frameWidth="56" frameHeight="43"/>
|
||||
<SubTexture name="survivor1_stand.png" x="301" y="0" width="35" height="43" frameX="-0" frameY="-0" frameWidth="35" frameHeight="43"/>
|
||||
<SubTexture name="survivor2_gun.png" x="110" y="308" width="51" height="43" frameX="-0" frameY="-0" frameWidth="51" frameHeight="43"/>
|
||||
<SubTexture name="survivor2_hold.png" x="294" y="132" width="37" height="43" frameX="-0" frameY="-0" frameWidth="37" frameHeight="43"/>
|
||||
<SubTexture name="survivor2_machine.png" x="110" y="264" width="51" height="43" frameX="-0" frameY="-0" frameWidth="51" frameHeight="43"/>
|
||||
<SubTexture name="survivor2_reload.png" x="212" y="396" width="41" height="43" frameX="-0" frameY="-0" frameWidth="41" frameHeight="43"/>
|
||||
<SubTexture name="survivor2_silencer.png" x="0" y="176" width="56" height="43" frameX="-0" frameY="-0" frameWidth="56" frameHeight="43"/>
|
||||
<SubTexture name="survivor2_stand.png" x="300" y="44" width="35" height="43" frameX="-0" frameY="-0" frameWidth="35" frameHeight="43"/>
|
||||
<SubTexture name="weapon_gun.png" x="26" y="495" width="19" height="10" frameX="-0" frameY="-0" frameWidth="19" frameHeight="10"/>
|
||||
<SubTexture name="weapon_machine.png" x="0" y="484" width="33" height="10" frameX="-0" frameY="-0" frameWidth="33" frameHeight="10"/>
|
||||
<SubTexture name="weapon_silencer.png" x="0" y="495" width="25" height="10" frameX="-0" frameY="-0" frameWidth="25" frameHeight="10"/>
|
||||
<SubTexture name="womanGreen_gun.png" x="110" y="176" width="52" height="43" frameX="-0" frameY="-0" frameWidth="52" frameHeight="43"/>
|
||||
<SubTexture name="womanGreen_hold.png" x="261" y="88" width="38" height="43" frameX="-0" frameY="-0" frameWidth="38" frameHeight="43"/>
|
||||
<SubTexture name="womanGreen_machine.png" x="58" y="88" width="52" height="43" frameX="-0" frameY="-0" frameWidth="52" frameHeight="43"/>
|
||||
<SubTexture name="womanGreen_reload.png" x="212" y="352" width="42" height="43" frameX="-0" frameY="-0" frameWidth="42" frameHeight="43"/>
|
||||
<SubTexture name="womanGreen_silencer.png" x="0" y="44" width="57" height="43" frameX="-0" frameY="-0" frameWidth="57" frameHeight="43"/>
|
||||
<SubTexture name="womanGreen_stand.png" x="295" y="308" width="36" height="43" frameX="-0" frameY="-0" frameWidth="36" frameHeight="43"/>
|
||||
<SubTexture name="womanOld_gun.png" x="58" y="44" width="52" height="43" frameX="-0" frameY="-0" frameWidth="52" frameHeight="43"/>
|
||||
<SubTexture name="womanOld_hold.png" x="293" y="220" width="38" height="43" frameX="-0" frameY="-0" frameWidth="38" frameHeight="43"/>
|
||||
<SubTexture name="womanOld_machine.png" x="57" y="176" width="52" height="43" frameX="-0" frameY="-0" frameWidth="52" frameHeight="43"/>
|
||||
<SubTexture name="womanOld_reload.png" x="212" y="308" width="42" height="43" frameX="-0" frameY="-0" frameWidth="42" frameHeight="43"/>
|
||||
<SubTexture name="womanOld_silencer.png" x="0" y="0" width="57" height="43" frameX="-0" frameY="-0" frameWidth="57" frameHeight="43"/>
|
||||
<SubTexture name="womanOld_stand.png" x="295" y="352" width="36" height="43" frameX="-0" frameY="-0" frameWidth="36" frameHeight="43"/>
|
||||
<SubTexture name="zoimbie1_gun.png" x="211" y="88" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="zoimbie1_hold.png" x="300" y="88" width="35" height="43" frameX="-0" frameY="-0" frameWidth="35" frameHeight="43"/>
|
||||
<SubTexture name="zoimbie1_machine.png" x="211" y="0" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="zoimbie1_reload.png" x="254" y="132" width="39" height="43" frameX="-0" frameY="-0" frameWidth="39" frameHeight="43"/>
|
||||
<SubTexture name="zoimbie1_silencer.png" x="55" y="264" width="54" height="43" frameX="-0" frameY="-0" frameWidth="54" frameHeight="43"/>
|
||||
<SubTexture name="zoimbie1_stand.png" x="368" y="220" width="33" height="43" frameX="-0" frameY="-0" frameWidth="33" frameHeight="43"/>
|
||||
<SubTexture name="zombie2_gun.png" x="162" y="396" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="zombie2_hold.png" x="332" y="132" width="35" height="43" frameX="-0" frameY="-0" frameWidth="35" frameHeight="43"/>
|
||||
<SubTexture name="zombie2_machine.png" x="162" y="308" width="49" height="43" frameX="-0" frameY="-0" frameWidth="49" frameHeight="43"/>
|
||||
<SubTexture name="zombie2_reload.png" x="213" y="176" width="39" height="43" frameX="-0" frameY="-0" frameWidth="39" frameHeight="43"/>
|
||||
<SubTexture name="zombie2_silencer.png" x="55" y="308" width="54" height="43" frameX="-0" frameY="-0" frameWidth="54" frameHeight="43"/>
|
||||
<SubTexture name="zombie2_stand.png" x="371" y="0" width="33" height="43" frameX="-0" frameY="-0" frameWidth="33" frameHeight="43"/>
|
||||
</TextureAtlas>
|
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.9" tiledversion="1.9.1" name="demo-tileset" tilewidth="16" tileheight="16" spacing="1" tilecount="1036" columns="37">
|
||||
<image source="../../../libgdx/assets/kenney/roguelike-modern-city-pack/Spritesheet/roguelikeCity_magenta.png" width="628" height="475"/>
|
||||
</tileset>
|
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.9" tiledversion="1.9.1" name="roguelike" tilewidth="16" tileheight="16" spacing="1" tilecount="1767" columns="57">
|
||||
<image source="D:/kenney/Kenney Game Assets/Art/Roguelike pack (1700 assets)/Spritesheet/roguelikeSheet_transparent.png" width="968" height="526"/>
|
||||
</tileset>
|
Binary file not shown.
After Width: | Height: | Size: 163 KiB |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
||||
package com.last.commit
|
||||
|
||||
import com.badlogic.gdx.math.Rectangle
|
||||
|
||||
interface Collidable {
|
||||
|
||||
fun getCollider(): Rectangle
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
package com.last.commit
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import com.badlogic.gdx.math.Rectangle
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
|
||||
|
||||
class Player(private val textureRegion: TextureRegion) : Collidable {
|
||||
|
||||
private var collider: Rectangle = Rectangle(0f, 0f, 0f, 0f)
|
||||
var position: Vector2 = Vector2.Zero
|
||||
private var direction = Vector2.Zero
|
||||
private val movementSpeed = 200f
|
||||
private val interactionRange = 60f
|
||||
|
||||
init {
|
||||
val size = Math.max(textureRegion.regionWidth, textureRegion.regionHeight).toFloat()
|
||||
collider = Rectangle(0f, 0f, size, size)
|
||||
position = Vector2()
|
||||
}
|
||||
|
||||
fun getX(): Float {
|
||||
return position.x
|
||||
}
|
||||
|
||||
fun getY(): Float {
|
||||
return position.y
|
||||
}
|
||||
|
||||
fun move(v: Vector2, delta: Float) {
|
||||
updatePosition(v, delta)
|
||||
updateCollider()
|
||||
}
|
||||
|
||||
private fun updatePosition(v: Vector2, delta: Float) {
|
||||
position.add(v.setLength(movementSpeed * delta))
|
||||
}
|
||||
|
||||
private fun updateCollider() {
|
||||
this.collider.x = position.x
|
||||
this.collider.y = position.y
|
||||
}
|
||||
|
||||
override fun getCollider(): Rectangle {
|
||||
return collider
|
||||
}
|
||||
|
||||
fun setPosition(x: Float, y: Float) {
|
||||
position[x] = y
|
||||
}
|
||||
|
||||
fun getWidth(): Float {
|
||||
return collider.getWidth()
|
||||
}
|
||||
|
||||
fun getHeight(): Float {
|
||||
return collider.getHeight()
|
||||
}
|
||||
|
||||
fun getSize(): Float {
|
||||
return Math.max(getWidth(), getHeight())
|
||||
}
|
||||
|
||||
fun lookAt(position: Vector2) {
|
||||
calculateRotationTo(position)
|
||||
}
|
||||
|
||||
private fun calculateRotationTo(position: Vector2) {
|
||||
val playerPosition = this.position.cpy()
|
||||
playerPosition.add(collider.width / 2f, collider.height / 2f)
|
||||
direction = position.cpy()
|
||||
direction.sub(playerPosition)
|
||||
direction.setLength(interactionRange)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the direction relative to the players center.
|
||||
*/
|
||||
fun getRelativeDirection(): Vector2 {
|
||||
return direction.cpy().add(getHalfPlayerWidth(), getHalfPlayerHeight())
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the direction of the player in World positon
|
||||
*/
|
||||
fun getAbsoluteDirection(): Vector2 {
|
||||
return position.cpy().add(getRelativeDirection())
|
||||
}
|
||||
|
||||
|
||||
private fun getHalfPlayerWidth(): Float {
|
||||
return getWidth() / 2
|
||||
}
|
||||
|
||||
private fun getHalfPlayerHeight(): Float {
|
||||
return getHeight() / 2
|
||||
}
|
||||
|
||||
fun getRotation(): Float {
|
||||
return direction.angleDeg()
|
||||
}
|
||||
|
||||
fun render(batch: SpriteBatch) {
|
||||
val halfPlayerWidth: Float = getHalfPlayerWidth() // TODO maybe use collider
|
||||
// dimensions
|
||||
val halfPlayerHeight: Float = getHalfPlayerHeight() // TODO maybe use collider
|
||||
// dimensions
|
||||
batch.draw(
|
||||
textureRegion, getX(), getY(),
|
||||
halfPlayerWidth, halfPlayerHeight, getWidth(),
|
||||
getHeight(), 1f, 1f,
|
||||
getRotation()
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.last.commit
|
||||
|
||||
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell
|
||||
import com.badlogic.gdx.math.Rectangle
|
||||
|
||||
open class Wall(var gridX: Int, var gridY: Int, wallCollider: Rectangle, cell: Cell) : Collidable {
|
||||
var wallCollider: Rectangle
|
||||
var cell: Cell
|
||||
|
||||
init {
|
||||
this.wallCollider = wallCollider
|
||||
this.cell = cell
|
||||
}
|
||||
|
||||
override fun getCollider(): Rectangle {
|
||||
return wallCollider
|
||||
}
|
||||
|
||||
fun collidesWidth(collidable: Collidable): Boolean {
|
||||
return if (isCollidable) {
|
||||
wallCollider.overlaps(collidable.getCollider())
|
||||
} else false
|
||||
}
|
||||
|
||||
open val isCollidable: Boolean
|
||||
get() = true
|
||||
|
||||
override fun toString(): String {
|
||||
return java.lang.String.format(
|
||||
"Wall: %f:%f - %f:%f", wallCollider.x, wallCollider.y, wallCollider.width,
|
||||
wallCollider.height
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.last.commit.map
|
||||
|
||||
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell
|
||||
import com.badlogic.gdx.math.Rectangle
|
||||
import com.last.commit.Wall
|
||||
|
||||
|
||||
class Door(gridX: Int, gridY: Int, wallCollider: Rectangle, cell: Cell) :
|
||||
Wall(gridX, gridY, wallCollider, cell), Toggleable {
|
||||
override fun toggle() {
|
||||
println("Toggling door$this")
|
||||
isOpen = !isOpen
|
||||
}
|
||||
|
||||
var isOpen: Boolean
|
||||
get() = !isClosed
|
||||
set(isOpen) {
|
||||
val currentRotation: Int = cell.getRotation()
|
||||
if (isOpen) {
|
||||
cell.setRotation(currentRotation + 1)
|
||||
} else {
|
||||
cell.setRotation(currentRotation - 1)
|
||||
}
|
||||
}
|
||||
val isClosed: Boolean
|
||||
get() {
|
||||
val currentRotation: Int = cell.getRotation()
|
||||
return currentRotation == 0
|
||||
}
|
||||
override val isCollidable: Boolean
|
||||
get() = !isOpen
|
||||
|
||||
override fun toString(): String {
|
||||
return String.format(
|
||||
"Door: %f:%f - %f:%f (isOpen: %b)", wallCollider.x, wallCollider.y, wallCollider.width,
|
||||
wallCollider.height, isOpen
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,144 @@
|
||||
package com.last.commit.map
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.maps.tiled.TiledMap
|
||||
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer
|
||||
import com.badlogic.gdx.maps.tiled.TmxMapLoader
|
||||
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer
|
||||
import com.badlogic.gdx.math.Rectangle
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.badlogic.gdx.utils.Array
|
||||
import com.last.commit.Collidable
|
||||
import com.last.commit.Wall
|
||||
|
||||
|
||||
class TimeMap(fileName: String) {
|
||||
private val CELL_SIZE = 64
|
||||
|
||||
private val walls: Array<Wall> = Array()
|
||||
val mapLoader:TmxMapLoader = TmxMapLoader()
|
||||
var mapRenderer: OrthogonalTiledMapRenderer
|
||||
val map: TiledMap
|
||||
var gridWidth = 0
|
||||
var gridHeight = 0
|
||||
var width = 0
|
||||
var height = 0
|
||||
var mapTileWidth = 0
|
||||
var mapTileHeight = 0
|
||||
var halfMapTileWidth = 0f
|
||||
var halfMapTileHeight = 0f
|
||||
|
||||
|
||||
init {
|
||||
map = mapLoader.load(fileName)
|
||||
mapRenderer = OrthogonalTiledMapRenderer(map)
|
||||
loadDimensions()
|
||||
loadWalls()
|
||||
}
|
||||
|
||||
fun getPlayerSpawn(): Vector2 {
|
||||
val mapLayers = map.layers
|
||||
val spawnPoints = mapLayers["Spawnpoints"].objects
|
||||
for (spawnPoint in spawnPoints) {
|
||||
val spawnPointProperties = spawnPoint.properties
|
||||
if (spawnPointProperties != null && spawnPointProperties.containsKey("playerSpawn")) {
|
||||
val isPlayerSpawn = spawnPointProperties.get("playerSpawn", Boolean::class.java)
|
||||
if (java.lang.Boolean.TRUE == isPlayerSpawn) {
|
||||
val x = spawnPointProperties.get("x", Float::class.java)
|
||||
val y = spawnPointProperties.get("y", Float::class.java)
|
||||
return Vector2(x, y)
|
||||
}
|
||||
}
|
||||
}
|
||||
Gdx.app.debug("SurvislandMap", "No spawn point found in map. Return map origin.")
|
||||
return Vector2.Zero
|
||||
}
|
||||
|
||||
private fun loadDimensions() {
|
||||
val prop = map.properties
|
||||
this.gridWidth = prop.get("width", Int::class.java)
|
||||
this.gridHeight = prop.get("height", Int::class.java)
|
||||
this.width = gridWidth * CELL_SIZE
|
||||
this.height = gridHeight * CELL_SIZE
|
||||
this.mapTileWidth = map.properties.get("tilewidth", Int::class.java)
|
||||
this.mapTileHeight = map.properties.get("tileheight", Int::class.java)
|
||||
this.halfMapTileWidth = mapTileWidth / 2f
|
||||
this.halfMapTileHeight = mapTileHeight / 2f
|
||||
}
|
||||
|
||||
private fun loadWalls() {
|
||||
val wallsLayer = map.layers["Walls"] as TiledMapTileLayer
|
||||
for (column in 0 until wallsLayer.width) {
|
||||
for (row in 0 until wallsLayer.height) {
|
||||
val cell: TiledMapTileLayer.Cell? = wallsLayer.getCell(column, row)
|
||||
if (cell != null) {
|
||||
val isDoor: Boolean = cell.getTile().getProperties().get("isDoor", false, Boolean::class.java)
|
||||
val wallCollider = Rectangle(
|
||||
column.toFloat() * wallsLayer.tileWidth,
|
||||
row.toFloat() * wallsLayer.tileHeight, wallsLayer.tileWidth.toFloat(),
|
||||
wallsLayer.tileHeight.toFloat()
|
||||
)
|
||||
val wall: Wall
|
||||
if (java.lang.Boolean.TRUE == isDoor) {
|
||||
wall = Door(column, row, wallCollider, cell)
|
||||
} else {
|
||||
wall = Wall(column, row, wallCollider, cell)
|
||||
}
|
||||
walls.add(wall)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun findDoorByGridPosition(gridX: Int, gridY: Int): Door? {
|
||||
for (wall in walls) {
|
||||
if (wall.gridX == gridX && wall.gridY == gridY && wall is Door) {
|
||||
return wall
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun toggleDoorAt(x: Float, y: Float, blockingCollider: Rectangle?) {
|
||||
val gridX = x.toInt() / CELL_SIZE
|
||||
val gridY = y.toInt() / CELL_SIZE
|
||||
println("Toggling door at $gridX:$gridY")
|
||||
val door: Door = this.findDoorByGridPosition(gridX, gridY) ?: return
|
||||
if (door.isClosed) {
|
||||
door.isOpen = true
|
||||
} else if (door.isOpen) {
|
||||
if (door.getCollider().overlaps(blockingCollider)) {
|
||||
// can't close the door cause it is colliding with given collider
|
||||
} else {
|
||||
door.isOpen = false
|
||||
}
|
||||
}
|
||||
println("Door is now open = ${door.isOpen}")
|
||||
}
|
||||
|
||||
|
||||
fun getTileWidth(): Float {
|
||||
return mapTileWidth.toFloat()
|
||||
}
|
||||
|
||||
fun getTileHeight(): Float {
|
||||
return mapTileHeight.toFloat()
|
||||
}
|
||||
|
||||
fun render(batch: SpriteBatch, camera: OrthographicCamera, delta: Float) {
|
||||
mapRenderer.setView(camera)
|
||||
mapRenderer.render()
|
||||
}
|
||||
|
||||
fun isCollidingWithWall(collidable: Collidable): Boolean {
|
||||
for (wall in walls) {
|
||||
if (wall.collidesWidth(collidable)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.last.commit.map
|
||||
|
||||
interface Toggleable {
|
||||
fun toggle()
|
||||
}
|
Loading…
Reference in New Issue