{"id":145,"date":"2010-10-30T03:24:00","date_gmt":"2010-10-30T09:24:00","guid":{"rendered":"http:\/\/elysianshadows.com\/2010\/10\/meandering-lua\/"},"modified":"2010-10-30T03:24:00","modified_gmt":"2010-10-30T09:24:00","slug":"meandering-lua","status":"publish","type":"post","link":"http:\/\/elysianshadows.com\/updates\/meandering-lua\/","title":{"rendered":"Meandering.lua"},"content":{"rendered":"\n<p style=\"color: #333333; font-family: Tahoma, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 15px;\">&nbsp;<\/p>\n<p style=\"color: #333333; font-family: Tahoma, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 15px;\">Gentle sirs, I present to you:<\/p>\n<p style=\"color: #333333; font-family: Tahoma, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 15px;\">[size=20]MEANDERING.Lua[\/size]<\/p>\n<pre>function Meander (chars) \tfor i = 1, #chars do  -- # returns the numer of elements in the array, so this loop iterates through the array \t\t-- MEANDERING AS FUCK \t\tif chars[i ].entity.transform:getPosition().y &lt;= chars[i ].y1 and chars[i ].entity.transform:getPosition().x &gt;= chars[i ].x1 then \t\t\tchars[i ].comp:Move(gyro.Vector2(-90, 0)*deltatime); \t\telseif chars[i ].entity.transform:getPosition().x &lt;= chars[i ].x1 and chars[i ].entity.transform:getPosition().y &lt;= chars[i ].y2 then \t\t\tchars[i ].comp:Move(gyro.Vector2(0, 90)*deltatime); \t\telseif chars[i ].entity.transform:getPosition().y &gt;= chars[i ].y2 and chars[i ].entity.transform:getPosition().x &lt;= chars[i ].x2 then \t\t\tchars[i ].comp:Move(gyro.Vector2(90, 0)*deltatime); \t\telseif chars[i ].entity.transform:getPosition().x &gt;= chars[i ].x2 and chars[i ].entity.transform:getPosition().y &gt;= chars[i ].y1 then \t\t\tchars[i ].comp:Move(gyro.Vector2(0, -90)*deltatime); \t\tend \tend end function OnLoad() \t-- Adds playable characters to party. \tLuaSingleton:getPartySystem():AddPlayableToParty(\"TestCharacter1\");  \tLuaSingleton:getPartySystem():AddPlayableToParty(\"TestCharacter2\"); \t \t-- Sets keyboard input to 'input' and sets player1 to active character. \tinput = LuaSingleton:getInput(); \tplayer1 = LuaSingleton:getPartySystem():getPlayablePartyMember(0); \t \t-- Grabs entities from .txt \tfuckbritches = Entity:getByName(\"Fuckbritches\"); \tdoucheass = Entity:getByName(\"Doucheass\"); \tassdouche = Entity:getByName(\"Assdouche\"); \t \t-- Fucking embeded Lua tables... Goddamn. \tmeanderingChars = { \t\t{ \t\t\tentity = Entity:getByName(\"Fuckbritches\"),  -- Entity name \t\t\tcomp = fuckbritches:getCharacter(),       -- Sets character component \t\t\tx1 = 700, -- Original position from Entity.txt \t\t\ty1 = 320, --\/ \t\t\tx2 = 963, -- \t\t\ty2 = 400  -- Perimeter boundry coord \t\t}, \t\t{ \t\t\tentity = Entity:getByName(\"Doucheass\"), \t\t\tcomp = doucheass:getCharacter(), \t\t\tx1 = 340, \t\t\ty1 = 360, \t\t\tx2 = 479, \t\t\ty2 = 587 \t\t}, \t\t{ \t\t\tentity = Entity:getByName(\"Assdouche\"),  \t\t\tcomp = assdouche:getCharacter(), \t\t\tx1 = 300, \t\t\ty1 = 340, \t\t\tx2 = 490, \t\t\ty2 = 380 \t\t} \t} \tprint(\"FUUUUCKING LOADED!!nn\"); end function Update() \tdeltatime = LuaSingleton:getTimerSystem():getDeltaTime();  -- sets delta time, all the time, everytime \tif input:getDown(input.BUT_F) then -- random ass debugging shit, hit F to see player1's X and Y location \t\tprint(player1.transform:getPosition().x .. \" \" .. player1.transform:getPosition().y .. \"n\"); end Meander(meanderingChars); -- calls Meander while passing the embeded mistakery end <\/pre>\n<p style=\"color: #333333; font-family: Tahoma, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 15px;\">In this script I emulated an array of classes in Lua&#8217;s (embedded) table data type. In this embedded table I was able to create a general entity name, call the character component, create an X\/Y origin, X\/Y pathing boundry in preparation to tell these assholes to get to steppin&#8217;.<\/p>\n<p style=\"color: #333333; font-family: Tahoma, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 15px;\">The meander function is called every frame (via Update() ) and moves the entities around the perimeter I have set using their original X\/Y position and the second X\/Y coordinate defined in the table. Because I am using<\/p>\n<pre>Chars[i ].comp:Move(gyro.Vector2(X,Y)*deltatime);<\/pre>\n<p style=\"color: #333333; font-family: Tahoma, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 15px;\">Not only is the sprite animated, but it also framerate independent and moves at the correct speed no matter how shitty your console (or computer) might be.<\/p>\n<p style=\"color: #333333; font-family: Tahoma, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 15px;\">Also&#8230; [size=20]SOUND WORKS[\/size]<\/p>\n<p><a href=\"http:\/\/www.youtube.com\/watch?v=Efoy2EH8B_E\">http:\/\/www.youtube.com\/watch?v=Efoy2EH8B_E<\/a><\/p>\n<p style=\"color: #333333; font-family: Tahoma, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 15px;\">Questions, comments?<\/p>\n","protected":false},"excerpt":{"rendered":"<p style=\"color: #333333; font-family: Tahoma, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 15px;\"><strong>Originally posted in our Private Development forums on 10.30.10.<\/strong><\/p>\n<p style=\"color: #333333; font-family: Tahoma, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 15px;\">In this script I emulated an array of classes in Lua&#8217;s (embedded) table data type. In this embedded table I was able to create a general entity name, call the character component, create an X\/Y origin, X\/Y pathing boundry in preparation to tell these assholes to get to steppin&#8217;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-145","post","type-post","status-publish","format-standard","hentry","category-underlying-technology"],"_links":{"self":[{"href":"http:\/\/elysianshadows.com\/updates\/wp-json\/wp\/v2\/posts\/145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/elysianshadows.com\/updates\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/elysianshadows.com\/updates\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/elysianshadows.com\/updates\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/elysianshadows.com\/updates\/wp-json\/wp\/v2\/comments?post=145"}],"version-history":[{"count":0,"href":"http:\/\/elysianshadows.com\/updates\/wp-json\/wp\/v2\/posts\/145\/revisions"}],"wp:attachment":[{"href":"http:\/\/elysianshadows.com\/updates\/wp-json\/wp\/v2\/media?parent=145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/elysianshadows.com\/updates\/wp-json\/wp\/v2\/categories?post=145"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/elysianshadows.com\/updates\/wp-json\/wp\/v2\/tags?post=145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}