{"author_name":"Craig Smye","cat":"LD #29","comments":[{"author_name":"BallpointPress","time":"April 30, 2014 12:54 pm","epoch":1398880440,"text":"I ended up using some of the above for a start. Mainly the gravity, scrolling, and platform functions. Also some of the player control functions.","spam":"N"}],"epoch":1398457620,"likes":2,"metadata":{"p_key":"32760","p_author":"Craig Smye","p_authorkey":"505027","p_urlkey":"68277","p_title":"Code I might end up re-using for the competition","p_cat":"LD #29","p_event":"LD29","p_time":"1398457620","p_likes":"2","p_comments":"1","p_status":"UPD5","us_key":"505027","us_name":"Craig Smye","us_username":"Craig Smye","event_start":"1398384000","event_key":"22","event_name":"LD29"},"text":"<p>I am not a real programmer. I am still on the level of hacking around in AS2 and AS3 and writing code onto the timeline. I have written some functions for scrolling platformers which I tend to re-use&#8230; I guess you could call it my own 2D platformer engine in AS2.\u00a0Anyhow, embarassing as it is I have pasted the parts I might re-use via cut-and-paste\u00a0below in case I end up making a scrolling\/platformer game. It&#8217;s all actionscript2.<\/p>\n <p>Note I have moved on to using AS3 and am making some games intended for platforms outside the web browser. But for the purposes of this contest I will build a rapid prototype in AS2. The code below is an atrocity but it&#8217;s the result of what&#8217;s only been my hobby for years, and my strength is more in combining animation skills with cheap timeline tricks. So while from a programming standpoint things are a mess I can make some fun stuff nontheless.<\/p>\n <p><span id=\"more-341310\"><\/span><\/p>\n <p>\/\/SCROLLING<\/p>\n <p>function ScrollPlayField() {<br \/>\n _root.AI.rightwall = _root.AI.rightwall+_root.scrollspeed;<br \/>\n _root.AI.leftwall = _root.AI.leftwall+_root.scrollspeed;<br \/>\n \/\/FOREGROUND PLANES<br \/>\n setProperty(&#8220;_root.fg1a&#8221;, _x, _root.fg1a._x+_root.scrollspeed*1.25);<br \/>\n }<\/p>\n <p>function SetScroll(sprite) {<br \/>\n \/\/UPDATE SCROLL SPEED TO HERO&#8217;S SPEED<br \/>\n \/\/IF THE HERO HAS LATERAL CONTROL<br \/>\n \/\/AND IS PRESSING LEFT OR RIGHT<br \/>\n \/\/SCROLL LEFT OR RIGHT ACCORDINGLY<br \/>\n if (sprite.lateral==&#8221;active&#8221;) {<br \/>\n if (Key.isDown(Key.LEFT)) {<br \/>\n if (sprite.MoveXpos &gt; _root.world_MinX) {<br \/>\n _root.scrolldirection = &#8220;LEFT&#8221;;<br \/>\n _root.scrollspeed = sprite.Walk_Speed;<br \/>\n sprite.MoveXpos = sprite.MoveXpos-_root.scrollspeed;<br \/>\n sprite.MovedMetres = sprite.MoveXpos\/72<br \/>\n ScrollPlayField();<br \/>\n }<br \/>\n } else if (Key.isDown(Key.RIGHT)) {<br \/>\n if (sprite.MoveXpos &lt; _root.world_MaxX) {<br \/>\n _root.scrolldirection = &#8220;RIGHT&#8221;<br \/>\n _root.scrollspeed = -sprite.Walk_Speed;<br \/>\n sprite.MoveXpos = sprite.MoveXpos-_root.scrollspeed;<br \/>\n sprite.MovedMetres = sprite.MoveXpos\/72<br \/>\n ScrollPlayField();<br \/>\n }<br \/>\n }<br \/>\n }<br \/>\n }<\/p>\n <p>\/\/LOOPING<\/p>\n <p>function LoopMe(Me) {<br \/>\n if (Me._x &lt; Me.LoopLeft) {<br \/>\n setProperty(Me, _x, Me.LoopRight);<br \/>\n } else if (Me._x &gt; Me.LoopRight) {<br \/>\n setProperty(Me, _x, Me.LoopLeft);<br \/>\n }<br \/>\n }<\/p>\n <p>&nbsp;<\/p>\n <p>&nbsp;<\/p>\n <p>\/\/VERTICAL SCROLLING<br \/>\n function VertPlayField() {<br \/>\n \/\/FOREGROUND PLANES<br \/>\n _root.hero.Ground_Level = 3000;<br \/>\n \/\/I THINK GROUND LEVEL IS NO LONGER IMPORTANT? I HAVE LOST TRACK OF MY OWN GAME ENGINE. LOL.<br \/>\n _root.AI.Ground_Level = _root.AI.Ground_Level+_root.Vscrollspeed;<br \/>\n setProperty(&#8220;_root.fg1a&#8221;, _y, _root.fg1a._y+(_root.Vscrollspeed*1.25));<br \/>\n setProperty(&#8220;_root.fg1b&#8221;, _y, _root.fg1b._y+(_root.Vscrollspeed*1.25));<br \/>\n setProperty(&#8220;_root.fg1c&#8221;, _y, _root.fg1c._y+(_root.Vscrollspeed*1.25));<br \/>\n setProperty(&#8220;_root.fg2a&#8221;, _y, _root.fg2a._y+(_root.Vscrollspeed*1.2));<br \/>\n setProperty(&#8220;_root.fg2b&#8221;, _y, _root.fg2b._y+(_root.Vscrollspeed*1.2));<br \/>\n setProperty(&#8220;_root.fg2c&#8221;, _y, _root.fg2c._y+(_root.Vscrollspeed*1.2));<br \/>\n setProperty(&#8220;_root.fg3a&#8221;, _y, _root.fg3a._y+(_root.Vscrollspeed*1.1));<br \/>\n setProperty(&#8220;_root.fg3b&#8221;, _y, _root.fg3b._y+(_root.Vscrollspeed*1.1));<br \/>\n setProperty(&#8220;_root.fg3c&#8221;, _y, _root.fg3c._y+(_root.Vscrollspeed*1.1));<br \/>\n setProperty(&#8220;_root.floor1&#8221;, _y, _root.floor1._y+(_root.Vscrollspeed));<br \/>\n setProperty(&#8220;_root.floor2&#8221;, _y, _root.floor2._y+(_root.Vscrollspeed));<br \/>\n \/\/MIDGROUND (HERO) PLANES<br \/>\n setProperty(&#8220;_root.ground1&#8221;, _y, _root.ground1._y + _root.Vscrollspeed);<br \/>\n setProperty(&#8220;_root.ground2&#8221;, _y, _root.ground2._y + _root.Vscrollspeed);<br \/>\n \/\/BACKGROUND PLANES<br \/>\n setProperty(&#8220;_root.mainbg01&#8221;, _y, _root.mainbg01._y +_root.Vscrollspeed);<br \/>\n setProperty(&#8220;_root.mainbg02&#8221;, _y, _root.mainbg02._y +_root.Vscrollspeed);<br \/>\n setProperty(&#8220;_root.mainbg03&#8221;, _y, _root.mainbg03._y +_root.Vscrollspeed);<br \/>\n setProperty(&#8220;_root.wall1&#8221;, _y, _root.wall1._y+(_root.Vscrollspeed\/1.5));<br \/>\n setProperty(&#8220;_root.wall2&#8221;, _y, _root.wall2._y+(_root.Vscrollspeed\/1.5));<br \/>\n }<br \/>\n function SetVertScroll() {<br \/>\n if (_root.hero._y &lt; 280 &amp;&amp; _root.shaking != &#8220;on&#8221;) {<br \/>\n \/\/SCROLL UP<br \/>\n _root.Vscrolldirection = &#8220;UP&#8221;;<br \/>\n _root.Vscrollspeed = 6;<br \/>\n VertPlayField();<br \/>\n \/\/END SCROLL UP<br \/>\n \/\/TELEPORT<br \/>\n if (_root.hero.stance==&#8221;teleporting&#8221;) {<br \/>\n _root.Vscrollspeed = 40;<br \/>\n }<br \/>\n } else if ((_root.hero._y&gt;460 &amp;&amp; _root.shaking != &#8220;on&#8221;) || (_root.hero.feet==&#8221;flying&#8221; &amp;&amp; _root.hero._y &gt; 360)) {<br \/>\n \/\/SCROLL DOWN<br \/>\n _root.Vscrolldirection = &#8220;DOWN&#8221;;<br \/>\n if (_root.hero.stance==&#8221;jetpack&#8221; &amp;&amp; _root.hero._y &lt; 460) {<br \/>\n \/\/JETPACK IS ACTIVE AND HERO IS ABOVE SCROLL THRESHOLD<br \/>\n _root.Vscrollspeed = -_root.hero.jetpack.gravity;<br \/>\n _root.scrollcase = &#8220;JPNORM&#8221;;<br \/>\n } else if (_root.hero.stance==&#8221;jetpack&#8221; &amp;&amp; _root.hero._y &gt; 460 ) {<br \/>\n \/\/EDGE CASE&#8230; HERO HAS FALLEN BELOW SCROLL THRESHOLD WHILE ACTIVATING JETPACK<br \/>\n if (Key.isDown(Key.UP)) {<br \/>\n _root.Vscrollspeed = _root.hero.jetpack.gravity*4;<br \/>\n } else {<br \/>\n _root.Vscrollspeed = -_root.hero.jetpack.gravity*4;<br \/>\n }<br \/>\n _root.scrollcase = &#8220;JPOUT&#8221;;<br \/>\n } else if (_root.hero._y &gt; 600 &amp;&amp; _root.hero.feet == &#8220;grnd&#8221;) {<br \/>\n _root.Vscrollspeed = -20;<br \/>\n } else if (_root.hero._y &gt; 460 &amp;&amp; _root.hero.feet == &#8220;grnd&#8221; &amp;&amp; _root.hero.plattype!=&#8221;elevator&#8221;) {<br \/>\n _root.Vscrollspeed = -2;<br \/>\n } else if (_root.hero._y &gt; 460 &amp;&amp; _root.hero.feet == &#8220;air&#8221;) {<br \/>\n _root.Vscrollspeed = -_root.hero.jump<br \/>\n } else if (_root.hero.plattype==&#8221;elevator&#8221; &amp;&amp; _root.hero._y &lt; 460) {<br \/>\n \/\/HERO IS ON ELEVATOR AND IS ABOVE SCROLL THRESHOLD<br \/>\n _root.Vscrollspeed = -herop.Vspeed;<br \/>\n _root.scrollcase = &#8220;ELNORM&#8221;;<br \/>\n } else {<br \/>\n \/\/ALL OTHER CASES<br \/>\n _root.Vscrollspeed = -_root.hero.jump;<br \/>\n _root.scrollcase = &#8220;-HERO&#8221;<br \/>\n }<br \/>\n \/\/<br \/>\n VertPlayField();<br \/>\n } else if (_root.shaking!=&#8221;on&#8221; &amp;&amp; _root.hero.feet==&#8221;grnd&#8221; ){<br \/>\n _root.Vscrollspeed = 0;<br \/>\n }<br \/>\n }<\/p>\n <p>&nbsp;<\/p>\n <p>&nbsp;<\/p>\n <p>\/\/PLATFORM LOGIC<br \/>\n function platformLogic (plat) {<br \/>\n \/\/CHECK FOR FALLING HERO<br \/>\n \/\/OR JUMPING HERO<br \/>\n \/\/GRAB HIM IF HE&#8217;S TOUCHING OR FALLING THROUGH PLATFORM<br \/>\n if (_root.hero.inpit==&#8221;false&#8221; &amp;&amp; _root.hero._y &lt; (plat._y + 20) &amp;&amp; plat.hitTest(_root.hero) &amp;&amp; (_root.hero.feet == &#8220;air&#8221; || _root.hero.feet==&#8221;laidout&#8221;) &amp;&amp; (_root.hero.jump &gt; 0 || _root.hero.lift &gt; 0)) {<br \/>\n setProperty(_root.hero, _y, plat._y);<br \/>\n if (_root.hero.jump&gt;10 &amp;&amp; _root.hero.stance!=&#8221;laidout&#8221; &amp;&amp; _root.hero.stance!=&#8221;airattack2&#8243;) {<br \/>\n _root.hero.gotoAndPlay(&#8220;land&#8221;);<br \/>\n } else if (_root.hero.stance==&#8221;laidout&#8221;) {<br \/>\n _root.hero.gotoAndPlay(&#8220;backslide&#8221;);<br \/>\n } else if (_root.hero.stance==&#8221;hurled&#8221;) {<br \/>\n _root.hero.gotoAndPlay(&#8220;faceslide&#8221;);<br \/>\n } else if (_root.hero.stance==&#8221;hammer&#8221;) {<br \/>\n _root.hero.gotoAndPlay(&#8220;failstomp&#8221;);<br \/>\n }else {<br \/>\n _root.hero.gotoAndPlay(_root.hero.Gait);<br \/>\n }<br \/>\n _root.hero.jump = 0;<br \/>\n if (_root.hero.stance != &#8220;laidout&#8221;) {<br \/>\n _root.hero.stance = &#8220;fight&#8221;;<br \/>\n }<br \/>\n _root.hero.feet = &#8220;grnd&#8221;;<br \/>\n plat.onplat = &#8220;true&#8221;;<br \/>\n plat.dbtag = plat._name;<br \/>\n _root.herop = plat._name;<br \/>\n _root.tx = plat._x;<br \/>\n _root.hero.plattype=plat.plattype;<br \/>\n }<br \/>\n \/\/CHECK FOR HERO WALKING OFF PLATFORM<br \/>\n \/\/PUSH HERO DOWN BEYOND THIS PLATFORM&#8217;S CATCH HEIGHT<br \/>\n \/\/SET HERO&#8217;S JUMP TO 1 AND PUT HIS FEET IN AIR<br \/>\n \/\/^THIS WILL MAKE HIM FALL TO GROUND LEVEL<br \/>\n \/\/START HERO&#8217;S DROP ANIMATION<br \/>\n \/\/SET ONPLAT TO FALSE<br \/>\n if (plat.onplat == &#8220;true&#8221; &amp;&amp; Math.abs(plat._x &#8211; _root.hero._x) &gt; plat._width\/2 &amp;&amp; (_root.hero.feet == &#8220;grnd&#8221; || _root.hero.stance==&#8221;sliding&#8221;) &amp;&amp; _root.herop == plat._name) {<br \/>\n setProperty(_root.hero, _y, plat._y);<br \/>\n _root.hero.feet = &#8220;air&#8221;;<br \/>\n plat.onplat = &#8220;false&#8221;;<br \/>\n _root.herop = &#8220;none&#8221;;<br \/>\n \/\/CHECK FOR HERO JUMPING OFF PLATFORM OR BEING LAID OUT WHILE ON PLATFORM<br \/>\n \/\/(BEING LAID OUT SENDS HERO FALLING TO GROUND)<br \/>\n } else if (plat.onplat == &#8220;true&#8221; &amp;&amp; _root.hero.feet != &#8220;grnd&#8221;) {<br \/>\n plat.onplat = &#8220;false&#8221;;<br \/>\n _root.herop = &#8220;none&#8221;;<br \/>\n }<br \/>\n \/\/<br \/>\n \/\/BUMP HERO&#8217;S HEAD (STOP HIS JUMP) IF THIS IS A CEILING<br \/>\n }<br \/>\n function heroHeadBump (plat) {<br \/>\n if (plat.hitTest(_root.hero) &amp;&amp; _root.hero.jump&lt;0) {<br \/>\n _root.hero.jump = -_root.hero.jump\/10;<br \/>\n }<br \/>\n }<\/p>\n <p>&nbsp;<\/p>\n <p>&nbsp;<\/p>\n <p>function elevatorLogic2(el) {<br \/>\n if (el.motor == &#8220;running&#8221; &amp;&amp; el.climb &gt; 0 &amp;&amp; el.climbed &lt; el.climb) {<br \/>\n \/\/ ELEVATOR GOING UP<br \/>\n el.climbed = el.climbed + el.Vspeed;<br \/>\n if (el.onplat==&#8221;true&#8221; &amp;&amp; el.scrolltype!=&#8221;static&#8221; &amp;&amp; el.motor==&#8221;running&#8221;)<br \/>\n {<br \/>\n _root.Vscrollspeed = el.baseVspeed*2;<br \/>\n _root.Vscrolldirection = &#8220;UP&#8221;;<br \/>\n _root.VertPlayField();<br \/>\n el.elevatorGoing=&#8221;up&#8221;;<br \/>\n _root.scrollcase = &#8220;ELUP&#8221;;<br \/>\n } else {<br \/>\n setProperty(el, _y, el._y &#8211; el.baseVspeed*2);<br \/>\n }<br \/>\n }<\/p>\n <p>else if (el.motor == &#8220;running&#8221; &amp;&amp; el.climb &lt; 0 &amp;&amp; el.climbed &gt; el.climb) {<br \/>\n \/\/ ELEVATOR GOING DOWN<br \/>\n el.climbed = el.climbed &#8211; el.Vspeed;<br \/>\n if (el.onplat==&#8221;true&#8221; &amp;&amp; el.scrolltype!=&#8221;static&#8221; &amp;&amp; el.motor==&#8221;running&#8221;)<br \/>\n {<br \/>\n _root.Vscrollspeed = -el.baseVspeed*2;<br \/>\n _root.Vscrolldirection = &#8220;DOWN&#8221;;<br \/>\n _root.VertPlayField();<br \/>\n el.elevatorGoing=&#8221;down&#8221;;<br \/>\n _root.scrollcase = &#8220;ELDOWN&#8221;;<br \/>\n } else {<br \/>\n setProperty(el, _y, el._y + el.baseVspeed*2);<br \/>\n }<br \/>\n }<br \/>\n if ((el.climb &gt; 0 &amp;&amp; el.climbed &gt;= el.climb) || (el.climb &lt; 0 &amp;&amp; el.climbed &lt;= el.climb)) {<br \/>\n if ((el.returntrip == &#8220;up&#8221; &amp;&amp; el.climb &lt; 0 ) || (el.returntrip == &#8220;down&#8221; &amp;&amp; el.climb &gt; 0)) {<br \/>\n \/\/el.roundtrip=&#8221;yes&#8221;;<br \/>\n } else {<br \/>\n \/\/el.roundtrip=&#8221;no&#8221;;<br \/>\n }<br \/>\n el.motor = &#8220;off&#8221;;<br \/>\n el.climbed = 0;<br \/>\n el.climb = -el.climb;<br \/>\n el.gotoAndPlay(&#8220;shutdown&#8221;);<br \/>\n }<br \/>\n \/\/Reduce the following singletons to a pure function<br \/>\n \/\/HERO ELEVATOR LOGIC<br \/>\n \/\/Remote note.. the following is broken because lookimng for hero below platform.. needs to be aboves<br \/>\n if (el.hitTest(_root.hero) &amp;&amp; _root.hero.stance == &#8220;press&#8221;) {<br \/>\n _root.herop = el._name;<br \/>\n _root.hero._y = (el._y -1);<br \/>\n el.onplat=&#8221;true&#8221;;<br \/>\n _root.hero.plattype=&#8221;elevator&#8221;;<br \/>\n }<br \/>\n \/\/NPC ELEVATOR LOGIC<br \/>\n if (el.hitTest(_root.NPC) &amp;&amp; _root.NPC.feet == &#8220;grnd&#8221;) {<br \/>\n _root.NPCp = el._name;<br \/>\n _root.NPC._y = (el._y -el._height\/2)+15;<br \/>\n NPC.onplat=&#8221;true&#8221;;<br \/>\n _root.NPC.plattype=&#8221;elevator&#8221;;<br \/>\n }<br \/>\n \/\/AI ELEVATOR LOGIC<br \/>\n if (el.hitTest(_root.AI)) {<br \/>\n _root.AIp = el._name;<br \/>\n _root.AI._y = el._y + 20;<br \/>\n AI.onplat=&#8221;true&#8221;;<br \/>\n _root.AI.plattype=&#8221;elevator&#8221;;<br \/>\n }<br \/>\n }<\/p>\n <p>&nbsp;<\/p>\n <p>&nbsp;<\/p>\n <p>&nbsp;<\/p>\n <p>\/\/FLYING SENTRY WALL BLOCKING LOGIC<br \/>\n function blockSentryX(wall) {<br \/>\n \/\/IS THE FLYING SENTRY TOUCHING ME?<br \/>\n if (wall.hitTest(_root.sentry)) {<br \/>\n \/\/BOUNCE SENTRY<br \/>\n _root.sentry.Xflight = &#8220;blocked&#8221;;<br \/>\n _root.sentry.Xspeed = -_root.sentry.Xspeed;<br \/>\n }<br \/>\n }<br \/>\n function blockSentryY(wall) {<br \/>\n \/\/IS THE FLYING SENTRY TOUCHING ME?<br \/>\n if (wall.hitTest(_root.sentry)) {<br \/>\n \/\/BOUNCE SENTRY<br \/>\n _root.sentry.Yflight = &#8220;blocked&#8221;;<br \/>\n _root.sentry.Yspeed = -_root.sentry.Yspeed;<br \/>\n }<br \/>\n }<br \/>\n \/\/BLOCK HERO<br \/>\n function blockHeroX (wall) {<br \/>\n \/\/IS THE HERO TOUCHING ME AND WALKING?<br \/>\n if (wall.hitTest(_root.hero) &amp;&amp; _root.hero.feet != &#8220;flying&#8221;) {<br \/>\n \/\/IF HERO IS FACING ME, SET HIS SPEED TO 0:<br \/>\n if (wall._x&lt;_root.hero._x &amp;&amp; _root.hero.facing==&#8221;left&#8221;) {<br \/>\n _root.hero.Walk_Speed=0;<br \/>\n _root.hero.Walk_Path=&#8221;blocked&#8221;;<br \/>\n } else if (wall._x&gt;_root.hero._x &amp;&amp; _root.hero.facing==&#8221;right&#8221;) {<br \/>\n _root.hero.Walk_Speed=0;<br \/>\n _root.hero.Walk_Path=&#8221;blocked&#8221;;<br \/>\n } else if (_root.hero.stance==&#8221;laidout&#8221;) {<br \/>\n _root.hero.Walk_Speed=0;<br \/>\n _root.hero.Walk_Path=&#8221;blocked&#8221;;<br \/>\n }<br \/>\n }<br \/>\n }<br \/>\n \/\/BLOCK AI<br \/>\n function blockAIX (wall) {<br \/>\n \/\/IS THE HERO TOUCHING ME AND WALKING?<br \/>\n if (wall.hitTest(_root.AI) &amp;&amp; _root.AI.feet != &#8220;flying&#8221;) {<br \/>\n \/\/IF HERO IS FACING ME, SET HIS SPEED TO 0:<br \/>\n if (wall._x&lt;_root.AI._x &amp;&amp; _root.AI.facing==&#8221;left&#8221;) {<br \/>\n _root.AI.Walk_Speed=0;<br \/>\n _root.AI.Walk_Path=&#8221;blocked&#8221;;<br \/>\n } else if (wall._x&gt;_root.AI._x &amp;&amp; _root.AI.facing==&#8221;right&#8221;) {<br \/>\n _root.AI.Walk_Speed=0;<br \/>\n _root.AI.Walk_Path=&#8221;blocked&#8221;;<br \/>\n }<br \/>\n }<br \/>\n }<br \/>\n \/\/BUMP HERO&#8217;S HEAD (STOP HIS JUMP) IF THIS IS A CEILING<br \/>\n function blockJetpack(wall) {<br \/>\n \/\/AM I TOUCHING THE HERO AND IS HE FLYING?<br \/>\n if (wall.hitTest(_root.hero) &amp;&amp; _root.hero.feet == &#8220;flying&#8221;) {<br \/>\n \/\/IS THE HERO TO THE LEFT OF ME AND MOVING TO THE RIGHT?<br \/>\n if (_root.hero._x &lt; wall._x &#8211; wall._width\/2 &amp;&amp; _root.scrollspeed&lt;0) {<br \/>\n _root.hero.rebound = (Math.round(-_root.scrollspeed*110))\/100 + 1;<br \/>\n _root.hero.jetspeed = 0;<br \/>\n \/\/_root.hero.Walk_Path=&#8221;blocked&#8221;;<br \/>\n \/\/IS THE HERO TO MY RIGHT AND MOVING TO THE LEFT?<br \/>\n } else if (_root.hero._x &gt; wall._x + wall._width\/2 &amp;&amp; _root.scrollspeed&gt;0) {<br \/>\n _root.hero.rebound = (Math.round(-_root.scrollspeed*110))\/100 &#8211; 1;<br \/>\n _root.hero.jetspeed = 0;<br \/>\n \/\/_root.hero.Walk_Path=&#8221;blocked&#8221;;<br \/>\n } else {<br \/>\n \/\/IF I&#8217;M TOUCHING THE HERO BUT HE&#8217;S INSIDE MY WIDTH HE MUST BE APPROACHING FROM ABOVE OR BELOW<br \/>\n \/\/BOUNCE ME UP\/DOWN BY REVERSING MY GRAVITY<br \/>\n if (wall._y &gt; _root.hero._y) {<br \/>\n _root.hero.jetpack.gravity = -_root.hero.jetpack.gravity\/2;<br \/>\n _root.hero._y = _root.hero._y &#8211; 2;<br \/>\n } else if (wall._y &lt; _root.hero._y) {<br \/>\n _root.hero.jetpack.gravity = -_root.hero.jetpack.gravity;<br \/>\n _root.hero._y = _root.hero._y + 2;<br \/>\n }<\/p>\n <p>\/\/FIGURE OUT IF THE HERO IS OVERLAPPING ME FROM TOP OR BOTTOM AND BUMP HIM UP OR DOWN ACCORDINGLY<br \/>\n }<\/p>\n <p>}<br \/>\n }<br \/>\n \/\/BOUNCE THE ASTEROIDS OFF AND\/OR CONTAIN THEM<br \/>\n function blockAsteroidX(wall,ast) {<br \/>\n if(wall.hitTest(ast)) {<br \/>\n ast._x = ast._x &#8211; ast.vx;<br \/>\n ast.vx = -ast.vx;<br \/>\n if (ast.vy &lt; 0 &amp;&amp; ast.rotspeed &lt; 6) {<br \/>\n ast.rotspeed = ast.rotspeed + .5;<br \/>\n } else if (ast.vy &gt; 0 &amp;&amp; ast.rotspeed &gt; -6) {<br \/>\n ast.rotspeed = ast.rotspeed &#8211; .5;<br \/>\n }<br \/>\n \/\/ if (Math.abs(ast.vx) &gt; 5) {<br \/>\n \/\/ ast.vx = -ast.vx;<br \/>\n \/\/ }<br \/>\n }<br \/>\n }<br \/>\n function blockAsteroidY(wall,ast) {<br \/>\n if(wall.hitTest(ast)) {<br \/>\n ast._y = ast._y &#8211; ast.vy;<br \/>\n ast.vy = -ast.vy;<br \/>\n \/\/SPIN THE ASTEROID<br \/>\n if (ast.vx &lt; 0 &amp;&amp; ast.rotspeed &gt; -6) {<br \/>\n ast.rotspeed = ast.rotspeed &#8211; .5;<br \/>\n } else if (ast.vx &gt; 0 &amp;&amp; ast.rotspeed &lt; 6) {<br \/>\n ast.rotspeed = ast.rotspeed + .5;<br \/>\n }<br \/>\n \/\/LIMIT THE BOUNCE TO A SANE SPEED IN THE CASE OF A LOOP CAUSED BY OVERLAPPING<br \/>\n \/\/ if (Math.abs(ast.vy) &gt; 5) {<br \/>\n \/\/ ast.vy = -ast.vy;<br \/>\n \/\/ }<br \/>\n }<br \/>\n }<br \/>\n function openForAsteroid(wall,ast) {<br \/>\n if (wall.hitTest(ast) &amp;&amp; ast._y &lt; wall._y &amp;&amp; wall.stance==&#8221;closed&#8221; &amp;&amp; wall._y &gt; ast._y) {<br \/>\n wall.gotoAndPlay(&#8220;trigger&#8221;);<br \/>\n }<br \/>\n }<br \/>\n function openForCharacter(wall,char) {<br \/>\n dx = wall._x &#8211; char._x;<br \/>\n dy = wall._y &#8211; char._y;<br \/>\n wall.dx = dx;<br \/>\n wall.dy = dy;<br \/>\n if (_root.hero.stance==&#8221;jetpack&#8221; &amp;&amp; Math.abs(dy)&lt;300 &amp;&amp; ((Math.abs(dx) &lt; wall._width\/2) &amp;&amp; Math.abs) ) {<br \/>\n if (wall.stance==&#8221;closed&#8221;) {<br \/>\n wall.gotoAndPlay(&#8220;trigger&#8221;);<br \/>\n } else {<br \/>\n wall.autoinput = &#8220;stayopen&#8221;;<br \/>\n }<br \/>\n } else {<br \/>\n wall.autoinput = &#8220;close&#8221;;<br \/>\n }<br \/>\n }<\/p>\n <p>&nbsp;<\/p>\n <p>&nbsp;<\/p>\n <p>function ShakeScene() {<br \/>\n \/\/IF SHAKING IS OFF AND SHAKESTRENGTH IS SET, TURN IT ON AND SET SHAKE DIRECTION TO DOWNWARDS<br \/>\n if (_root.shaking!=&#8221;on&#8221; &amp;&amp; _root.shakestrength&gt;0) {<br \/>\n _root.shaking = &#8220;on&#8221;;<br \/>\n _root.shake = &#8220;down&#8221;;<br \/>\n }<br \/>\n \/\/CALL THE VSCROLL FUNCTION<br \/>\n VertPlayField();<br \/>\n \/\/CHECK FOR SHAKE DIRECTION, SET VSCROLL NEGATIVE FOR UP AND POSITIVE FOR DOWN<br \/>\n \/\/IF SHAKING DOWN, INCREMENT SHAKE STRENGTH (KEEPS UP AND DOWN SHAKES EQUAL STRENGTH)<br \/>\n if (_root.shake==&#8221;down&#8221;) {<br \/>\n _root.Vscrollspeed = _root.shakestrength;<br \/>\n _root.shake = &#8220;up&#8221;;<br \/>\n } else if (_root.shake==&#8221;up&#8221;) {<br \/>\n _root.Vscrollspeed = -_root.shakestrength;<br \/>\n _root.shake = &#8220;down&#8221;;<br \/>\n if (_root.shakestrength&gt;0) {<br \/>\n _root.shakestrength = _root.shakestrength-1;<br \/>\n }<br \/>\n }<br \/>\n \/\/ IF SHAKING HAS STOPPED ON THE UPSTROKE (GONE TO 0 SHAKESTRENGTH) SHAKE IT DOWNWARDS ONE MORE TIME)<br \/>\n if (_root.shakestrength == 0 &amp;&amp; shaking == &#8220;on&#8221;) {<br \/>\n if (_root.shake==&#8221;down&#8221;) {<br \/>\n _root.Vscrollspeed = -1;<br \/>\n VertPlayField();<br \/>\n }<br \/>\n _root.shaking = &#8220;off&#8221;;<br \/>\n _root.Vscrollspeed = 0;<br \/>\n }<br \/>\n }<\/p>\n <p>&nbsp;<\/p>\n <p>&nbsp;<\/p>\n <p>&nbsp;<\/p>\n <p>\/\/BRICK LOGIC<\/p>\n <p>function brickLogic(plat) {<br \/>\n \/\/CHECK FOR FALLING HERO<br \/>\n \/\/OR JUMPING HERO<br \/>\n \/\/GRAB HIM IF HE&#8217;S FALLING THROUGH PLATFORM<br \/>\n if (_root.hero.inpit==&#8221;false&#8221; &amp;&amp; _root.hero._y &lt; (plat._y + _root.hero._height) &amp;&amp; plat.hitTest(_root.hero) &amp;&amp; (_root.hero.feet == &#8220;air&#8221; || _root.hero.feet==&#8221;laidout&#8221;) &amp;&amp; (_root.hero.jump &gt; 0 || _root.hero.lift &gt; 0))<br \/>\n {<br \/>\n setProperty(_root.hero, _y, plat._y);<br \/>\n if (_root.hero.jump&gt;10 &amp;&amp; _root.hero.stance!=&#8221;laidout&#8221; &amp;&amp; _root.hero.stance!=&#8221;airattack2&#8243;) {<br \/>\n _root.hero.gotoAndPlay(&#8220;land&#8221;);<br \/>\n } else if (_root.hero.stance==&#8221;laidout&#8221;) {<br \/>\n _root.hero.gotoAndPlay(&#8220;backslide&#8221;);<br \/>\n } else if (_root.hero.stance==&#8221;hurled&#8221;) {<br \/>\n _root.hero.gotoAndPlay(&#8220;faceslide&#8221;);<br \/>\n } else if (_root.hero.stance==&#8221;hammer&#8221;) {<br \/>\n _root.hero.gotoAndPlay(&#8220;failstomp&#8221;);<br \/>\n }else {<br \/>\n _root.hero.gotoAndPlay(_root.hero.Gait);<br \/>\n }<br \/>\n _root.hero.jump = 0;<br \/>\n _root.hero.feet = &#8220;grnd&#8221;;<br \/>\n _root.hero.stance = &#8220;fight&#8221;;<br \/>\n plat.onplat = &#8220;true&#8221;;<br \/>\n plat.dbtag = plat._name;<br \/>\n _root.herop = plat._name;<br \/>\n _root.tx = plat._x;<br \/>\n }<br \/>\n \/\/ CHECK FOR HERO WALKING FROM BRICK TO BRICK<br \/>\n if (_root.hero.feet == &#8220;grnd&#8221; &amp;&amp; plat.hitTest(_root.hero) &amp;&amp; Math.abs(plat._x &#8211; _root.hero._x) &lt; plat._width \/ 2 &amp;&amp; _root.hero.jump == 0 &amp;&amp; (Math.abs(plat._y &#8211; _root.hero._y) &lt; 2)) {<br \/>\n plat.onplat = &#8220;true&#8221;;<br \/>\n _root.herop = plat._name;<br \/>\n }<br \/>\n \/\/ CHECK FOR HERO HITTING BRICK FROM BELOW<br \/>\n if (plat.hitTest(_root.hero) &amp;&amp; (Math.abs(plat._x &#8211; _root.hero._x) &lt; plat._width\/2) &amp;&amp; (_root.hero._y-_root.hero._height&gt;plat._y-10) &amp;&amp; _root.hero.jump &lt; 0) {<br \/>\n _root.hero.jump = 0;<br \/>\n plat.play();<br \/>\n targ.play();<br \/>\n }<br \/>\n \/\/CHECK FOR HERO WALKING OFF PLATFORM<br \/>\n \/\/PUSH HERO DOWN BEYOND THIS PLATFORM&#8217;S CATCH HEIGHT<br \/>\n \/\/SET HERO&#8217;S JUMP TO 1 AND PUT HIS FEET IN AIR<br \/>\n \/\/^THIS WILL MAKE HIM FALL TO GROUND LEVEL<br \/>\n \/\/START HERO&#8217;S DROP ANIMATION<br \/>\n \/\/SET ONPLAT TO FALSE<br \/>\n if (plat.onplat == &#8220;true&#8221; &amp;&amp; Math.abs(plat._x &#8211; _root.hero._x) &gt; plat._width \/ 2 &amp;&amp; _root.hero.feet == &#8220;grnd&#8221;) {<br \/>\n plat.onplat = &#8220;false&#8221;;<br \/>\n if (_root.herop == plat._name) {<br \/>\n _root.herop = &#8220;assbiscuits&#8221;;<br \/>\n _root.herop2 = plat._name;<br \/>\n }<br \/>\n } else if (plat.onplat == &#8220;true&#8221; &amp;&amp; _root.hero.feet != &#8220;grnd&#8221;) {<br \/>\n plat.onplat = &#8220;false&#8221;;<br \/>\n }<br \/>\n if (Math.abs(plat._x &#8211; _root.hero._x) &gt; plat._width\/.75 &amp;&amp; _root.hero.feet == &#8220;grnd&#8221;) {<br \/>\n if (_root.herop2 == plat._name) {<br \/>\n _root.herop2 = &#8220;nada&#8221;;<br \/>\n }<br \/>\n }<br \/>\n }<\/p>\n <p>&nbsp;<\/p>\n <p>&nbsp;<\/p>\n <p>&nbsp;<\/p>\n <p>\/\/<br \/>\n \/\/\/ LEFT OR RIGHT FUNCTION<br \/>\n function LeftOrRight(sprite) {<br \/>\n \/\/MOVE LEFT<br \/>\n \/\/<br \/>\n \/\/ADDITIONALLY COULD ADD IN SMOOTH ANIMATION FOR CHANGING DIRECTIONS<br \/>\n \/\/NOTE THE SCALEFACTOR<br \/>\n _root.heroxscale = _root.hero._xscale;<br \/>\n if (Key.isDown(Key.LEFT)) {<br \/>\n if (sprite.feet == &#8220;grnd&#8221; || sprite.feet == &#8220;flying&#8221;) {<br \/>\n setProperty(sprite, _xscale, -100);<br \/>\n }<br \/>\n \/\/MOVE RIGHT<br \/>\n } else if (Key.isDown(Key.RIGHT)) {<br \/>\n if (sprite.feet == &#8220;grnd&#8221; || sprite.feet == &#8220;flying&#8221;) {<br \/>\n setProperty(sprite, _xscale, 100);<br \/>\n }<br \/>\n }<br \/>\n }<br \/>\n \/\/\/ END LEFT OR RIGHT FUNCTION<br \/>\n \/\/<br \/>\n function Attack(sprite) {<br \/>\n if (Key.isDown(Key.DOWN) &amp;&amp; Key.isDown(Key.SPACE) &amp;&amp; sprite.dive == &#8220;enabled&#8221; &amp;&amp; sprite.feet == &#8220;air&#8221;) {<br \/>\n sprite.gotoAndPlay(&#8220;airattack2&#8243;);<br \/>\n }<br \/>\n if (Key.isDown( 70 )) {<br \/>\n \/\/F key<br \/>\n if (sprite.stance==&#8221;cover&#8221;) {<br \/>\n sprite.gotoAndPlay(&#8220;uppercut&#8221;);<br \/>\n sprite.stance = &#8220;uppercut&#8221;;<br \/>\n } else if (sprite.feet == &#8220;air&#8221;) {<br \/>\n sprite.gotoAndPlay(&#8220;airattack1&#8243;);<br \/>\n } else if (sprite.stance!=&#8221;cover&#8221;) {<br \/>\n sprite.gotoAndPlay(&#8220;attack1&#8221;);<br \/>\n }<br \/>\n }<br \/>\n }<br \/>\n function Combo(sprite) {<br \/>\n if (Key.isDown( 70 )) {<br \/>\n \/\/F key<br \/>\n if (sprite.combo != &#8220;closed&#8221; &amp;&amp; (_root.AI.stance == &#8220;hitchin&#8221;)) {<br \/>\n sprite.gotoAndPlay(sprite.combo);<br \/>\n }<br \/>\n }<br \/>\n }<br \/>\n function Cover(sprite) {<br \/>\n if (Key.isDown(Key.DOWN)) {<br \/>\n if (sprite.stance == &#8220;fight&#8221; &amp;&amp; sprite.feet == &#8220;grnd&#8221;) {<br \/>\n sprite.stance = &#8220;cover&#8221;;<br \/>\n \/\/TO KILL FLYING FEET BUG<br \/>\n sprite.feet = &#8220;grnd&#8221;;<br \/>\n sprite.gotoAndPlay(&#8220;cover&#8221;);<br \/>\n }<br \/>\n }<br \/>\n }<br \/>\n function KneeSlide(sprite) {<br \/>\n if (Key.isDown(Key.DOWN) &amp;&amp; sprite.momentum &gt; 8) {<br \/>\n sprite.gotoAndPlay(&#8220;kneeslide&#8221;);<br \/>\n }<br \/>\n }<br \/>\n function PressGrab(sprite) {<br \/>\n \/\/G key<br \/>\n if (Key.isDown(71) &amp;&amp; sprite.feet == &#8220;grnd&#8221; &amp;&amp; sprite.stance!=&#8221;cover&#8221;) {<br \/>\n sprite.gotoAndPlay(&#8220;press&#8221;);<br \/>\n } else if (Key.isDown(71) &amp;&amp; sprite.stance==&#8221;jetpack&#8221;) {<\/p>\n <p>}<br \/>\n \/\/START JETPACK<br \/>\n if (sprite.feet == &#8220;air&#8221; &amp;&amp; sprite.stance != &#8220;jetpack&#8221; &amp;&amp; Key.isDown(Key.UP) &amp;&amp; Key.isDown(Key.SPACE)) {<br \/>\n if (_root.hero.jetpacktype == &#8220;minisub&#8221;) {<br \/>\n sprite.gotoAndPlay(&#8220;minisubon&#8221;);<br \/>\n } else {<br \/>\n sprite.gotoAndPlay(&#8220;jetpackon&#8221;);<br \/>\n }<br \/>\n sprite.stance=&#8221;jetpack&#8221;;<br \/>\n sprite.setspeed=_root.scrollspeed;<br \/>\n sprite.jump=0;<br \/>\n }<br \/>\n }<br \/>\n \/\/JUMP ON INPUT<br \/>\n function SpriteJump(sprite) {<br \/>\n if (Key.isDown(Key.SPACE) &amp;&amp; sprite.feet == &#8220;grnd&#8221; &amp;&amp; sprite.stance == &#8220;fight&#8221;) {<br \/>\n sprite.gotoAndPlay(&#8220;jump&#8221;);<br \/>\n sprite.inpit = &#8220;false&#8221;;<br \/>\n sprite.jump = -1*(sprite.Jump_Height);<br \/>\n sprite.Speed_Boost = 0;<br \/>\n sprite.Walk_Speed = sprite.Walk_Speed + sprite.Speed_Boost;<br \/>\n sprite.feet = &#8220;air&#8221;;<br \/>\n sprite.stance = &#8220;jump&#8221;;<br \/>\n sprite.dive = &#8220;disabled&#8221;;<br \/>\n sprite._y=sprite._y-16;<br \/>\n }<br \/>\n if (Key.isDown(Key.SPACE) &amp;&amp; Key.isDown(Key.DOWN) &amp;&amp; sprite.feet == &#8220;grnd&#8221; &amp;&amp; sprite.stance == &#8220;cover&#8221;) {<br \/>\n sprite.gotoAndPlay(&#8220;diveroll&#8221;);<br \/>\n }<br \/>\n }<br \/>\n \/\/GRAVITY<br \/>\n function SpriteGravity(sprite) {<br \/>\n if (sprite._y &lt; sprite.Ground_Level &amp;&amp; sprite.feet == &#8220;air&#8221; &amp;&amp; sprite.jump &lt; sprite.Max_Yvel) {<br \/>\n sprite.jump = sprite.jump + _root.gravity;<br \/>\n }<br \/>\n }<br \/>\n \/\/FALL THROUGH AIR<br \/>\n function SpriteFall(sprite) {<br \/>\n if (sprite.feet!=&#8221;grnd&#8221; &amp;&amp; sprite.feet!=&#8221;sliding&#8221;) {<br \/>\n setProperty(sprite, _y, sprite._y + sprite.jump);<br \/>\n }<br \/>\n }<br \/>\n \/\/START THE FRAME BY STORING CURRENT X,Y,FRAME#<br \/>\n function SpriteFrameStart(sprite) {<br \/>\n sprite.x1 = sprite._x;<br \/>\n sprite.y1 = sprite._y;<br \/>\n sprite.myframe = sprite._currentframe;<br \/>\n }<br \/>\n function SpriteFrameEnd(sprite) {<br \/>\n sprite.x2 = sprite._x;<br \/>\n sprite.y2 = sprite._y;<br \/>\n sprite.xvel = _root.scrollspeed;<br \/>\n sprite.yvel = sprite.y2-sprite.y1;<br \/>\n }<\/p>\n <p>&nbsp;<\/p>\n <p>&nbsp;<\/p>\n <p>&nbsp;<\/p>","time":"April 25th, 2014 3:27 pm","title":"Code I might end up re-using for the competition"}