mirror of
https://github.com/curioustorvald/Terrarum-sans-bitmap.git
synced 2026-03-07 11:51:50 +09:00
typewriting sound on typewriter
This commit is contained in:
10
.gitattributes
vendored
Normal file
10
.gitattributes
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
*.psd filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ogg filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tga filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.opus filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pdf filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.kra filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.wav filter=lfs diff=lfs merge=lfs -text
|
||||||
@@ -2,23 +2,25 @@ import com.badlogic.gdx.Game
|
|||||||
import com.badlogic.gdx.Gdx
|
import com.badlogic.gdx.Gdx
|
||||||
import com.badlogic.gdx.Input
|
import com.badlogic.gdx.Input
|
||||||
import com.badlogic.gdx.InputAdapter
|
import com.badlogic.gdx.InputAdapter
|
||||||
|
import com.badlogic.gdx.audio.AudioDevice
|
||||||
|
import com.badlogic.gdx.audio.Sound
|
||||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
|
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
|
||||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
|
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.GL20
|
import com.badlogic.gdx.graphics.GL20
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera
|
import com.badlogic.gdx.graphics.OrthographicCamera
|
||||||
import com.badlogic.gdx.graphics.Pixmap
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
import com.badlogic.gdx.utils.GdxRuntimeException
|
||||||
import net.torvald.terrarum.gamecontroller.InputStrober
|
import net.torvald.terrarum.gamecontroller.InputStrober
|
||||||
import net.torvald.terrarumsansbitmap.gdx.CodepointSequence
|
import net.torvald.terrarumsansbitmap.gdx.CodepointSequence
|
||||||
import net.torvald.terrarumtypewriterbitmap.gdx.TerrarumTypewriterBitmap
|
import net.torvald.terrarumtypewriterbitmap.gdx.TerrarumTypewriterBitmap
|
||||||
import java.io.StringReader
|
import java.io.StringReader
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2021-11-05.
|
* Created by minjaesong on 2021-11-05.
|
||||||
*/
|
*/
|
||||||
class TypewriterGDX(val width: Int, val height: Int) : Game() {
|
class TypewriterGDX(val width: Int, val height: Int, val cols: Int) : Game() {
|
||||||
|
|
||||||
lateinit var font: TerrarumTypewriterBitmap
|
lateinit var font: TerrarumTypewriterBitmap
|
||||||
lateinit var batch: SpriteBatch
|
lateinit var batch: SpriteBatch
|
||||||
@@ -27,12 +29,22 @@ class TypewriterGDX(val width: Int, val height: Int) : Game() {
|
|||||||
|
|
||||||
lateinit var inputStrober: InputStrober
|
lateinit var inputStrober: InputStrober
|
||||||
|
|
||||||
|
lateinit var sndMovingkey: Sound
|
||||||
|
lateinit var sndDeadkey: Sound
|
||||||
|
lateinit var sndShiftin: Sound
|
||||||
|
lateinit var sndShiftout: Sound
|
||||||
|
lateinit var sndSpace: Sound
|
||||||
|
lateinit var sndCRs: Array<Sound>
|
||||||
|
lateinit var sndLF: Sound
|
||||||
|
|
||||||
override fun create() {
|
override fun create() {
|
||||||
font = TerrarumTypewriterBitmap(
|
font = TerrarumTypewriterBitmap(
|
||||||
"./assets/typewriter",
|
"./assets/typewriter",
|
||||||
StringReader("""ko_kr_3set-390_typewriter,typewriter_ko_3set-390.tga,16
|
StringReader(
|
||||||
|
"""ko_kr_3set-390_typewriter,typewriter_ko_3set-390.tga,16
|
||||||
|en_intl_qwerty_typewriter,typewriter_intl_qwerty.tga,0
|
|en_intl_qwerty_typewriter,typewriter_intl_qwerty.tga,0
|
||||||
""".trimMargin()),
|
""".trimMargin()
|
||||||
|
),
|
||||||
true, false, 256, true
|
true, false, 256, true
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -47,6 +59,23 @@ class TypewriterGDX(val width: Int, val height: Int) : Game() {
|
|||||||
|
|
||||||
|
|
||||||
inputStrober = InputStrober(this)
|
inputStrober = InputStrober(this)
|
||||||
|
|
||||||
|
try {
|
||||||
|
sndMovingkey = Gdx.audio.newSound(Gdx.files.internal("assets/typewriter/audio/movingkey.wav"))
|
||||||
|
sndDeadkey = Gdx.audio.newSound(Gdx.files.internal("assets/typewriter/audio/deadkey.wav"))
|
||||||
|
sndShiftin = Gdx.audio.newSound(Gdx.files.internal("assets/typewriter/audio/shiftin.wav"))
|
||||||
|
sndShiftout = Gdx.audio.newSound(Gdx.files.internal("assets/typewriter/audio/shiftout.wav"))
|
||||||
|
sndSpace = Gdx.audio.newSound(Gdx.files.internal("assets/typewriter/audio/space.wav"))
|
||||||
|
|
||||||
|
sndCRs = Array(6) {
|
||||||
|
Gdx.audio.newSound(Gdx.files.internal("assets/typewriter/audio/cr$it.wav"))
|
||||||
|
}
|
||||||
|
|
||||||
|
sndLF = Gdx.audio.newSound(Gdx.files.internal("assets/typewriter/audio/crlf.wav"))
|
||||||
|
}
|
||||||
|
catch (e: GdxRuntimeException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val textbuf: ArrayList<CodepointSequence> = arrayListOf(
|
private val textbuf: ArrayList<CodepointSequence> = arrayListOf(
|
||||||
@@ -68,19 +97,45 @@ class TypewriterGDX(val width: Int, val height: Int) : Game() {
|
|||||||
CodepointSequence(/* new line */)
|
CodepointSequence(/* new line */)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var keylayoutbase = 0xF3000
|
||||||
private val printableKeys = ((Input.Keys.NUM_0..Input.Keys.NUM_9) + (Input.Keys.A..Input.Keys.PERIOD) + 62 + (Input.Keys.BACKSPACE..Input.Keys.SLASH)).toHashSet()
|
private val printableKeys = ((Input.Keys.NUM_0..Input.Keys.NUM_9) + (Input.Keys.A..Input.Keys.PERIOD) + 62 + (Input.Keys.BACKSPACE..Input.Keys.SLASH)).toHashSet()
|
||||||
|
|
||||||
fun acceptKey(keycode: Int) {
|
fun acceptKey(keycode: Int) {
|
||||||
println("[TypewriterGDX] Accepting key: $keycode")
|
println("[TypewriterGDX] Accepting key: $keycode")
|
||||||
|
|
||||||
if (keycode == Input.Keys.ENTER) {
|
if (keycode == Input.Keys.ENTER) {
|
||||||
|
val tbufsize = textbuf.last().size.div(cols.toFloat()).times(6f).coerceIn(0f,6f).roundToInt() // 0..6
|
||||||
textbuf.add(CodepointSequence())
|
textbuf.add(CodepointSequence())
|
||||||
|
if (tbufsize == 0) sndLF.play()
|
||||||
|
else sndCRs[tbufsize - 1].play()
|
||||||
}
|
}
|
||||||
else if (printableKeys.contains(keycode and 127)) {
|
else if (printableKeys.contains(keycode and 127)) {
|
||||||
val cp = keycode + 0xF3000
|
val cp = keycode + keylayoutbase
|
||||||
textbuf.last().add(cp)
|
textbuf.last().add(cp)
|
||||||
// println("[TypewriterGDX] width: ${font.glyphProps[cp]}")
|
// println("[TypewriterGDX] width: ${font.glyphProps[cp]}")
|
||||||
|
|
||||||
|
// play audio
|
||||||
|
val isDeadkey = font.glyphProps[cp]?.width == 0
|
||||||
|
if (isDeadkey) {
|
||||||
|
sndDeadkey.play()
|
||||||
|
}
|
||||||
|
else if (keycode == Input.Keys.SPACE || keycode == Input.Keys.BACKSPACE) {
|
||||||
|
sndSpace.play()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sndMovingkey.play()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else if (keycode == 128+Input.Keys.SHIFT_LEFT || keycode == 128+Input.Keys.SHIFT_RIGHT) {
|
||||||
|
sndShiftin.play()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For Shift-out only
|
||||||
|
*/
|
||||||
|
fun shiftOut() {
|
||||||
|
sndShiftout.play()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -111,6 +166,13 @@ class TypewriterGDX(val width: Int, val height: Int) : Game() {
|
|||||||
font.dispose()
|
font.dispose()
|
||||||
batch.dispose()
|
batch.dispose()
|
||||||
inputStrober.dispose()
|
inputStrober.dispose()
|
||||||
|
sndMovingkey.dispose()
|
||||||
|
sndDeadkey.dispose()
|
||||||
|
sndShiftin.dispose()
|
||||||
|
sndShiftout.dispose()
|
||||||
|
sndSpace.dispose()
|
||||||
|
sndCRs.forEach { it.dispose() }
|
||||||
|
sndLF.dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,5 +199,5 @@ fun main(args: Array<String>) {
|
|||||||
appConfig.setWindowedMode(600, 800)
|
appConfig.setWindowedMode(600, 800)
|
||||||
appConfig.setTitle("Terrarum Typewriter Bitmap Test")
|
appConfig.setTitle("Terrarum Typewriter Bitmap Test")
|
||||||
|
|
||||||
Lwjgl3Application(TypewriterGDX(600, 800), appConfig)
|
Lwjgl3Application(TypewriterGDX(600, 800, 64), appConfig)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class InputStrober(val typewriter: TypewriterGDX) {
|
|||||||
|
|
||||||
// println("Key strobed: ${keys.joinToString()}")
|
// println("Key strobed: ${keys.joinToString()}")
|
||||||
|
|
||||||
if (stroboStatus % 2 == 0 && keys[0] != 0) {
|
if (stroboStatus % 2 == 0 && (keys[0] != 0 || oldKeys[0] != 0)) {
|
||||||
stroboStatus += 1
|
stroboStatus += 1
|
||||||
stroboTime = System.nanoTime()
|
stroboTime = System.nanoTime()
|
||||||
repeatCount += 1
|
repeatCount += 1
|
||||||
@@ -73,6 +73,13 @@ class InputStrober(val typewriter: TypewriterGDX) {
|
|||||||
// App.inputStrobed(TerrarumKeyboardEvent(KEY_DOWN, newKeysym, headKeyCode, repeatCount, keys))
|
// App.inputStrobed(TerrarumKeyboardEvent(KEY_DOWN, newKeysym, headKeyCode, repeatCount, keys))
|
||||||
typewriter.acceptKey(headKeyCode)
|
typewriter.acceptKey(headKeyCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// println("shiftin=${shiftin} oldkeys=${oldKeys.joinToString()}")
|
||||||
|
|
||||||
|
if (!shiftin && (oldKeys.contains(Input.Keys.SHIFT_LEFT) || oldKeys.contains(Input.Keys.SHIFT_RIGHT))) {
|
||||||
|
typewriter.shiftOut()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
oldKeys = keys // don't put this outside of if-cascade
|
oldKeys = keys // don't put this outside of if-cascade
|
||||||
|
|||||||
BIN
assets/typewriter/audio/cr0.wav
LFS
Normal file
BIN
assets/typewriter/audio/cr0.wav
LFS
Normal file
Binary file not shown.
BIN
assets/typewriter/audio/cr1.wav
LFS
Normal file
BIN
assets/typewriter/audio/cr1.wav
LFS
Normal file
Binary file not shown.
BIN
assets/typewriter/audio/cr2.wav
LFS
Normal file
BIN
assets/typewriter/audio/cr2.wav
LFS
Normal file
Binary file not shown.
BIN
assets/typewriter/audio/cr3.wav
LFS
Normal file
BIN
assets/typewriter/audio/cr3.wav
LFS
Normal file
Binary file not shown.
BIN
assets/typewriter/audio/cr4.wav
LFS
Normal file
BIN
assets/typewriter/audio/cr4.wav
LFS
Normal file
Binary file not shown.
BIN
assets/typewriter/audio/cr5.wav
LFS
Normal file
BIN
assets/typewriter/audio/cr5.wav
LFS
Normal file
Binary file not shown.
BIN
assets/typewriter/audio/crlf.wav
LFS
Normal file
BIN
assets/typewriter/audio/crlf.wav
LFS
Normal file
Binary file not shown.
BIN
assets/typewriter/audio/deadkey.wav
LFS
Normal file
BIN
assets/typewriter/audio/deadkey.wav
LFS
Normal file
Binary file not shown.
BIN
assets/typewriter/audio/movingkey.wav
LFS
Normal file
BIN
assets/typewriter/audio/movingkey.wav
LFS
Normal file
Binary file not shown.
BIN
assets/typewriter/audio/shiftin.wav
LFS
Normal file
BIN
assets/typewriter/audio/shiftin.wav
LFS
Normal file
Binary file not shown.
BIN
assets/typewriter/audio/shiftout.wav
LFS
Normal file
BIN
assets/typewriter/audio/shiftout.wav
LFS
Normal file
Binary file not shown.
BIN
assets/typewriter/audio/space.wav
LFS
Normal file
BIN
assets/typewriter/audio/space.wav
LFS
Normal file
Binary file not shown.
Reference in New Issue
Block a user