WIP collision solver, colour-codes in game fonts

Former-commit-id: 0bb85999176d89956398bbcc24e1b33cacd3e87c
Former-commit-id: 0ef0c1ac9b88f8fe42a7439fee69a8d4792be96a
This commit is contained in:
Song Minjae
2016-04-23 23:08:42 +09:00
parent cffc9a9ba2
commit 1a1159b643
33 changed files with 557 additions and 230 deletions

View File

@@ -53,7 +53,7 @@ constructor() : Font {
private fun isHangul(c: Char) = c.toInt() >= 0xAC00 && c.toInt() < 0xD7A4
private fun isAscii(c: Char) = c.toInt() > 0 && c.toInt() <= 0xFF
private fun isAscii(c: Char) = c.toInt() > 0x20 && c.toInt() <= 0xFF
private fun isRunic(c: Char) = runicList.contains(c)
@@ -138,7 +138,9 @@ constructor() : Font {
}
if (c == SHEET_ASCII_EF || c == SHEET_EXTA_EF || c == SHEET_CYRILIC_EF)
if (c == SHEET_COLOURCODE)
len += 0
else if (c == SHEET_ASCII_EF || c == SHEET_EXTA_EF || c == SHEET_CYRILIC_EF)
len += W_LATIN_NARROW
else if (c == SHEET_KANA || c == SHEET_HANGUL || c == SHEET_CJK_PUNCT)
len += W_CJK
@@ -163,12 +165,19 @@ constructor() : Font {
GL11.glColorMask(true, true, true, true)
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
var thisCol = color
// hangul fonts first
//hangulSheet.startUse() // disabling texture binding to make the font coloured
// JOHAB
for (i in 0..s.length - 1) {
val ch = s[i]
if (ch.isColourCode()) {
thisCol = colourKey[ch]!!
continue
}
if (isHangul(ch)) {
val hIndex = ch.toInt() - 0xAC00
@@ -204,17 +213,17 @@ constructor() : Font {
hangulSheet.getSubImage(indexCho, choRow).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f).toFloat(),
color
thisCol
)
hangulSheet.getSubImage(indexJung, jungRow).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f).toFloat(),
color
thisCol
)
hangulSheet.getSubImage(indexJong, jongRow).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f).toFloat(),
color
thisCol
)
}
}
@@ -246,6 +255,11 @@ constructor() : Font {
for (i in 0..s.length - 1) {
val ch = s[i]
if (ch.isColourCode()) {
thisCol = colourKey[ch]!!
continue
}
if (isWenQuanYi1(ch)) {
val glyphW = getWidth("" + ch)
/*wenQuanYi_1.renderInUse(
@@ -257,7 +271,7 @@ constructor() : Font {
wenQuanYi_1.getSubImage(wenQuanYiIndexX(ch), wenQuanYi1IndexY(ch)).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round((H - H_UNIHAN) / 2 + y).toFloat(),
color
thisCol
)
}
}
@@ -269,6 +283,11 @@ constructor() : Font {
for (i in 0..s.length - 1) {
val ch = s[i]
if (ch.isColourCode()) {
thisCol = colourKey[ch]!!
continue
}
if (isWenQuanYi2(ch)) {
val glyphW = getWidth("" + ch)
/*wenQuanYi_2.renderInUse(
@@ -280,7 +299,7 @@ constructor() : Font {
wenQuanYi_2.getSubImage(wenQuanYiIndexX(ch), wenQuanYi2IndexY(ch)).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round((H - H_UNIHAN) / 2 + y).toFloat(),
color
thisCol
)
}
}
@@ -292,6 +311,11 @@ constructor() : Font {
for (i in 0..s.length - 1) {
val ch = s[i]
if (ch.isColourCode()) {
thisCol = colourKey[ch]!!
continue
}
if (!isHangul(ch) && !isUniHan(ch)) {
// if not init, endUse first
@@ -369,7 +393,7 @@ constructor() : Font {
else if (prevInstance == SHEET_FW_UNI) (H - H_HANGUL) / 2
else 0).toFloat(),
color
thisCol
)
}
catch (e: ArrayIndexOutOfBoundsException) {
@@ -413,6 +437,8 @@ constructor() : Font {
return SHEET_CJK_PUNCT
else if (isFullwidthUni(c))
return SHEET_FW_UNI
else if (c.isColourCode())
return SHEET_COLOURCODE
else
return SHEET_ASCII_EM// fixed width punctuations
// fixed width
@@ -464,6 +490,8 @@ constructor() : Font {
Terrarum.appgc.graphics.setDrawMode(Graphics.MODE_NORMAL)
}
fun Char.isColourCode() = colourKey.containsKey(this)
companion object {
lateinit internal var hangulSheet: SpriteSheet
@@ -510,6 +538,8 @@ constructor() : Font {
internal val SHEET_WENQUANYI_1 = 13
internal val SHEET_WENQUANYI_2 = 14
internal val SHEET_COLOURCODE = 255
lateinit internal var sheetKey: Array<SpriteSheet>
internal val asciiEFList = arrayOf(' ', '!', '"', '\'', '(', ')', ',', '.', ':', ';', 'I', '[', ']', '`', 'f', 'i', 'j', 'l', 't', '{', '|', '}', 0xA1.toChar(), 'Ì', 'Í', 'Î', 'Ï', 'ì', 'í', 'î', 'ï', '·')
@@ -554,5 +584,30 @@ constructor() : Font {
internal val runicList = arrayOf('ᚠ', 'ᚢ', 'ᚦ', 'ᚬ', 'ᚱ', 'ᚴ', 'ᚼ', 'ᚾ', '', 'ᛅ', 'ᛋ', 'ᛏ', 'ᛒ', 'ᛘ', 'ᛚ', 'ᛦ', 'ᛂ', '', '᛫', '', 'ᛮ', 'ᛯ', 'ᛰ')
internal var interchar = 0
val colourKey = hashMapOf(
Pair(0x11.toChar(), Color(0xFFFFFF)), //w
Pair(0x12.toChar(), Color(0xFF8080)), //r
Pair(0x13.toChar(), Color(0x80FF80)), //g
Pair(0x14.toChar(), Color(0x8080FF)), //b
Pair(0x15.toChar(), Color(0xFFE080)), //y
Pair(0x16.toChar(), Color(0x808080)) //k
)
val colToCode = hashMapOf(
Pair("w", 0x11.toChar()),
Pair("r", 0x12.toChar()),
Pair("g", 0x13.toChar()),
Pair("b", 0x14.toChar()),
Pair("y", 0x15.toChar()),
Pair("k", 0x16.toChar())
)
val codeToCol = hashMapOf(
Pair("w", colourKey[0x11.toChar()]),
Pair("r", colourKey[0x12.toChar()]),
Pair("g", colourKey[0x13.toChar()]),
Pair("b", colourKey[0x14.toChar()]),
Pair("y", colourKey[0x15.toChar()]),
Pair("k", colourKey[0x16.toChar()])
)
}
}

View File

@@ -47,7 +47,7 @@ constructor() : GameFontBase() {
GameFontBase.wenQuanYi_2 = SpriteSheet(
"./res/graphics/fonts/wenquanyi_11pt_part2.png", 16, 18, 2)
val shk = arrayOf<SpriteSheet>(
val shk = arrayOf(
GameFontBase.asciiSheet,
GameFontBase.asciiSheetEF,
GameFontBase.hangulSheet,

View File

@@ -1,50 +0,0 @@
package net.torvald.imagefont
import org.newdawn.slick.Color
import org.newdawn.slick.Font
import org.newdawn.slick.SpriteSheet
/**
* Created by minjaesong on 16-04-15.
*/
class SmallNumbers : Font {
internal val fontSheet: SpriteSheet
internal val W = 8
internal val H = 8
private val chars = arrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-')
init {
fontSheet = SpriteSheet("./res/graphics/fonts/numeric_small.png", W, H)
}
override fun getHeight(str: String): Int = H
override fun getWidth(str: String): Int = str.length * W
override fun getLineHeight(): Int = H
override fun drawString(x: Float, y: Float, text: String) = drawString(x, y, text, Color.white)
override fun drawString(x: Float, y: Float, text: String, col: Color) {
for (i in 0..text.length - 1) {
val index = charToSpriteNum(text.codePointAt(i))
if (index != null) {
fontSheet.getSubImage(index, 0).draw(
x + i * W, y, col
)
}
}
}
override fun drawString(x: Float, y: Float, text: String, col: Color, startIndex: Int, endIndex: Int) {
throw UnsupportedOperationException()
}
private fun charToSpriteNum(ch: Int): Int? =
if (ch in '0'.toInt()..'9'.toInt()) ch - '0'.toInt()
else if (ch == '-'.toInt()) 10
else null
}

View File

@@ -0,0 +1,78 @@
package net.torvald.imagefont
import org.newdawn.slick.Color
import org.newdawn.slick.Font
import org.newdawn.slick.SpriteSheet
import java.util.*
/**
* Created by minjaesong on 16-04-15.
*/
class TinyAlphNum : Font {
internal val fontSheet: SpriteSheet
internal val W = 8
internal val H = 8
private val chars = arrayOf(
'0','1','2','3','4','5','6','7',
'8','9','[','#','@',':','>','?',
' ','A','B','C','D','E','F','G',
'H','I','&','.',']','(','<','\\',
'^','J','K','L','M','N','O','P',
'Q','R','-','¤','*',')',';','\'',
'+','/','S','T','U','V','W','X',
'Y','Z','_',',','%','=','"','!'
)
private val mappingTable = HashMap<Int, Int>()
init {
fontSheet = SpriteSheet("./res/graphics/fonts/alphanumeric_small.png", W, H)
chars.forEachIndexed { i, c -> mappingTable[c.toInt()] = i }
}
override fun getHeight(str: String): Int = H
override fun getWidth(str: String): Int {
var ret = 0
for (i in 0..str.length - 1) {
val c = str.codePointAt(i).toChar()
if (!c.isColourCode())
ret += W
}
return ret
}
override fun getLineHeight(): Int = H
override fun drawString(x: Float, y: Float, text: String) = drawString(x, y, text, Color.white)
override fun drawString(x: Float, y: Float, text: String, col: Color) {
var thisCol = col
var textPosOffset = 0
for (i in 0..text.length - 1) {
val index = charToSpriteNum(text.toUpperCase().codePointAt(i))
val ch = text[i]
if (ch.isColourCode()) {
thisCol = GameFontBase.colourKey[ch]!!
continue
}
if (index != null) {
fontSheet.getSubImage(index % 8, index / 8).draw(
x + textPosOffset, y, thisCol
)
}
textPosOffset += W
}
}
override fun drawString(x: Float, y: Float, text: String, col: Color, startIndex: Int, endIndex: Int) {
throw UnsupportedOperationException()
}
private fun charToSpriteNum(ch: Int): Int? = mappingTable[ch]
fun Char.isColourCode() = GameFontBase.colourKey.containsKey(this)
}