mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 02:24:05 +09:00
tossing items on the inventory
This commit is contained in:
@@ -352,6 +352,7 @@ open class IngameInstance(val batch: FlippingSpriteBatch, val isMultiplayer: Boo
|
|||||||
* If the actor is null, this function will do nothing.
|
* If the actor is null, this function will do nothing.
|
||||||
*/
|
*/
|
||||||
open fun queueActorAddition(actor: Actor?) {
|
open fun queueActorAddition(actor: Actor?) {
|
||||||
|
printdbg(this, "New actor $actor")
|
||||||
if (actor == null) return
|
if (actor == null) return
|
||||||
actorAdditionQueue.add(actor to StackTraceRecorder())
|
actorAdditionQueue.add(actor to StackTraceRecorder())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ typealias RGBA8888 = Int
|
|||||||
* Slick2d Version Created by minjaesong on 2015-12-30.
|
* Slick2d Version Created by minjaesong on 2015-12-30.
|
||||||
*
|
*
|
||||||
* LibGDX Version Created by minjaesong on 2017-06-15.
|
* LibGDX Version Created by minjaesong on 2017-06-15.
|
||||||
|
*
|
||||||
|
* Note: Blocks are NOT automatically added; they must be registered manually on the module's EntryPoint
|
||||||
*/
|
*/
|
||||||
object Terrarum : Disposable {
|
object Terrarum : Disposable {
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
import net.torvald.gdx.graphics.Cvec
|
import net.torvald.gdx.graphics.Cvec
|
||||||
|
import net.torvald.terrarum.App.printdbg
|
||||||
import net.torvald.terrarum.BlockCodex
|
import net.torvald.terrarum.BlockCodex
|
||||||
import net.torvald.terrarum.INGAME
|
import net.torvald.terrarum.INGAME
|
||||||
import net.torvald.terrarum.ItemCodex
|
import net.torvald.terrarum.ItemCodex
|
||||||
@@ -11,6 +12,7 @@ import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
|||||||
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||||
import net.torvald.terrarum.gameactors.*
|
import net.torvald.terrarum.gameactors.*
|
||||||
import net.torvald.terrarum.gameitems.*
|
import net.torvald.terrarum.gameitems.*
|
||||||
|
import org.dyn4j.geometry.Vector2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-03-15.
|
* Created by minjaesong on 2016-03-15.
|
||||||
@@ -48,7 +50,7 @@ open class DroppedItem : ActorWithBody {
|
|||||||
* @param topLeftX world-wise coord
|
* @param topLeftX world-wise coord
|
||||||
* @param topLeftY world-wise coord
|
* @param topLeftY world-wise coord
|
||||||
*/
|
*/
|
||||||
constructor(itemID: ItemID, topLeftX: Double, topLeftY: Double) : super(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT) {
|
constructor(itemID: ItemID, centreX: Double, bottomY: Double, spawnVelo: Vector2? = null) : super(RenderOrder.MIDTOP, PhysProperties.PHYSICS_OBJECT) {
|
||||||
this.itemID = itemID
|
this.itemID = itemID
|
||||||
|
|
||||||
if (itemID.isActor())
|
if (itemID.isActor())
|
||||||
@@ -56,10 +58,7 @@ open class DroppedItem : ActorWithBody {
|
|||||||
|
|
||||||
isVisible = true
|
isVisible = true
|
||||||
|
|
||||||
avBaseMass = if (itemID.isItem() || itemID.isWire())
|
avBaseMass = (ItemCodex[itemID]?.mass ?: 2.0).coerceAtMost(2.0)
|
||||||
(ItemCodex[itemID]?.mass ?: 2.0).coerceAtMost(2.0)
|
|
||||||
else
|
|
||||||
BlockCodex[itemID].density / 1000.0 // block and wall
|
|
||||||
|
|
||||||
actorValue[AVKey.SCALE] = ItemCodex[itemID]?.scale ?: 1.0
|
actorValue[AVKey.SCALE] = ItemCodex[itemID]?.scale ?: 1.0
|
||||||
|
|
||||||
@@ -69,16 +68,21 @@ open class DroppedItem : ActorWithBody {
|
|||||||
0, 0
|
0, 0
|
||||||
)
|
)
|
||||||
|
|
||||||
setPosition(topLeftX + (hitbox.width / 2.0), topLeftY + hitbox.height)
|
setPosition(centreX, bottomY)
|
||||||
|
|
||||||
// random horizontal movement
|
// random horizontal movement
|
||||||
val magn = Math.random() * 1.3
|
if (spawnVelo == null) {
|
||||||
externalV.x = if (isWalled(hitbox, COLLIDING_LEFT))
|
val magn = Math.random() * 1.3
|
||||||
Math.cos(Math.random() * Math.PI / 2) * magn
|
externalV.x = if (isWalled(hitbox, COLLIDING_LEFT))
|
||||||
else if (isWalled(hitbox, COLLIDING_RIGHT))
|
Math.cos(Math.random() * Math.PI / 2) * magn
|
||||||
Math.cos(Math.random() * Math.PI / 2 + Math.PI / 2) * magn
|
else if (isWalled(hitbox, COLLIDING_RIGHT))
|
||||||
else
|
Math.cos(Math.random() * Math.PI / 2 + Math.PI / 2) * magn
|
||||||
Math.cos(Math.random() * Math.PI) * magn
|
else
|
||||||
|
Math.cos(Math.random() * Math.PI) * magn
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
externalV.set(spawnVelo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun drawBody(batch: SpriteBatch) {
|
override fun drawBody(batch: SpriteBatch) {
|
||||||
@@ -108,11 +112,23 @@ open class DroppedItem : ActorWithBody {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getLum(itemID: ItemID): Cvec {
|
||||||
|
return if (itemID.isBlock() || itemID.isWall()) {
|
||||||
|
BlockCodex[itemID.substringAfter('@')].getLumCol(randKey1, randKey2)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Cvec(
|
||||||
|
ItemCodex[itemID]?.itemProperties?.getAsFloat(AVKey.LUMR) ?: 0f,
|
||||||
|
ItemCodex[itemID]?.itemProperties?.getAsFloat(AVKey.LUMG) ?: 0f,
|
||||||
|
ItemCodex[itemID]?.itemProperties?.getAsFloat(AVKey.LUMB) ?: 0f,
|
||||||
|
ItemCodex[itemID]?.itemProperties?.getAsFloat(AVKey.LUMA) ?: 0f,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
if (this.itemID.isBlock() || this.itemID.isItem()) {
|
if (this.itemID.isBlock() || this.itemID.isItem()) {
|
||||||
BlockCodex[this.itemID].let {
|
this.lightBoxList[0].light = getLum(this.itemID)
|
||||||
this.lightBoxList[0].light = it.getLumCol(randKey1, randKey2)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.update(delta)
|
super.update(delta)
|
||||||
@@ -121,8 +137,9 @@ open class DroppedItem : ActorWithBody {
|
|||||||
|
|
||||||
// merge into the already existing droppeditem with isStationary==true if one is detected
|
// merge into the already existing droppeditem with isStationary==true if one is detected
|
||||||
if (!this.isStationary) {
|
if (!this.isStationary) {
|
||||||
INGAME.findNearestActor(this) { it is DroppedItem && it.itemID == this.itemID && it.isStationary }?.let {
|
INGAME.findNearestActor(this) { it is DroppedItem && it.itemID == this.itemID && it.isStationary && !it.flagDespawn }?.let {
|
||||||
if (it.distance <= MERGER_RANGE) {
|
if (it.distance <= MERGER_RANGE) {
|
||||||
|
// printdbg(this, "Dropped merger $itemID (${(it.get() as DroppedItem).itemCount} -> ${(it.get() as DroppedItem).itemCount + this.itemCount})")
|
||||||
(it.get() as DroppedItem).itemCount += this.itemCount
|
(it.get() as DroppedItem).itemCount += this.itemCount
|
||||||
this.flagDespawn()
|
this.flagDespawn()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ object PickaxeCore {
|
|||||||
if (Math.random() < dropProbability) {
|
if (Math.random() < dropProbability) {
|
||||||
val drop = BlockCodex[tileBroken].drop
|
val drop = BlockCodex[tileBroken].drop
|
||||||
if (drop.isNotBlank()) {
|
if (drop.isNotBlank()) {
|
||||||
INGAME.queueActorAddition(DroppedItem(drop, x * TILE_SIZED, y * TILE_SIZED))
|
INGAME.queueActorAddition(DroppedItem(drop, (x + 0.5) * TILE_SIZED, (y + 1.0) * TILE_SIZED))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package net.torvald.terrarum.modulebasegame.gameitems
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
|
||||||
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.gameactors.AVKey
|
import net.torvald.terrarum.gameactors.AVKey
|
||||||
import net.torvald.terrarum.gameactors.ActorWithBody
|
import net.torvald.terrarum.gameactors.ActorWithBody
|
||||||
@@ -91,7 +93,7 @@ object SledgehammerCore {
|
|||||||
if (Math.random() < dropProbability) {
|
if (Math.random() < dropProbability) {
|
||||||
val drop = BlockCodex[tileBroken].drop
|
val drop = BlockCodex[tileBroken].drop
|
||||||
if (drop.isNotBlank()) {
|
if (drop.isNotBlank()) {
|
||||||
INGAME.queueActorAddition(DroppedItem("wall@$drop", x * TerrarumAppConfiguration.TILE_SIZED, y * TerrarumAppConfiguration.TILE_SIZED))
|
INGAME.queueActorAddition(DroppedItem("wall@$drop", (x + 0.5) * TILE_SIZED, (y + 1.0) * TILE_SIZED))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.ui
|
package net.torvald.terrarum.modulebasegame.ui
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.graphics.Camera
|
import com.badlogic.gdx.graphics.Camera
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.*
|
import net.torvald.terrarum.*
|
||||||
import net.torvald.terrarum.App.printdbg
|
import net.torvald.terrarum.App.printdbg
|
||||||
|
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZED
|
||||||
import net.torvald.terrarum.langpack.Lang
|
import net.torvald.terrarum.langpack.Lang
|
||||||
|
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
|
||||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_HOR
|
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_HOR
|
||||||
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_VRT
|
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_VRT
|
||||||
@@ -18,6 +21,7 @@ import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.
|
|||||||
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun
|
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.createInvCellGenericTouchDownFun
|
||||||
import net.torvald.terrarum.ui.Toolkit
|
import net.torvald.terrarum.ui.Toolkit
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
|
import org.dyn4j.geometry.Vector2
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
@@ -83,6 +87,25 @@ internal class UIInventoryCells(
|
|||||||
override fun updateUI(delta: Float) {
|
override fun updateUI(delta: Float) {
|
||||||
itemList.update(delta)
|
itemList.update(delta)
|
||||||
equipped.update(delta)
|
equipped.update(delta)
|
||||||
|
|
||||||
|
// make tossing work on the inventory ui
|
||||||
|
if (Gdx.input.isKeyJustPressed(ControlPresets.getKey("control_key_discard"))) {
|
||||||
|
itemList.find { it.mouseUp }?.let { cell -> cell.item?.let { item ->
|
||||||
|
val player = full.actor
|
||||||
|
// remove an item from the inventory
|
||||||
|
player.inventory.remove(item, 1)
|
||||||
|
// create and spawn the droppeditem
|
||||||
|
DroppedItem(item.dynamicID,
|
||||||
|
player.hitbox.centeredX,
|
||||||
|
player.hitbox.centeredY,
|
||||||
|
Vector2(-4.0 * player.scale.sqrt() * player.sprite!!.flipHorizontal.toInt(1).minus(1), -0.1)
|
||||||
|
).let { drop ->
|
||||||
|
INGAME.queueActorAddition(drop)
|
||||||
|
}
|
||||||
|
// update inventory
|
||||||
|
rebuildList()
|
||||||
|
} }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: OrthographicCamera) {
|
override fun renderUI(batch: SpriteBatch, camera: OrthographicCamera) {
|
||||||
|
|||||||
@@ -636,4 +636,19 @@ open class UIItemInventoryItemGrid(
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun find(predicate: (UIItemInventoryCellBase) -> Boolean): UIItemInventoryCellBase? {
|
||||||
|
var c = 0
|
||||||
|
var ret: UIItemInventoryCellBase? = null
|
||||||
|
while (c < items.size) {
|
||||||
|
if (predicate(items[c])) {
|
||||||
|
ret = items[c]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
c++
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user