wall now uses terrain tileset

Former-commit-id: 13b5389d905c1c302ec4e7991fbfdd06ed333814
Former-commit-id: 1416055d9aa0755147c461512f9b638e25df908e
This commit is contained in:
Song Minjae
2017-01-09 22:56:15 +09:00
parent 0b7485fd57
commit 0f8f64cddf
17 changed files with 72 additions and 50 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 340 KiB

View File

@@ -99,7 +99,7 @@ final public class FastMath {
* @param number The number to obtain the POT for. * @param number The number to obtain the POT for.
* @return The next power of two. * @return The next power of two.
*/ */
public static int nearestPowerOfTwo(int number) { public static int nextPowerOfTwo(int number) {
number--; number--;
number |= number >> 1; number |= number >> 1;
number |= number >> 2; number |= number >> 2;

View File

@@ -127,14 +127,12 @@ class SpriteAnimation(val parentActor: ActorWithBody) {
val flippedImage = currentImage!!.getFlippedCopy(flipHorizontal, flipVertical) val flippedImage = currentImage!!.getFlippedCopy(flipHorizontal, flipVertical)
flippedImage.startUse() flippedImage.draw(
flippedImage.drawEmbedded(
Math.round(posX).toFloat(), Math.round(posX).toFloat(),
FastMath.floor(posY).toFloat(), FastMath.floor(posY).toFloat(),
FastMath.floor(width * scale).toFloat(), FastMath.floor(width * scale).toFloat(),
FastMath.floor(height * scale).toFloat() FastMath.floor(height * scale).toFloat()
) )
flippedImage.endUse()
} }
} }

View File

@@ -291,7 +291,12 @@ constructor() : BasicGameState() {
blendNormal() blendNormal()
drawSkybox(worldDrawFrameBuffer.graphics) drawSkybox(gwin)
/*drawSkybox(worldDrawFrameBuffer.graphics)
uisDrawFrameBuffer.graphics.color = Color(255, 255, 255, 0)
uisDrawFrameBuffer.graphics.fillRect(
0f, 0f, uisDrawFrameBuffer.width.toFloat(), uisDrawFrameBuffer.height.toFloat()
)*/
// make camara work // // make camara work //
@@ -304,20 +309,19 @@ constructor() : BasicGameState() {
// draw map related stuffs // // draw map related stuffs //
///////////////////////////// /////////////////////////////
TilesDrawer.renderBehind(gc, worldDrawFrameBuffer.graphics) TilesDrawer.renderBehind(gc, worldDrawFrameBuffer.graphics)
// --> blendNormal() <-- by TilesDrawer.renderBehind
///////////////// /////////////////
// draw actors // // draw actors //
///////////////// /////////////////
// --> Change of blend mode <-- introduced by ActorWithBody //
actorContainer.forEach { actor -> actorContainer.forEach { actor ->
if (actor is ActorWithBody && actor.inScreen() && actor !is Player && !actor.drawTopmost) { if (actor is ActorWithBody && actor.inScreen() && actor !is Player && !actor.drawTopmost) {
actor.drawBody(gc, worldDrawFrameBuffer.graphics) actor.drawBody(gc, worldDrawFrameBuffer.graphics)
} }
} }
// --> Change of blend mode <-- introduced by ActorWithBody //
player.drawBody(gc, worldDrawFrameBuffer.graphics) player.drawBody(gc, worldDrawFrameBuffer.graphics)
// --> Change of blend mode <-- introduced by ActorWithBody // // actors that are drawTopmost
actorContainer.forEach { actor -> actorContainer.forEach { actor ->
if (actor is ActorWithBody && actor.inScreen() && actor !is Player && actor.drawTopmost) { if (actor is ActorWithBody && actor.inScreen() && actor !is Player && actor.drawTopmost) {
actor.drawBody(gc, worldDrawFrameBuffer.graphics) actor.drawBody(gc, worldDrawFrameBuffer.graphics)
@@ -331,13 +335,11 @@ constructor() : BasicGameState() {
///////////////////////////// /////////////////////////////
LightmapRenderer.renderLightMap() LightmapRenderer.renderLightMap()
// --> blendMul() <-- by TilesDrawer.renderFront TilesDrawer.renderFront(gc, worldDrawFrameBuffer.graphics, false)
TilesDrawer.renderFront(gc, worldDrawFrameBuffer.graphics)
// --> blendNormal() <-- by TilesDrawer.renderFront // --> blendNormal() <-- by TilesDrawer.renderFront
FeaturesDrawer.render(gc, worldDrawFrameBuffer.graphics) FeaturesDrawer.render(gc, worldDrawFrameBuffer.graphics)
// --> blendMul() <-- by TilesDrawer.drawEnvOverlay
FeaturesDrawer.drawEnvOverlay(worldDrawFrameBuffer.graphics) FeaturesDrawer.drawEnvOverlay(worldDrawFrameBuffer.graphics)
if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul() if (!KeyToggler.isOn(KEY_LIGHTMAP_RENDER)) blendMul()
@@ -348,14 +350,19 @@ constructor() : BasicGameState() {
////////////////////// //////////////////////
// draw actor glows // // draw actor glows //
////////////////////// //////////////////////
// --> blendLightenOnly() <-- introduced by ActorWithBody //
actorContainer.forEach { actor -> actorContainer.forEach { actor ->
if (actor is ActorWithBody && actor.inScreen() && actor !is Player) { if (actor is ActorWithBody && actor.inScreen() && actor !is Player) {
actor.drawGlow(gc, worldDrawFrameBuffer.graphics) actor.drawGlow(gc, worldDrawFrameBuffer.graphics)
} }
} }
// --> blendLightenOnly() <-- introduced by ActorWithBody //
player.drawGlow(gc, worldDrawFrameBuffer.graphics) player.drawGlow(gc, worldDrawFrameBuffer.graphics)
// actors that are drawTopmost
actorContainer.forEach { actor ->
if (actor is ActorWithBody && actor.inScreen() && actor !is Player && actor.drawTopmost) {
actor.drawGlow(gc, worldDrawFrameBuffer.graphics)
}
}
// --> blendLightenOnly() <-- introduced by ActorWithBody //
//////////////////////// ////////////////////////

View File

@@ -460,7 +460,7 @@ fun blendNormal() {
// semitransparent textures working as intended with this, // semitransparent textures working as intended with this,
// but needs further investigation in the case of: // but needs further investigation in the case of:
// TODO blend semitransparent over semitransparent // TODO test blend in the situation of semitransparent over semitransparent
GL14.glBlendFuncSeparate( GL14.glBlendFuncSeparate(
GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, // blend func for RGB channels GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, // blend func for RGB channels
GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA // blend func for alpha channels GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA // blend func for alpha channels
@@ -469,14 +469,9 @@ fun blendNormal() {
fun blendLightenOnly() { fun blendLightenOnly() {
GL11.glEnable(GL11.GL_BLEND) GL11.glEnable(GL11.GL_BLEND)
GL14.glBlendFuncSeparate( GL11.glColorMask(true, true, true, false)
GL11.GL_ONE, GL11.GL_ONE, // blend func for RGB channels GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE)
GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA // blend func for alpha channels GL14.glBlendEquation(GL14.GL_MAX)
)
GL20.glBlendEquationSeparate(
GL14.GL_MAX,
GL14.GL_FUNC_ADD
)
} }
fun blendAlphaMap() { fun blendAlphaMap() {

View File

@@ -12,23 +12,18 @@ open class FixtureBase : ActorWithBody() {
* 2: Platform; can be stood on, press DOWN to go down. Also allows other blocks can be places on top of it (e.g. torch) * 2: Platform; can be stood on, press DOWN to go down. Also allows other blocks can be places on top of it (e.g. torch)
* 3: Wall_left; blocks rightward movement * 3: Wall_left; blocks rightward movement
* 4: Wall_right: blocks leftward movement * 4: Wall_right: blocks leftward movement
* 5: Same as 2 but player CANNOT go down
* For example, flag of 4 is good for tables; player can stand on, which means * For example, flag of 4 is good for tables; player can stand on, which means
* downward movement is blocked within the fixtures' AABB. * downward movement is blocked within the fixtures' AABB.
*/ */
var collisionFlag: Int = 0 var collisionFlag: Int = 0
/**
* Normally if player is standing on the fixtures (with flag 2 -- COLLISION_PLATFORM),
* pressing DOWN wiil allow player to get down.
* Setting this flag TRUE will block such movement (player cannot get down)
*/
var cannotPassThru = false
companion object { companion object {
val COLLISION_OPEN = 0 val COLLISION_OPEN = 0
val COLLISION_BLOCKED = 1 val COLLISION_BLOCKED = 1
val COLLISION_PLATFORM = 2 val COLLISION_PLATFORM = 2
val COLLISION_WALL_LEFT = 3 val COLLISION_WALL_LEFT = 3
val COLLISION_WALL_RIGHT = 4 val COLLISION_WALL_RIGHT = 4
val COLLISION_PLATFORM_NOGODOWN = 5
} }
} }

View File

@@ -6,6 +6,7 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.tileproperties.Tile import net.torvald.terrarum.tileproperties.Tile
import net.torvald.terrarum.tileproperties.TileCodex import net.torvald.terrarum.tileproperties.TileCodex
import com.jme3.math.FastMath import com.jme3.math.FastMath
import net.torvald.terrarum.blendAlphaMap
import net.torvald.terrarum.concurrent.ThreadParallel import net.torvald.terrarum.concurrent.ThreadParallel
import net.torvald.terrarum.blendMul import net.torvald.terrarum.blendMul
import net.torvald.terrarum.blendNormal import net.torvald.terrarum.blendNormal
@@ -25,14 +26,10 @@ object TilesDrawer {
private val world: GameWorld = Terrarum.ingame.world private val world: GameWorld = Terrarum.ingame.world
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
var tilesWall: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wall.png", TILE_SIZE, TILE_SIZE)
private set
var tilesTerrain: SpriteSheet = SpriteSheet("./assets/graphics/terrain/terrain.tga", TILE_SIZE, TILE_SIZE) var tilesTerrain: SpriteSheet = SpriteSheet("./assets/graphics/terrain/terrain.tga", TILE_SIZE, TILE_SIZE)
private set // Slick has some weird quirks with PNG's transparency. I'm using 32-bit targa here. private set // Slick has some weird quirks with PNG's transparency. I'm using 32-bit targa here.
var tilesWire: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wire.png", TILE_SIZE, TILE_SIZE) var tilesWire: SpriteSheet = SpriteSheet("./assets/graphics/terrain/wire.png", TILE_SIZE, TILE_SIZE)
private set private set
var tilesetBook: Array<SpriteSheet> = arrayOf(tilesWall, tilesTerrain, tilesWire)
private set
val WALL = GameWorld.WALL val WALL = GameWorld.WALL
val TERRAIN = GameWorld.TERRAIN val TERRAIN = GameWorld.TERRAIN
@@ -229,18 +226,45 @@ object TilesDrawer {
val player = Terrarum.ingame.player val player = Terrarum.ingame.player
} }
val wallOverlayColour = Color(2f/3f, 2f/3f, 2f/3f, 1f)
fun renderBehind(gc: GameContainer, g: Graphics) { fun renderBehind(gc: GameContainer, g: Graphics) {
/** /**
* render to camera * render to camera
*/ */
blendNormal() blendNormal()
tilesTerrain.startUse()
drawTiles(g, WALL, false) drawTiles(g, WALL, false)
tilesTerrain.endUse() // you absolutely need this
blendMul()
g.color = wallOverlayColour
g.fillRect(MapCamera.x.toFloat(), MapCamera.y.toFloat(),
MapCamera.width.toFloat() + 1, MapCamera.height.toFloat() + 1
)
blendNormal()
tilesTerrain.startUse() // you absolutely need this
drawTiles(g, TERRAIN, false) drawTiles(g, TERRAIN, false)
tilesTerrain.endUse()
} }
fun renderFront(gc: GameContainer, g: Graphics) { fun renderFront(gc: GameContainer, g: Graphics, drawWires: Boolean) {
blendMul() blendMul()
tilesTerrain.startUse()
drawTiles(g, TERRAIN, true) drawTiles(g, TERRAIN, true)
tilesTerrain.endUse()
if (drawWires) {
tilesWire.startUse()
drawTiles(g, WIRE, false)
tilesWire.endUse()
}
blendNormal() blendNormal()
} }
@@ -251,9 +275,6 @@ object TilesDrawer {
val for_x_start = x / TILE_SIZE - 1 val for_x_start = x / TILE_SIZE - 1
val for_x_end = for_x_start + (width / TILE_SIZE) + 3 val for_x_end = for_x_start + (width / TILE_SIZE) + 3
// initialise
TilesDrawer.tilesetBook[mode].startUse()
var zeroTileCounter = 0 var zeroTileCounter = 0
// loop // loop
@@ -333,8 +354,6 @@ object TilesDrawer {
} }
} }
TilesDrawer.tilesetBook[mode].endUse()
} }
/** /**
@@ -461,11 +480,20 @@ object TilesDrawer {
} }
private fun drawTile(mode: Int, tilewisePosX: Int, tilewisePosY: Int, sheetX: Int, sheetY: Int) { private fun drawTile(mode: Int, tilewisePosX: Int, tilewisePosY: Int, sheetX: Int, sheetY: Int) {
tilesetBook[mode].renderInUse( if (mode == TERRAIN || mode == WALL)
FastMath.floor((tilewisePosX * TILE_SIZE).toFloat()), tilesTerrain.renderInUse(
FastMath.floor((tilewisePosY * TILE_SIZE).toFloat()), FastMath.floor((tilewisePosX * TILE_SIZE).toFloat()),
sheetX, sheetY FastMath.floor((tilewisePosY * TILE_SIZE).toFloat()),
) sheetX, sheetY
)
else if (mode == WIRE)
tilesWire.renderInUse(
FastMath.floor((tilewisePosX * TILE_SIZE).toFloat()),
FastMath.floor((tilewisePosY * TILE_SIZE).toFloat()),
sheetX, sheetY
)
else
throw IllegalArgumentException()
} }
fun clampH(x: Int): Int { fun clampH(x: Int): Int {

View File

@@ -82,15 +82,14 @@ object WeatherMixer {
val skyColourFill = GradientFill( val skyColourFill = GradientFill(
0f, 0f, 0f, 0f,
getGradientColour(skyboxColourMap, 0, timeNow), getGradientColour(skyboxColourMap, 0, timeNow),
0f, Terrarum.HEIGHT / Terrarum.ingame.screenZoom, 0f, Terrarum.HEIGHT.toFloat(),// / Terrarum.ingame.screenZoom,
getGradientColour(skyboxColourMap, 1, timeNow) getGradientColour(skyboxColourMap, 1, timeNow)
) )
g.fill(Rectangle( g.fill(Rectangle(
0f, 0f, 0f, 0f,
Terrarum.WIDTH / Terrarum.ingame.screenZoom, Terrarum.WIDTH.toFloat(),// / Terrarum.ingame.screenZoom,
Terrarum.HEIGHT / Terrarum.ingame.screenZoom), Terrarum.HEIGHT.toFloat()// / Terrarum.ingame.screenZoom
skyColourFill ),skyColourFill)
)
// calculate global light // calculate global light
val gradCol = getGradientColour(lightColourMap, 0, timeNow) val gradCol = getGradientColour(lightColourMap, 0, timeNow)

View File

Before

Width:  |  Height:  |  Size: 90 KiB

After

Width:  |  Height:  |  Size: 90 KiB

View File

Before

Width:  |  Height:  |  Size: 87 KiB

After

Width:  |  Height:  |  Size: 87 KiB

View File

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB