mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
no secondary click; tiki torch kinda spawns?
This commit is contained in:
@@ -94,16 +94,18 @@ open class IngameInstance(val batch: SpriteBatch) : Screen {
|
||||
}
|
||||
|
||||
/**
|
||||
* I have decided that left and right clicks must do the same thing, so no secondary use from now on. --Torvald on 2019-05-26
|
||||
*
|
||||
* Event for triggering held item's `startSecondaryUse(Float)`
|
||||
*/
|
||||
open fun worldSecondaryClickStart(delta: Float) {
|
||||
}
|
||||
//open fun worldSecondaryClickStart(delta: Float) { }
|
||||
|
||||
/**
|
||||
* I have decided that left and right clicks must do the same thing, so no secondary use from now on. --Torvald on 2019-05-26
|
||||
*
|
||||
* Event for triggering held item's `endSecondaryUse(Float)`
|
||||
*/
|
||||
open fun worldSecondaryClickEnd(delta: Float) {
|
||||
}
|
||||
//open fun worldSecondaryClickEnd(delta: Float) { }
|
||||
|
||||
/**
|
||||
* Event for triggering fixture update when something is placed/removed on the world.
|
||||
|
||||
@@ -188,7 +188,7 @@ class UIItemInventoryElem(
|
||||
// equip da shit
|
||||
val itemEquipSlot = item!!.equipPosition
|
||||
if (itemEquipSlot == GameItem.EquipPosition.NULL) {
|
||||
TODO("Equip position is NULL, does this mean it's single-consume items like a potion?")
|
||||
TODO("Equip position is NULL, does this mean it's single-consume items like a potion? (from item: \"$item\" with itemID: ${item?.originalID}/${item?.dynamicID})")
|
||||
}
|
||||
|
||||
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
|
||||
|
||||
@@ -116,7 +116,7 @@ object Block {
|
||||
const val DAYLIGHT_CAPACITOR = 258
|
||||
|
||||
|
||||
const val ACTORBLOCK_NO_COLLISION = 4191
|
||||
const val ACTORBLOCK_NO_COLLISION = 4091
|
||||
const val ACTORBLOCK_FULL_COLLISION = 4092
|
||||
const val ACTORBLOCK_ALLOW_MOVE_DOWN = 4093
|
||||
const val ACTORBLOCK_NO_PASS_RIGHT = 4094
|
||||
|
||||
@@ -58,12 +58,14 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
||||
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event
|
||||
if (ingame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
||||
|
||||
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary"))) {
|
||||
if (
|
||||
Gdx.input.isButtonPressed(AppLoader.getConfigInt("mouseprimary")) ||
|
||||
Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) {
|
||||
ingame.worldPrimaryClickStart(AppLoader.UPDATE_RATE.toFloat())
|
||||
}
|
||||
if (Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary"))) {
|
||||
/*if Gdx.input.isButtonPressed(AppLoader.getConfigInt("mousesecondary")) {
|
||||
ingame.worldSecondaryClickStart(AppLoader.UPDATE_RATE.toFloat())
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,12 +148,14 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
|
||||
// fire world click events; the event is defined as Ingame's (or any others') WorldClick event
|
||||
if (ingame.uiContainer.map { if ((it.isOpening || it.isOpened) && it.mouseUp) 1 else 0 }.sum() == 0) { // no UI on the mouse, right?
|
||||
|
||||
if (button == AppLoader.getConfigInt("mouseprimary")) {
|
||||
if (
|
||||
button == AppLoader.getConfigInt("mouseprimary") ||
|
||||
button == AppLoader.getConfigInt("mousesecondary")) {
|
||||
ingame.worldPrimaryClickEnd(AppLoader.UPDATE_RATE.toFloat())
|
||||
}
|
||||
if (button == AppLoader.getConfigInt("mousesecondary")) {
|
||||
/*if (button == AppLoader.getConfigInt("mousesecondary")) {
|
||||
ingame.worldSecondaryClickEnd(AppLoader.UPDATE_RATE.toFloat())
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,13 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
||||
/**
|
||||
* Where to equip the item.
|
||||
*
|
||||
* Can't use 'open val' as GSON don't like that
|
||||
* Can't use 'open val' as GSON doesn't like that. Initialise this property like:
|
||||
*
|
||||
* ```
|
||||
* init {
|
||||
* equipPosition = EquipPosition.HAND_GRIP
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
var equipPosition: Int = EquipPosition.NULL
|
||||
|
||||
@@ -165,6 +171,8 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
||||
open fun startPrimaryUse(delta: Float): Boolean = false
|
||||
|
||||
/**
|
||||
* I have decided that left and right clicks must do the same thing, so no secondary use from now on. --Torvald on 2019-05-26
|
||||
*
|
||||
* Apply effects (continuously or not) while secondary button is down
|
||||
* The item will NOT be consumed, so you will want to consume it yourself by inventory.consumeItem(item)
|
||||
*
|
||||
@@ -174,7 +182,7 @@ abstract class GameItem(val originalID: ItemID) : Comparable<GameItem>, Cloneabl
|
||||
*
|
||||
* note: DO NOT super() this!
|
||||
*/
|
||||
open fun startSecondaryUse(delta: Float): Boolean = false
|
||||
//open fun startSecondaryUse(delta: Float): Boolean = false
|
||||
|
||||
open fun endPrimaryUse(delta: Float): Boolean = false
|
||||
open fun endSecondaryUse(delta: Float): Boolean = false
|
||||
|
||||
@@ -210,12 +210,12 @@ open class GameWorld {
|
||||
terrain * PairedMapLayer.RANGE + terrainDamage
|
||||
}
|
||||
|
||||
fun getWallLowBits(x: Int, y: Int): Int? {
|
||||
private fun getWallLowBits(x: Int, y: Int): Int? {
|
||||
val (x, y) = coerceXY(x, y)
|
||||
return layerWallLowBits.getData(x, y)
|
||||
}
|
||||
|
||||
fun getTerrainLowBits(x: Int, y: Int): Int? {
|
||||
private fun getTerrainLowBits(x: Int, y: Int): Int? {
|
||||
val (x, y) = coerceXY(x, y)
|
||||
return layerTerrainLowBits.getData(x, y)
|
||||
}
|
||||
@@ -226,57 +226,49 @@ open class GameWorld {
|
||||
* *
|
||||
* @param y
|
||||
* *
|
||||
* @param combinedTilenum Item id of the wall block. Less-than-4096-value is permitted.
|
||||
* @param tilenum Item id of the wall block. Less-than-4096-value is permitted.
|
||||
*/
|
||||
fun setTileWall(x: Int, y: Int, combinedTilenum: Int) {
|
||||
fun setTileWall(x: Int, y: Int, tilenum: Int) {
|
||||
val (x, y) = coerceXY(x, y)
|
||||
val combinedTilenum = combinedTilenum % GameWorld.TILES_SUPPORTED // does work without this, but to be safe...
|
||||
setTileWall(x, y, (combinedTilenum / PairedMapLayer.RANGE).toByte(), combinedTilenum % PairedMapLayer.RANGE)
|
||||
val tilenum = tilenum % TILES_SUPPORTED // does work without this, but to be safe...
|
||||
|
||||
val oldWall = getTileFromWall(x, y)
|
||||
layerWall.setTile(x, y, (tilenum / PairedMapLayer.RANGE).toByte())
|
||||
layerWallLowBits.setData(x, y, tilenum % PairedMapLayer.RANGE)
|
||||
wallDamages.remove(LandUtil.getBlockAddr(this, x, y))
|
||||
|
||||
if (oldWall != null)
|
||||
Terrarum.ingame?.queueWallChangedEvent(oldWall, tilenum, LandUtil.getBlockAddr(this, x, y))
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the tile of wall as specified, with damage value of zero.
|
||||
*
|
||||
* Warning: this function alters fluid lists: be wary of call order!
|
||||
*
|
||||
* @param x
|
||||
* *
|
||||
* @param y
|
||||
* *
|
||||
* @param combinedTilenum Item id of the terrain block, <4096
|
||||
* @param tilenum Item id of the terrain block, <4096
|
||||
*/
|
||||
fun setTileTerrain(x: Int, y: Int, combinedTilenum: Int) {
|
||||
fun setTileTerrain(x: Int, y: Int, tilenum: Int) {
|
||||
val (x, y) = coerceXY(x, y)
|
||||
setTileTerrain(x, y, (combinedTilenum / PairedMapLayer.RANGE).toByte(), combinedTilenum % PairedMapLayer.RANGE)
|
||||
}
|
||||
|
||||
fun setTileWall(x: Int, y: Int, tile: Byte, damage: Int) {
|
||||
val (x, y) = coerceXY(x, y)
|
||||
val oldWall = getTileFromWall(x, y)
|
||||
layerWall.setTile(x, y, tile)
|
||||
layerWallLowBits.setData(x, y, damage)
|
||||
wallDamages.remove(LandUtil.getBlockAddr(this, x, y))
|
||||
|
||||
if (oldWall != null)
|
||||
Terrarum.ingame?.queueWallChangedEvent(oldWall, tile.toUint() * PairedMapLayer.RANGE + damage, LandUtil.getBlockAddr(this, x, y))
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning: this function alters fluid lists: be wary of call order!
|
||||
*/
|
||||
fun setTileTerrain(x: Int, y: Int, tile: Byte, damage: Int) {
|
||||
val (x, y) = coerceXY(x, y)
|
||||
val oldTerrain = getTileFromTerrain(x, y)
|
||||
layerTerrain.setTile(x, y, tile)
|
||||
layerTerrainLowBits.setData(x, y, damage)
|
||||
layerTerrain.setTile(x, y, (tilenum / PairedMapLayer.RANGE).toByte())
|
||||
layerTerrainLowBits.setData(x, y, tilenum % PairedMapLayer.RANGE)
|
||||
val blockAddr = LandUtil.getBlockAddr(this, x, y)
|
||||
terrainDamages.remove(blockAddr)
|
||||
|
||||
if (BlockCodex[tile * PairedMapLayer.RANGE + damage].isSolid) {
|
||||
if (BlockCodex[tilenum].isSolid) {
|
||||
fluidFills.remove(blockAddr)
|
||||
fluidTypes.remove(blockAddr)
|
||||
}
|
||||
// fluid tiles-item should be modified so that they will also place fluid onto their respective map
|
||||
|
||||
if (oldTerrain != null)
|
||||
Terrarum.ingame?.queueTerrainChangedEvent(oldTerrain, tile.toUint() * PairedMapLayer.RANGE + damage, LandUtil.getBlockAddr(this, x, y))
|
||||
Terrarum.ingame?.queueTerrainChangedEvent(oldTerrain, tilenum, LandUtil.getBlockAddr(this, x, y))
|
||||
}
|
||||
|
||||
/*fun setTileWire(x: Int, y: Int, tile: Byte) {
|
||||
|
||||
@@ -404,7 +404,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
ItemCodex[itemOnGrip]?.endPrimaryUse(delta)
|
||||
}
|
||||
|
||||
override fun worldSecondaryClickStart(delta: Float) {
|
||||
// I have decided that left and right clicks must do the same thing, so no secondary use from now on. --Torvald on 2019-05-26
|
||||
/*override fun worldSecondaryClickStart(delta: Float) {
|
||||
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
|
||||
val consumptionSuccessful = ItemCodex[itemOnGrip]?.startSecondaryUse(delta) ?: false
|
||||
if (consumptionSuccessful)
|
||||
@@ -414,7 +415,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
override fun worldSecondaryClickEnd(delta: Float) {
|
||||
val itemOnGrip = actorNowPlaying?.inventory?.itemEquipped?.get(GameItem.EquipPosition.HAND_GRIP)
|
||||
ItemCodex[itemOnGrip]?.endSecondaryUse(delta)
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -42,20 +42,27 @@ open class FixtureBase(val blockBox: BlockBox, val blockBoxProps: BlockBoxProps
|
||||
// posY: bottom of the blockBox
|
||||
// using the actor's hitbox
|
||||
|
||||
// TODO: obviously check for collision
|
||||
|
||||
for (x in posX until posX + blockBox.width) {
|
||||
for (y in posY until posY + blockBox.height) {
|
||||
world.setTileTerrain(x, y, blockBox.collisionType)
|
||||
}
|
||||
}
|
||||
|
||||
// set the position of this actor
|
||||
worldBlockPos = Point2i(posX, posY)
|
||||
|
||||
this.isVisible = true
|
||||
this.hitbox.setFromWidthHeight(posX * TSIZE, posY * TSIZE, blockBox.width * TSIZE, blockBox.height * TSIZE)
|
||||
|
||||
// actually add this actor into the world
|
||||
Terrarum.ingame!!.addNewActor(this)
|
||||
|
||||
|
||||
return true // TODO for the tests' sake, just get fucking spawned
|
||||
|
||||
// TODO TESTING RESULTS SO FAR: tiki torch does emit lights, but its body cannot be seen
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,10 +25,17 @@ class TikiTorchTester(originalID: ItemID) : GameItem(originalID) {
|
||||
get() = AppLoader.resourcePool.getAsTextureRegion("itemplaceholder_48")
|
||||
override var baseToolSize: Double? = baseMass
|
||||
|
||||
init {
|
||||
equipPosition = EquipPosition.HAND_GRIP
|
||||
}
|
||||
|
||||
override fun startPrimaryUse(delta: Float): Boolean {
|
||||
val torch = FixtureTikiTorch()
|
||||
|
||||
//println("aroisetn")
|
||||
|
||||
return torch.spawn(Terrarum.mouseTileX, Terrarum.mouseTileY - torch.blockBox.height + 1)
|
||||
// return true when placed, false when cannot be placed
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameworld
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import net.torvald.aa.KDHeapifiedTree
|
||||
import net.torvald.aa.KDTree
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
@@ -52,7 +52,7 @@ object WorldSimulator {
|
||||
private val ingame = Terrarum.ingame!!
|
||||
private val world = ingame.world
|
||||
|
||||
private var actorsKDTree: KDHeapifiedTree? = null
|
||||
private var actorsKDTree: KDTree? = null
|
||||
|
||||
fun resetForThisFrame() {
|
||||
actorsKDTree = null
|
||||
@@ -61,7 +61,7 @@ object WorldSimulator {
|
||||
operator fun invoke(player: ActorHumanoid?, delta: Float) {
|
||||
// build the kdtree that will be used during a single frame of updating
|
||||
if (actorsKDTree == null)
|
||||
actorsKDTree = KDHeapifiedTree(ingame.actorContainerActive.filter { it is ActorWBMovable })
|
||||
actorsKDTree = KDTree(ingame.actorContainerActive.filter { it is ActorWBMovable })
|
||||
|
||||
//printdbg(this, "============================")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user