First, one advice: Linux is case-sensitive. If you want to make your game compatible with Linux, too, then you should make sure that you write all you filenames with correct cases (icon.png vs. icon.PNG).
Now for your problem: Indeed you spawn a new zombie in every frame. That is why you get a long "snake" of zombies. This still looks cool, but that's not what you want. Instead you should only spawn the zombies once. The simplest way of implementing this is by making a function:
Code: Select all
function loadLevel(n)
if n == 1 then
-- spawn four zombies, for example
zombie_spawn(200,200)
zombie_spawn(300,200)
zombie_spawn(200,300)
zombie_spawn(300,300)
elseif n == 2 then
-- do whatever you need for the second level....
end
end
And then call
when the game is started (when the start button is pressed and the gamestate changes).
However, this would spawn zombies only on start up. If you want to spawn zombies after some time, then you would have to use a timer. First make a table of the times and coordinates at which you want to spawn zombies:
Code: Select all
spawnList = {
{t=1,x=200,y=300},{t=2,x=200,y=300},{t=5,x=500,y=500},
}
Then you add a timer variable, that you set to zero when the level starts (put this into the same place when you switch the gamestate to "playing".) Then in the update you do this:
Code: Select all
timer = timer + dt
for i,v in ipairs(spawnList) do
if timer >= v.t and timer - dt < v.t then
zombie_spawn(v.x,v.y)
end
end
These lines check if the timer passed the time of one of the items in the spawnList (check if the previous time was smaller and the current time is greater or equal) and if so, then it spawns a zombie in the given coordinates.