mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 03:54:06 +09:00
fixed: noclipped player won't move up and down when gamepad is plugged in
This commit is contained in:
@@ -273,11 +273,6 @@ open class ActorHumanoid(
|
|||||||
/**
|
/**
|
||||||
* U-D stop
|
* U-D stop
|
||||||
*/
|
*/
|
||||||
if (hasController) {
|
|
||||||
if (axisY == 0f) {
|
|
||||||
walkVStop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ↑E
|
// ↑E
|
||||||
// ↑D
|
// ↑D
|
||||||
if (isNoClip && !isUpDown && !isDownDown && axisY == 0f) {
|
if (isNoClip && !isUpDown && !isDownDown && axisY == 0f) {
|
||||||
@@ -319,7 +314,7 @@ open class ActorHumanoid(
|
|||||||
if (isNoClip || COLLISION_TEST_MODE) {
|
if (isNoClip || COLLISION_TEST_MODE) {
|
||||||
if (hasController) {
|
if (hasController) {
|
||||||
if (axisY != 0f) {
|
if (axisY != 0f) {
|
||||||
walkVertical(axisY < 0, axisY.abs())
|
walkVertical(axisY > 0, axisY.abs())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ↑E, ↓D
|
// ↑E, ↓D
|
||||||
|
|||||||
@@ -1,26 +1,36 @@
|
|||||||
package net.torvald.terrarum.modulebasegame.gameactors
|
package net.torvald.terrarum.modulebasegame.gameactors
|
||||||
|
|
||||||
import net.torvald.terrarum.IngameInstance
|
import net.torvald.terrarum.IngameInstance
|
||||||
import net.torvald.terrarum.Point2d
|
import net.torvald.terrarum.Point2i
|
||||||
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.gameactors.ActorWBMovable
|
import net.torvald.terrarum.gameactors.ActorWBMovable
|
||||||
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2016-06-17.
|
* Created by minjaesong on 2016-06-17.
|
||||||
*/
|
*/
|
||||||
open class FixtureBase(val blockBox: BlockBox, val blockBoxProps: BlockBoxProps = BlockBoxProps(0)) :
|
open class FixtureBase(val blockBox: BlockBox, val blockBoxProps: BlockBoxProps = BlockBoxProps(0)) :
|
||||||
// disabling physics (not allowing the fixture to move) WILL make things easier
|
// disabling physics (not allowing the fixture to move) WILL make things easier in many ways
|
||||||
ActorWBMovable(RenderOrder.BEHIND, immobileBody = true, usePhysics = false), CuedByTerrainChange {
|
ActorWBMovable(RenderOrder.BEHIND, immobileBody = true, usePhysics = false), CuedByTerrainChange {
|
||||||
|
|
||||||
|
private val world: GameWorld
|
||||||
|
get() = Terrarum.ingame!!.world
|
||||||
|
|
||||||
|
private val TSIZE = TILE_SIZE.toDouble()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block-wise position of this fixture when it's placed on the world. Null if it's not on the world
|
* Block-wise position of this fixture when it's placed on the world. Null if it's not on the world
|
||||||
*/
|
*/
|
||||||
private var worldBlockPos: Point2d? = null
|
private var worldBlockPos: Point2i? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds this instance of the fixture to the world
|
* Adds this instance of the fixture to the world
|
||||||
|
*
|
||||||
|
* @param posX top-left position of the fixture, tile-wise
|
||||||
|
* @param posY top-left position of the fixture, tile-wise
|
||||||
*/
|
*/
|
||||||
open fun spawn() {
|
open fun spawn(posX: Int, posY: Int) {
|
||||||
// place filler blocks
|
// place filler blocks
|
||||||
// place the filler blocks where:
|
// place the filler blocks where:
|
||||||
// origin posX: centre-left if mouseX is on the right-half of the game window,
|
// origin posX: centre-left if mouseX is on the right-half of the game window,
|
||||||
@@ -31,10 +41,22 @@ open class FixtureBase(val blockBox: BlockBox, val blockBoxProps: BlockBoxProps
|
|||||||
// posY: bottom of the blockBox
|
// posY: bottom of the blockBox
|
||||||
// using the actor's hitbox
|
// using the actor's hitbox
|
||||||
|
|
||||||
|
for (x in posX until posX + blockBox.width) {
|
||||||
|
for (y in posY until posY + blockBox.height) {
|
||||||
|
world.setTileTerrain(x, y, blockBox.collisionType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
worldBlockPos = Point2i(posX, posY)
|
||||||
|
|
||||||
|
this.isVisible = true
|
||||||
|
this.hitbox.setFromWidthHeight(posX * TSIZE, posY * TSIZE, blockBox.width * TSIZE, blockBox.height * TSIZE)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update code that runs once for every frame
|
||||||
|
*/
|
||||||
open fun updateSelf() {
|
open fun updateSelf() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -43,7 +65,61 @@ open class FixtureBase(val blockBox: BlockBox, val blockBoxProps: BlockBoxProps
|
|||||||
* Removes this instance of the fixture from the world
|
* Removes this instance of the fixture from the world
|
||||||
*/
|
*/
|
||||||
open fun despawn() {
|
open fun despawn() {
|
||||||
|
val posX = worldBlockPos!!.x
|
||||||
|
val posY = worldBlockPos!!.y
|
||||||
|
|
||||||
// remove filler block
|
// remove filler block
|
||||||
|
for (x in posX until posX + blockBox.width) {
|
||||||
|
for (y in posY until posY + blockBox.height) {
|
||||||
|
world.setTileTerrain(x, y, Block.AIR)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
worldBlockPos = null
|
||||||
|
|
||||||
|
this.isVisible = false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fired by world's BlockChanged event (fired when blocks are placed/removed).
|
||||||
|
* The flooding check must run on every frame. use updateSelf() for that.
|
||||||
|
*
|
||||||
|
* E.g. if a fixture block that is inside of BlockBox is missing, destroy and drop self.
|
||||||
|
*/
|
||||||
|
override fun updateForWorldChange(cue: IngameInstance.BlockChangeQueueItem) {
|
||||||
|
// check for marker blocks.
|
||||||
|
// if at least one of them is missing, destroy all the markers and drop self as an item
|
||||||
|
|
||||||
|
// you need to implement Dropped Item first to satisfyingly implement this function
|
||||||
|
|
||||||
|
val posX = worldBlockPos!!.x
|
||||||
|
val posY = worldBlockPos!!.y
|
||||||
|
var dropThis = false
|
||||||
|
|
||||||
|
// remove filler block
|
||||||
|
outerLoop@
|
||||||
|
for (x in posX until posX + blockBox.width) {
|
||||||
|
for (y in posY until posY + blockBox.height) {
|
||||||
|
if (world.getTileFromTerrain(x, y) != blockBox.collisionType) {
|
||||||
|
dropThis = true
|
||||||
|
break@outerLoop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dropThis) {
|
||||||
|
// fill blockbox with air
|
||||||
|
for (x in posX until posX + blockBox.width) {
|
||||||
|
for (y in posY until posY + blockBox.height) {
|
||||||
|
if (world.getTileFromTerrain(x, y) == blockBox.collisionType) {
|
||||||
|
world.setTileTerrain(x, y, Block.AIR)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO drop self as an item (instance of DroppedItem)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,9 +130,7 @@ interface CuedByTerrainChange {
|
|||||||
*
|
*
|
||||||
* E.g. if a fixture block that is inside of BlockBox is missing, destroy and drop self.
|
* E.g. if a fixture block that is inside of BlockBox is missing, destroy and drop self.
|
||||||
*/
|
*/
|
||||||
fun updateForWorldChange(cue: IngameInstance.BlockChangeQueueItem) {
|
fun updateForWorldChange(cue: IngameInstance.BlockChangeQueueItem)
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,6 +148,11 @@ inline class BlockBoxProps(val flags: Int) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param collisionType Collision type defined in BlockBox.Companion
|
||||||
|
* @param width Width of the block box, tile-wise
|
||||||
|
* @param height Height of the block box, tile-wise
|
||||||
|
*/
|
||||||
data class BlockBox(var collisionType: Int, var width: Int, var height: Int) {
|
data class BlockBox(var collisionType: Int, var width: Int, var height: Int) {
|
||||||
|
|
||||||
fun redefine(collisionType: Int, width: Int, height: Int) {
|
fun redefine(collisionType: Int, width: Int, height: Int) {
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ open class UIItemTextButton(
|
|||||||
else inactiveCol
|
else inactiveCol
|
||||||
|
|
||||||
font.draw(batch,
|
font.draw(batch,
|
||||||
label,
|
label, //"$label/H:${highlighted.toInt()}, M:${mouseUp.toInt()}",
|
||||||
when (alignment) {
|
when (alignment) {
|
||||||
Alignment.CENTRE -> posX.toFloat() + width.minus(textW).div(2) + (preGapX - postGapX).div(2)
|
Alignment.CENTRE -> posX.toFloat() + width.minus(textW).div(2) + (preGapX - postGapX).div(2)
|
||||||
Alignment.LEFT -> posX.toFloat() + preGapX
|
Alignment.LEFT -> posX.toFloat() + preGapX
|
||||||
|
|||||||
Reference in New Issue
Block a user