Updating the enemy position and animation
The enemy's position and animation need constant update. First, we have to know the enemy's current state (dead or alive). If the enemy is alive, update the position and play animation; if not, don't.
First of all, add the enemy information to the list of solid tiles in FindSolidTiles(map)
:
function LoadTileMap(levelFile) map = loader.load(levelFile) ---set gravity to 1000 gravity = 1000 FindSolidTiles(map) ---list all solid tiles for i, obj in pairs( map("Characters").objects ) do if obj.type == "player" then PlayerSpawn(obj.x,obj.y-8) end if obj.type == "enemy" then EnemySpawn(obj.x,obj.y-16, obj.properties.dir ) end end map.drawObjects = false end
Then update the enemy's current state and movement, as shown in the following code:
function EnemyUpdate(dt) if EnemyDied then EnemyDied = false --remove the enemy from scene when player kills enemy, scan through the table and check if dead == true remove enemy...