generalised things so that they would work outside of ingame.world; title screen wip

This commit is contained in:
minjaesong
2017-07-21 19:59:51 +09:00
parent cb8d3fd8b9
commit f1391bea6f
68 changed files with 1141 additions and 328 deletions

View File

@@ -0,0 +1,120 @@
package net.torvald.terrarum
object CreditSingleton {
val contents = """Terrarum
Copyright (C) 2013-2017 Minjaesong (Torvald)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*Simplex Noise Generator*, version 2012-03-09 by Stefan Gustavson
Released as public domain
Joise
opyright (C) 2013 Jason Taylor
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Accidental Noise Library
Joise is a derivative work based on Josua Tippetts' C++ library:
http://accidentalnoise.sourceforge.net/index.html
Copyright (C) 2011 Joshua Tippetts
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Vector2
Copyright (c) 2010-2015 William Bittle http://www.dyn4j.org/
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the
distribution.
* Neither the name of dyn4j nor the names of its contributors may be used to endorse or
promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kotlin translated and modified code Copyright (C) 2016 Minjaesong (Torvald)
Ambient sound recordings:
ambient_forest_01.ogg
ambient_meadow_01.ogg
ambient_windy_01.ogg
ambient_woods_01.ogg
crickets_01.ogg
crickets_02.ogg
Copyright (C) 2012, 2013, 2015, 2016, 2017 Klankbeeld
Sound from http://www.freesound.org/people/klankbeeld/
""" }

View File

@@ -269,7 +269,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
// add new player and put it to actorContainer
//playableActorDelegate = PlayableActorDelegate(PlayerBuilderSigrid())
//playableActorDelegate = PlayableActorDelegate(PlayerBuilderTestSubject1())
//addNewActor(player!!)
//addNewActor(player)
// test actor
@@ -399,7 +399,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
private class ThreadIngameUpdate(val ingame: Ingame): Runnable {
override fun run() {
while (ingame.updateDeltaCounter >= ingame.updateRate) {
ingame.updateGame(Gdx.graphics.deltaTime)
ingame.updateGame(Terrarum.deltaTime)
ingame.updateDeltaCounter -= ingame.updateRate
}
}
@@ -541,12 +541,10 @@ class Ingame(val batch: SpriteBatch) : Screen {
// Post-update; ones that needs everything is completed //
// update lightmap on every other frames, OR full-frame if the option is true
if (Terrarum.getConfigBoolean("fullframelightupdate") or (Terrarum.GLOBAL_RENDER_TIMER % 2 == 1)) { //
LightmapRenderer.fireRecalculateEvent() //
} //
// end of post-update /
if (Terrarum.getConfigBoolean("fullframelightupdate") or (Terrarum.GLOBAL_RENDER_TIMER % 2 == 1)) {
LightmapRenderer.fireRecalculateEvent()
}
@@ -590,7 +588,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
/////////////////
actorsRenderMiddle.forEach { it.drawBody(batch) }
actorsRenderMidTop.forEach { it.drawBody(batch) }
player?.drawBody(batch)
player.drawBody(batch)
actorsRenderFront.forEach { it.drawBody(batch) }
// --> Change of blend mode <-- introduced by childs of ActorWithBody //
@@ -668,7 +666,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
particlesContainer.forEach { it.drawGlow(batch) }
actorsRenderMiddle.forEach { it.drawGlow(batch) }
actorsRenderMidTop.forEach { it.drawGlow(batch) }
player?.drawGlow(batch)
player.drawGlow(batch)
actorsRenderFront.forEach { it.drawGlow(batch) }
// --> blendNormal() <-- introduced by childs of ActorWithBody //
@@ -891,7 +889,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
/////////////////
actorsRenderMiddle.forEach { it.drawBody(batch) }
actorsRenderMidTop.forEach { it.drawBody(batch) }
player?.drawBody(batch)
player.drawBody(batch)
actorsRenderFront.forEach { it.drawBody(batch) }
// --> Change of blend mode <-- introduced by childs of ActorWithBody //
@@ -918,7 +916,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
//////////////////////
actorsRenderMiddle.forEach { it.drawGlow(batch) }
actorsRenderMidTop.forEach { it.drawGlow(batch) }
player?.drawGlow(batch)
player.drawGlow(batch)
actorsRenderFront.forEach { it.drawGlow(batch) }
// --> blendLightenOnly() <-- introduced by childs of ActorWithBody //
@@ -1133,7 +1131,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
}
playableActorDelegate = newActor
WorldSimulator(player, Gdx.graphics.deltaTime)
WorldSimulator(player, Terrarum.deltaTime)
}
private fun changePossession(refid: Int) {
@@ -1150,7 +1148,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
// accept new delegate
playableActorDelegate = PlayableActorDelegate(getActorByID(refid) as ActorHumanoid)
playableActorDelegate!!.actor.collisionType = ActorWithPhysics.COLLISION_KINEMATIC
WorldSimulator(player, Gdx.graphics.deltaTime)
WorldSimulator(player, Terrarum.deltaTime)
}
/** Send message to notifier UI and toggle the UI as opened. */
@@ -1242,7 +1240,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
}
}
playableActorDelegate?.update(delta)
//AmmoMeterProxy(player!!, uiVitalItem.UI as UIVitalMetre)
//AmmoMeterProxy(player, uiVitalItem.UI as UIVitalMetre)
}
}
@@ -1314,7 +1312,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
* This is how remove function of [java.util.ArrayList] is defined.
*/
fun removeActor(actor: Actor) {
if (actor.referenceID == player?.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
if (actor.referenceID == player.referenceID || actor.referenceID == 0x51621D) // do not delete this magic
throw RuntimeException("Attempted to remove player.")
val indexToDelete = actorContainer.binarySearch(actor.referenceID)
if (indexToDelete >= 0) {

View File

@@ -13,6 +13,7 @@ import com.badlogic.gdx.graphics.glutils.ShaderProgram
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.google.gson.JsonArray
import com.google.gson.JsonPrimitive
import net.torvald.random.HQRNG
import net.torvald.terrarum.Terrarum.RENDER_FPS
import net.torvald.terrarum.gameactors.floorInt
import net.torvald.terrarum.gamecontroller.IngameController
@@ -92,6 +93,9 @@ object Terrarum : Game() {
val HEIGHT: Int
get() = if (screenH!! % 2 == 0) screenH!! else screenH!! + 1
val WIDTH_MIN = 800
val HEIGHT_MIN = 600
inline val HALFW: Int
get() = WIDTH.ushr(1)
inline val HALFH: Int
@@ -265,6 +269,8 @@ object Terrarum : Game() {
lateinit var fullscreenQuad: Mesh; private set
val deltaTime: Float; get() = Gdx.graphics.rawDeltaTime
init {
println("$NAME version $VERSION_STRING")
@@ -423,7 +429,7 @@ object Terrarum : Game() {
}
override fun render() {
super.screen.render(Gdx.graphics.deltaTime)
super.screen.render(deltaTime)
GLOBAL_RENDER_TIMER += 1
}
@@ -452,6 +458,12 @@ object Terrarum : Game() {
}
override fun resize(width: Int, height: Int) {
var width = maxOf(width, WIDTH_MIN)
var height = maxOf(height, HEIGHT_MIN)
if (width % 2 == 1) width += 1
if (height % 2 == 1) height += 1
screenW = width
screenH = height
@@ -466,7 +478,10 @@ object Terrarum : Game() {
fullscreenQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
super.screen.resize(WIDTH, HEIGHT)
super.resize(width, height)
//Gdx.graphics.setWindowedMode(width, height)
println("newsize: ${Gdx.graphics.width}x${Gdx.graphics.height}")
}
@@ -658,10 +673,6 @@ object Terrarum : Game() {
get() = Gdx.input.x
inline val mouseScreenY: Int
get() = Gdx.input.y
}
inline fun SpriteBatch.inUse(action: (SpriteBatch) -> Unit) {

View File

@@ -8,8 +8,8 @@ import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.glutils.FrameBuffer
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.Hitbox
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameactors.ai.ActorAI
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.langpack.Lang
@@ -47,17 +47,14 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
private var loadDone = false
private lateinit var demoWorld: GameWorld
private val cameraPlayer = object : ActorWithBody(RenderOrder.BEHIND) {
override fun drawBody(batch: SpriteBatch) { }
override fun drawGlow(batch: SpriteBatch) { }
override fun dispose() { }
override fun onActorValueChange(key: String, value: Any?) { }
override fun run() { }
override fun update(delta: Float) {
// camera walk?
private val cameraAI = object : ActorAI {
override fun update(actor: HumanoidNPC, delta: Float) {
// pan camera
//actor.moveRight() // why no work?
actor.controllerMoveDelta!!.x = 0.5
}
}
private lateinit var cameraPlayer: HumanoidNPC
private val gradWhiteTop = Color(0xf8f8f8ff.toInt())
private val gradWhiteBottom = Color(0xd8d8d8ff.toInt())
@@ -74,11 +71,18 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
private fun loadThingsWhileIntroIsVisible() {
demoWorld = ReadLayerData(FileInputStream(ModMgr.getFile("basegame", "demoworld")))
cameraPlayer.hitbox.setPosition(
demoWorld.spawnX * FeaturesDrawer.TILE_SIZE.toDouble(),
demoWorld.spawnY * FeaturesDrawer.TILE_SIZE.toDouble()
)
cameraPlayer.hitbox.setDimension(2.0, 2.0)
cameraPlayer = object : HumanoidNPC(demoWorld, cameraAI, GameDate(1, 1), usePhysics = false) {
init {
setHitboxDimension(2, 2, 0, 0)
hitbox.setPosition(
demoWorld.spawnX * FeaturesDrawer.TILE_SIZE.toDouble(),
(demoWorld.height / 3) * 0.75 * FeaturesDrawer.TILE_SIZE.toDouble()//demoWorld.spawnY * FeaturesDrawer.TILE_SIZE.toDouble()
)
actorValue[AVKey.SPEED] = 1.0
actorValue[AVKey.ACCEL] = 1.0
}
}
demoWorld.time.timeDelta = 60
@@ -146,14 +150,6 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
}
}
else {
//if (Terrarum.GLOBAL_RENDER_TIMER % 2 == 1) {
LightmapRenderer.fireRecalculateEvent()
//}
cameraPlayer.hitbox.setPosition(1024 * 16.0, 340 * 16.0)
demoWorld.updateWorldTime(delta)
WeatherMixer.update(delta, cameraPlayer)
cameraPlayer.update(delta)
@@ -165,11 +161,19 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
uiContainer.forEach { it.update(delta) }
if (Terrarum.GLOBAL_RENDER_TIMER % 2 == 1) {
LightmapRenderer.fireRecalculateEvent()
}
// render and blur lightmap
//processBlur(LightmapRenderer.DRAW_FOR_RGB)
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE)
// render world
batch.inUse {
setCameraPosition(0f, 0f)
batch.color = Color.WHITE
batch.shader = null
camera.position.set(WorldCamera.gdxCamX, WorldCamera.gdxCamY, 0f) // make camara work
camera.update()
@@ -215,6 +219,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
BlocksDrawer.renderTerrain(batch)
BlocksDrawer.renderFront(batch, false)
FeaturesDrawer.drawEnvOverlay(batch)
}
private fun renderMenus() {

View File

@@ -129,7 +129,7 @@ class UIItemInventoryElem(
override fun keyDown(keycode: Int): Boolean {
if (item != null && Terrarum.ingame != null && keycode in Input.Keys.NUM_1..Input.Keys.NUM_0) {
val inventory = Terrarum.ingame!!.player?.inventory
val inventory = Terrarum.ingame!!.player.inventory
val slot = if (keycode == Input.Keys.NUM_0) 9 else keycode - Input.Keys.NUM_1
val currentSlotItem = inventory?.getQuickBar(slot)
@@ -161,11 +161,11 @@ class UIItemInventoryElem(
val itemEquipSlot = item!!.equipPosition
val player = Terrarum.ingame!!.player
if (item != player?.inventory?.itemEquipped?.get(itemEquipSlot)) { // if this item is unequipped, equip it
player?.equipItem(item!!)
if (item != player.inventory?.itemEquipped?.get(itemEquipSlot)) { // if this item is unequipped, equip it
player.equipItem(item!!)
}
else { // if not, unequip it
player?.unequipItem(item!!)
player.unequipItem(item!!)
}
}

View File

@@ -63,9 +63,9 @@ object BlockPropUtil {
internal fun dynamicLumFuncTickClock() {
// FPS-time compensation
if (Gdx.graphics.framesPerSecond > 0) {
flickerFuncX += Gdx.graphics.deltaTime * 1000f
breathFuncX += Gdx.graphics.deltaTime * 1000f
pulsateFuncX += Gdx.graphics.deltaTime * 1000f
flickerFuncX += Terrarum.deltaTime * 1000f
breathFuncX += Terrarum.deltaTime * 1000f
pulsateFuncX += Terrarum.deltaTime * 1000f
}
// flicker-related vars

View File

@@ -33,9 +33,9 @@ object BlockStats {
val renderHeight = FastMath.ceil(Terrarum.HEIGHT.toFloat())
val noZoomCameraX = Math.round(FastMath.clamp(
(player?.hitbox?.centeredX?.toFloat() ?: 0f) - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat()))
(player.hitbox?.centeredX?.toFloat() ?: 0f) - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat()))
val noZoomCameraY = Math.round(FastMath.clamp(
(player?.hitbox?.centeredY?.toFloat() ?: 0f) - renderHeight / 2, TSIZE.toFloat(), map.width * TSIZE - renderHeight - TSIZE.toFloat()))
(player.hitbox?.centeredY?.toFloat() ?: 0f) - renderHeight / 2, TSIZE.toFloat(), map.width * TSIZE - renderHeight - TSIZE.toFloat()))
val for_x_start = noZoomCameraX / TSIZE
val for_y_start = noZoomCameraY / TSIZE

View File

@@ -13,7 +13,7 @@ internal object ExportAV : ConsoleCommand {
if (args.size == 2) {
try {
JsonWriter.writeToFile(
Terrarum.ingame!!.player!!.actorValue,
Terrarum.ingame!!.player.actorValue,
Terrarum.defaultDir + "/Exports/" + args[1] + ".json")
Echo("ExportAV: exported to " + args[1] + ".json")

View File

@@ -12,7 +12,7 @@ internal object GetAV : ConsoleCommand {
try {
if (args.size == 1 && Terrarum.ingame!!.player != null) {
// print all actorvalue of player
val av = Terrarum.ingame!!.player!!.actorValue
val av = Terrarum.ingame!!.player.actorValue
val keyset = av.keySet
Echo("$ccW== ActorValue list for ${ccY}player $ccW==")
@@ -30,14 +30,14 @@ internal object GetAV : ConsoleCommand {
if (!args[1].isNum()) { // args[1] is ActorValue name
Echo("${ccW}player.$ccM${args[1]} $ccW= " +
ccG +
Terrarum.ingame!!.player!!.actorValue[args[1]] +
Terrarum.ingame!!.player.actorValue[args[1]] +
" $ccO" +
Terrarum.ingame!!.player!!.actorValue[args[1]]!!.javaClass.simpleName
Terrarum.ingame!!.player.actorValue[args[1]]!!.javaClass.simpleName
)
println("[GetAV] player.${args[1]} = " +
Terrarum.ingame!!.player!!.actorValue[args[1]] +
Terrarum.ingame!!.player.actorValue[args[1]] +
" " +
Terrarum.ingame!!.player!!.actorValue[args[1]]!!.javaClass.simpleName
Terrarum.ingame!!.player.actorValue[args[1]]!!.javaClass.simpleName
)
}
else {

View File

@@ -59,7 +59,7 @@ internal object SetAV : ConsoleCommand {
return
}
Terrarum.ingame!!.player!!.actorValue[args[1]] = newValue
Terrarum.ingame!!.player.actorValue[args[1]] = newValue
Echo("${ccW}Set $ccM${args[1]} ${ccW}for ${ccY}player ${ccW}to $ccG$newValue")
println("[SetAV] set ActorValue '${args[1]}' for player to '$newValue'.")
}

View File

@@ -10,7 +10,7 @@ internal object SetScale : ConsoleCommand {
override fun execute(args: Array<String>) {
if (args.size == 2 || args.size == 3) {
try {
val targetID = if (args.size == 3) args[1].toInt() else Terrarum.ingame!!.player!!.referenceID
val targetID = if (args.size == 3) args[1].toInt() else Terrarum.ingame!!.player.referenceID
val scale = args[if (args.size == 3) 2 else 1].toDouble()
val target = Terrarum.ingame!!.getActorByID(targetID)

View File

@@ -20,7 +20,7 @@ internal object SpawnPhysTestBall : ConsoleCommand {
val xvel = args[2].toDouble()
val yvel = if (args.size >= 4) args[3].toDouble() else 0.0
val ball = PhysTestBall()
val ball = PhysTestBall(Terrarum.ingame!!.world)
ball.setPosition(
(mouseX + WorldCamera.x).toDouble(),
(mouseY + WorldCamera.y).toDouble()
@@ -33,7 +33,7 @@ internal object SpawnPhysTestBall : ConsoleCommand {
else if (args.size == 2) {
val elasticity = args[1].toDouble()
val ball = PhysTestBall()
val ball = PhysTestBall(Terrarum.ingame!!.world)
ball.setPosition(
(mouseX + WorldCamera.x).toDouble(),
(mouseY + WorldCamera.y).toDouble()

View File

@@ -8,7 +8,7 @@ import net.torvald.terrarum.gameactors.FixtureTikiTorch
*/
internal object SpawnTikiTorch : ConsoleCommand {
override fun execute(args: Array<String>) {
val torch = FixtureTikiTorch()
val torch = FixtureTikiTorch(Terrarum.ingame!!.world)
torch.setPosition(Terrarum.mouseX, Terrarum.mouseY)
Terrarum.ingame!!.addNewActor(torch)

View File

@@ -23,7 +23,7 @@ internal object Teleport : ConsoleCommand {
return
}
Terrarum.ingame!!.player!!.setPosition(x.toDouble(), y.toDouble())
Terrarum.ingame!!.player.setPosition(x.toDouble(), y.toDouble())
}
else if (args.size == 4) {
if (args[2].toLowerCase() != "to") {
@@ -35,7 +35,7 @@ internal object Teleport : ConsoleCommand {
try {
val fromActorID = args[1].toInt()
val targetActorID = if (args[3].toLowerCase() == "player")
Terrarum.ingame!!.player!!.referenceID
Terrarum.ingame!!.player.referenceID
else
args[3].toInt()

View File

@@ -7,9 +7,9 @@ import net.torvald.terrarum.Terrarum
*/
internal object ToggleNoClip : ConsoleCommand {
override fun execute(args: Array<String>) {
val status = Terrarum.ingame!!.player!!.isNoClip()
val status = Terrarum.ingame!!.player.isNoClip()
Terrarum.ingame!!.player!!.setNoClip(!status)
Terrarum.ingame!!.player.setNoClip(!status)
Echo("Set no-clip status to " + (!status).toString())
}

View File

@@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.Color
import com.jme3.math.FastMath
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.faction.Faction
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.Material
import net.torvald.terrarum.realestate.LandUtil
@@ -18,8 +19,14 @@ import java.util.*
*
* Created by minjaesong on 16-10-24.
*/
open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
: HistoricalFigure(birth, death), Controllable, Pocketed, Factionable, Luminous, LandHolder {
open class ActorHumanoid(
world: GameWorld,
birth: GameDate,
death: GameDate? = null,
usePhysics: Boolean = true
) : HistoricalFigure(world, birth, death, usePhysics = usePhysics), Controllable, Pocketed, Factionable, Luminous, LandHolder {
var vehicleRiding: Controllable? = null // usually player only
@@ -38,11 +45,11 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
override var houseDesignation: ArrayList<Long>? = ArrayList()
override fun addHouseTile(x: Int, y: Int) {
if (houseDesignation != null) houseDesignation!!.add(LandUtil.getBlockAddr(x, y))
if (houseDesignation != null) houseDesignation!!.add(LandUtil.getBlockAddr(world, x, y))
}
override fun removeHouseTile(x: Int, y: Int) {
if (houseDesignation != null) houseDesignation!!.remove(LandUtil.getBlockAddr(x, y))
if (houseDesignation != null) houseDesignation!!.remove(LandUtil.getBlockAddr(world, x, y))
}
override fun clearHouseDesignation() {
@@ -135,7 +142,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
protected var isRightDown = false
protected var isJumpDown = false
protected inline val isGamer: Boolean
get() = this == Terrarum.ingame!!.player
get() = if (Terrarum.ingame == null) false else this == Terrarum.ingame!!.player
private val nullItem = object : GameItem() {
@@ -164,6 +171,8 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
// don't put this into keyPressed; execution order is important!
updateGamerControlBox()
processInput(delta)
updateSprite(delta)
if (noClip) {
@@ -224,7 +233,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
get() = if (isGamer) Terrarum.controller != null
else true
override fun processInput(delta: Float) {
private fun processInput(delta: Float) {
/**
* L-R stop
@@ -538,11 +547,11 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
// flipping the sprite
if (walkHeading == LEFT) {
sprite!!.flip(true, false)
sprite?.flip(true, false)
spriteGlow?.flip(true, false)
}
else {
sprite!!.flip(false, false)
sprite?.flip(false, false)
spriteGlow?.flip(false, false)
}
}

View File

@@ -202,7 +202,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
actor.avStrength / 1000.0
else
1.0 // TODO variable: scale, strength
val swingDmgToFrameDmg = Gdx.graphics.deltaTime.toDouble() / actor.actorValue.getAsDouble(AVKey.ACTION_INTERVAL)!!
val swingDmgToFrameDmg = Terrarum.deltaTime.toDouble() / actor.actorValue.getAsDouble(AVKey.ACTION_INTERVAL)!!
// damage the item
newItem.durability -= (baseDamagePerSwing * swingDmgToFrameDmg).toFloat()

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.gameactors
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.jme3.math.FastMath
import net.torvald.point.Point2d
@@ -23,15 +22,15 @@ typealias Second = Float
/**
* Base class for every actor that has animated sprites. This includes furnishings, paintings, gadgets, etc.
* Also has all the physics
* Also has all the usePhysics
*
* @param renderOrder Rendering order (BEHIND, MIDDLE, MIDTOP, FRONT)
* @param immobileBody use realistic air friction (1/1000 of "unrealistic" canonical setup)
* @param physics use physics simulation
* @param usePhysics use usePhysics simulation
*
* Created by minjaesong on 16-01-13.
*/
open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean = false, physics: Boolean = true) :
open class ActorWithPhysics(val world: GameWorld, renderOrder: RenderOrder, val immobileBody: Boolean = false, var usePhysics: Boolean = true) :
ActorWithBody(renderOrder) {
@@ -45,8 +44,6 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
var drawMode = BlendMode.NORMAL
@Transient private val world: GameWorld = Terrarum.ingame!!.world
var hitboxTranslateX: Int = 0// relative to spritePosX
protected set
var hitboxTranslateY: Int = 0// relative to spritePosY
@@ -133,7 +130,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
@Transient private val ELASTICITY_MAX = 1.0//0.993 // No perpetual motion!
/**
* what pretty much every physics engine has, instead of my 'elasticity'
* what pretty much every usePhysics engine has, instead of my 'elasticity'
*
* This is just a simple macro for 'elasticity'.
*
@@ -164,7 +161,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
/** Default to 'true' */
var isVisible = true
/** Default to 'true' */
var isUpdate = physics
var isUpdate = true
var isNoSubjectToGrav = false
var isNoCollideWorld = false
var isNoSubjectToFluidResistance = false
@@ -239,7 +236,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
internal var colliding = false
protected inline val updateDelta: Float
get() = Gdx.graphics.deltaTime
get() = Terrarum.deltaTime
var isWalkingH = false
@@ -336,6 +333,12 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
isNoSubjectToFluidResistance = isPlayerNoClip
}
if (!usePhysics) {
isNoCollideWorld = true
isNoSubjectToFluidResistance = true
isNoSubjectToGrav = true
}
////////////////////////////////////////////////////////////////
// Codes that modifies velocity (moveDelta and externalForce) //
@@ -366,7 +369,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
* If and only if:
* This body is NON-STATIC and the other body is STATIC
*/
if (!isPlayerNoClip) {
if (!isNoCollideWorld) {
// // HOW IT SHOULD WORK // //
// ////////////////////////
// combineVeloToMoveDelta now
@@ -428,7 +431,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
walledTop = isWalled(hitbox, COLLIDING_TOP)
walledBottom = isWalled(hitbox, COLLIDING_BOTTOM)
colliding = isColliding(hitbox)
if (isPlayerNoClip) {
if (isNoCollideWorld) {
walledLeft = false
walledRight = false
walledTop = false
@@ -586,7 +589,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
val stepBox = sixteenStep[step]
forEachOccupyingTilePos(stepBox) {
val tileCoord = LandUtil.resolveBlockAddr(it)
val tileCoord = LandUtil.resolveBlockAddr(this.world, it)
val tileProp = BlockCodex.getOrNull(world.getTileFromTerrain(tileCoord.first, tileCoord.second))
if (tileProp == null || tileProp.isSolid) {
@@ -632,7 +635,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
debug1("Collision type: $selfCollisionStatus")
affectingTiles.forEach {
val tileCoord = LandUtil.resolveBlockAddr(it)
val tileCoord = LandUtil.resolveBlockAddr(this.world, it)
debug2("affectign tile: ${tileCoord.first}, ${tileCoord.second}")
}
@@ -1265,7 +1268,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
private fun assertInit() {
// errors
if (baseHitboxW == 0 || baseHitboxH == 0)
throw Error("Hitbox dimension was not set.")
throw Error("Hitbox dimension was not set. (don't modify hitbox directly -- use 'setHitboxDimension()')")
// warnings
if (sprite == null && isVisible)
@@ -1315,7 +1318,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
val tilePosList = ArrayList<BlockAddress>()
for (y in newTilewiseHitbox.startY.toInt()..newTilewiseHitbox.endY.toInt()) {
for (x in newTilewiseHitbox.startX.toInt()..newTilewiseHitbox.endX.toInt()) {
tilePosList.add(LandUtil.getBlockAddr(x, y))
tilePosList.add(LandUtil.getBlockAddr(this.world, x, y))
}
}
@@ -1437,12 +1440,12 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
}
internal val avAcceleration: Double
get() = actorValue.getAsDouble(AVKey.ACCEL)!! *
actorValue.getAsDouble(AVKey.ACCELBUFF)!! *
(actorValue.getAsDouble(AVKey.ACCELBUFF) ?: 1.0) *
accelMultMovement *
scale.sqrt()
internal val avSpeedCap: Double
get() = actorValue.getAsDouble(AVKey.SPEED)!! *
actorValue.getAsDouble(AVKey.SPEEDBUFF)!! *
(actorValue.getAsDouble(AVKey.SPEEDBUFF) ?: 1.0) *
speedMultByTile *
scale.sqrt()

View File

@@ -7,8 +7,6 @@ package net.torvald.terrarum.gameactors
* Created by minjaesong on 15-12-31.
*/
interface Controllable {
fun processInput(delta: Float)
fun keyDown(keycode: Int): Boolean
}

View File

@@ -1,5 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 16-02-05.
@@ -10,8 +12,8 @@ object CreatureBuilder {
/**
* @Param jsonFileName with extension
*/
operator fun invoke(module: String, jsonFileName: String): ActorWithPhysics {
val actor = ActorWithPhysics(Actor.RenderOrder.MIDDLE)
operator fun invoke(world: GameWorld, module: String, jsonFileName: String): ActorWithPhysics {
val actor = ActorWithPhysics(world, Actor.RenderOrder.MIDDLE)
InjectCreatureRaw(actor.actorValue, module, jsonFileName)

View File

@@ -2,6 +2,7 @@ package net.torvald.terrarum.gameactors
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Pixmap
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameworld.toUint
import java.io.File
import java.nio.charset.Charset
@@ -171,6 +172,6 @@ object DecodeTapestry {
readCounter++
}
return TapestryObject(outImageData, artName, authorName)
return TapestryObject(Terrarum.ingame!!.world, outImageData, artName, authorName)
}
}

View File

@@ -4,11 +4,12 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 16-03-15.
*/
open class DroppedItem(private val item: GameItem) : ActorWithPhysics(Actor.RenderOrder.MIDTOP) {
open class DroppedItem(world: GameWorld, private val item: GameItem) : ActorWithPhysics(world, Actor.RenderOrder.MIDTOP) {
init {
if (item.dynamicID >= ItemCodex.ACTORID_MIN)

View File

@@ -1,12 +1,12 @@
package net.torvald.terrarum.gameactors
import net.torvald.spriteanimation.SpriteAnimation
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 16-06-17.
*/
open class FixtureBase(physics: Boolean = true) :
ActorWithPhysics(Actor.RenderOrder.BEHIND, immobileBody = true, physics = physics) {
open class FixtureBase(world: GameWorld, physics: Boolean = true) :
ActorWithPhysics(world, Actor.RenderOrder.BEHIND, immobileBody = true, usePhysics = physics) {
/**
* 0: Open
* 1: Blocked

View File

@@ -4,13 +4,14 @@ import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.util.*
/**
* Created by minjaesong on 16-06-17.
*/
internal class FixtureTikiTorch : FixtureBase(), Luminous {
internal class FixtureTikiTorch(world: GameWorld) : FixtureBase(world), Luminous {
override var color: Color
get() = BlockCodex[Block.TORCH].luminosity

View File

@@ -2,6 +2,7 @@ package net.torvald.terrarum.gameactors
import net.torvald.random.HQRNG
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.gameworld.WorldTime
typealias AnyPlayer = HistoricalFigure
@@ -15,10 +16,12 @@ typealias AnyPlayer = HistoricalFigure
* Created by minjaesong on 16-10-10.
*/
open class HistoricalFigure(
world: GameWorld,
val born: GameDate,
val dead: GameDate? = null,
realAirFriction: Boolean = false
) : ActorWithPhysics(Actor.RenderOrder.MIDDLE, realAirFriction) {
realAirFriction: Boolean = false,
usePhysics: Boolean = true
) : ActorWithPhysics(world, Actor.RenderOrder.MIDDLE, realAirFriction, usePhysics) {
var historicalFigureIdentifier: Int = generateHistoricalFigureIdentifier()
internal set

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.gameactors
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ai.ActorAI
import net.torvald.terrarum.gameactors.ai.LuaAIWrapper
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.Material
@@ -12,11 +13,13 @@ import net.torvald.terrarum.itemproperties.Material
* Created by minjaesong on 16-01-31.
*/
open class HumanoidNPC(
world: GameWorld,
override val ai: ActorAI, // it's there for written-in-Kotlin, "hard-wired" AIs
born: GameDate
) : ActorHumanoid(born), AIControlled, CanBeAnItem {
born: GameDate,
usePhysics: Boolean = true
) : ActorHumanoid(world, born, usePhysics = usePhysics), AIControlled, CanBeAnItem {
constructor(luaAi: LuaAIWrapper, born: GameDate) : this(luaAi as ActorAI, born) {
constructor(world: GameWorld, luaAi: LuaAIWrapper, born: GameDate) : this(world, luaAi as ActorAI, born) {
luaAi.attachActor(this)
}
@@ -78,8 +81,8 @@ open class HumanoidNPC(
}
override fun update(delta: Float) {
ai.update(this, delta)
super.update(delta)
ai.update(delta)
}
override fun moveLeft(amount: Float) { // hit the buttons on the controller box

View File

@@ -20,7 +20,7 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, maxLifeTime: Second? = n
/** Will NOT actually delete from the CircularArray */
@Volatile var flagDespawn = false
override fun run() = update(Gdx.graphics.deltaTime)
override fun run() = update(Terrarum.deltaTime)
var isNoSubjectToGrav = false
var dragCoefficient = 3.0

View File

@@ -3,12 +3,13 @@ package net.torvald.terrarum.gameactors
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.worldgenerator.RoguelikeRandomiser
/**
* Created by minjaesong on 16-03-05.
*/
class PhysTestBall : ActorWithPhysics(Actor.RenderOrder.MIDDLE, immobileBody = true) {
class PhysTestBall(world: GameWorld) : ActorWithPhysics(world, Actor.RenderOrder.MIDDLE, immobileBody = true) {
private var color = Color.GOLD

View File

@@ -1,5 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.gameworld.GameWorld
/**
* Game player (YOU!)
@@ -7,7 +9,7 @@ package net.torvald.terrarum.gameactors
* Created by minjaesong on 15-12-31.
*/
class Player(born: GameDate) : ActorHumanoid(born) {
class Player(world: GameWorld, born: GameDate) : ActorHumanoid(world, born) {
companion object {
@Transient const val PLAYER_REF_ID: Int = 0x91A7E2

View File

@@ -8,7 +8,7 @@ import net.torvald.terrarum.Terrarum
object PlayerBuilder {
operator fun invoke(): Actor {
val p: Actor = Player(Terrarum.ingame!!.world.time.currentTimeAsGameDate)
val p: Actor = Player(Terrarum.ingame!!.world, Terrarum.ingame!!.world.time.currentTimeAsGameDate)
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")
// attach sprite

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ai.LuaAIWrapper
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -13,6 +14,7 @@ object PlayerBuilderCynthia {
operator fun invoke(): ActorWithPhysics {
//val p: Player = Player(GameDate(100, 143)) // random value thrown
val p: HumanoidNPC = HumanoidNPC(
Terrarum.ingame!!.world,
LuaAIWrapper("/net/torvald/terrarum/gameactors/ai/scripts/PokemonNPCAI.lua"),
GameDate(100, 143)) // random value thrown
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.faction.FactionFactory
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
@@ -14,7 +15,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
object PlayerBuilderSigrid {
operator fun invoke(): Player {
val p = Player(GameDate(-2147483648, 0)) // XD
val p = Player(Terrarum.ingame!!.world, GameDate(-2147483648, 0)) // XD
p.referenceID = 0x51621D // the only constant of this procedural universe
p.historicalFigureIdentifier = 0x51621D // the only constant of this procedural universe

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -9,7 +10,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
object PlayerBuilderTestSubject1 {
operator fun invoke(): Player {
val p: Player = Player(GameDate(100, 143)) // random value thrown
val p: Player = Player(Terrarum.ingame!!.world, GameDate(100, 143)) // random value thrown
InjectCreatureRaw(p.actorValue, "basegame", "CreatureHuman.json")

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.gameactors
import com.badlogic.gdx.Gdx
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
@@ -27,7 +28,7 @@ interface Pocketed {
}
inventory.itemEquipped[item.equipPosition] = null
item.effectOnUnequip(Gdx.graphics.deltaTime)
item.effectOnUnequip(Terrarum.deltaTime)
}
// no need for equipSlot(Int)
@@ -49,7 +50,7 @@ interface Pocketed {
if (item.equipPosition >= 0) {
inventory.itemEquipped[item.equipPosition] = item
item.effectWhenEquipped(Gdx.graphics.deltaTime)
item.effectWhenEquipped(Terrarum.deltaTime)
}
// else do nothing
}
@@ -68,13 +69,13 @@ interface Pocketed {
fun consumePrimary(item: GameItem) {
if (item.primaryUse(Gdx.graphics.deltaTime)) {
if (item.primaryUse(Terrarum.deltaTime)) {
inventory.consumeItem(this as Actor, item) // consume on successful
}
}
fun consumeSecondary(item: GameItem) {
if (item.secondaryUse(Gdx.graphics.deltaTime))
if (item.secondaryUse(Terrarum.deltaTime))
inventory.consumeItem(this as Actor, item) // consume on successful
}
}

View File

@@ -1,15 +1,17 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.gameworld.GameWorld
import org.dyn4j.geometry.Vector2
/**
* Created by minjaesong on 16-08-29.
*/
class ProjectileHoming(
world: GameWorld,
type: Int,
fromPoint: Vector2, // projected coord
toPoint: Vector2 // arriving coord
) : ProjectileSimple(type, fromPoint, toPoint) {
) : ProjectileSimple(world, type, fromPoint, toPoint) {

View File

@@ -6,6 +6,7 @@ import net.torvald.point.Point2d
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.gameworld.GameWorld
import org.dyn4j.geometry.Vector2
import java.util.*
@@ -17,10 +18,11 @@ import java.util.*
// TODO simplified, lightweight physics (does not call PhysicsSolver)
open class ProjectileSimple(
world: GameWorld,
private val type: Int,
fromPoint: Vector2, // projected coord
toPoint: Vector2 // arriving coord
) : ActorWithPhysics(Actor.RenderOrder.MIDTOP), Luminous, Projectile {
) : ActorWithPhysics(world, Actor.RenderOrder.MIDTOP), Luminous, Projectile {
val damage: Int
val displayColour: Color

View File

@@ -4,12 +4,13 @@ import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
* Created by minjaesong on 2017-01-07.
*/
class TapestryObject(pixmap: Pixmap, val artName: String, val artAuthor: String) : FixtureBase(physics = false) {
class TapestryObject(world: GameWorld, pixmap: Pixmap, val artName: String, val artAuthor: String) : FixtureBase(world, physics = false) {
// physics = false only speeds up for ~2 frames with 50 tapestries

View File

@@ -10,13 +10,13 @@ class ThreadActorUpdate(val startIndex: Int, val endIndex: Int) : Runnable {
override fun run() {
for (i in startIndex..endIndex) {
val it = Terrarum.ingame!!.actorContainer[i]
it.update(Gdx.graphics.deltaTime)
it.update(Terrarum.deltaTime)
if (it is Pocketed) {
it.inventory.forEach { inventoryEntry ->
inventoryEntry.item.effectWhileInPocket(Gdx.graphics.deltaTime)
inventoryEntry.item.effectWhileInPocket(Terrarum.deltaTime)
if (it.equipped(inventoryEntry.item)) {
inventoryEntry.item.effectWhenEquipped(Gdx.graphics.deltaTime)
inventoryEntry.item.effectWhenEquipped(Terrarum.deltaTime)
}
}
}

View File

@@ -1,11 +1,12 @@
package net.torvald.terrarum.gameactors
import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 16-04-26.
*/
class WeaponSwung(val itemID: Int) : ActorWithPhysics(Actor.RenderOrder.MIDTOP), Luminous {
class WeaponSwung(world: GameWorld, val itemID: Int) : ActorWithPhysics(world, Actor.RenderOrder.MIDTOP), Luminous {
// just let the solver use AABB; it's cheap but works just enough
/**

View File

@@ -1,8 +1,10 @@
package net.torvald.terrarum.gameactors.ai
import net.torvald.terrarum.gameactors.HumanoidNPC
/**
* Created by minjaesong on 16-03-02.
*/
interface ActorAI {
fun update(delta: Float)
fun update(actor: HumanoidNPC, delta: Float)
}

View File

@@ -1,7 +1,9 @@
package net.torvald.terrarum.gameactors.ai
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorHumanoid
import net.torvald.terrarum.gameactors.ActorWithPhysics
import net.torvald.terrarum.gameactors.HumanoidNPC
import org.luaj.vm2.Globals
import org.luaj.vm2.LuaError
import org.luaj.vm2.LuaInteger
@@ -45,7 +47,7 @@ class LuaAIWrapper(private val scriptPath: String) : ActorAI {
luaInstance.call()
}
override fun update(delta: Float) {
override fun update(actor: HumanoidNPC, delta: Float) {
// run "update()" function in the script
luag.get("update").call(delta.toLua())
}

View File

@@ -33,23 +33,6 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
get() = (mouseY / FeaturesDrawer.TILE_SIZE).floorInt()
fun update(delta: Float) {
// actor process input
if (!ingame.consoleHandler.isTakingControl) {
if (ingame.canPlayerControl) {
ingame.actorContainer.forEach {
if (it is Controllable) {
// disable control of actor if the actor is riding something?
if ((it as ActorHumanoid).vehicleRiding != null) {
it.vehicleRiding!!.processInput(delta)
}
else {
it.processInput(delta)
}
}
}
}
}
///////////////////
// MOUSE CONTROL //
@@ -133,10 +116,10 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
if (itemOnGrip != null) {
if (button == Terrarum.getConfigInt("mouseprimary")) {
itemOnGrip.endPrimaryUse(Gdx.graphics.deltaTime)
itemOnGrip.endPrimaryUse(Terrarum.deltaTime)
}
if (button == Terrarum.getConfigInt("mousesecondary")) {
itemOnGrip.endSecondaryUse(Gdx.graphics.deltaTime)
itemOnGrip.endSecondaryUse(Terrarum.deltaTime)
}
}
}

View File

@@ -158,13 +158,13 @@ class GameWorld(val width: Int, val height: Int) {
fun setTileWall(x: Int, y: Int, tile: Byte, damage: Int) {
layerWall.setTile(x fmod width, y, tile)
layerWallLowBits.setData(x fmod width, y, damage)
wallDamages.remove(LandUtil.getBlockAddr(x, y))
wallDamages.remove(LandUtil.getBlockAddr(this, x, y))
}
fun setTileTerrain(x: Int, y: Int, tile: Byte, damage: Int) {
layerTerrain.setTile(x fmod width, y, tile)
layerTerrainLowBits.setData(x fmod width, y, damage)
terrainDamages.remove(LandUtil.getBlockAddr(x, y))
terrainDamages.remove(LandUtil.getBlockAddr(this, x, y))
}
fun setTileWire(x: Int, y: Int, tile: Byte) {
@@ -235,7 +235,7 @@ class GameWorld(val width: Int, val height: Int) {
*/
fun inflictTerrainDamage(x: Int, y: Int, damage: Double): Boolean {
val damage = damage.toFloat()
val addr = LandUtil.getBlockAddr(x, y)
val addr = LandUtil.getBlockAddr(this, x, y)
//println("[GameWorld] ($x, $y) Damage: $damage")
@@ -260,14 +260,14 @@ class GameWorld(val width: Int, val height: Int) {
return false
}
fun getTerrainDamage(x: Int, y: Int): Float =
terrainDamages[LandUtil.getBlockAddr(x, y)] ?: 0f
terrainDamages[LandUtil.getBlockAddr(this, x, y)] ?: 0f
/**
* @return true if block is broken
*/
fun inflictWallDamage(x: Int, y: Int, damage: Double): Boolean {
val damage = damage.toFloat()
val addr = LandUtil.getBlockAddr(x, y)
val addr = LandUtil.getBlockAddr(this, x, y)
if (wallDamages[addr] == null) { // add new
wallDamages[addr] = damage
@@ -288,7 +288,7 @@ class GameWorld(val width: Int, val height: Int) {
return false
}
fun getWallDamage(x: Int, y: Int): Float =
wallDamages[LandUtil.getBlockAddr(x, y)] ?: 0f
wallDamages[LandUtil.getBlockAddr(this, x, y)] ?: 0f
fun getTemperature(worldTileX: Int, worldTileY: Int): Float? {

View File

@@ -130,7 +130,7 @@ object ItemCodex {
override fun primaryUse(delta: Float): Boolean {
val mousePoint = Point2d(Terrarum.mouseTileX.toDouble(), Terrarum.mouseTileY.toDouble())
val actorvalue = Terrarum.ingame!!.player!!.actorValue
val actorvalue = Terrarum.ingame!!.player.actorValue
using = true
@@ -153,7 +153,7 @@ object ItemCodex {
Terrarum.ingame!!.world.inflictTerrainDamage(
Terrarum.mouseTileX,
Terrarum.mouseTileY,
Calculate.pickaxePower(Terrarum.ingame!!.player!!, material) * swingDmgToFrameDmg
Calculate.pickaxePower(Terrarum.ingame!!.player, material) * swingDmgToFrameDmg
)
return true
}
@@ -161,7 +161,7 @@ object ItemCodex {
override fun endPrimaryUse(delta: Float): Boolean {
using = false
// reset action timer to zero
Terrarum.ingame!!.player!!.actorValue[AVKey.__ACTION_TIMER] = 0.0
Terrarum.ingame!!.player.actorValue[AVKey.__ACTION_TIMER] = 0.0
return true
}
}*/

View File

@@ -37,7 +37,7 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() {
val mouseTileY = Terrarum.mouseTileY
val mousePoint = Point2d(mouseTileX.toDouble(), mouseTileY.toDouble())
val actorvalue = Terrarum.ingame!!.player!!.actorValue
val actorvalue = Terrarum.ingame!!.player.actorValue
using = true
@@ -57,7 +57,7 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() {
Terrarum.ingame!!.world.inflictTerrainDamage(
mouseTileX, mouseTileY,
Calculate.pickaxePower(Terrarum.ingame!!.player!!, material) * swingDmgToFrameDmg
Calculate.pickaxePower(Terrarum.ingame!!.player, material) * swingDmgToFrameDmg
)
return true
@@ -66,7 +66,7 @@ class PickaxeGeneric(override val originalID: ItemID) : GameItem() {
override fun endPrimaryUse(delta: Float): Boolean {
using = false
// reset action timer to zero
Terrarum.ingame!!.player!!.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
Terrarum.ingame!!.player.actorValue.set(AVKey.__ACTION_TIMER, 0.0)
return true
}
}

View File

@@ -3,16 +3,17 @@ package net.torvald.terrarum.realestate
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.faction.FactionCodex
import net.torvald.terrarum.gameworld.BlockAddress
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by minjaesong on 16-03-27.
*/
object LandUtil {
fun getBlockAddr(x: Int, y: Int): BlockAddress =
(Terrarum.ingame!!.world.width * y).toLong() + x
fun getBlockAddr(world: GameWorld, x: Int, y: Int): BlockAddress =
(world.width * y).toLong() + x
fun resolveBlockAddr(t: BlockAddress): Pair<Int, Int> =
Pair((t % Terrarum.ingame!!.world.width).toInt(), (t / Terrarum.ingame!!.world.width).toInt())
fun resolveBlockAddr(world: GameWorld, t: BlockAddress): Pair<Int, Int> =
Pair((t % world.width).toInt(), (t / world.width).toInt())
/**
* Get owner ID as an Actor/Faction

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.realestate
import net.torvald.terrarum.gameworld.GameWorld
import java.util.*
/**
@@ -13,14 +14,14 @@ object RealEstateCodex {
*/
private var ownershipRegistry: HashMap<Long, Int> = HashMap()
fun setOwner(tileX: Int, tileY: Int, refID: Int) {
ownershipRegistry[LandUtil.getBlockAddr(tileX, tileY)] = refID
fun setOwner(world: GameWorld, tileX: Int, tileY: Int, refID: Int) {
ownershipRegistry[LandUtil.getBlockAddr(world, tileX, tileY)] = refID
}
fun removeOwner(tileX: Int, tileY: Int) {
ownershipRegistry.remove(LandUtil.getBlockAddr(tileX, tileY))
fun removeOwner(world: GameWorld, tileX: Int, tileY: Int) {
ownershipRegistry.remove(LandUtil.getBlockAddr(world, tileX, tileY))
}
fun getOwner(tileX: Int, tileY: Int): Int? =
ownershipRegistry[LandUtil.getBlockAddr(tileX, tileY)]
fun getOwner(world: GameWorld, tileX: Int, tileY: Int): Int? =
ownershipRegistry[LandUtil.getBlockAddr(world, tileX, tileY)]
}

View File

@@ -19,8 +19,6 @@ class BasicDebugInfoWindow : UICanvas() {
override var openCloseTime: Float = 0f
override var handler: UIHandler? = null
private var prevPlayerX = 0.0
private var prevPlayerY = 0.0
@@ -30,7 +28,7 @@ class BasicDebugInfoWindow : UICanvas() {
override fun update(delta: Float) {
val player = Terrarum.ingame!!.player!!
val player = Terrarum.ingame!!.player
val hitbox = player.hitbox
xdelta = hitbox.canonicalX - prevPlayerX
@@ -49,7 +47,7 @@ class BasicDebugInfoWindow : UICanvas() {
batch.color = Color(0xFFEE88FF.toInt())
val hitbox = player?.hitbox
val hitbox = player.hitbox
/**
* First column
@@ -80,11 +78,11 @@ class BasicDebugInfoWindow : UICanvas() {
+ "${(hitbox?.endY?.div(FeaturesDrawer.TILE_SIZE))?.toInt()}"
+ ")")
printLine(batch, 3, "veloX reported $ccG${player?.externalForce?.x}")
printLine(batch, 4, "veloY reported $ccG${player?.externalForce?.y}")
printLine(batch, 3, "veloX reported $ccG${player.externalForce?.x}")
printLine(batch, 4, "veloY reported $ccG${player.externalForce?.y}")
printLine(batch, 5, "p_WalkX $ccG${player?.controllerMoveDelta?.x}")
printLine(batch, 6, "p_WalkY $ccG${player?.controllerMoveDelta?.y}")
printLine(batch, 5, "p_WalkX $ccG${player.controllerMoveDelta?.x}")
printLine(batch, 6, "p_WalkY $ccG${player.controllerMoveDelta?.y}")
printLineColumn(batch, 2, 3, "veloX measured $ccG${xdelta}")
printLineColumn(batch, 2, 4, "veloY measured $ccG${ydelta}")
@@ -130,9 +128,9 @@ class BasicDebugInfoWindow : UICanvas() {
printLineColumn(batch, 2, 5, "Time $ccG${Terrarum.ingame!!.world.time.todaySeconds.toString().padStart(5, '0')}" +
" (${Terrarum.ingame!!.world.time.getFormattedTime()})")
printLineColumn(batch, 2, 6, "Mass $ccG${player?.mass}")
printLineColumn(batch, 2, 6, "Mass $ccG${player.mass}")
printLineColumn(batch, 2, 7, "noClip $ccG${player?.noClip}")
printLineColumn(batch, 2, 7, "noClip $ccG${player.noClip}")
drawHistogram(batch, LightmapRenderer.histogram,

View File

@@ -40,8 +40,6 @@ class ConsoleWindow : UICanvas() {
private var drawOffY: Float = -height.toFloat()
private var openingTimeCounter = 0f
override var handler: UIHandler? = null
private var historyIndex = -1
init {

View File

@@ -23,8 +23,6 @@ class MessageWindow(override var width: Int, isBlackVariant: Boolean) : UICanvas
override var openCloseTime: Second = OPEN_CLOSE_TIME
override var handler: UIHandler? = null
private val LRmargin = 0f // there's "base value" of 8 px for LR (width of segment tile)

View File

@@ -26,14 +26,12 @@ class Notification : UICanvas() {
override var openCloseTime: Second = MessageWindow.OPEN_CLOSE_TIME
override var handler: UIHandler? = null
override fun update(delta: Float) {
if (handler!!.isOpened)
if (handler.isOpened)
displayTimer += delta
if (displayTimer >= visibleTime) {
handler!!.setAsClose()
handler.setAsClose()
displayTimer = 0f
}
}
@@ -61,9 +59,9 @@ class Notification : UICanvas() {
fun sendNotification(message: Array<String>) {
this.message = message
msgUI.setMessage(this.message)
handler!!.openCloseCounter = 0f
handler!!.opacity = 0f
handler!!.setAsOpen()
handler.openCloseCounter = 0f
handler.opacity = 0f
handler.setAsOpen()
}
override fun dispose() {

View File

@@ -8,7 +8,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
class NullUI : UICanvas() {
override var width: Int = 0
override var height: Int = 0
override var handler: UIHandler? = null
override var openCloseTime = 0f
override fun update(delta: Float) {

View File

@@ -18,7 +18,6 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
override var width = 116
override var height = 24
override var handler: UIHandler? = null
override var openCloseTime: Second = 0f
private var ELuptimer = 10f // to make the light turned off by default

View File

@@ -20,7 +20,7 @@ abstract class UICanvas {
/**
* Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField
*/
abstract var handler: UIHandler?
open lateinit var handler: UIHandler
/**
* In milliseconds
@@ -34,9 +34,9 @@ abstract class UICanvas {
val relativeMouseX: Int
get() = (Terrarum.mouseScreenX - (handler?.posX ?: 0))
get() = Terrarum.mouseScreenX - handler.posX
val relativeMouseY: Int
get() = (Terrarum.mouseScreenY - (handler?.posY ?: 0))
get() = Terrarum.mouseScreenY - handler.posY
/** If mouse is hovering over it */
val mouseUp: Boolean
@@ -51,22 +51,22 @@ abstract class UICanvas {
abstract fun render(batch: SpriteBatch)
/**
* Do not modify handler!!.openCloseCounter here.
* Do not modify handler.openCloseCounter here.
*/
abstract fun doOpening(delta: Float)
/**
* Do not modify handler!!.openCloseCounter here.
* Do not modify handler.openCloseCounter here.
*/
abstract fun doClosing(delta: Float)
/**
* Do not modify handler!!.openCloseCounter here.
* Do not modify handler.openCloseCounter here.
*/
abstract fun endOpening(delta: Float)
/**
* Do not modify handler!!.openCloseCounter here.
* Do not modify handler.openCloseCounter here.
*/
abstract fun endClosing(delta: Float)
@@ -118,82 +118,82 @@ abstract class UICanvas {
companion object {
const val OPENCLOSE_GENERIC = 0.2f
fun doOpeningFade(handler: UIHandler?, openCloseTime: Second) {
handler!!.opacity = handler.openCloseCounter / openCloseTime
fun doOpeningFade(handler: UIHandler, openCloseTime: Second) {
handler.opacity = handler.openCloseCounter / openCloseTime
}
fun doClosingFade(handler: UIHandler?, openCloseTime: Second) {
handler!!.opacity = (openCloseTime - handler.openCloseCounter) / openCloseTime
fun doClosingFade(handler: UIHandler, openCloseTime: Second) {
handler.opacity = (openCloseTime - handler.openCloseCounter) / openCloseTime
}
fun endOpeningFade(handler: UIHandler?) {
handler!!.opacity = 1f
fun endOpeningFade(handler: UIHandler) {
handler.opacity = 1f
}
fun endClosingFade(handler: UIHandler?) {
handler!!.opacity = 0f
fun endClosingFade(handler: UIHandler) {
handler.opacity = 0f
}
fun doOpeningPopOut(handler: UIHandler?, openCloseTime: Second, position: Position) {
fun doOpeningPopOut(handler: UIHandler, openCloseTime: Second, position: Position) {
when (position) {
Position.LEFT -> handler!!.posX = Movement.fastPullOut(
Position.LEFT -> handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
-handler.UI.width.toFloat(),
0f
).roundInt()
Position.TOP -> handler!!.posY = Movement.fastPullOut(
Position.TOP -> handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
-handler.UI.height.toFloat(),
0f
).roundInt()
Position.RIGHT -> handler!!.posX = Movement.fastPullOut(
Position.RIGHT -> handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Terrarum.WIDTH.toFloat(),
Terrarum.WIDTH - handler.UI.width.toFloat()
).roundInt()
Position.BOTTOM -> handler!!.posY = Movement.fastPullOut(
Position.BOTTOM -> handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Terrarum.HEIGHT.toFloat(),
Terrarum.HEIGHT - handler.UI.height.toFloat()
).roundInt()
}
}
fun doClosingPopOut(handler: UIHandler?, openCloseTime: Second, position: Position) {
fun doClosingPopOut(handler: UIHandler, openCloseTime: Second, position: Position) {
when (position) {
Position.LEFT -> handler!!.posX = Movement.fastPullOut(
Position.LEFT -> handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
0f,
-handler.UI.width.toFloat()
).roundInt()
Position.TOP -> handler!!.posY = Movement.fastPullOut(
Position.TOP -> handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
0f,
-handler.UI.height.toFloat()
).roundInt()
Position.RIGHT -> handler!!.posX = Movement.fastPullOut(
Position.RIGHT -> handler.posX = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Terrarum.WIDTH - handler.UI.width.toFloat(),
Terrarum.WIDTH.toFloat()
).roundInt()
Position.BOTTOM -> handler!!.posY = Movement.fastPullOut(
Position.BOTTOM -> handler.posY = Movement.fastPullOut(
handler.openCloseCounter / openCloseTime,
Terrarum.HEIGHT - handler.UI.height.toFloat(),
Terrarum.HEIGHT.toFloat()
).roundInt()
}
}
fun endOpeningPopOut(handler: UIHandler?, position: Position) {
fun endOpeningPopOut(handler: UIHandler, position: Position) {
when (position) {
Position.LEFT -> handler!!.posX = 0
Position.TOP -> handler!!.posY = 0
Position.RIGHT -> handler!!.posX = Terrarum.WIDTH - handler.UI.width
Position.BOTTOM -> handler!!.posY = Terrarum.HEIGHT - handler.UI.height
Position.LEFT -> handler.posX = 0
Position.TOP -> handler.posY = 0
Position.RIGHT -> handler.posX = Terrarum.WIDTH - handler.UI.width
Position.BOTTOM -> handler.posY = Terrarum.HEIGHT - handler.UI.height
}
}
fun endClosingPopOut(handler: UIHandler?, position: Position) {
fun endClosingPopOut(handler: UIHandler, position: Position) {
when (position) {
Position.LEFT -> handler!!.posX = -handler.UI.width
Position.TOP -> handler!!.posY = -handler.UI.height
Position.RIGHT -> handler!!.posX = Terrarum.WIDTH
Position.BOTTOM -> handler!!.posY = Terrarum.HEIGHT
Position.LEFT -> handler.posX = -handler.UI.width
Position.TOP -> handler.posY = -handler.UI.height
Position.RIGHT -> handler.posX = Terrarum.WIDTH
Position.BOTTOM -> handler.posY = Terrarum.HEIGHT
}
}

View File

@@ -31,7 +31,6 @@ class UIInventory(
//val actorValue: ActorValue
// get() = (actor as Actor).actorValue
override var handler: UIHandler? = null
override var openCloseTime: Second = 0.12f
val catButtonsToCatIdent = HashMap<String, String>()
@@ -204,7 +203,7 @@ class UIInventory(
// monitor and check if category selection has been changed
// OR UI is being opened from closed state
if (oldCatSelect != catButtons.selectedIndex ||
!rebuildList && handler!!.openFired) {
!rebuildList && handler.openFired) {
rebuildList = true
}

View File

@@ -19,11 +19,10 @@ class UIPieMenu : UICanvas() {
private val slotCount = UIQuickBar.SLOT_COUNT
private val slotDistanceFromCentre: Double
get() = cellSize * 2.7 * handler!!.scale
get() = cellSize * 2.8 * handler.scale
override var width: Int = cellSize * 7
override var height: Int = width
override var handler: UIHandler? = null
/**
* In milliseconds
@@ -35,16 +34,14 @@ class UIPieMenu : UICanvas() {
var selection: Int = -1
override fun update(delta: Float) {
if (Terrarum.ingame!!.player != null) {
if (selection >= 0)
Terrarum.ingame!!.player!!.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
selection % slotCount
}
if (selection >= 0)
Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
selection % slotCount
// update controls
if (handler!!.isOpened || handler!!.isOpening) {
val cursorPos = Vector2(Terrarum.mouseX, Terrarum.mouseY)
if (handler.isOpened || handler.isOpening) {
val cursorPos = Vector2(Terrarum.mouseScreenX.toDouble(), Terrarum.mouseScreenY.toDouble())
val centre = Vector2(Terrarum.HALFW.toDouble(), Terrarum.HALFH.toDouble())
val deg = -(centre - cursorPos).direction.toFloat()
@@ -60,7 +57,7 @@ class UIPieMenu : UICanvas() {
for (i in 0..slotCount - 1) {
// set position
val angle = Math.PI * 2.0 * (i.toDouble() / slotCount) + Math.PI // 180 deg monitor-wise
val slotCentrePoint = Vector2(0.0, slotDistanceFromCentre).setDirection(-angle)// + centrePoint
val slotCentrePoint = Vector2(0.0, slotDistanceFromCentre).setDirection(-angle) // NOTE: NOT a center of circle!
// draw cells
val image = if (i == selection)
@@ -70,10 +67,10 @@ class UIPieMenu : UICanvas() {
val slotSize = image.width
val slotX = slotCentrePoint.x.toFloat() - (slotSize / 2) + Terrarum.HALFW
val slotY = slotCentrePoint.y.toFloat() - (slotSize / 2) + Terrarum.HALFH
val slotX = slotCentrePoint.x.toFloat() - (slotSize / 2)
val slotY = slotCentrePoint.y.toFloat() - (slotSize / 2)
batch.color = Color(1f, 1f, 1f, handler!!.opacity * UIQuickBar.finalOpacity)
batch.color = Color(1f, 1f, 1f, handler.opacity * UIQuickBar.finalOpacity)
batch.draw(
image,
slotX,
@@ -82,14 +79,14 @@ class UIPieMenu : UICanvas() {
// draw item
val itemPair = Terrarum.ingame!!.player!!.inventory.getQuickBar(i)
val itemPair = Terrarum.ingame!!.player.inventory.getQuickBar(i)
if (itemPair != null) {
val itemImage = ItemCodex.getItemImage(itemPair.item)
val itemW = itemImage.regionWidth
val itemH = itemImage.regionHeight
batch.color = Color(1f, 1f, 1f, handler!!.opacity)
batch.color = Color(1f, 1f, 1f, handler.opacity)
batch.draw(
itemImage, // using fixed CELL_SIZE for reasons
slotX + (CELL_SIZE - itemW) / 2f,
@@ -101,22 +98,22 @@ class UIPieMenu : UICanvas() {
override fun doOpening(delta: Float) {
UICanvas.doOpeningFade(handler, openCloseTime)
handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
handler.scale = smallenSize + (1f.minus(smallenSize) * handler.opacity)
}
override fun doClosing(delta: Float) {
UICanvas.doClosingFade(handler, openCloseTime)
handler!!.scale = smallenSize + (1f.minus(smallenSize) * handler!!.opacity)
handler.scale = smallenSize + (1f.minus(smallenSize) * handler.opacity)
}
override fun endOpening(delta: Float) {
UICanvas.endOpeningFade(handler)
handler!!.scale = 1f
handler.scale = 1f
}
override fun endClosing(delta: Float) {
UICanvas.endClosingFade(handler)
handler!!.scale = 1f
handler.scale = 1f
}
override fun dispose() {

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
@@ -23,12 +24,9 @@ class UIQuickBar : UICanvas() {
private val startPointX = ItemSlotImageBuilder.slotLarge.width / 2
private val startPointY = ItemSlotImageBuilder.slotLarge.height / 2
override var handler: UIHandler? = null
private var selection: Int
get() = Terrarum.ingame!!.player?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
set(value) { Terrarum.ingame!!.player?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
get() = Terrarum.ingame!!.player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
set(value) { Terrarum.ingame!!.player.actorValue.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
override fun update(delta: Float) {
}
@@ -45,7 +43,7 @@ class UIQuickBar : UICanvas() {
val slotY = startPointY.toFloat()
// draw slots
batch.color = Color(1f, 1f, 1f, handler!!.opacity * finalOpacity)
batch.color = Color(1f, 1f, 1f, handler.opacity * finalOpacity)
batch.draw(
image,
slotX,
@@ -53,14 +51,14 @@ class UIQuickBar : UICanvas() {
)
// draw item
val itemPair = Terrarum.ingame!!.player!!.inventory.getQuickBar(i)
val itemPair = Terrarum.ingame!!.player.inventory.getQuickBar(i)
if (itemPair != null) {
val itemImage = ItemCodex.getItemImage(itemPair.item)
val itemW = itemImage.regionWidth
val itemH = itemImage.regionHeight
batch.color = Color(1f, 1f, 1f, handler!!.opacity)
batch.color = Color(1f, 1f, 1f, handler.opacity)
batch.draw(
itemImage, // using fixed CELL_SIZE for reasons
slotX + (CELL_SIZE - itemW) / 2f,
@@ -72,29 +70,47 @@ class UIQuickBar : UICanvas() {
override fun doOpening(delta: Float) {
handler!!.opacity = handler!!.openCloseCounter.toFloat() / openCloseTime
handler.opacity = handler.openCloseCounter.toFloat() / openCloseTime
}
override fun doClosing(delta: Float) {
handler!!.opacity = (openCloseTime - handler!!.openCloseCounter.toFloat()) / openCloseTime
handler.opacity = (openCloseTime - handler.openCloseCounter.toFloat()) / openCloseTime
}
override fun endOpening(delta: Float) {
handler!!.opacity = 1f
handler.opacity = 1f
}
override fun endClosing(delta: Float) {
handler!!.opacity = 0f
handler.opacity = 0f
}
override fun scrolled(amount: Int): Boolean {
super.scrolled(amount)
// super.scrolled(amount) // no UIItems here
selection = selection.plus(if (amount > 1) 1 else if (amount < -1) -1 else 0).fmod(SLOT_COUNT)
return true
}
override fun keyDown(keycode: Int): Boolean {
selection = when (keycode) {
Input.Keys.NUM_1 -> 0
Input.Keys.NUM_2 -> 1
Input.Keys.NUM_3 -> 2
Input.Keys.NUM_4 -> 3
Input.Keys.NUM_5 -> 4
Input.Keys.NUM_6 -> 5
Input.Keys.NUM_7 -> 6
Input.Keys.NUM_8 -> 7
Input.Keys.NUM_9 -> 8
Input.Keys.NUM_0 -> 9
else -> return false
}
return true
}
override fun dispose() {
}

View File

@@ -13,7 +13,8 @@ class UIStartMenu : UICanvas() {
"MENU_OPTIONS",
"MENU_MODULES",
"MENU_LABEL_LANGUAGE",
"MENU_LABEL_EXIT"
"MENU_LABEL_CREDITS",
"MENU_LABEL_QUIT"
)
val menubarOffY: Int; get() = Terrarum.HEIGHT / 2 - (Terrarum.fontGame.lineHeight * 1.5).toInt()
@@ -23,7 +24,6 @@ class UIStartMenu : UICanvas() {
override var width: Int = 240
override var height: Int = 40 * menuLabels.size.plus(1)
override var handler: UIHandler? = null
override var openCloseTime = 0f
@@ -45,7 +45,7 @@ class UIStartMenu : UICanvas() {
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_EXIT")].clickOnceListener = { _, _, _ -> System.exit(0) }
menubar.buttons[menuLabels.indexOf("MENU_LABEL_QUIT")].clickOnceListener = { _, _, _ -> System.exit(0) }
}
override fun update(delta: Float) {

View File

@@ -20,7 +20,6 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() {
override var width = 85
override var height = 52
override var handler: UIHandler? = null
override var openCloseTime: Second = 0f
private var ELuptimer = 10f // to make the light turned off by default

View File

@@ -12,7 +12,7 @@ import net.torvald.terrarum.gameactors.Second
* Created by SKYHi14 on 2017-03-03.
*/
class UIVitalMetre(
var player: ActorHumanoid?,
var player: ActorHumanoid,
var vitalGetterVal: () -> Float?,
var vitalGetterMax: () -> Float?,
var color: Color?,
@@ -28,20 +28,13 @@ class UIVitalMetre(
private val gap = 4f
override var width: Int = 80 + 2 * margin; set(value) { throw Error("operation not permitted") }
override var height: Int; get() = player?.baseHitboxH ?: 0 * 3 + margin; set(value) { throw Error("operation not permitted") }
override var handler: UIHandler? = null
set(value) {
// override customPositioning to be true
if (value != null) {
value.customPositioning = true
}
field = value
}
override var height: Int; get() = player.baseHitboxH ?: 0 * 3 + margin; set(value) { throw Error("operation not permitted") }
override var openCloseTime: Second = 0.05f
//private val relativePX = width / 2f
private val offsetY: Float; get() = (player?.baseHitboxH ?: 0) * 1.5f
private val circleRadius: Float; get() = (player?.baseHitboxH ?: 0) * 3f
private val offsetY: Float; get() = (player.baseHitboxH ?: 0) * 1.5f
private val circleRadius: Float; get() = (player.baseHitboxH ?: 0) * 3f
private val theta = 33f
private val halfTheta = theta / 2f
@@ -54,7 +47,7 @@ class UIVitalMetre(
}
override fun update(delta: Float) {
handler!!.setPosition(
handler.setPosition(
Terrarum.HALFW,
Terrarum.HALFH
)
@@ -68,8 +61,8 @@ class UIVitalMetre(
/*if (vitalGetterVal() != null && vitalGetterMax() != null && player != null) {
g.translate(
Terrarum.ingame!!.screenZoom * (player!!.centrePosPoint.x.toFloat() - (WorldCamera.x)),
Terrarum.ingame!!.screenZoom * (player!!.centrePosPoint.y.toFloat() - (WorldCamera.y))
Terrarum.ingame!!.screenZoom * (player.centrePosPoint.x.toFloat() - (WorldCamera.x)),
Terrarum.ingame!!.screenZoom * (player.centrePosPoint.y.toFloat() - (WorldCamera.y))
)

View File

@@ -155,7 +155,7 @@ import org.luaj.vm2.lib.*
private val spriteBuffer = ImageBuffer(VSprite.width * 2, VSprite.height)
fun render(g: Graphics) {
cursorBlinkTimer += Gdx.graphics.deltaTime
cursorBlinkTimer += Terrarum.deltaTime
if (cursorBlinkTimer > cursorBlinkTime) {
cursorBlinkTimer -= cursorBlinkTime
cursorBlinkOn = !cursorBlinkOn

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.virtualcomputer.worldobject
import com.badlogic.gdx.graphics.Color
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameactors.FixtureBase
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
import net.torvald.terrarum.virtualcomputer.worldobject.ui.UITextTerminal
@@ -11,7 +12,7 @@ import java.util.*
/**
* Created by minjaesong on 16-09-08.
*/
class FixtureBasicTerminal(phosphor: Color) : FixtureBase() {
class FixtureBasicTerminal(world: GameWorld, phosphor: Color) : FixtureBase(world) {
/*val computer = TerrarumComputer(8)
val vt: Terminal = SimpleTextTerminal(phosphor, 80, 25, computer)

View File

@@ -1,6 +1,7 @@
package net.torvald.terrarum.virtualcomputer.worldobject
import net.torvald.terrarum.gameactors.FixtureBase
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.virtualcomputer.computer.TerrarumComputer
import net.torvald.terrarum.virtualcomputer.terminal.Terminal
import java.io.PrintStream
@@ -10,7 +11,7 @@ import java.util.*
/**
* Created by minjaesong on 16-09-08.
*/
open class FixtureComputerBase() : FixtureBase() {
open class FixtureComputerBase(world: GameWorld) : FixtureBase(world) {
/** Connected terminal */
var terminal: FixtureBasicTerminal? = null

View File

@@ -15,12 +15,7 @@ class UITextTerminal(val terminal: Terminal) : UICanvas() {
override var width: Int = terminal.displayW// + some
override var height: Int = terminal.displayH// + frame
/**
* Usage: (in StateInGame:) uiHandlerField.ui.handler = uiHandlerField
*/
override var handler: UIHandler? = null
/**
* In milliseconds
@@ -38,25 +33,25 @@ class UITextTerminal(val terminal: Terminal) : UICanvas() {
}
/**
* Do not modify handler!!.openCloseCounter here.
* Do not modify handler.openCloseCounter here.
*/
override fun doOpening(delta: Float) {
}
/**
* Do not modify handler!!.openCloseCounter here.
* Do not modify handler.openCloseCounter here.
*/
override fun doClosing(delta: Float) {
}
/**
* Do not modify handler!!.openCloseCounter here.
* Do not modify handler.openCloseCounter here.
*/
override fun endOpening(delta: Float) {
}
/**
* Do not modify handler!!.openCloseCounter here.
* Do not modify handler.openCloseCounter here.
*/
override fun endClosing(delta: Float) {
}

View File

@@ -94,10 +94,12 @@ object WeatherMixer {
}
private val parallaxZeroPos = WorldGenerator.TERRAIN_AVERAGE_HEIGHT// + WorldGenerator.TERRAIN_UNDULATION.div(2)
//private val parallaxZeroPos = WorldGenerator.TERRAIN_AVERAGE_HEIGHT * 0.75f // just an arb multiplier (266.66666 -> 200)
private val parallaxDomainSize = WorldGenerator.TERRAIN_UNDULATION / 2f
fun render(camera: Camera, world: GameWorld) {
val parallaxZeroPos = (world.height / 3) * 0.75f // just an arb multiplier (266.66666 -> 200)
// we will not care for nextSkybox for now
val timeNow = world.time.todaySeconds

View File

@@ -33,24 +33,21 @@ object WorldCamera {
get() = y + height.ushr(1)
fun update(world: GameWorld, player: ActorWithBody) {
if (Terrarum.ingame != null) {
width = FastMath.ceil(Terrarum.WIDTH / (Terrarum.ingame?.screenZoom ?: 1f)) // div, not mul
height = FastMath.ceil(Terrarum.HEIGHT / (Terrarum.ingame?.screenZoom ?: 1f))
width = FastMath.ceil(Terrarum.WIDTH / (Terrarum.ingame?.screenZoom ?: 1f)) // div, not mul
height = FastMath.ceil(Terrarum.HEIGHT / (Terrarum.ingame?.screenZoom ?: 1f))
// position - (WH / 2)
x = (// X only: ROUNDWORLD implementation
player.hitbox.centeredX.toFloat() - width / 2).floorInt()
y = (FastMath.clamp(
player.hitbox.centeredY.toFloat() - height / 2,
TILE_SIZE.toFloat(),
world.height * TILE_SIZE - height - TILE_SIZE.toFloat()
)).floorInt().clampCameraY(world)
// position - (WH / 2)
x = (// X only: ROUNDWORLD implementation
player.hitbox.centeredX.toFloat() - width / 2).floorInt()
y = (FastMath.clamp(
player.hitbox.centeredY.toFloat() - height / 2,
TILE_SIZE.toFloat(),
world.height * TILE_SIZE - height - TILE_SIZE.toFloat()
)).floorInt().clampCameraY(world)
gdxCamX = x + (width / 2f).floor()
gdxCamY = y + (height / 2f).floor()
}
gdxCamX = x + (width / 2f).floor()
gdxCamY = y + (height / 2f).floor()
}
private fun Int.clampCameraY(world: GameWorld): Int {