Continuous moves
This commit is contained in:
parent
10fb067de2
commit
7eb64985c7
|
@ -207,7 +207,23 @@ class GameFrame(val map: RawMap) extends JFrame("Jeu") {
|
||||||
})
|
})
|
||||||
mobs.foreach(mob => {
|
mobs.foreach(mob => {
|
||||||
val s = mob.getSprite
|
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 => {
|
towers.foreach(tower => {
|
||||||
val s = tower.getSprite
|
val s = tower.getSprite
|
||||||
|
|
|
@ -28,13 +28,15 @@ object Mob {
|
||||||
abstract class Mob() {
|
abstract class Mob() {
|
||||||
private var hp = getMaxHP
|
private var hp = getMaxHP
|
||||||
private var tickRemains = 0L
|
private var tickRemains = 0L
|
||||||
|
private var initialTicks = 0L
|
||||||
private var sprite = null: Sprite
|
private var sprite = null: Sprite
|
||||||
private var x = 0
|
private var x = 0
|
||||||
private var y = 0
|
private var y = 0
|
||||||
private var freezeTime = 0
|
private var freezeTime = 0
|
||||||
private var speedMultiplier = 1
|
private var speedMultiplier = 1
|
||||||
|
|
||||||
tickRemains = getSlowness
|
initialTicks = getSlowness
|
||||||
|
tickRemains = initialTicks
|
||||||
|
|
||||||
def getMaxHP: Int
|
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
|
(_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 getReward: Int
|
||||||
|
|
||||||
def getName: String
|
def getName: String
|
||||||
|
@ -63,8 +67,10 @@ abstract class Mob() {
|
||||||
}
|
}
|
||||||
|
|
||||||
def freeze(time: Int): Unit = {
|
def freeze(time: Int): Unit = {
|
||||||
if (freezeTime == 0)
|
if (freezeTime == 0) {
|
||||||
|
initialTicks += tickRemains
|
||||||
tickRemains *= 2
|
tickRemains *= 2
|
||||||
|
}
|
||||||
freezeTime = time
|
freezeTime = time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +105,8 @@ abstract class Mob() {
|
||||||
|
|
||||||
if (tickRemains > 0) tickRemains -= 1
|
if (tickRemains > 0) tickRemains -= 1
|
||||||
else {
|
else {
|
||||||
tickRemains = getSlowness
|
initialTicks = getSlowness
|
||||||
|
tickRemains = initialTicks
|
||||||
val current = game.getMap.getCase(getX, getY)
|
val current = game.getMap.getCase(getX, getY)
|
||||||
if (current.getPosX == 0) {
|
if (current.getPosX == 0) {
|
||||||
move(-1, getY)
|
move(-1, getY)
|
||||||
|
|
Loading…
Reference in New Issue