From 2610f4469717c3a46688285bb67bf10460be6dcf Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 1 Feb 2019 17:28:08 +0900 Subject: [PATCH] wall block item to use its own texture (for real) --- src/net/torvald/terrarum/Terrarum.kt | 8 ++++++ .../terrarum/itemproperties/ItemCodex.kt | 2 +- .../terrarum/worlddrawer/BlocksDrawerNew.kt | 27 ++++++++++++++++--- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt index e61f62873..320d9160c 100644 --- a/src/net/torvald/terrarum/Terrarum.kt +++ b/src/net/torvald/terrarum/Terrarum.kt @@ -535,6 +535,14 @@ fun SpriteBatch.drawStraightLine(x: Float, y: Float, otherEnd: Float, thickness: infix fun Color.mul(other: Color): Color = this.cpy().mul(other) +infix fun Color.mulAndAssign(other: Color): Color { + this.r *= other.r + this.g *= other.g + this.b *= other.b + this.a *= other.a + + return this +} fun blendMul(batch: SpriteBatch) { diff --git a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt index ddc712ed1..29c85c5b3 100644 --- a/src/net/torvald/terrarum/itemproperties/ItemCodex.kt +++ b/src/net/torvald/terrarum/itemproperties/ItemCodex.kt @@ -269,7 +269,7 @@ object ItemCodex { // wall else if (item.originalID in ITEM_WALLS) { return BlocksDrawer.tileItemWall.get( - (item.originalID.minus(ITEM_WALLS.first) % 16) * 16, + (item.originalID.minus(ITEM_WALLS.first) % 16), (item.originalID.minus(ITEM_WALLS.first) / 16) ) } diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt index 568c30ba2..00e986883 100644 --- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt +++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt @@ -143,13 +143,32 @@ internal object BlocksDrawer { printdbg(this, "Making wall item textures...") // create item_wall images - // will just use the terrain texture :p - tileItemWall = weatherTerrains[1] + // because some limitation, we'll use summer image + // CPU render shits (lots of magic numbers xD) + val itemWallPixmap = Pixmap(_terrainPixMap[1].width / 16, _terrainPixMap[1].height, Pixmap.Format.RGBA8888) + for (blocksCol in 0 until itemWallPixmap.width / TILE_SIZE) { // 0..15 + val pxColStart = blocksCol * 256 // 0, 256, 512, 768, ... + for (pxCol in pxColStart until pxColStart + TILE_SIZE) { + val x = blocksCol * TILE_SIZE + (pxCol fmod TILE_SIZE) + + for (y in 0 until itemWallPixmap.height) { + val colour = Color(_terrainPixMap[1].getPixel(pxCol, y)) mulAndAssign wallOverlayColour + itemWallPixmap.drawPixel(x, y, colour.toRGBA()) + } + } + } + + // test print + //PixmapIO2.writeTGA(Gdx.files.local("wallitem.tga"), itemWallPixmap, false) + + val itemWallTexture = Texture(itemWallPixmap) + itemWallPixmap.dispose() + tileItemWall = TextureRegionPack(itemWallTexture, TILE_SIZE, TILE_SIZE) - _terrainPixMap.forEach { it.dispose() } // finally - + // finally + _terrainPixMap.forEach { it.dispose() } tilesTerrain = weatherTerrains[1]