Added movement abilities to NPCs
This commit is contained in:
@@ -6,12 +6,17 @@ import fmon._
|
||||
import fmon.draw._
|
||||
import fmon.util.Direction
|
||||
|
||||
class Actor(val sprite: Sprite, var pos: Position, var move: Movement) {
|
||||
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
|
||||
@@ -20,8 +25,21 @@ class Actor(val sprite: Sprite, var pos: Position, var move: Movement) {
|
||||
def slide(dt: Duration): Unit = {
|
||||
move.completion -= dt.toSeconds() * Config.moveSpeed
|
||||
if (move.completion <= 0) {
|
||||
//pos += move.direction
|
||||
move = new Movement(Direction.Stationary, 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)
|
||||
}
|
||||
Reference in New Issue
Block a user