detailed impl of fixtures WIP

This commit is contained in:
Minjae Song
2018-12-29 04:11:26 +09:00
parent 1afd50cf2d
commit f417ce00dc
9 changed files with 259 additions and 135 deletions

View File

@@ -1,31 +1,53 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.Point2d
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 2016-06-17.
*/
open class FixtureBase(physics: Boolean = true) :
ActorWBMovable(RenderOrder.BEHIND, immobileBody = true, usePhysics = physics) {
/**
* 0: Open
* 1: Blocked
* 2: Platform; can be stood on, press DOWN to go down. Also allows other blocks can be places on top of it (e.g. torch)
* 3: Wall_left; blocks rightward movement
* 4: Wall_right: blocks leftward movement
* 5: Same as 2 but player CANNOT go down
* For example, flag of 4 is good for tables; player can stand on, which means
* downward movement is blocked within the fixtures' AABB.
*/
var collisionFlag: Int = 0
open class FixtureBase(val blockBox: BlockBox) :
// disabling physics (not allowing the fixture to move) WILL make things easier
ActorWBMovable(RenderOrder.BEHIND, immobileBody = true, usePhysics = false) {
/**
* 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
/**
* Adds this instance of the fixture to the world
*/
open fun spawn() {
// place filler blocks
// place the filler blocks where:
// origin posX: centre-left if mouseX is on the right-half of the game window,
// centre-right otherwise
// origin posY: bottom
// place the actor within the blockBox where:
// posX: centre of the blockBox
// posY: bottom of the blockBox
// using the actor's hitbox
}
/**
* Removes this instance of the fixture from the world
*/
open fun despawn() {
// remove filler block
}
}
data class BlockBox(val collisionType: Int, val width: Int, val height: Int) {
companion object {
val COLLISION_OPEN = 0
val COLLISION_BLOCKED = 1
val COLLISION_PLATFORM = 2
val COLLISION_WALL_LEFT = 3
val COLLISION_WALL_RIGHT = 4
val COLLISION_PLATFORM_NOGODOWN = 5
const val NO_COLLISION = Block.ACTORBLOCK_NO_COLLISION
const val FULL_COLLISION = Block.ACTORBLOCK_FULL_COLLISION
const val ALLOW_MOVE_DOWN = Block.ACTORBLOCK_ALLOW_MOVE_DOWN
const val NO_PASS_RIGHT = Block.ACTORBLOCK_NO_PASS_RIGHT
const val NO_PASS_LEFT = Block.ACTORBLOCK_NO_PASS_LEFT
}
}

View File

@@ -7,14 +7,15 @@ import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.util.*
/**
* Created by minjaesong on 2016-06-17.
*/
internal class FixtureTikiTorch : FixtureBase(), Luminous {
internal class FixtureTikiTorch : FixtureBase(
BlockBox(BlockBox.NO_COLLISION, 1, 2)
), Luminous {
override var color: Color
get() = BlockCodex[Block.TORCH].luminosity

View File

@@ -0,0 +1,25 @@
package net.torvald.terrarum.modulebasegame.gameactors
import net.torvald.terrarum.ui.UICanvas
/**
* Furnitures that opens its own UI when right-clicked/interact-key-downed
*
* It is recommended to override dispose() as follows:
* ```
* override fun dispose() {
* closeUI() // UI will be closed when the furniture is being destroyed while the UI is opened
* super.dispose()
* }
* ```
*
* Created by minjaesong on 2018-12-29.
*/
interface Interactable {
val ui: UICanvas
fun openUI()
fun closeUI()
}