com.torvald → net.torvald

Former-commit-id: 375604da8a20a6ba7cd0a8d05a44add02b2d04f4
Former-commit-id: 287287c5920b07618174d7a7573f049d350ded66
This commit is contained in:
Song Minjae
2016-04-12 12:29:02 +09:00
parent 2a34efb489
commit ac9f5b5138
148 changed files with 473 additions and 524 deletions

View File

@@ -0,0 +1,9 @@
package net.torvald.terrarum.gamecontroller
/**
* Created by minjaesong on 15-12-31.
*/
enum class EnumKeyFunc {
UI_CONSOLE, UI_BASIC_INFO,
MOVE_LEFT, MOVE_RIGHT, MOVE_UP, MOVE_DOWN, JUMP
}

View File

@@ -0,0 +1,122 @@
package net.torvald.terrarum.gamecontroller
import net.torvald.terrarum.gameactors.Controllable
import net.torvald.terrarum.gameactors.Player
import net.torvald.terrarum.mapdrawer.MapCamera
import net.torvald.terrarum.mapdrawer.MapDrawer
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.tileproperties.TileNameCode
import net.torvald.terrarum.tileproperties.TilePropCodex
import net.torvald.terrarum.ui.UIHandler
import org.newdawn.slick.Input
/**
* Created by minjaesong on 15-12-31.
*/
object GameController {
fun processInput(input: Input) {
val mouseTileX = ((MapCamera.cameraX + input.mouseX / Terrarum.game.screenZoom) / MapDrawer.TILE_SIZE).toInt()
val mouseTileY = ((MapCamera.cameraY + input.mouseY / Terrarum.game.screenZoom) / MapDrawer.TILE_SIZE).toInt()
KeyToggler.update(input)
if (!Terrarum.game.consoleHandler.isTakingControl) {
if (Terrarum.game.player.vehicleRiding != null) {
Terrarum.game.player.vehicleRiding!!.processInput(input)
}
Terrarum.game.player.processInput(input)
for (ui in Terrarum.game.uiContainer) {
ui.processInput(input)
}
}
else {
Terrarum.game.consoleHandler.processInput(input)
}
if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
// test tile remove
try {
Terrarum.game.map.setTileTerrain(mouseTileX, mouseTileY, TileNameCode.AIR)
// terrarum.game.map.setTileWall(mouseTileX, mouseTileY, TileNameCode.AIR);
}
catch (e: ArrayIndexOutOfBoundsException) {
}
}
else if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
// test tile place
try {
Terrarum.game.map.setTileTerrain(mouseTileX, mouseTileY, Terrarum.game.player.actorValue.getAsInt("selectedtile")!!)
}
catch (e: ArrayIndexOutOfBoundsException) {
}
}
}
fun keyPressed(key: Int, c: Char) {
if (keyPressedByCode(key, EnumKeyFunc.UI_CONSOLE)) {
Terrarum.game.consoleHandler.toggleOpening()
}
else if (keyPressedByCode(key, EnumKeyFunc.UI_BASIC_INFO)) {
Terrarum.game.debugWindow.toggleOpening()
}
if (!Terrarum.game.consoleHandler.isTakingControl) {
if (Terrarum.game.player.vehicleRiding != null) {
Terrarum.game.player.vehicleRiding!!.keyPressed(key, c)
}
Terrarum.game.player.keyPressed(key, c)
}
else {
Terrarum.game.consoleHandler.keyPressed(key, c)
}
//System.out.println(String.valueOf(key) + ", " + String.valueOf(c));
}
fun keyReleased(key: Int, c: Char) {
}
fun mouseMoved(oldx: Int, oldy: Int, newx: Int, newy: Int) {
}
fun mouseDragged(oldx: Int, oldy: Int, newx: Int, newy: Int) {
}
fun mousePressed(button: Int, x: Int, y: Int) {
}
fun mouseReleased(button: Int, x: Int, y: Int) {
}
fun mouseWheelMoved(change: Int) {
}
fun controllerButtonPressed(controller: Int, button: Int) {
}
fun controllerButtonReleased(controller: Int, button: Int) {
}
private fun keyPressedByCode(key: Int, fn: EnumKeyFunc): Boolean {
return KeyMap.getKeyCode(fn) == key
}
}

View File

@@ -0,0 +1,86 @@
package net.torvald.terrarum.gamecontroller
/**
* Created by minjaesong on 16-01-15.
*/
object Key {
val RET = 28
val BKSP = 14
val GRAVE = 41
val TAB = 15
val ESCAPE = 1
val SPACE = 57
val L_SHIFT = 42
val R_SHIFT = 54
val UP = 200
val DOWN = 208
val LEFT = 203
val RIGHT = 205
val F1 = 59
val F2 = 60
val F3 = 61
val F4 = 62
val F5 = 63
val F6 = 64
val F7 = 65
val F8 = 66
val F9 = 67
val F10 = 68
val F11 = 87
val F12 = 88
val NUM_1 = 2
val NUM_2 = 3
val NUM_3 = 4
val NUM_4 = 5
val NUM_5 = 6
val NUM_6 = 7
val NUM_7 = 8
val NUM_8 = 9
val NUM_9 = 10
val NUM_0 = 11
val Q = 16
val W = 17
val E = 18
val R = 19
val T = 20
val Y = 21
val U = 22
val I = 23
val O = 24
val P = 25
val A = 30
val S = 31
val D = 32
val F = 33
val G = 34
val H = 35
val J = 36
val K = 37
val L = 38
val SEMICOLON = 39
val Z = 44
val X = 45
val C = 46
val V = 47
val B = 48
val N = 49
val M = 50
val PGUP = 201
val PGDN = 209
val HOME = 199
val END = 207
}

View File

@@ -0,0 +1,31 @@
package net.torvald.terrarum.gamecontroller
import java.util.Hashtable
/**
* Created by minjaesong on 15-12-31.
*/
object KeyMap {
var map_code = Hashtable<EnumKeyFunc, Int>()
fun build() {
map_code.put(EnumKeyFunc.MOVE_UP, Key.E)
map_code.put(EnumKeyFunc.MOVE_LEFT, Key.S)
map_code.put(EnumKeyFunc.MOVE_DOWN, Key.D)
map_code.put(EnumKeyFunc.MOVE_RIGHT, Key.F)
map_code.put(EnumKeyFunc.JUMP, Key.SPACE)
map_code.put(EnumKeyFunc.UI_CONSOLE, Key.GRAVE)
map_code.put(EnumKeyFunc.UI_BASIC_INFO, Key.F3)
}
fun getKeyCode(fn: EnumKeyFunc): Int {
return map_code[fn]!!
}
operator fun set(func: EnumKeyFunc, key: Int) {
map_code.put(func, key)
}
}

View File

@@ -0,0 +1,48 @@
package net.torvald.terrarum.gamecontroller
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Input
import java.util.*
object KeyToggler {
private val currentState = BitSet(256)
private val isPressed = BitSet(256)
private val isToggled = BitSet(256)
fun isOn(key: Int): Boolean {
return currentState[key]
}
fun update(input: Input) {
for (i in 0..255) {
if (input.isKeyDown(i)) {
isPressed[i] = true
}
else {
isPressed[i] = false
}
}
for (i in 0..255) {
if (isPressed[i] && !currentState[i] && !isToggled[i]) {
currentState[i] = true
isToggled[i] = true
}
else if (isPressed[i] && currentState[i] && !isToggled[i]) {
currentState[i] = false
isToggled[i] = true
}
if (!isPressed[i] && isToggled[i]) {
isToggled[i] = false
}
}
}
fun forceSet(key: Int, b: Boolean) {
currentState[key] = b
isToggled[key] = true
}
}