Continuous moves

This commit is contained in:
Yohann D'ANELLO 2020-05-26 18:40:15 +02:00
parent 10fb067de2
commit 7eb64985c7
2 changed files with 27 additions and 4 deletions

View File

@ -207,7 +207,23 @@ class GameFrame(val map: RawMap) extends JFrame("Jeu") {
})
mobs.foreach(mob => {
val s = mob.getSprite
g.drawImage(s.getImage, SPRITE_SIZE * mob.getX, SPRITE_SIZE * mob.getY, SPRITE_SIZE, SPRITE_SIZE, null, null)
val nextCase = getPathFinder.nextPos(mob.getX, mob.getY)
var nextX = 0
var nextY = 0
if (nextCase != null) {
nextX = nextCase.getPosX
nextY = nextCase.getPosY
}
else {
nextX = mob.getX - 1
nextY = mob.getY
}
val progress = mob.progress
val newX = progress * mob.getX + (1 - progress) * nextX
val newY = progress * mob.getY + (1 - progress) * nextY
g.drawImage(s.getImage, (SPRITE_SIZE * newX).toInt, (SPRITE_SIZE * newY).toInt, SPRITE_SIZE, SPRITE_SIZE, null, null)
})
towers.foreach(tower => {
val s = tower.getSprite

View File

@ -28,13 +28,15 @@ object Mob {
abstract class Mob() {
private var hp = getMaxHP
private var tickRemains = 0L
private var initialTicks = 0L
private var sprite = null: Sprite
private var x = 0
private var y = 0
private var freezeTime = 0
private var speedMultiplier = 1
tickRemains = getSlowness
initialTicks = getSlowness
tickRemains = initialTicks
def getMaxHP: Int
@ -44,6 +46,8 @@ abstract class Mob() {
(_getSlowness * Random.between(0.95, 1.05) * (if (freezeTime > 0) 2 else 1) / speedMultiplier).toLong
}
def progress: Float = tickRemains.toFloat / initialTicks.toFloat
def getReward: Int
def getName: String
@ -63,8 +67,10 @@ abstract class Mob() {
}
def freeze(time: Int): Unit = {
if (freezeTime == 0)
if (freezeTime == 0) {
initialTicks += tickRemains
tickRemains *= 2
}
freezeTime = time
}
@ -99,7 +105,8 @@ abstract class Mob() {
if (tickRemains > 0) tickRemains -= 1
else {
tickRemains = getSlowness
initialTicks = getSlowness
tickRemains = initialTicks
val current = game.getMap.getCase(getX, getY)
if (current.getPosX == 0) {
move(-1, getY)