add usable key

main
Matthias 1 year 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,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,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,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
import com.badlogic.gdx.Input
import com.badlogic.gdx.InputProcessor
import com.last.commit.screen.TimeTravelScreen
class GameInputProcessor(val game: Game, ) : InputProcessor{
class GameInputProcessor(val game: Game) : InputProcessor {
lateinit var activeScreen: TimeTravelScreen
@ -13,6 +12,7 @@ class GameInputProcessor(val game: Game, ) : InputProcessor{
}
override fun keyTyped(character: Char): Boolean {
return false
}

@ -1,15 +1,17 @@
package com.last.commit.map
import GameState
import Position
import com.badlogic.gdx.math.Rectangle
import com.last.commit.audio.GameSoundEffect
import Position
import GameState
import com.last.commit.inventory.InventoryItem
class Collectible(
name: String,
val pos: Position,
width: Float,
height: Float
name: String,
val pos: Position,
width: Float,
height: Float,
val requiredItem: String
) : Interactable {
val name: String
@ -26,6 +28,20 @@ class Collectible(
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 {
return this.collider
}

@ -5,9 +5,24 @@ import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell
import com.badlogic.gdx.math.Rectangle
import com.last.commit.Wall
import com.last.commit.audio.GameSoundEffect
import com.last.commit.inventory.InventoryItem
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) {
println("interacting with door $this")
@ -46,12 +61,12 @@ class Door(gridX: Int, gridY: Int, wallCollider: Rectangle, cell: Cell) :
override fun toString(): String {
return String.format(
"Door: %f:%f - %f:%f (isOpen: %b)",
wallCollider.x,
wallCollider.y,
wallCollider.width,
wallCollider.height,
isOpen
"Door: %f:%f - %f:%f (isOpen: %b)",
wallCollider.x,
wallCollider.y,
wallCollider.width,
wallCollider.height,
isOpen
)
}
}

@ -1,10 +1,12 @@
package com.last.commit.map
import com.badlogic.gdx.math.Rectangle
import GameState
import com.badlogic.gdx.math.Rectangle
interface Interactable {
fun getCollider(): Rectangle
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)
if (mapObject is RectangleMapObject) {
val itemName = mapObjectProperties.get("item", String::class.java)
itemName?. let {
this.collectibles.add(Collectible(itemName, Position(x, y, gridX, gridY), width, height))
}
//check wether itemName is null and continue in case it is
val itemName = mapObjectProperties.get("item", String::class.java) ?: continue
val requiredItem = mapObjectProperties.get("requiredItem", String::class.java) ?: ""
this.collectibles.add(Collectible(itemName, Position(x, y, gridX, gridY), width, height, requiredItem))
} else {
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) {
val gridX = x.toInt() / CELL_SIZE
val gridY = y.toInt() / CELL_SIZE
println("Interacting with element at $gridX:$gridY")
//if no door is found return
val interactable: Interactable = this.findInteractableAtPosition(gridX, gridY) ?: return
//else continue
interactable.interact(blockingCollider, state)
if (interactable.canInteract(state)) {
println("Interacting with element at $gridX:$gridY")
interactable.interact(blockingCollider, state)
} else {
println("Cannot interact with $gridX:$gridY")
}
}

Loading…
Cancel
Save