mirror of
				https://github.com/ynerant/Level-Editor.git
				synced 2025-11-03 23:52:05 +01:00 
			
		
		
		
	Continuous moves
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user