Add adding an item to the inventory when interacting with it
parent
d23f0bdab0
commit
cf99f9b6f7
@ -1,11 +1,22 @@
|
|||||||
package com.last.commit
|
package com.last.commit
|
||||||
|
|
||||||
import com.badlogic.gdx.Game
|
import com.badlogic.gdx.Game
|
||||||
|
import com.last.commit.inventory.Inventory
|
||||||
|
import GameState
|
||||||
|
|
||||||
/** [com.badlogic.gdx.ApplicationListener] implementation shared by all platforms. */
|
/** [com.badlogic.gdx.ApplicationListener] implementation shared by all platforms. */
|
||||||
class Game : Game() {
|
class Game : Game() {
|
||||||
|
|
||||||
|
private lateinit var state: GameState
|
||||||
|
|
||||||
override fun create() {
|
override fun create() {
|
||||||
setScreen(FirstScreen())
|
createState()
|
||||||
|
setScreen(FirstScreen(state))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createState() {
|
||||||
|
state = GameState(
|
||||||
|
Inventory()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
import com.last.commit.inventory.Inventory
|
||||||
|
|
||||||
|
public data class GameState(
|
||||||
|
public val inventory: Inventory,
|
||||||
|
)
|
@ -1,18 +1,20 @@
|
|||||||
package com.last.commit.inventory
|
package com.last.commit.inventory
|
||||||
|
|
||||||
class Inventory(path: String) {
|
class Inventory {
|
||||||
|
|
||||||
val items: MutableList<InventoryItem> = ArrayList()
|
val items: MutableList<InventoryItem> = ArrayList()
|
||||||
val textureLoader = InventoryItemTextureLoader(path)
|
public var updated = false
|
||||||
|
private set
|
||||||
init {
|
|
||||||
textureLoader.parse()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name the name of the subtexture loaded from xml
|
* @param name the name of the subtexture loaded from xml
|
||||||
*/
|
*/
|
||||||
fun add(name: String) {
|
fun add(name: String) {
|
||||||
items.add(InventoryItem(name, textureLoader.loadTexture(name)))
|
items.add(InventoryItem(name))
|
||||||
|
this.updated = true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun remove(name: String) {
|
||||||
|
items.removeIf() {item -> item.name == name}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +1,10 @@
|
|||||||
package com.last.commit.map
|
package com.last.commit.map
|
||||||
|
|
||||||
import com.badlogic.gdx.math.Rectangle
|
import com.badlogic.gdx.math.Rectangle
|
||||||
|
import GameState
|
||||||
|
|
||||||
interface Interactable {
|
interface Interactable {
|
||||||
fun getCollider(): Rectangle
|
fun getCollider(): Rectangle
|
||||||
|
|
||||||
fun interact(otherCollider: Rectangle)
|
fun interact(otherCollider: Rectangle, state: GameState)
|
||||||
}
|
}
|
Loading…
Reference in New Issue