Drawing the enemy character to the screen
We have defined our enemy character in the previous chunks, but we will now draw it to screen with the following chunk:
function DrawEnemy() for i,v in ipairs(enemyTable) do v.animation:draw(enemyImage, v.l-8, v.t-16) end end
You should call the
DrawEnemy()
function within the love.draw()
function; if not, it will not display on the screen.
function love.draw() map:draw() DrawPlayer() DrawEnemy() end
Finally, add the enemy's bump configuration:
--Bump configuration function bump.collision(obj1, obj2, dx, dy) --Bump configuration for player if obj1 == player then collidePlayerWithPlatform(dx,dy,obj2) elseif obj2 == player then collidePlayerWithPlatform(-dx,-dy,obj1) end --Bump configuration for enemy for i,v in ipairs(enemyTable) do if obj1 == v then collideEnemyWithPlatform(dx,dy,v,obj2) elseif obj2 == v then collideEnemyWithPlatform(-dx,-dy,v,obj1) end end end