more screwing around and commenting

This commit is contained in:
Minjae Song
2018-12-31 00:50:44 +09:00
parent 738d5e669a
commit 1263360d06
5 changed files with 45 additions and 53 deletions

View File

@@ -21,6 +21,7 @@ import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorID
import net.torvald.terrarum.imagefont.TinyAlphNum
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
@@ -394,18 +395,18 @@ object Terrarum : Screen {
// jump right into the ingame
/*val ingame = Ingame(batch)
// jump straight into the ingame
val ingame = Ingame(batch)
ingame.gameLoadInfoPayload = Ingame.NewWorldParameters(2400, 800, HQRNG().nextLong())
ingame.gameLoadMode = Ingame.GameLoadMode.CREATE_NEW
LoadScreen.screenToLoad = ingame
this.ingame = ingame
setScreen(LoadScreen)*/
setScreen(LoadScreen)
// title screen
AppLoader.getINSTANCE().setScreen(TitleScreen(batch))
//AppLoader.getINSTANCE().setScreen(TitleScreen(batch))
}
fun setScreen(screen: Screen) {

View File

@@ -66,21 +66,32 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
*/
override val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0) // Hitbox is implemented using Double;
/** half integer tilewise hitbox */ // got the idea from gl_FragCoord
/** half integer tilewise hitbox.
* May hold width/height of zero; the end point should be inclusive!
*
* e.g. USE `for (x in hitbox.startX..hitbox.endX)`, NOT `for (x in hitbox.startX until hitbox.endX)`
*/ // got the idea from gl_FragCoord
val hIntTilewiseHitbox: Hitbox
get() = Hitbox.fromTwoPoints(
hitbox.startX.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f,
hitbox.startY.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f,
hitbox.endX.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f,
hitbox.endY.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f
)
hitbox.endY.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f,
true
)
/** May hold width/height of zero; the end point should be inclusive!
*
* e.g. USE `for (x in hitbox.startX..hitbox.endX)`, NOT `for (x in hitbox.startX until hitbox.endX)`
*/
val intTilewiseHitbox: Hitbox
get() = Hitbox.fromTwoPoints(
hitbox.startX.plus(0.00001f).div(TILE_SIZE).floor(),
hitbox.startY.plus(0.00001f).div(TILE_SIZE).floor(),
hitbox.endX.plus(0.00001f).div(TILE_SIZE).floor(),
hitbox.endY.plus(0.00001f).div(TILE_SIZE).floor()
hitbox.endY.plus(0.00001f).div(TILE_SIZE).floor(),
true
)
/**
@@ -601,7 +612,8 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
hitbox.startX.div(TILE_SIZE).floor(),
hitbox.startY.div(TILE_SIZE).floor(),
hitbox.endX.minus(0.00001).div(TILE_SIZE).floor(),
hitbox.endY.minus(0.00001).div(TILE_SIZE).floor()
hitbox.endY.minus(0.00001).div(TILE_SIZE).floor(),
true
)
// offset 1 pixel to the down so that friction would work
@@ -1491,8 +1503,9 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
hitbox.startX.div(TILE_SIZE).floor(),
hitbox.startY.div(TILE_SIZE).floor(),
hitbox.endX.minus(0.00001).div(TILE_SIZE).floor(),
hitbox.endY.minus(0.00001).div(TILE_SIZE).floor()
)
hitbox.endY.minus(0.00001).div(TILE_SIZE).floor(),
true
) // NOT the same as intTilewiseHitbox !!
val tilePosList = ArrayList<BlockAddress>()
for (y in newTilewiseHitbox.startY.toInt()..newTilewiseHitbox.endY.toInt()) {

View File

@@ -10,7 +10,7 @@ import org.dyn4j.geometry.Vector2
*
* Created by minjaesong on 2016-01-15.
*/
class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
class Hitbox(x1: Double, y1: Double, width: Double, height: Double, var suppressWarning: Boolean = false) {
@Volatile var hitboxStart: Point2d
private set
@@ -25,6 +25,11 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
hitboxStart = Point2d(x1, y1)
this.width = width
this.height = height
if (!suppressWarning && (width == 0.0 || height == 0.0)) {
println("[Hitbox] width or height is zero ($this), perhaps you want to check it out?")
Thread.currentThread().stackTrace.forEach { println(it) }
}
}
override fun toString(): String {
@@ -59,6 +64,12 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
hitboxStart = Point2d(x1, y1)
this.width = width
this.height = height
if (!suppressWarning && (width == 0.0 || height == 0.0)) {
println("[Hitbox] width or height is zero ($this), perhaps you want to check it out?")
Thread.currentThread().stackTrace.forEach { println(it) }
}
return this
}
fun setFromTwoPoints(x1: Double, y1: Double, x2: Double, y2: Double): Hitbox {
@@ -72,8 +83,8 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
fun setPosition(x1: Double, y1: Double): Hitbox {
hitboxStart = Point2d(x1, y1)
if (width == 0.0 || height == 0.0) {
println("[Hitbox] width or height is zero, perhaps you want to check it out?")
if (!suppressWarning && (width == 0.0 || height == 0.0)) {
println("[Hitbox] width or height is zero ($this), perhaps you want to check it out?")
Thread.currentThread().stackTrace.forEach { println(it) }
}
@@ -125,7 +136,7 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
val centeredY: Double
get() = (hitboxStart.y + hitboxEnd.y) * 0.5
fun intersects(position: Point2d) =
infix fun intersects(position: Point2d) =
(position.x >= startX && position.x <= startX + width) &&
(position.y >= startY && position.y <= startY + height)
@@ -134,8 +145,8 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
fun clone(): Hitbox = Hitbox(startX, startY, width, height)
companion object {
fun fromTwoPoints(x1: Double, y1: Double, x2: Double, y2: Double) =
Hitbox(x1, y1, x2 - x1, y2 - y1)
fun fromTwoPoints(x1: Double, y1: Double, x2: Double, y2: Double, nowarn: Boolean = false) =
Hitbox(x1, y1, x2 - x1, y2 - y1, nowarn)
}
operator fun minus(other: Hitbox): Vector2 {

View File

@@ -5,14 +5,10 @@ import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.Second
import net.torvald.terrarum.abs
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.roundInt
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegSmall
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.worlddrawer.LightmapRenderer
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
@@ -117,21 +113,8 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
batch.draw(atlas.get(0, 2), 0f, 0f)
}
else {
val lightLevel: Color
if (player != null) {
val playerPos = player.hIntTilewiseHitbox
lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?:
(Terrarum.ingame!!.world).globalLight
)
}
else {
lightLevel = (Terrarum.ingame!!.world).globalLight
}
// backplate
batch.color = Color(lightLevel.r, lightLevel.g, lightLevel.b, 1f)
batch.color = Color.WHITE
batch.draw(atlas.get(0, 0), 0f, 0f)
}

View File

@@ -6,16 +6,12 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.Second
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.roundInt
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegMain
import net.torvald.terrarum.modulebasegame.imagefont.Watch7SegSmall
import net.torvald.terrarum.modulebasegame.imagefont.WatchDotAlph
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.worlddrawer.LightmapRenderer
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
@@ -66,20 +62,8 @@ class UITierOneWatch(private val player: ActorHumanoid?) : UICanvas() {
batch.draw(atlas.get(0, 2), 0f, 0f)
}
else {
val lightLevel: Color
if (player != null) {
val playerPos = player.hIntTilewiseHitbox
lightLevel = (LightmapRenderer.getLight(playerPos.centeredX.toInt(), playerPos.centeredY.toInt()) ?:
(Terrarum.ingame!!.world).globalLight
)
}
else {
lightLevel = (Terrarum.ingame!!.world).globalLight
}
// backplate
batch.color = Color(lightLevel.r, lightLevel.g, lightLevel.b, 1f)
batch.color = Color.WHITE
batch.draw(atlas.get(0, 0), 0f, 0f)
}