45 lines
1.2 KiB
Scala
45 lines
1.2 KiB
Scala
package fmon.world
|
|
|
|
import scalafx.util.Duration
|
|
|
|
import fmon._
|
|
import fmon.draw._
|
|
import fmon.util.Direction
|
|
|
|
abstract class Actor(val sprite: Sprite, var pos: Position, var move: Movement) {
|
|
def x: Int = pos.x
|
|
def y: Int = pos.y
|
|
def xreal: Double = x - move.direction.x * move.completion
|
|
def yreal: Double = y - move.direction.y * move.completion
|
|
|
|
val imgView = new AnimatedImageView(sprite, new Duration(600)) {
|
|
x = pos.x * Config.tileSize
|
|
y = pos.y * Config.tileSize + Config.yOffset
|
|
}
|
|
|
|
def pose: String = sprite.pose
|
|
def pose_=(p: String) = {
|
|
sprite.pose = p
|
|
}
|
|
|
|
def slide(dt: Duration): Unit = {
|
|
move.completion -= dt.toSeconds() * Config.moveSpeed
|
|
if (move.completion <= 0) {
|
|
move = selectNextMove
|
|
pos += move.direction
|
|
if (move.direction != Direction.Stationary) {
|
|
imgView.play()
|
|
} else {
|
|
imgView.stop()
|
|
}
|
|
}
|
|
imgView.x = xreal * Config.tileSize
|
|
imgView.y = yreal * Config.tileSize + Config.yOffset
|
|
}
|
|
|
|
def selectNextMove: Movement
|
|
}
|
|
|
|
class Hero(sprite: Sprite, pos: Position) extends Actor(sprite, pos, new Movement(Direction.Stationary, 0)) {
|
|
def selectNextMove = new Movement(Direction.Stationary, 0)
|
|
} |