add usable key

main
Matthias 2 years ago
parent 1b00a5fc0f
commit d9081f5d83

@ -356,7 +356,7 @@
0,0,0,0,184,185,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,176,0,0,0,0,0,0,0,0,177,0,0,0,0,0,0,0,0,0, 0,0,0,0,184,185,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,176,0,0,0,0,0,0,0,0,177,0,0,0,0,0,0,0,0,0,
0,0,0,0,211,212,0,0,184,185,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,176,129,129,0,0,0,0,0,129,177,0,0,0,0,0,0,0,0,0, 0,0,0,0,211,212,0,0,184,185,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,176,129,129,0,0,0,0,0,129,177,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,211,212,0,0,0,0,0,0,0,0,184,185,0,0,0,0,0,0,184,185,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,176,129,129,0,0,0,0,129,129,177,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,211,212,0,0,0,0,0,0,0,0,184,185,0,0,0,0,0,0,184,185,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,176,129,129,0,0,0,0,129,129,177,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,211,212,0,0,0,0,0,0,211,212,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,152,204,204,204,467,204,204,204,204,153,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,211,212,0,0,0,0,0,0,211,212,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,152,204,204,204,299,204,204,204,204,153,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,184,185,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,184,185,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 KiB

After

Width:  |  Height:  |  Size: 187 KiB

File diff suppressed because it is too large Load Diff

@ -1,10 +1,9 @@
package com.last.commit package com.last.commit
import com.badlogic.gdx.Input
import com.badlogic.gdx.InputProcessor import com.badlogic.gdx.InputProcessor
import com.last.commit.screen.TimeTravelScreen import com.last.commit.screen.TimeTravelScreen
class GameInputProcessor(val game: Game, ) : InputProcessor{ class GameInputProcessor(val game: Game) : InputProcessor {
lateinit var activeScreen: TimeTravelScreen lateinit var activeScreen: TimeTravelScreen
@ -13,6 +12,7 @@ class GameInputProcessor(val game: Game, ) : InputProcessor{
} }
override fun keyTyped(character: Char): Boolean { override fun keyTyped(character: Char): Boolean {
return false return false
} }

@ -1,15 +1,17 @@
package com.last.commit.map package com.last.commit.map
import GameState
import Position
import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Rectangle
import com.last.commit.audio.GameSoundEffect import com.last.commit.audio.GameSoundEffect
import Position import com.last.commit.inventory.InventoryItem
import GameState
class Collectible( class Collectible(
name: String, name: String,
val pos: Position, val pos: Position,
width: Float, width: Float,
height: Float height: Float,
val requiredItem: String
) : Interactable { ) : Interactable {
val name: String val name: String
@ -26,6 +28,20 @@ class Collectible(
state.inventory.add(this.name) state.inventory.add(this.name)
} }
override fun canInteract(state: GameState): Boolean {
if (requiredItem == "") {
return true
}
val item: InventoryItem? = state.inventory.items.find { it.name == requiredItem }
if (item == null) {
return false
}
return true
}
override fun getCollider(): Rectangle { override fun getCollider(): Rectangle {
return this.collider return this.collider
} }

@ -5,9 +5,24 @@ import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell
import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Rectangle
import com.last.commit.Wall import com.last.commit.Wall
import com.last.commit.audio.GameSoundEffect import com.last.commit.audio.GameSoundEffect
import com.last.commit.inventory.InventoryItem
class Door(gridX: Int, gridY: Int, wallCollider: Rectangle, cell: Cell) : class Door(gridX: Int, gridY: Int, wallCollider: Rectangle, cell: Cell) :
Wall(gridX, gridY, wallCollider, cell), Interactable { Wall(gridX, gridY, wallCollider, cell), Interactable {
override fun canInteract(state: GameState): Boolean {
val requiredItem: String = cell.getTile().getProperties().get("requiredItem", "", String::class.java)
val item: InventoryItem? = state.inventory.items.find { it.name == requiredItem }
if (item == null) {
return requiredItem == ""
} else {
return requiredItem == item.name
}
}
override fun interact(otherCollider: Rectangle, state: GameState) { override fun interact(otherCollider: Rectangle, state: GameState) {
println("interacting with door $this") println("interacting with door $this")
@ -46,12 +61,12 @@ class Door(gridX: Int, gridY: Int, wallCollider: Rectangle, cell: Cell) :
override fun toString(): String { override fun toString(): String {
return String.format( return String.format(
"Door: %f:%f - %f:%f (isOpen: %b)", "Door: %f:%f - %f:%f (isOpen: %b)",
wallCollider.x, wallCollider.x,
wallCollider.y, wallCollider.y,
wallCollider.width, wallCollider.width,
wallCollider.height, wallCollider.height,
isOpen isOpen
) )
} }
} }

@ -1,10 +1,12 @@
package com.last.commit.map package com.last.commit.map
import com.badlogic.gdx.math.Rectangle
import GameState import GameState
import com.badlogic.gdx.math.Rectangle
interface Interactable { interface Interactable {
fun getCollider(): Rectangle fun getCollider(): Rectangle
fun interact(otherCollider: Rectangle, state: GameState) fun interact(otherCollider: Rectangle, state: GameState)
fun canInteract(state: GameState): Boolean
} }

@ -158,10 +158,11 @@ class TimeMap(fileName: String, val state: GameState) {
val height = mapObjectProperties.get("height", Float::class.java) val height = mapObjectProperties.get("height", Float::class.java)
if (mapObject is RectangleMapObject) { if (mapObject is RectangleMapObject) {
val itemName = mapObjectProperties.get("item", String::class.java) //check wether itemName is null and continue in case it is
itemName?. let { val itemName = mapObjectProperties.get("item", String::class.java) ?: continue
this.collectibles.add(Collectible(itemName, Position(x, y, gridX, gridY), width, height)) val requiredItem = mapObjectProperties.get("requiredItem", String::class.java) ?: ""
}
this.collectibles.add(Collectible(itemName, Position(x, y, gridX, gridY), width, height, requiredItem))
} else { } else {
println("Found non-rectangular map object at ${x}-${y} skipping it") println("Found non-rectangular map object at ${x}-${y} skipping it")
} }
@ -186,13 +187,16 @@ class TimeMap(fileName: String, val state: GameState) {
fun interactWith(x: Float, y: Float, blockingCollider: Rectangle) { fun interactWith(x: Float, y: Float, blockingCollider: Rectangle) {
val gridX = x.toInt() / CELL_SIZE val gridX = x.toInt() / CELL_SIZE
val gridY = y.toInt() / CELL_SIZE val gridY = y.toInt() / CELL_SIZE
println("Interacting with element at $gridX:$gridY")
//if no door is found return //if no door is found return
val interactable: Interactable = this.findInteractableAtPosition(gridX, gridY) ?: return val interactable: Interactable = this.findInteractableAtPosition(gridX, gridY) ?: return
//else continue //else continue
if (interactable.canInteract(state)) {
interactable.interact(blockingCollider, state) println("Interacting with element at $gridX:$gridY")
interactable.interact(blockingCollider, state)
} else {
println("Cannot interact with $gridX:$gridY")
}
} }

Loading…
Cancel
Save