Post Fri Mar 21, 2014 3:41 pm

threads omnispace

  Code:
width = (7*255); --255 is 1 grid space from 0,0 (so actually radius)
height = width;

function main()
    subscribe(Event.Tick);
    for i=1,50 do
        logprint("");
    end
end

function onTick(delta)
    --unfortunately, phasers can't be wrapped
    local results = {};
    bf:findAllObjects(results,
        ObjType.Asteroid,
        ObjType.Burst,
        ObjType.Seeker,
        ObjType.SoccerBallItem,
        ObjType.ResourceItem,
        ObjType.TestItem
        );
    for i,item in ipairs(results) do
        local pos = item:getPos();
        --check x
        if (pos.x > width) then
            item:setPos(pos - point.new(width*2,0));
        elseif (pos.x < 0-width) then
            item:setPos(pos + point.new(width*2,0));
        end
        --check y
        if (pos.y > height) then
            item:setPos(pos - point.new(0,height*2));
        elseif (pos.y < 0-height) then
            item:setPos(pos + point.new(0,height*2));
        end
    end
   
    --now do ships...
    local players = bf:getGameInfo():getPlayers();
    for i,player in ipairs(players) do
        local name = player:getName();
        local ship = player:getShip();
        local pos = ship:getPos();
            --check x
            if (pos.x > width) then
                ship:setPos(pos - point.new(width*2,0));
            elseif (pos.x < 0-width) then
                ship:setPos(pos + point.new(width*2,0));
            end
            --check y
            if (pos.y > height) then
                ship:setPos(pos - point.new(0,height*2));
            elseif (pos.y < 0-height) then
                ship:setPos(pos + point.new(0,height*2));
            end
    end
end

this translates you from one edge to the other.

To play the original omnispace, join pleides and type
  Code:
/dlmap omnispace


I'm trying to make a version of omnispace that instead of having the edges outside, has inside edges

  Code:
width2 = (4*255);
height2 = width2;

function main()
    subscribe(Event.Tick);
    for i=1,50 do
        logprint("");
    end
end

function onTick(delta)
    --unfortunately, phasers can't be wrapped
    local results = {};
    bf:findAllObjects(results,
        ObjType.Asteroid,
        ObjType.Burst,
        ObjType.Seeker,
        ObjType.SoccerBallItem,
        ObjType.ResourceItem,
        ObjType.TestItem
        );
    for i,item in ipairs(results) do
        local pos = item:getPos();
        --check x2
        if (pos.x < width2) then
            item:setPos(pos - point.new(width2*2,0));
        elseif (pos.x > 0-width2) then
            item:setPos(pos + point.new(width2*2,0));
        end
        --check y2
        if (pos.y < height2) then
            item:setPos(pos - point.new(0,height2*2));
        elseif (pos.y > 0-height2) then
            item:setPos(pos + point.new(0,height2*2));
        end
    end
   
    --now do ships...
    local players = bf:getGameInfo():getPlayers();
    for i,player in ipairs(players) do
        local name = player:getName();
        local ship = player:getShip();
        local pos = ship:getPos();
            --check x2
            if (pos.x < width2) then
                ship:setPos(pos - point.new(width2*2,0));
            elseif (pos.x > 0-width2) then
                ship:setPos(pos + point.new(width2*2,0));
            end
            --check y2
            if (pos.y < height2) then
                ship:setPos(pos - point.new(0,height2*2));
            elseif (pos.y > 0-height2) then
                ship:setPos(pos + point.new(0,height2*2));
            end
    end
end
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002