limitedly successful attempt to create a title screen

This commit is contained in:
minjaesong
2017-07-20 00:36:41 +09:00
parent 33a774b5b7
commit 528fdc9fc5
34 changed files with 1168 additions and 410 deletions

View File

@@ -1,9 +1,5 @@
package net.torvald.terrarum.gameworld
import java.io.Serializable
import java.util.Spliterator
import java.util.function.Consumer
/**
* Created by minjaesong on 16-02-15.
*/
@@ -17,14 +13,14 @@ class PairedMapLayer(width: Int, val height: Int) : Iterable<Byte> {
* 0110 1101 is interpreted as
* 6 for tile 0, 13 for tile 1.
*/
internal @Volatile var dataPair: Array<ByteArray>
internal @Volatile var data: ByteArray
val width: Int
init {
this.width = width / 2
dataPair = Array(height) { ByteArray(width / 2) }
data = ByteArray(width * height / 2)
}
/**
@@ -48,7 +44,7 @@ class PairedMapLayer(width: Int, val height: Int) : Iterable<Byte> {
// advance counter
iteratorCount += 1
return dataPair[y][x]
return data[y * width + x]
}
}
}
@@ -59,10 +55,10 @@ class PairedMapLayer(width: Int, val height: Int) : Iterable<Byte> {
else {
if (x and 0x1 == 0)
// higher four bits for i = 0, 2, 4, ...
(java.lang.Byte.toUnsignedInt(dataPair[y][x / 2]) and 0xF0) ushr 4
(java.lang.Byte.toUnsignedInt(data[y * width + x / 2]) and 0xF0) ushr 4
else
// lower four bits for i = 1, 3, 5, ...
java.lang.Byte.toUnsignedInt(dataPair[y][x / 2]) and 0x0F
java.lang.Byte.toUnsignedInt(data[y * width + x / 2]) and 0x0F
}
}
@@ -70,12 +66,12 @@ class PairedMapLayer(width: Int, val height: Int) : Iterable<Byte> {
if (data < 0 || data >= 16) throw IllegalArgumentException("[PairedMapLayer] $data: invalid data value.")
if (x and 0x1 == 0)
// higher four bits for i = 0, 2, 4, ...
dataPair[y][x / 2] =
(java.lang.Byte.toUnsignedInt(dataPair[y][x / 2]) and 0x0F
this.data[y * width + x / 2] =
(java.lang.Byte.toUnsignedInt(this.data[y * width + x / 2]) and 0x0F
or (data and 0xF shl 4)).toByte()
else
// lower four bits for i = 1, 3, 5, ...
dataPair[y][x / 2] = (java.lang.Byte.toUnsignedInt(dataPair[y][x / 2]) and 0xF0
this.data[y * width + x / 2] = (java.lang.Byte.toUnsignedInt(this.data[y * width + x / 2]) and 0xF0
or (data and 0xF)).toByte()
}