Page 1 of 1

Levelgen Script request

PostPosted: Wed Nov 13, 2013 4:33 pm
by tazinator
Hi, I saw a level where there was a chain of resource items swinging around. I am planning to use that in my levels.
I have no knowledge of levelgen

Re: Levelgen Script request

PostPosted: Mon Nov 25, 2013 4:24 pm
by thread
I made a level like that once. PM me with what you are looking for in particular and I'll see what I can do.

Re: Levelgen Script request

PostPosted: Tue Nov 26, 2013 10:31 am
by sam686

Re: Levelgen Script request

PostPosted: Tue Nov 26, 2013 11:42 am
by bobdaduck
  Code:
tau = math.pi * 2

-------------------------
--copy this block of code if you want multiple swingy-chain items, modifying the center and truecenter values accordingly.
beater1 = {}
beater1["type"] = ResourceItem --capitalization is important here.
beater1["center"] = point.new(0, 0) --Just set this to be the same as the "trueCenter" below.
beater1["trueCenter"] = point.new(0, 0) --the center of the chain
beater1["length"] = 5 --how many to make + 1. (so this will do 4)
beater1["objects"] = {} --ignore this
beater1["orbitTime"] = 2500 --2500 milliseconds to make a rotation (2 and a half seconds)
beater1["x"] = 0 --these two x and y variables are added to the ["center"] variable above each time it makes an item.
beater1["y"] = 50 --a resourceItem is about this big.
beater1["orbitDirection"] = -1 -- positive for counter clockwise, negative for clockwise
--If you make multiple, they won't show up unless you add them to the beaterArray below.
--------------------------



beaterArray = {beater1} --if you want more, put them within the {} seperated by commas.  {beater1, beater2}

origin = point.zero

function doBeaters(deltaTime)
    for index, value in ipairs(beaterArray)
    do
        for dex, val in ipairs(value["objects"])
        do
            local t = getMachineTime() % (value["orbitTime"]) / value["orbitTime"]
 
            local center = value["trueCenter"]
            local radius = point.distanceTo(val["loc"], center)
           
            local pos = center + point.new(math.sin((t + 1/5) * tau * value["orbitDirection"]), math.cos((t + 1/5) * tau * value["orbitDirection"])) * radius
            local unitVec = point.normalize(center - pos)
            val["item"]:setVel(point.new(value["orbitDirection"] * -unitVec.y, value["orbitDirection"] * unitVec.x) * tau * radius / (value["orbitTime"] / 1000))
            val["item"]:setLoc(pos)
        end
    end
end

function onTick(deltaTime)
    doBeaters(deltaTime)
end

function main()
    subscribe(Event.tick)
   
    for index, value in ipairs(beaterArray)
    do
        for i = 1, value["length"]
        do
            item = {}
            item["loc"] = value["center"]
            item["item"] = value["type"].new()
            item["item"]:setLoc(value["center"])
            levelgen:addItem(item["item"])
            table.insert(value["objects"], item)
            value["center"] = point.new(value["center"].x + value["x"], value["center"].y + value["y"])
        end
    end
    Timer:scheduleRepeating(function()
        beater11["orbitDirection"] = beater11["orbitDirection"] * -1
    end, 10000)
end

Re: Levelgen Script request

PostPosted: Tue Nov 26, 2013 6:03 pm
by Fordcars
Bobydaducky!

Re: Levelgen Script request

PostPosted: Wed Nov 27, 2013 2:32 am
by tazinator
I put it in my level and it came apart! All I did was drive into it a few times :lol:
Edit: Ooh I see, it automatically comes apart after 10 seconds. Ha!
Edit 2: searched code after figuring out, if it's so controlled, it much be on a timer. sure enuf! :)

Another question then. Can asteroid size be controlled in a spawn?