06. Draw Enemies

Image (Original Source)

Start by adding a table to track enemies. Populate it with 10 enemies.

 
function _init()
cls()
ship={sp=1,x=60,y=60}
bullets={}
enemies={}
for i=1,10 do
add(enemies, {
sp=17,
x=i*16,
y=60-i*8
})
end
end
 

At the end of the _draw function, add code to display the enemies.

 
for e in all(enemies) do
spr(e.sp,e.x,e.y)
end
 

Finally, let's add an enemy at location 017.

Press ctrl-r to run the game and you should see some enemies! You won't be able to destroy them and they don't move, but it is a start!

End Result

Download