generating levels

Having trouble based mostly on how the Codea draw function works. I want to draw a series of designs for a level that is pretty much just square sprites drawn one after another. I can’t get the squares to keep drawing, but only to draw a single square, or to make a single square move. I’m sure it is something to do with the draw function, or however it is I am using it wrong. Any help appreciated.

@Jrohanian imagine a world where things only updated 60 times per second, so you could only see a ball fly through the air at 60 different points in 1 second, pretty messed up world I know but imagine you can send information to that world using function calls such as sprite rect ellipse etc but you need to supply this information with size and position every frame along with the image to display. This way you can add a variable in the setup function which gets called once at the very start and then add to that variable (a vec2 or number) then put that in the draw function inside your sprite call, and watch it grow. Any increment you give will be added 60 times per second (every frame) so remember to divide n by 60 if you’re trying to get roughly an increment of n every second, hope that makes enough sense so that you can continue on it. If not ask some other Codean!

Also I can’t remember who but someone wrote a pretty good looking code/function persisting class that will continuously display sprites if the draw function doesn’t make sense for you.

@jrohanian Here’s an example to draw multiple sprites and to move one around the screen. Not sure if this is what you’re after.


displayMode(FULLSCREEN)

function setup()
    dx=WIDTH/2
    dy=100
end

function draw()
    background(40, 40, 50)
    fill(255)
    text("move your finger around the screen",WIDTH/2,HEIGHT-20)
    sprite("Planet Cute:Character Boy",WIDTH/2,HEIGHT-100)
    sprite("Planet Cute:Character Cat Girl",WIDTH/2,HEIGHT-200)
    sprite("Planet Cute:Character Horn Girl",WIDTH/2,HEIGHT-300)
    sprite("Planet Cute:Character Pink Girl",WIDTH/2,HEIGHT-400)
    sprite("Planet Cute:Character Princess Girl",dx,dy)
end

function touched(t)
    if t.state==MOVING then
        dx=dx+t.deltaX
        dy=dy+t.deltaY
    end
end

@Luatee , I think I know what you mean, but that is to move a sprite, yes? I am trying to make multiple sprites, generated (duplicated) on a different x-position over a distance of the screen, so it would involve multiple images. Do I need to psychically write a new sprite for each one to do this, because if so what I am trying to do is impossible with Codea.

@jrohanian If you want to draw the same sprite multiple times across the screen, maybe this will give you an idea.


displayMode(FULLSCREEN)

function setup()
end

function draw()
    background(40, 40, 50)
    fill(255)
    for z=1,20 do
        sprite("Planet Cute:Character Boy",z*50,HEIGHT/2)
    end
end

@jrohanian Or are you after something more like this.


displayMode(FULLSCREEN)

function setup()
    dx=WIDTH/2
    dy=HEIGHT/2
    tab={}
    for z=1,30 do
        x=math.random(20)
        y=math.random(20)
        table.insert(tab,vec2(x*50,y*50))      
    end
end

function draw()
    background(40, 40, 50)

    for x=0,20 do
        for y=0,20 do
            sprite("Planet Cute:Grass Block",x*50,y*50,50,80)
        end
    end
    for a,b in pairs(tab) do
        sprite("Planet Cute:Rock",b.x,b.y,50,50)       
    end
    fill(255)
    text("move your finger around the screen",WIDTH/2,HEIGHT-40)
    sprite("Platformer Art:Guy Standing",dx,dy,30)
end

function touched(t)
    dx=dx+t.deltaX
    dy=dy+t.deltaY
end

I am half way through create a level generator for box2D in Codea, so it is definitely possible. I even incorporated a little copy and paste for making tile maps on the fly.

@jrohanian, You can download and take a look at the code I share for my mapeditor. I think that’s what you are asking for. You can swap in your own tileset and use the mapeditor.

http://codea.io/talk/discussion/4915/map-editor#Item_20