mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 02:24:05 +09:00
detailed impl of fixtures WIP
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package net.torvald.terrarum.modulebasegame
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.InputAdapter
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.IngameInstance
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.Yaml
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.gameactors.*
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
@@ -11,8 +15,8 @@ import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
|
||||
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
|
||||
import net.torvald.terrarum.modulebasegame.ui.Notification
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIBuildingMakerToolbox
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UINSMenu
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import net.torvald.terrarum.worlddrawer.WorldCamera
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
@@ -23,6 +27,32 @@ import kotlin.system.measureNanoTime
|
||||
*/
|
||||
class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
private val menuYaml = Yaml("""
|
||||
- File
|
||||
- New
|
||||
- Export…
|
||||
- Export sel…
|
||||
- Import…
|
||||
- Save world…
|
||||
- Load world…
|
||||
- Tool
|
||||
- Pencil
|
||||
- Eyedropper
|
||||
- Select mrq.
|
||||
- Move
|
||||
- Undo
|
||||
- Redo
|
||||
- Time
|
||||
- Morning
|
||||
- Noon
|
||||
- Dusk
|
||||
- Night
|
||||
- Set…
|
||||
- Weather
|
||||
- Sunny
|
||||
- Raining
|
||||
""".trimIndent())
|
||||
|
||||
private val timeNow = System.currentTimeMillis() / 1000
|
||||
|
||||
val gameWorld = GameWorldExtension(1, 1024, 256, timeNow, timeNow, 0)
|
||||
@@ -49,7 +79,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
override var actorNowPlaying: ActorHumanoid? = MovableWorldCamera()
|
||||
|
||||
val uiToolbox = UIBuildingMakerToolbox()
|
||||
val uiToolbox = UINSMenu("Menu", 100, menuYaml)
|
||||
val notifier = Notification()
|
||||
|
||||
val uiContainer = ArrayList<UICanvas>()
|
||||
@@ -106,7 +136,8 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
|
||||
|
||||
uiToolbox.setPosition(Terrarum.WIDTH - 20, 4)
|
||||
uiToolbox.setPosition(0, 0)
|
||||
uiToolbox.isVisible = true
|
||||
notifier.setPosition(
|
||||
(Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height)
|
||||
|
||||
@@ -118,6 +149,11 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
LightmapRenderer.fireRecalculateEvent()
|
||||
}
|
||||
|
||||
override fun show() {
|
||||
Gdx.input.inputProcessor = BuildingMakerController(this)
|
||||
super.show()
|
||||
}
|
||||
|
||||
override fun render(delta: Float) {
|
||||
Gdx.graphics.setTitle(Ingame.getCanonicalTitle())
|
||||
|
||||
@@ -172,7 +208,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
override fun resize(width: Int, height: Int) {
|
||||
IngameRenderer.resize(Terrarum.WIDTH, Terrarum.HEIGHT)
|
||||
uiToolbox.setPosition(Terrarum.WIDTH - 20, 4)
|
||||
uiToolbox.setPosition(0, 0)
|
||||
notifier.setPosition(
|
||||
(Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height)
|
||||
println("[BuildingMaker] Resize event")
|
||||
@@ -181,16 +217,49 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
override fun dispose() {
|
||||
IngameRenderer.dispose()
|
||||
}
|
||||
|
||||
private val menuYaml = Yaml("""
|
||||
- File
|
||||
- New
|
||||
- Export
|
||||
- Import
|
||||
- Edit
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
class BuildingMakerController(val screen: BuildingMaker) : InputAdapter() {
|
||||
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
screen.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
|
||||
screen.uiContainer.forEach { it.mouseMoved(screenX, screenY) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun keyTyped(character: Char): Boolean {
|
||||
screen.uiContainer.forEach { it.keyTyped(character) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun scrolled(amount: Int): Boolean {
|
||||
screen.uiContainer.forEach { it.scrolled(amount) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun keyUp(keycode: Int): Boolean {
|
||||
screen.uiContainer.forEach { it.keyUp(keycode) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||
screen.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
screen.uiContainer.forEach { it.keyDown(keycode) }
|
||||
return true
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
screen.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) }
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
class MovableWorldCamera : ActorHumanoid(0, usePhysics = false) {
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user