keycap font, edit on Thai font, actor can now flagged to despawn, draft for projectile "actor"

Former-commit-id: 5a46366ac1680f040fe6e5ace742b71a86982efa
Former-commit-id: 30e481f10cc8c09d4fc4ff1f52a4a45d91e3ab2d
This commit is contained in:
Song Minjae
2016-08-31 01:05:35 +09:00
parent 720df532aa
commit 6e51b0c751
59 changed files with 288 additions and 117 deletions

View File

@@ -78,6 +78,7 @@ constructor() : Font {
|| (c.toInt() >= 0xE47 && c.toInt() <= 0xE4E)
|| (c.toInt() == 0xE31)
private fun isThaiEF(c: Char) = c.toInt() == 0xE40
private fun isKeycap(c: Char) = c.toInt() >= 0xE000 && c.toInt() <= 0xE07F
@@ -138,6 +139,9 @@ constructor() : Font {
private fun thaiEFIndexX(c: Char) = 3
private fun thaiEFIndexY(c: Char) = 0
private fun keycapIndexX(c: Char) = (c.toInt() - 0xE000) % 16
private fun keycapIndexY(c: Char) = (c.toInt() - 0xE000) / 16
private val narrowWidthSheets = arrayOf(
SHEET_ASCII_EF,
SHEET_EXTA_EF,
@@ -193,6 +197,8 @@ constructor() : Font {
len += W_UNIHAN
else if (isThaiDiacritics(s[i]))
len += 0 // set width of the glyph as -W_LATIN_WIDE
else if (ctype == SHEET_KEYCAP)
len += SIZE_KEYCAP
else
len += W_LATIN_WIDE
@@ -435,6 +441,10 @@ constructor() : Font {
sheetX = thaiIndexX(ch)
sheetY = thaiIndexY(ch)
}
SHEET_KEYCAP -> {
sheetX = keycapIndexX(ch)
sheetY = keycapIndexY(ch)
}
else -> {
sheetX = ch.toInt() % 16
sheetY = ch.toInt() / 16
@@ -455,9 +465,9 @@ constructor() : Font {
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
// to deal with the height difference of the sheets
Math.round(y).toFloat() + (if (prevInstance == SHEET_CJK_PUNCT) -1
else if (prevInstance == SHEET_FW_UNI) (H - H_HANGUL) / 2
Math.round(y).toFloat() + (if (prevInstance == SHEET_CJK_PUNCT) -1 // height hack
else if (prevInstance == SHEET_FW_UNI) (H - H_HANGUL) / 2 // completely legit height adjustment
else if (prevInstance == SHEET_KEYCAP) (H - SIZE_KEYCAP) / 2 // completely legit height adjustment
else 0).toFloat(),
scale.toFloat(), thisCol
@@ -522,6 +532,8 @@ constructor() : Font {
return SHEET_THAI_EM
else if (c.isColourCode())
return SHEET_COLOURCODE
else if (isKeycap(c))
return SHEET_KEYCAP
else
return SHEET_ASCII_EM// fixed width punctuations
// fixed width
@@ -584,6 +596,7 @@ constructor() : Font {
lateinit internal var romanianSheet: SpriteSheet
lateinit internal var romanianSheetEF: SpriteSheet
lateinit internal var thaiSheet: SpriteSheet
lateinit internal var keycapSheet: SpriteSheet
internal val JUNG_COUNT = 21
internal val JONG_COUNT = 28
@@ -600,6 +613,8 @@ constructor() : Font {
internal val H_UNIHAN = 16
internal val H_KANA = 20
internal val SIZE_KEYCAP = 18
internal val SHEET_ASCII_EM = 0
internal val SHEET_ASCII_EF = 1
internal val SHEET_HANGUL = 2
@@ -621,6 +636,7 @@ constructor() : Font {
internal val SHEET_EXTB_ROMANIAN_EF = 18
internal val SHEET_THAI_EM = 19
internal val SHEET_THAI_EF = 20
internal val SHEET_KEYCAP = 21
internal val SHEET_COLOURCODE = 255
lateinit internal var sheetKey: Array<SpriteSheet?>

View File

@@ -56,6 +56,8 @@ constructor() : GameFontBase() {
"./assets/graphics/fonts/romana_ef.png", GameFontBase.W_LATIN_NARROW, GameFontBase.H)
GameFontBase.thaiSheet = SpriteSheet(
"./assets/graphics/fonts/thai_fullwidth.png", GameFontBase.W_LATIN_WIDE, GameFontBase.H)
GameFontBase.keycapSheet = SpriteSheet(
"./assets/graphics/fonts/puae000-e07f.png", GameFontBase.SIZE_KEYCAP, GameFontBase.SIZE_KEYCAP)
val shk = arrayOf(
GameFontBase.asciiSheet,
@@ -78,7 +80,8 @@ constructor() : GameFontBase() {
GameFontBase.romanianSheet,
GameFontBase.romanianSheetEF,
GameFontBase.thaiSheet,
null // Filler
null, // Filler
GameFontBase.keycapSheet
)
GameFontBase.sheetKey = shk
}

View File

@@ -1,5 +1,8 @@
package net.torvald.serialise
import java.io.IOException
import java.io.InputStream
/**
* Created by minjaesong on 16-08-24.
*/

View File

@@ -18,6 +18,8 @@ object DefaultConfig {
jsonObject.addProperty("notificationshowuptime", 6500)
jsonObject.addProperty("multithread", true) // experimental!
// control-gamepad
jsonObject.addProperty("joypadkeyn", 4)
jsonObject.addProperty("joypadkeyw", 1)
@@ -34,6 +36,10 @@ object DefaultConfig {
jsonObject.addProperty("joypadrstickx", 2)
jsonObject.addProperty("joypadrsticky", 3) // logitech indices
jsonObject.addProperty("joypadlabelstyle", "generic") // "nwii", "logitech", "sonyps", "msxb360", "generic"
// control-keyboard (Java key codes. This is what Minecraft also uses)
jsonObject.addProperty("keyup", Key.E)
jsonObject.addProperty("keyleft", Key.S)

View File

@@ -31,4 +31,10 @@ Connect two or more tracker head to play the array of trackers play simultaneous
*int: (0-63) number of the note pitch that is struck. 32: Middle C (C3).
'A' just above of Middle C (A3) has base pitch of 440 Hz.
*speed: in BPM
*speed: in BPM
## Aimhack ##
- Include a valid way of obtaining Aimhack (possessed weapon shit?)
- Implement it on ```<item>.primaryUse(gc, delta)```

View File

@@ -227,8 +227,8 @@ constructor() : BasicGameState() {
private fun setAppTitle() {
Terrarum.appgc.setTitle(
"Simple Slick Game" +
" — FPS: ${Terrarum.appgc.fps} (${Terrarum.TARGET_INTERNAL_FPS})" +
"${memInUse}M / ${totalVMMem}M")
" — F: ${Terrarum.appgc.fps} (${Terrarum.TARGET_INTERNAL_FPS})" +
" M: ${memInUse}M / ${totalVMMem}M")
}
override fun render(gc: GameContainer, sbg: StateBasedGame, g: Graphics) {
@@ -431,7 +431,10 @@ constructor() : BasicGameState() {
val actor = actorContainer[i]
val actorIndex = i
if (actor is Visible && !actor.inUpdateRange()) {
actorContainerInactive.add(actor) // naïve add; duplicates are checked when the actor is re-activated
// inactive instead of delete, if not flagged to delete
if (!actor.flagDespawn)
actorContainerInactive.add(actor) // naïve add; duplicates are checked when the actor is re-activated
actorContainer.removeAt(actorIndex)
actorContainerSize -= 1
i-- // array removed 1 elem, so we also decrement counter by 1

View File

@@ -41,12 +41,7 @@ class StateMonitorCheck : BasicGameState() {
private val backgroundCol = Color(0x404040)
private val colourLUT = arrayOf(
0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38, 0x40,
0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78, 0x80,
0x88, 0x90, 0x98, 0xA0, 0xA8, 0xB0, 0xB8, 0xC0,
0xC8, 0xD0, 0xD8, 0xE0, 0xE8, 0xF0, 0xF8, 0xFF
)
private val colourLUT = IntArray(32, { 255.times(it + 1).div(32) })
val pictograms = ArrayList<Image>()
lateinit var imageGallery: ItemImageGallery
@@ -147,7 +142,7 @@ class StateMonitorCheck : BasicGameState() {
// anykey
Typography.printCentered(
g, Lang["MENU_LABEL_PRESS_ANYKEY_CONTINUE"],
g, Lang["MENU_LABEL_PRESS_ANYKEY"],
anykeyY,
this
)

View File

@@ -32,7 +32,7 @@ class StateSplash : BasicGameState() {
var opacity = 0f
val fadeTime = 500
var fadeTimer = 0
var fadeTimer = -1
var anykey_hit = false
@@ -67,13 +67,14 @@ class StateSplash : BasicGameState() {
override fun update(container: GameContainer, game: StateBasedGame, delta: Int) {
// next splash or load next scene
if (anykey_hit && opened) {
if (anykey_hit && opacity < 0.0001f) {
game.enterState(Terrarum.STATE_ID_GAME)
}
// fade-in
if (delta < deltathre) {
init = true
fadeTimer += delta
if (opacity < 1f && !anykey_hit) {
opacity = FastMath.interpolateLinear(
@@ -93,11 +94,9 @@ class StateSplash : BasicGameState() {
}
// auto dismiss
if (opened && fadeTimer >= auto_dismiss)
//doAnykeyThingy()
fadeTimer += delta
println(fadeTimer)
if (opened && fadeTimer >= auto_dismiss) {
doAnykeyThingy()
}
}
override fun getID(): Int = Terrarum.STATE_ID_SPLASH
@@ -111,7 +110,7 @@ class StateSplash : BasicGameState() {
Typography.printCentered(thisG, Lang["APP_WARNING_HEALTH_AND_SAFETY"],
thisG.font.lineHeight * 2)
Typography.printCentered(thisG, Lang["MENU_LABEL_PRESS_ANYKEY_CONTINUE"],
Typography.printCentered(thisG, Lang["MENU_LABEL_PRESS_ANYKEY"],
Terrarum.HEIGHT - thisG.font.lineHeight.times(3))
imageGallery.render(container, thisG)
@@ -119,13 +118,6 @@ class StateSplash : BasicGameState() {
g.drawImage(fadeSheet, 0f, 0f, Color(1f, 1f, 1f, opacity))
}
private fun knowYourPlace(i: Int): Int {
val gutter = (imageBoardHeight - virtualImageHeight.times(pictogramCollection.size)).toFloat().div(
pictogramCollection.size + 1f
)
return (gutter * i.plus(1) + virtualImageHeight * i).roundInt()
}
override fun keyPressed(key: Int, c: Char) {
doAnykeyThingy()
}

View File

@@ -34,6 +34,21 @@ constructor(gamename: String) : StateBasedGame(gamename) {
gameConfig = GameConfig()
joypadLabelStart = when (getConfigString("joypadlabelstyle")) {
"nwii" -> 0xE04B.toChar() // + mark
"logitech" -> 0xE05A.toChar() // number 10
else -> 0xE042.toChar() // > mark (sonyps, msxb360, generic)
}
joypadLableSelect = when (getConfigString("joypadlabelstyle")) {
"nwii" -> 0xE04D.toChar() // - mark
"logitech" -> 0xE059.toChar() // number 9
"sonyps" -> 0xE043.toChar() // solid rectangle
"msxb360" -> 0xE041.toChar() // < mark
else -> 0xE043.toChar() // solid rectangle
}
getDefaultDirectory()
createDirs()
@@ -69,6 +84,11 @@ constructor(gamename: String) : StateBasedGame(gamename) {
fontGame = GameFontWhite()
fontSmallNumbers = TinyAlphNum()
fontControlGuide = SpriteSheetFont(SpriteSheet(
"./assets/graphics/fonts/" +
if (environment == RunningEnvironment.CONSOLE) "keycaps_gamepad.png"
else "keycaps.png", 18, 18)
, ' ')
hasController = gc.input.controllerCount > 0
if (hasController) {
@@ -133,7 +153,7 @@ constructor(gamename: String) : StateBasedGame(gamename) {
lateinit var environment: RunningEnvironment
private val localeSimple = arrayOf("de", "en", "es", "it")
var gameLocale = "####" // locale override
var gameLocale = "####" // lateinit placeholder
set(value) {
if (localeSimple.contains(value.substring(0..1)))
field = value.substring(0..1)
@@ -145,6 +165,23 @@ constructor(gamename: String) : StateBasedGame(gamename) {
private set
lateinit var fontSmallNumbers: Font
private set
lateinit var fontControlGuide: Font
private set
var joypadLabelStart: Char = 0x00.toChar() // lateinit
var joypadLableSelect:Char = 0x00.toChar() // lateinit
var joypadLabelNinA: Char = 0x00.toChar() // lateinit TODO
var joypadLabelNinB: Char = 0x00.toChar() // lateinit TODO
var joypadLabelNinX: Char = 0x00.toChar() // lateinit TODO
var joypadLabelNinY: Char = 0x00.toChar() // lateinit TODO
var joypadLabelNinL: Char = 0x00.toChar() // lateinit TODO
var joypadLabelNinR: Char = 0x00.toChar() // lateinit TODO
var joypadLabelNinZL: Char = 0x00.toChar() // lateinit TODO
var joypadLabelNinZR: Char = 0x00.toChar() // lateinit TODO
val joypadLabelLEFT = 0xE068.toChar()
val joypadLabelDOWN = 0xE069.toChar()
val joypadLabelUP = 0xE06A.toChar()
val joypadLabelRIGHT = 0xE06B.toChar()
// 0x0 - 0xF: Game-related
// 0x10 - 0x1F: Config

View File

@@ -17,8 +17,8 @@ abstract class Actor : Comparable<Actor>, Runnable {
* @return Reference ID. (32768-0x7FFF_FFFF)
*/
abstract var referenceID: Int
abstract var actorValue: ActorValue
abstract var flagDespawn: Boolean
override fun equals(other: Any?) = referenceID == (other as Actor).referenceID
override fun hashCode() = referenceID

View File

@@ -127,7 +127,9 @@ open class ActorWithBody : Actor(), Visible {
* Flags and Properties
*/
var grounded = false
override var flagDespawn = false
/** Default to 'false' */
var isVisible = false
/** Default to 'true' */
@@ -269,7 +271,7 @@ open class ActorWithBody : Actor(), Visible {
}
override fun update(gc: GameContainer, delta: Int) {
if (isUpdate) {
if (isUpdate && !flagDespawn) {
/**
* Temporary variables to reset

View File

@@ -13,7 +13,7 @@ object PBCynthia {
CreatureRawInjector.inject(p.actorValue, "CreatureHuman.json")
p.actorValue[AVKey._PLAYER_QUICKBARSEL] = 0
p.actorValue["selectedtile"] = 16
p.actorValue["__selectedtile"] = 16
p.sprite = SpriteAnimation()

View File

@@ -58,7 +58,8 @@ object PBSigrid {
p.actorValue[AVKey.BASEDEFENCE] = 141
p.actorValue["selectedtile"] = 16
p.actorValue["__selectedtile"] = 16 // test code; replace with <tile_item>.primaryUse(gc, delta)
p.actorValue["__aimhelper"] = true
p.setHitboxDimension(15, p.actorValue.getAsInt(AVKey.BASEHEIGHT)!!, 10, 0)

View File

@@ -0,0 +1,13 @@
package net.torvald.terrarum.gameactors
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) {
}

View File

@@ -0,0 +1,61 @@
package net.torvald.terrarum.gameactors
import net.torvald.terrarum.gameactors.ActorWithBody
import org.dyn4j.geometry.Vector2
import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
import java.util.*
/**
* Created by minjaesong on 16-08-29.
*/
open class ProjectileSimple(
type: Int,
position: Vector2,
velocity: Vector2,
override var luminosity: Int = 0) : ActorWithBody(), Luminous {
val damage: Int
val displayColour: Color
/**
* Arguments:
*
* Hitbox(x-offset, y-offset, width, height)
* (Use ArrayList for normal circumstances)
*/
override val lightBoxList = ArrayList<Hitbox>()
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))
this.velocity.set(velocity)
damage = bulletDatabase[type][0] as Int
displayColour = bulletDatabase[type][1] as Color
}
override fun update(gc: GameContainer, delta: Int) {
// hit something and despawn! (use ```flagDespawn = true```)
super.update(gc, delta)
}
override fun drawBody(gc: GameContainer, g: Graphics) {
// draw trail of solid colour (Terraria style maybe?)
}
companion object {
val TYPE_BULLET_BASIC = 0
val bulletDatabase = arrayOf(
arrayOf(7, Color(0xFF5429)),
arrayOf(8, Color(0xFF5429))
// ...
)
}
}

View File

@@ -52,7 +52,10 @@ object GameController {
else if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
// test tile place
try {
Terrarum.ingame.world.setTileTerrain(mouseTileX, mouseTileY, Terrarum.ingame.player.actorValue.getAsInt("selectedtile")!!)
Terrarum.ingame.world.setTileTerrain(
mouseTileX, mouseTileY,
Terrarum.ingame.player.actorValue.getAsInt("__selectedtile")!!
)
}
catch (e: ArrayIndexOutOfBoundsException) {
}

View File

@@ -113,9 +113,15 @@ object Lang {
operator fun get(key: String): String {
fun fallback(): String = langpack["${key}_$FALLBACK_LANG_CODE"] ?: "ERRNULL:$key"
val ret = langpack["${key}_${Terrarum.gameLocale}"]
return if (ret.isNullOrEmpty()) fallback() else ret!!
val ret = langpack["${key}_${Terrarum.gameLocale}"]
val ret2 = if (ret.isNullOrEmpty()) fallback() else ret!!
// special treatment
if (key.startsWith("MENU_LABEL_PRESS_START_SYMBOL"))
return ret2.replace('>', Terrarum.joypadLabelStart)
return ret2
}
fun pluraliseLang(key: String, count: Int): String {

View File

@@ -16,8 +16,7 @@ class ItemImageGallery(
val width: Int,
val height: Int,
val imageList: ArrayList<Image>,
val column: Int = 1
) : UIItem {
val column: Int = 1) : UIItem {
override fun update(gc: GameContainer, delta: Int) {
}

View File

@@ -5,9 +5,9 @@ import com.jme3.math.FastMath
/**
* Created by minjaesong on 16-03-22.
*/
object MovementInterpolator {
object Movement{
/**
* Pretty fast at the beginning, getting slow over time.
* Fast at the beginning, getting slow over time.
*/
fun fastPullOut(scale: Float, start: Float = 0f, end: Float = 1f): Float =
if (scale < 0f) start