From d817c586e90d89607fd0770b70b7d7ebcac97453 Mon Sep 17 00:00:00 2001 From: Song Minjae Date: Mon, 5 Sep 2016 17:15:51 +0900 Subject: [PATCH] =?UTF-8?q?Finally=20fixed=20CIELabUtil's=20anomaly;=20app?= =?UTF-8?q?arently=20past=20me=20was=20dumb=20fucking=20perkeleen=20vittup?= =?UTF-8?q?=C3=A4=C3=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 731df40639ccf1463238f70dd615bd1771eee259 Former-commit-id: fdf00fbe30f876731d9d952b2a65f448b90c7913 --- src/net/torvald/colourutil/CIELChUtil.kt | 2 +- src/net/torvald/colourutil/CIELabUtil.kt | 10 ++-- .../torvald/terrarum/StateTestingSandbox.kt | 34 ++++++++++++++ src/net/torvald/terrarum/Terrarum.kt | 2 + .../terrarum/gameactors/ProjectileHoming.kt | 7 ++- .../terrarum/gameactors/ProjectileSimple.kt | 47 ++++++++++++++----- .../terrarum/mapdrawer/LightmapRenderer.kt | 6 +-- 7 files changed, 86 insertions(+), 22 deletions(-) create mode 100644 src/net/torvald/terrarum/StateTestingSandbox.kt diff --git a/src/net/torvald/colourutil/CIELChUtil.kt b/src/net/torvald/colourutil/CIELChUtil.kt index f96720fc3..34d3c1833 100644 --- a/src/net/torvald/colourutil/CIELChUtil.kt +++ b/src/net/torvald/colourutil/CIELChUtil.kt @@ -15,7 +15,7 @@ import org.newdawn.slick.Color object CIELChUtil { - /** Sweet Lch linear gradient */ + /** Sweet LCh linear gradient */ fun getGradient(scale: Float, fromCol: Color, toCol: Color): Color { val from = fromCol.toLCh() val to = toCol.toLCh() diff --git a/src/net/torvald/colourutil/CIELabUtil.kt b/src/net/torvald/colourutil/CIELabUtil.kt index d5a04eade..a10ac96b9 100644 --- a/src/net/torvald/colourutil/CIELabUtil.kt +++ b/src/net/torvald/colourutil/CIELabUtil.kt @@ -60,20 +60,20 @@ object CIELabUtil { } fun CIEXYZ.toRGB(): Color { - var r = 3.2404542f * x + -1.5371385f * y + -0.4985314f * z - var g = -0.9692660f * x + 1.8760108f * y + 0.0415560f * z - var b = 0.0556434f * x + -0.2040259f * y + 1.0572252f * z + var r = 3.2404542f * x - 1.5371385f * y - 0.4985314f * z + var g = -0.9692660f * x + 1.8760108f * y + 0.0415560f * z + var b = 0.0556434f * x - 0.2040259f * y + 1.0572252f * z if (r > 0.0031308f) r = 1.055f * r.powerOf(1f / 2.4f) - 0.055f else r *= 12.92f if (g > 0.0031308f) - g = 1.055f * r.powerOf(1f / 2.4f) - 0.055f + g = 1.055f * g.powerOf(1f / 2.4f) - 0.055f else g *= 12.92f if (b > 0.0031308f) - b = 1.055f * r.powerOf(1f / 2.4f) - 0.055f + b = 1.055f * b.powerOf(1f / 2.4f) - 0.055f else b *= 12.92f diff --git a/src/net/torvald/terrarum/StateTestingSandbox.kt b/src/net/torvald/terrarum/StateTestingSandbox.kt new file mode 100644 index 000000000..f82318f98 --- /dev/null +++ b/src/net/torvald/terrarum/StateTestingSandbox.kt @@ -0,0 +1,34 @@ +package net.torvald.terrarum + +import net.torvald.colourutil.CIELabUtil.toXYZ +import net.torvald.colourutil.CIELabUtil.toLab +import net.torvald.colourutil.CIELabUtil.toRGB +import org.newdawn.slick.Color +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics +import org.newdawn.slick.state.BasicGameState +import org.newdawn.slick.state.StateBasedGame + +/** + * Created by minjaesong on 16-09-05. + */ +class StateTestingSandbox : BasicGameState() { + val colRGB = Color(0x51621D) + val colAfter1 = colRGB.toXYZ().toRGB() + //val colAfter2 = colRGB.toXYZ().toLab().toXYZ().toRGB() + + override fun init(container: GameContainer?, game: StateBasedGame?) { + println("Color:\n$colRGB") + println("Color -> XYZ -> Color:\n$colAfter1") + //println("Color -> XYZ -> Lab -> XYZ -> Color:\n$colAfter2") + } + + override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) { + throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun getID() = Terrarum.STATE_ID_TEST_SHIT + + override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) { + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index d0a44ff78..f78feea4d 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -99,6 +99,7 @@ constructor(gamename: String) : StateBasedGame(gamename) { gc.graphics.clear() // clean up any 'dust' in the buffer + //addState(StateTestingSandbox()) //addState(StateSplash()) //addState(StateMonitorCheck()) //addState(StateFontTester()) @@ -192,6 +193,7 @@ constructor(gamename: String) : StateBasedGame(gamename) { val STATE_ID_CONFIG_CALIBRATE = 0x11 val STATE_ID_TEST_FONT = 0x100 + val STATE_ID_TEST_SHIT = 0x5617 var hasController = false val CONTROLLER_DEADZONE = 0.1f diff --git a/src/net/torvald/terrarum/gameactors/ProjectileHoming.kt b/src/net/torvald/terrarum/gameactors/ProjectileHoming.kt index 5ab32b6f8..061b88618 100644 --- a/src/net/torvald/terrarum/gameactors/ProjectileHoming.kt +++ b/src/net/torvald/terrarum/gameactors/ProjectileHoming.kt @@ -5,8 +5,11 @@ import org.dyn4j.geometry.Vector2 /** * Created by minjaesong on 16-08-29. */ -class ProjectileHoming(type: Int, position: Vector2, velocity: Vector2, luminosity: Int = 0) : - ProjectileSimple(type, position, velocity, luminosity) { +class ProjectileHoming( + type: Int, + fromPoint: Vector2, // projected coord + toPoint: Vector2, // arriving coord + override var luminosity: Int = 0) : ProjectileSimple(type, fromPoint, toPoint, luminosity) { diff --git a/src/net/torvald/terrarum/gameactors/ProjectileSimple.kt b/src/net/torvald/terrarum/gameactors/ProjectileSimple.kt index 79ef07492..c6f3391fb 100644 --- a/src/net/torvald/terrarum/gameactors/ProjectileSimple.kt +++ b/src/net/torvald/terrarum/gameactors/ProjectileSimple.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.gameactors import net.torvald.colourutil.CIELabUtil.brighterLab +import net.torvald.spriteanimation.SpriteAnimation import org.dyn4j.geometry.Vector2 import org.newdawn.slick.Color import org.newdawn.slick.GameContainer @@ -8,16 +9,20 @@ import org.newdawn.slick.Graphics import java.util.* /** + * Simplest projectile. + * * Created by minjaesong on 16-08-29. */ open class ProjectileSimple( type: Int, - position: Vector2, - velocity: Vector2, + fromPoint: Vector2, // projected coord + toPoint: Vector2, // arriving coord override var luminosity: Int = 0) : ActorWithBody(), Luminous { val damage: Int val displayColour: Color + /** scalar part of velocity */ + val speed: Int /** * Arguments: @@ -28,19 +33,35 @@ open class ProjectileSimple( override val lightBoxList = ArrayList() init { - hitbox.set(position.x, position.y, 2.0, 2.0) // 2.0: size of the hitbox in pixels - lightBoxList.add(Hitbox(0.0, 0.0, 2.0, 2.0)) + hitbox.set(fromPoint.x, fromPoint.y, 2.0, 2.0) // 2.0: size of the hitbox in pixels + // lightbox sized 8x8 centered to the bullet + lightBoxList.add(Hitbox(-4.0, -4.0, 8.0, 8.0)) this.velocity.set(velocity) - damage = bulletDatabase[type][0] as Int - displayColour = bulletDatabase[type][1] as Color + damage = bulletDatabase[type][OFFSET_DAMAGE] as Int + displayColour = bulletDatabase[type][OFFSET_COL] as Color + isNoSubjectToGrav = bulletDatabase[type][OFFSET_NOGRAVITY] as Boolean + speed = bulletDatabase[type][OFFSET_SPEED] as Int + + if (displayColour == Color(254, 0, 0, 0)) { + sprite = bulletDatabase[type][OFFSET_SPRITE] as SpriteAnimation + } + + + + val initVelo = Vector2(speed.toDouble(), 0.0) + initVelo.setDirection((fromPoint to toPoint).direction) + + velocity.set(initVelo) + + collisionType = KINEMATIC } override fun update(gc: GameContainer, delta: Int) { // hit something and despawn - if (ccdCollided) flagDespawn() + if (ccdCollided || grounded) flagDespawn() super.update(gc, delta) } @@ -59,11 +80,15 @@ open class ProjectileSimple( } companion object { - val TYPE_BULLET_BASIC = 0 - + val OFFSET_DAMAGE = 0 + val OFFSET_COL = 1 // set it to Color(254, 0, 0, 0) to use sprite + val OFFSET_NOGRAVITY = 2 + val OFFSET_SPEED = 3 + val OFFSET_SPRITE = 4 val bulletDatabase = arrayOf( - arrayOf(7, Color(0xFF5429)), - arrayOf(8, Color(0xFF5429)) + // damage, display colour, no gravity, speed + arrayOf(7, Color(0xFF5429), true, 50), + arrayOf(8, Color(0xFF5429), true, 50) // ... ) } diff --git a/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt b/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt index 5017859ae..ac2173832 100644 --- a/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt +++ b/src/net/torvald/terrarum/mapdrawer/LightmapRenderer.kt @@ -86,7 +86,7 @@ object LightmapRenderer { * * true: overscanning is limited to 8 tiles in width (overscan_opaque) * * false: overscanning will fully applied to 32 tiles in width (overscan_open) */ - /*val rect_width = for_x_end - for_x_start + val rect_width = for_x_end - for_x_start val rect_height_rem_hbars = for_y_end - for_y_start - 2 val noop_mask = BitSet(2 * (rect_width) + 2 * (rect_height_rem_hbars)) @@ -148,11 +148,11 @@ object LightmapRenderer { // build noop map for (i in 0..rect_size) { val point = edgeToMaskNum(i) - val tile = Terrarum.game.map.getTileFromTerrain(point.first, point.second) ?: TileNameCode.NULL + val tile = Terrarum.ingame.world.getTileFromTerrain(point.first, point.second) ?: TileNameCode.NULL val isSolid = TilePropCodex.getProp(tile).isSolid noop_mask.set(i, isSolid) - }*/ + } /** * Updating order: