Guest User

Untitled

a guest
Jul 16th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. package {
  2. import flash.display.*;
  3. import flash.events.*;
  4. import flash.ui.Keyboard;
  5.  
  6. public class Tridraw extends MovieClip {
  7. public function Tridraw() {
  8. stage.addEventListener(MouseEvent.MOUSE_DOWN, clicked);
  9. stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);
  10. var infoScreen:Info = new Info();
  11. stage.addChild(infoScreen);
  12. infoScreen.x=stage.stageWidth/2-infoScreen.width/2;
  13. infoScreen.y=stage.stageHeight/2-infoScreen.height/2;
  14. }
  15.  
  16. private var points:int=0;
  17. private var newGame:Boolean=true;
  18. private var colors:Boolean=false;
  19.  
  20. private var p1x:int=0;
  21. private var p1y:int=0;
  22. private var p2x:int=0;
  23. private var p2y:int=0;
  24. private var p3x:int=0;
  25. private var p3y:int=0;
  26. private var shade:int=0;
  27.  
  28. private function clicked(e:MouseEvent):void {
  29.  
  30. if (newGame) {
  31. stage.removeChildAt(1);
  32. newGame=false;
  33. }
  34.  
  35. p3x=p2x;
  36. p3y=p2y;
  37. p2x=p1x;
  38. p2y=p1y;
  39. p1x=stage.mouseX;
  40. p1y=stage.mouseY;
  41. points++;
  42.  
  43. if (points>2) {
  44. var triangleShape:Shape = new Shape();
  45. stage.addChild(triangleShape);
  46. if (colors) {
  47. triangleShape.graphics.beginFill(Math.round(Math.random()*0xFFFFFF));
  48. } else {
  49. shade=Math.round(Math.random()*200)+55;
  50. triangleShape.graphics.beginFill(rgb2hex(shade,shade,shade));
  51. }
  52. triangleShape.graphics.moveTo(p3x, p3y);
  53. triangleShape.graphics.lineTo(p2x, p2y);
  54. triangleShape.graphics.lineTo(p1x, p1y);
  55. triangleShape.graphics.endFill();
  56. }
  57.  
  58. }
  59.  
  60. private function rgb2hex(r,g,b):Number {
  61. return (r<<16 | g<<8 | b);
  62. }
  63.  
  64. private function KeyPressed(e:KeyboardEvent):void {
  65. switch (e.keyCode) {
  66. case Keyboard.SPACE :
  67. while (stage.numChildren>1) {
  68. stage.removeChildAt(1);
  69. }
  70. points=0;
  71. p1x=0;
  72. p1y=0;
  73. p2x=0;
  74. p2y=0;
  75. p3x=0;
  76. p3y=0;
  77. break;
  78. case Keyboard.UP :
  79. colors=true;
  80. break;
  81. case Keyboard.DOWN :
  82. colors=false;
  83. break;
  84. }
  85. }
  86. }
  87. }
Add Comment
Please, Sign In to add comment