Advertisement
matthewdvista

broken code

Dec 4th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package {
  2.     import flash.display.MovieClip;
  3.     import flash.events.Event;
  4.     import flash.events.MouseEvent;
  5.     import flash.text.TextField;
  6.     import flash.text.TextFormat;
  7.     import flash.media.Sound;
  8.     import flash.media.SoundChannel;
  9.     import flash.geom.ColorTransform;
  10.  
  11.     public class BowmanCode extends MovieClip {
  12.  
  13.         public function BowmanCode() {
  14.  
  15.             // variables
  16.            
  17.             var balloonArray:Array = new Array();
  18.             var arrowArray:Array = new Array();
  19.             var xArray:Array = new Array();
  20.             var yArray:Array = new Array();
  21.  
  22.             var shootCheck: Boolean = false;
  23.             var arrowCheck: Boolean = false;
  24.             var tempNum: Number = 0;
  25.             var xSpeed: Number = 0;
  26.             var ySpeed: Number = 0;
  27.            
  28.             var numScore:Number = 0;
  29.            
  30.             var randomColor: ColorTransform = new ColorTransform();
  31.  
  32.             // on load
  33.  
  34.             var b: bow = new bow();
  35.             addChild(b);
  36.             b.x = 275;
  37.             b.y = 375;
  38.  
  39.             /*var a: arrow = new arrow();
  40.             addChild(a);
  41.             a.x = -550;
  42.             */
  43.            
  44.             var al: aimline = new aimline();
  45.             addChild(al);
  46.             al.x = -50;
  47.            
  48.             var score: TextField = new TextField;
  49.             addChild(score);
  50.             score.x = -30;
  51.             score.y = 330;
  52.             score.width = 500;
  53.             score.height = 100;
  54.             score.text = String(numScore);
  55.            
  56.             var scoretf: TextFormat = new TextFormat;
  57.             scoretf.size = 36;
  58.             scoretf.color = 0x000000;
  59.             scoretf.font = "Comic Sans MS";
  60.             score.setTextFormat(scoretf);
  61.  
  62.             // events
  63.  
  64.             addEventListener(Event.ENTER_FRAME, mainFun);
  65.             function mainFun(evt: Event): void {
  66.  
  67.                 aimFun();
  68.                 shootArrow();
  69.  
  70.             }
  71.            
  72.             stage.addEventListener(MouseEvent.CLICK, shootArrow);
  73.             function shootArrow(e: MouseEvent): void {
  74.                 var a: arrow = new arrow();
  75.                 arrowArray.push(a);
  76.                 addChild(arrowArray[arrowArray.length - 1]);
  77.                 arrowArray[arrowArray.length - 1].x = b.x;
  78.                 arrowArray[arrowArray.length - 1].y = b.y;
  79.  
  80.                 var angle: Number = Math.atan2(mouseY - b.y, mouseX - b.x);
  81.                 xArray.push(15 * Math.cos(angle));
  82.                 yArray.push(15 * Math.sin(angle));
  83.             }
  84.  
  85.             stage.addEventListener(MouseEvent.MOUSE_DOWN, dFun);
  86.             function dFun(evt: MouseEvent): void {
  87.  
  88.                 b.gotoAndStop(5);
  89.                 if (arrowCheck == false) {
  90.  
  91.                     shootCheck = true;
  92.  
  93.                     // arrow
  94.                     arrowArray[arrowArray.length - 1].x = b.x;
  95.                     arrowArray[arrowArray.length - 1].y = b.y;
  96.  
  97.                     // line for aiming
  98.                     al.x = mouseX;
  99.                     al.y = mouseY;
  100.  
  101.                 }
  102.  
  103.             }
  104.  
  105.             stage.addEventListener(MouseEvent.MOUSE_UP, uFun);
  106.             function uFun(evt: MouseEvent): void {
  107.  
  108.                 if (arrowCheck == false) {
  109.  
  110.                     shootCheck = false;
  111.                     arrowCheck = true; // restricts to one arrow on stage
  112.                     b.rotation = al.rotation - 180;
  113.  
  114.                     xSpeed = Math.cos((b.rotation - 90) * Math.PI / 180) * (10 * tempNum / 100);
  115.                     ySpeed = Math.sin((b.rotation + 90) * Math.PI / 180) * (10 * tempNum / 100);
  116.                     al.x = -550;
  117.  
  118.                 }
  119.             }
  120.            
  121.             stage.addEventListener(MouseEvent.MOUSE_MOVE, moveBow);
  122.             function moveBow(evt:MouseEvent):void{
  123.                 b.rotation = Math.atan2(mouseY - b.y, mouseX - b.x) * 180 / Math.PI + 90;
  124.             }
  125.  
  126.             // functions
  127.  
  128.             function aimFun(): void {
  129.  
  130.                 if (shootCheck == true) {
  131.                     b.rotation = Math.atan2(b.y - mouseY, b.x - mouseX) * 180 / Math.PI - 90;
  132.  
  133.                     // redraw the aim line to reflect the distance the mouse moved
  134.                     tempNum = Math.sqrt((al.x - mouseX) * (al.x - mouseX) + (al.y - mouseY) * (al.y - mouseY));
  135.                     al.scaleY = tempNum / 100;
  136.                     al.rotation = Math.atan2((al.y - mouseY), (al.x - mouseX)) * 180 / Math.PI - 90;
  137.                     b.rotation = al.rotation - 180;
  138.                     arrowArray[arrowArray.length - 1].rotation = b.rotation;
  139.                 }
  140.  
  141.             }
  142.  
  143.             /*function shootArrow(): void {
  144.                 if (shootCheck == false) {
  145.                     arrowCheck = true;
  146.  
  147.                     if (arrowCheck == true) {
  148.                         a.y -= ySpeed;
  149.                         a.x += xSpeed;
  150.                         ySpeed -= 0.5;
  151.                         a.rotation = Math.atan2(ySpeed,- xSpeed) * 180 / Math.PI - 90;
  152.                     }
  153.  
  154.                     if (a.x > 550 || a.x < 0 || a.y > 400) {
  155.                         a.x = -550;
  156.                         arrowCheck = false;
  157.                         shootCheck = false;
  158.                     }
  159.  
  160.                 }
  161.             }*/
  162.  
  163.         }
  164.  
  165.     }
  166.  
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement