Howdy, Stranger!

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

Swarm of ships

edited February 2013 in General Posts: 521

I've been playing around with making a swarm of ships. Move with one or more fingers, and press fire to create a mayhem. :)

https://gist.github.com/tnlogy/4971294

Comments

  • SimeonSimeon Admin Mod
    Posts: 5,587

    The behaviour is mesmerising and has a real retro feeling.

    Love the fact that they destroy each other.

  • Posts: 521

    I wanted to create waves of enemies, like in old top-down shooters. But instead I became the wave of ships. :)

  • edited April 12 Posts: 972

    I hope no one minds me exhuming stuff from this far back, but this is a cool little project, so I fixed it up a little, for anyone who wanders across it like I did,

    I corrected a couple lines that were causing errors due to lua updates, and I made an icon for it, and I made it a .zip so you don’t have to go to GitHub to get it,

    @tnlogy, nice job!

  • Posts: 972

    I made a little tweak that added more ships and put them in random positions in screen instead of all in a straight line. Just a little more chaos for everybody’s enjoyment.

  • dave1707dave1707 Mod
    Posts: 9,109

    Reminded me of a mob program I wrote in the past. Tap the screen to make the sprites exchange positions.

    viewer.mode=FULLSCREEN
    
    function setup()
        size=35
        objects1,objects2,objects3,objects4={},{},{},{}    
        for z=1,120 do
            a=physics.body(CIRCLE,size)
            a.x=math.random(WIDTH)
            a.y=math.random(HEIGHT)
            a.gravityScale=0
            ob=z%4
            if ob==0 then
                table.insert(objects1,a)
            elseif ob==1 then
                table.insert(objects2,a)
            elseif ob==2 then
                table.insert(objects3,a)
            elseif ob==3 then
                table.insert(objects4,a)
            end
        end    
        target1=vec2(WIDTH/2,HEIGHT-150)
        target2=vec2(WIDTH/2,150)
        target3=vec2(150,HEIGHT/2)
        target4=vec2(WIDTH-150,HEIGHT/2)
    end
    
    function draw()
        background(142, 88, 38, 255)
        drawMob(objects1,target1,asset.builtin.Planet_Cute.Character_Boy)
        drawMob(objects2,target2,asset.builtin.Planet_Cute.Character_Cat_Girl)
        drawMob(objects3,target3,asset.builtin.Planet_Cute.Character_Horn_Girl)
        drawMob(objects4,target4,asset.builtin.Planet_Cute.Character_Pink_Girl)
    end
    
    function drawMob(obj,tar,spr)
        for i,v in ipairs(obj) do
            move=tar-vec2(v.x, v.y)   
            if move:len()>10 then
                move=move:normalize()*10
            end
            v.x=v.x+move.x
            v.y=v.y+move.y
            sprite(spr,v.x,v.y,25)
        end
    end
    
    function touched(touch)
        if touch.state==BEGAN then
            target1,target2=target2,target1
            target3,target4=target4,target3
        end
    end
    
Sign In or Register to comment.