Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Wave of Enemies

edited January 2015 in General Posts: 8

I'm trying to make waves of enemies and am stuck on drawing a certain amount/certain enemies. I want to loop 10 of certain enemies in a single wave and then wait a certain amount of time before the next wave(s) are drawn.

-- Final Creatures

-- Use this function to perform your initial setup
function setup()

    health={5,2,8,10}
    wave={"meteor1","meteor2","meteor3","meteor4","meteor5","meteor6","meteor7","meteo8r","meteor9","meteor10"}
    rTable={}
    timeout=ElapsedTime+1
end

-- This function gets called once every frame
function draw()
    background(141, 47, 47, 255)
    --floor
    strokeWidth(15)
    line(0,250,WIDTH,250)
    strokeWidth(7)
    rect(-5,-5,WIDTH+10,250)

    time()

    --beast
    strokeWidth(0)
    for meteor1,meteor10 in pairs(wave) do
        for nbr,rock in pairs(rTable) do
            ellipse(rock.x,rock.y,30)
            rock.x=rock.x+.1
            if rock.x>=WIDTH/2-30 then
                rock.x=WIDTH/2-30
            end
        end
    end
end

function time()
    if (ElapsedTime>timeout) then
        table.insert(rTable,vec2(0,300))
        timeout=ElapsedTime+1
    end
end

Comments

  • dave1707dave1707 Mod
    Posts: 7,809

    @ZacharyU Here's a simple example of creating a wave of objects.


    displayMode(FULLSCREEN) function setup() tab={} tm=0 create() end function create() for z=1,10 do table.insert(tab,vec2(z*50,HEIGHT)) end end function draw() background(0) fill(255) for a,b in pairs(tab) do ellipse(b.x,b.y,20) b.y=b.y-5 end for a,b in pairs(tab) do if b.y<0 then table.remove(tab,a) end end tm=tm+1 if tm>60 then create() tm=0 end end
  • @dave1707 What if I wanted to draw, say, only 5 of the circles. What would I have to change to make it only draw 5?

  • dave1707dave1707 Mod
    Posts: 7,809

    @ZacharyU In the function create(), change the 10 in the 'for' loop to 5.

  • Sorry, I meant draw the circles only 5 times and then they stop getting drawn.

  • dave1707dave1707 Mod
    edited January 2015 Posts: 7,809

    @ZacharyU You could add a variable that gets incremented each time create() is called. If that variable is greater than 5 then you stop calling create().

Sign In or Register to comment.