FAQ  •  Register  •  Login

_k's Curvegen

<<

karamazovapy

Posts: 1567

Joined: Tue Feb 23, 2010 7:52 pm

Post Thu Sep 22, 2011 1:56 pm

_k's Curvegen

To Use:
1) Copy this code and save it as curve.levelgen in your levels folder.
2) Modify the variables in the header and resave.
3) Go to LEVEL PARAMETERS in the editor and type curve.levelgen where it says Levegen Script:
4) From the editor, press Ctrl-R to run the script and then Ctrl-I to insert the barrier, goalzone, or loadoutzone.

As a bonus, by setting PercentofCircle to 1, you can use a low Resolution number to produce regular polygons!
  Code:
--Adjust the following variables to modify your Circle or Curve.
--To run this levelgen in your level, press Ctrl-R in the Editor.
--To add the created curve to your level, press Ctrl-I after running.

--Item Type
--Choose "BarrierMaker" or "GoalZone" or "LoadoutZone" or "PolyWall"
ItemType = "BarrierMaker"

--Barrier Width of Circle
BarrierWidth = 50

--X Coordinate of Center of Circle
CenterX = 0

--Y Coordinate of Center of Circle
CenterY = 0

--Radius in X Direction of Circle (Keep XRadius and YRadius the same for Circles.  Make them different for elipses.)
XRadius = 1

--Radius in Y Direction of Circle (Keep XRadius and YRadius the same for Circles.  Make them different for elipses.)
YRadius = 1

--Percent of Circle you want to Draw
--Use 1 for 100% of circle, .75 for 75%, etc.
--You may have to use .51 for 50%.
PercentofCircle = 1

--Where you want point 0 of the curve to be
--Use 0 to Start at (1,0)
--Use .5 * math.pi to Start at (0,-1)
--Use math.pi to Start at (-1,0)
--Use 1.5 * math.pi to Start at (0,1)
StartPoint = 0

--For Higher Resolution Curves, use a higher number.
--Some values might produce curves with too many points to plot.
--if PercentofCircle = 1, lower values will produce regular polygons.
--Suggested Resolutions: 30 or 60
Resolution = 30

-----------------------------------
--Do not edit the following code.--
-----------------------------------
if(ItemType=="BarrierMaker") then
    Curve = ItemType .. " " .. BarrierWidth .. " "
elseif(ItemType=="PolyWall") then
    Curve = ItemType .. " "
else
    Curve = ItemType .. " 0 "
end

Destination = PercentofCircle * 2 * math.pi + StartPoint
for x = StartPoint, Destination,  2 * math.pi / Resolution do
    Curve = Curve .. XRadius * math.cos(x) + CenterX .. " " .. YRadius * math.sin(x) - CenterY .. "  "
end

if(PercentofCircle == 1) then
    Curve = Curve .. XRadius * math.cos(StartPoint) + CenterX .. " " .. YRadius * math.sin(StartPoint) - CenterY .. "  "
end

levelgen:addLevelLine(Curve)
<<

watusimoto

Site Admin

Posts: 1558

Joined: Tue Feb 23, 2010 7:07 pm

Location: Quartz's mom's house

Post Fri Sep 23, 2011 6:11 am

Re: _k's Curvegen

Ok, I haven't tried this yet, but I will give you the benefit of the doubt and say "this is awesome!!!"

I have been waiting for someone to do something like this, to give me reason to take the next step toward better integration of lua scripts and the editor. I plan to make a way to use scripts like this without defining them as levelgens; this will allow us to add user-generated plugins to the editor. They will have access to selected objects, so you could select a wall, then run a plugin to, say, reshape it into a poodle. Or whatever. There will also need to be a way to have the script request input from the user, such as what size poodle to make.

The best plugins could even be distributed with the game, and preconfigured in the INI for ease of use.

Good work!!
<<

BlackBird

User avatar

Posts: 404

Joined: Wed Jun 15, 2011 7:25 pm

Location: Maryland USA

Post Fri Sep 23, 2011 2:48 pm

Re: _k's Curvegen

umm, im not so sure it works (at least for mac). When i put the curve.levelgen in the levelgen thing, this weird circle is at the center of my level when i test it. it dosnt show up when im in editor unless i hit control r. help?
You cannot legislate the poor into prosperity by legislating the wealthy out of prosperity.
<<

karamazovapy

Posts: 1567

Joined: Tue Feb 23, 2010 7:52 pm

Post Fri Sep 23, 2011 3:37 pm

Re: _k's Curvegen

karamazovapy wrote:4) From the editor, press Ctrl-R to run the script and then Ctrl-I to insert the barrier, goalzone, or loadoutzone.

Return to Misc.

Who is online

Users browsing this forum: No registered users and 1 guest

cron