/src/nl/iTouch/eyecatcher/Lucas.as

https://github.com/Hu-Werring/iTouch
ActionScript | 189 lines | 151 code | 29 blank | 9 comment | 30 complexity | 75458d6ffa9adea5067342d070b750f7 MD5 | raw file
  1. package nl.iTouch.eyecatcher
  2. {
  3. import flash.display.Sprite;
  4. import flash.events.*;
  5. import flash.utils.*;
  6. public class Lucas extends Sprite {
  7. private var beweeg:Array = new Array();
  8. private var a:Array = [boven, onder, links, rechts];
  9. private var snelheid:Number;
  10. public var lucasLinks:LucasImage = new LucasImage();
  11. public var lucasRechts:LucasImage = new LucasImage();
  12. public var lucasBoven:LucasImage = new LucasImage();
  13. public var lucasOnder:LucasImage = new LucasImage();
  14. public function Lucas() {
  15. var tralalala:LucasImage = new LucasImage();
  16. tralalala.visible = false;
  17. addChild(tralalala);
  18. width = 125; //25
  19. height = 265;//53
  20. beweeg['links'] = false;
  21. beweeg['rechts'] = false;
  22. beweeg['boven'] = false;
  23. beweeg['onder'] = false;
  24. addEventListener(Event.ADDED_TO_STAGE,init);
  25. }
  26. public function links():void
  27. {
  28. addEventListener(Event.ENTER_FRAME,beweegLucasLinks);
  29. }
  30. public function rechts():void
  31. {
  32. addEventListener(Event.ENTER_FRAME,beweegLucasRechts);
  33. }
  34. public function onder():void
  35. {
  36. addEventListener(Event.ENTER_FRAME,beweegLucasOnder);
  37. }
  38. public function boven():void
  39. {
  40. addEventListener(Event.ENTER_FRAME,beweegLucasBoven);
  41. }
  42. public function init(e:Event):void
  43. {
  44. removeEventListener(Event.ADDED_TO_STAGE,init);
  45. lucasLinks.x = -5;
  46. lucasLinks.y = 0;
  47. lucasLinks.rotation = 90;
  48. addChild(lucasLinks);
  49. lucasRechts.x= 2565;
  50. lucasRechts.y= 0;
  51. lucasRechts.rotation = 270;
  52. addChild(lucasRechts);
  53. lucasOnder.x = 0;
  54. lucasOnder.y = 2100;
  55. lucasOnder.rotation = 0;
  56. addChild(lucasOnder);
  57. lucasBoven.x = 0;
  58. lucasBoven.y = 0;
  59. lucasBoven.rotation= 180;
  60. addChild(lucasBoven);
  61. randomZijde();
  62. }
  63. public function randomZijde():void
  64. {
  65. a[Math.floor(Math.random() * a.length)]();
  66. snelheid = Math.floor(Math.random() * 8 + 4);
  67. //snelheid = 8;
  68. lucasRechts.y = Math.random() * 2200 + 100;
  69. lucasLinks.y = Math.random() * 1900 + 100;
  70. lucasBoven.x = Math.random() * 2200 + 100;
  71. lucasOnder.x = Math.random() * 2200 + 100;
  72. }
  73. public function beweegLucasOnder(e:Event):void
  74. {
  75. if(beweeg['onder'] == false){
  76. lucasOnder.y -= snelheid;
  77. if(lucasOnder.y <= 1800)
  78. {
  79. beweeg['onder'] = true;
  80. }
  81. }
  82. else if(beweeg['onder'] == true){
  83. lucasOnder.y += snelheid;
  84. if(lucasOnder.y >= 2100)
  85. {
  86. beweeg['onder'] = false;
  87. //lucasOnder.x = Math.random() * 2300;
  88. //lucasOnder.y = 2100;
  89. this.removeEventListener(Event.ENTER_FRAME,beweegLucasOnder);
  90. randomZijde();
  91. }
  92. }
  93. }
  94. public function beweegLucasBoven(e:Event):void
  95. {
  96. if(beweeg['boven'] == false){
  97. lucasBoven.y += snelheid;
  98. if(lucasBoven.y >= 250)
  99. {
  100. beweeg['boven'] = true;
  101. }
  102. }
  103. else if(beweeg['boven'] == true){
  104. lucasBoven.y -= snelheid;
  105. if(lucasBoven.y <= 0)
  106. {
  107. beweeg['boven'] = false;
  108. //lucasBoven.x = Math.random() * 2300;
  109. //lucasBoven.y = 0;
  110. this.removeEventListener(Event.ENTER_FRAME,beweegLucasBoven);
  111. randomZijde();
  112. }
  113. }
  114. }
  115. public function beweegLucasLinks(e:Event):void
  116. {
  117. if(beweeg['links'] == false){
  118. if(lucasLinks.x >= 250)
  119. {
  120. beweeg['links'] = true;
  121. } else {
  122. lucasLinks.x += snelheid;
  123. }
  124. }
  125. else if(beweeg['links'] == true){
  126. if(lucasLinks.x <= -5)
  127. {
  128. beweeg['links'] = false;
  129. //lucasLinks.y = Math.random() * 1800;
  130. //lucasLinks.x = 0;
  131. this.removeEventListener(Event.ENTER_FRAME,beweegLucasLinks);
  132. randomZijde();
  133. } else {
  134. lucasLinks.x -= snelheid;
  135. }
  136. }
  137. }
  138. public function beweegLucasRechts(e:Event):void
  139. {
  140. if(beweeg['rechts'] == false){
  141. lucasRechts.x -= snelheid;
  142. if(lucasRechts.x <= 2300)
  143. {
  144. beweeg['rechts'] = true;
  145. }
  146. }
  147. else if(beweeg['rechts'] == true){
  148. lucasRechts.x += snelheid;
  149. if(lucasRechts.x >= 2565)
  150. {
  151. beweeg['rechts'] = false;
  152. //lucasRechts.y = Math.random() * 2300;
  153. // lucasRechts.x= 2550;
  154. this.removeEventListener(Event.ENTER_FRAME,beweegLucasRechts);
  155. randomZijde();
  156. }
  157. }
  158. }
  159. }
  160. }