still WIP inventory impl, held item impl

Former-commit-id: 9468cfae21ff09c3dd30352a849910364e01d780
Former-commit-id: 50247ccebf3284f739877a1d6c6d8574449a9824
This commit is contained in:
Song Minjae
2016-12-14 00:28:42 +09:00
parent 6571bf5038
commit 4bafccdaa0
22 changed files with 126 additions and 116 deletions

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.tileproperties.TileNameCode
import net.torvald.terrarum.tileproperties.TilePropCodex
import net.torvald.terrarum.ui.UIHandler
import org.dyn4j.geometry.Vector2
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Input
/**
@@ -17,38 +18,45 @@ import org.newdawn.slick.Input
*/
object GameController {
val mouseX: Float
// these four values can also be accessed with GameContainer.<varname>
// e.g. gc.mouseTileX
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */
internal val mouseX: Float
get() = (MapCamera.cameraX + Terrarum.appgc.input.mouseX / Terrarum.ingame.screenZoom)
val mouseY: Float
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise)*/
internal val mouseY: Float
get() = (MapCamera.cameraY + Terrarum.appgc.input.mouseY / Terrarum.ingame.screenZoom)
val mouseTileX: Int
/** currently pointing tile coordinate */
internal val mouseTileX: Int
get() = (mouseX / MapDrawer.TILE_SIZE).toInt()
val mouseTileY: Int
/** currently pointing tile coordinate */
internal val mouseTileY: Int
get() = (mouseY / MapDrawer.TILE_SIZE).toInt()
fun processInput(input: Input) {
fun processInput(gc: GameContainer, delta: Int, input: Input) {
KeyToggler.update(input)
if (!Terrarum.ingame.consoleHandler.isTakingControl) {
if (Terrarum.ingame.player is Player && (Terrarum.ingame.player as Player).vehicleRiding != null) {
(Terrarum.ingame.player as Player).vehicleRiding!!.processInput(input)
(Terrarum.ingame.player as Player).vehicleRiding!!.processInput(gc, delta, input)
}
Terrarum.ingame.player.processInput(input)
Terrarum.ingame.player.processInput(gc, delta, input)
for (ui in Terrarum.ingame.uiContainer) {
ui.processInput(input)
ui.processInput(gc, delta, input)
}
}
else {
Terrarum.ingame.consoleHandler.processInput(input)
Terrarum.ingame.consoleHandler.processInput(gc, delta, input)
}
if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
// test tile remove
// test tile remove
/*if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
try {
Terrarum.ingame.world.setTileTerrain(mouseTileX, mouseTileY, TileNameCode.AIR)
// terrarum.game.map.setTileWall(mouseTileX, mouseTileY, TileNameCode.AIR);
@@ -58,8 +66,8 @@ object GameController {
}
// test tile place
else if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
// test tile place
try {
Terrarum.ingame.world.setTileTerrain(
mouseTileX, mouseTileY,
@@ -69,7 +77,22 @@ object GameController {
catch (e: ArrayIndexOutOfBoundsException) {
}
}
}*/
///////////////////
// MOUSE CONTROL //
///////////////////
// PRIMARY/SECONDARY IS FIXED TO LEFT/RIGHT BUTTON //
/////////////////////
// GAMEPAD CONTROL //
/////////////////////
}
fun keyPressed(key: Int, c: Char) {
@@ -109,13 +132,14 @@ object GameController {
}
fun mousePressed(button: Int, x: Int, y: Int) {
if (button == 0) {
// bullet test
/*if (button == 0) {
Terrarum.ingame.addActor(ProjectileSimple(
0,
Terrarum.ingame.player.centrePosition,
Vector2(mouseX.toDouble(), mouseY.toDouble())
))
}
}*/
}
fun mouseReleased(button: Int, x: Int, y: Int) {
@@ -138,3 +162,16 @@ object GameController {
return KeyMap.getKeyCode(fn) == key
}
}
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */
val GameContainer.mouseX: Float
get() = GameController.mouseX
/** position of the mouse (pixelwise) relative to the world (also, currently pointing world-wise coordinate, if the world coordinate is pixel-wise) */
val GameContainer.mouseY: Float
get() = GameController.mouseY
/** currently pointing tile coordinate */
val GameContainer.mouseTileX: Int
get() = GameController.mouseTileX
/** currently pointing tile coordinate */
val GameContainer.mouseTileY: Int
get() = GameController.mouseTileY