diametric projection -- up 1 over 2 grid

This is sometimes called isometric projection in gaming but it’s actually diametric.

Think FarmVille (or Zaxxon) grid system.

A still picture of this doesn’t show it as well as running it.

It’s not a game, just an example of a type of projection/drawing style.

I also learned to use table.sort finally :slight_smile:


--zaxdea
function setup()
    displayMode(FULLSCREEN)
    mgp = 0 -- modular grid position, just used to move horizontal grid lines
    s = 1 -- speed
    st = {} -- sprite table
end

function draw()
    rect(0,0,0,0)
    background(0, 0, 0)
    stroke(0, 255, 16, 255)
    strokeWidth(3)
    drawgrid()   
    for i,v in ipairs(st) do
        sprite("Tyrian Remastered:Tower",st[i].x,st[i].y)
        st[i].x = st[i].x - (s*2)
        st[i].y = st[i].y - s
        if st[i].y < -50 or st[i].x < -50 then
            st[i] = {x=1100,y=300 + 20 + math.random(750)}
        end
    end
    if table.maxn(st) < 50 then
        if math.random(100) < 2 then --add new ones slowly
            table.insert(st,{x=1100,y=300 + 20 + math.random(750)})
        end
    end
    --sort so that the higher y will draw first
    table.sort(st,function(a,b) return a.y>b.y end)
end

function drawgrid()
    mgp = mgp + s
    if mgp == 50 then mgp = 0 end
    local i
    for i = -250, 500, 50 do
        line(-100,-50+i,1100,550+i)
    end
    for i = 0, 800, 50 do
        line(-1000+((i-mgp)*2),i-mgp,500+((i-mgp)*2),i-mgp)
    end
end

Fantastic. That’s very nice, I can see that code being useful to a lot of people.

Good demo of how to accomplish a commonly wanted effect - bravo!

@Simeon - Oddly - I had the same “black screen” problem with this at first, even with a rect(0,0,0,0) at the beginning. Changed it to rect(0,0,1,1) and it worked.

Lots to learn from reading your code. Thank you!