Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package {
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import flash.text.TextField;
- import flash.text.TextFormat;
- import flash.media.Sound;
- import flash.media.SoundChannel;
- import flash.geom.ColorTransform;
- public class BowmanCode extends MovieClip {
- public function BowmanCode() {
- // variables
- var balloonArray:Array = new Array();
- var arrowArray:Array = new Array();
- var xArray:Array = new Array();
- var yArray:Array = new Array();
- var shootCheck: Boolean = false;
- var arrowCheck: Boolean = false;
- var tempNum: Number = 0;
- var xSpeed: Number = 0;
- var ySpeed: Number = 0;
- var numScore:Number = 0;
- var randomColor: ColorTransform = new ColorTransform();
- // on load
- var b: bow = new bow();
- addChild(b);
- b.x = 275;
- b.y = 375;
- /*var a: arrow = new arrow();
- addChild(a);
- a.x = -550;
- */
- var al: aimline = new aimline();
- addChild(al);
- al.x = -50;
- var score: TextField = new TextField;
- addChild(score);
- score.x = -30;
- score.y = 330;
- score.width = 500;
- score.height = 100;
- score.text = String(numScore);
- var scoretf: TextFormat = new TextFormat;
- scoretf.size = 36;
- scoretf.color = 0x000000;
- scoretf.font = "Comic Sans MS";
- score.setTextFormat(scoretf);
- // events
- addEventListener(Event.ENTER_FRAME, mainFun);
- function mainFun(evt: Event): void {
- aimFun();
- shootArrow();
- }
- stage.addEventListener(MouseEvent.CLICK, shootArrow);
- function shootArrow(e: MouseEvent): void {
- var a: arrow = new arrow();
- arrowArray.push(a);
- addChild(arrowArray[arrowArray.length - 1]);
- arrowArray[arrowArray.length - 1].x = b.x;
- arrowArray[arrowArray.length - 1].y = b.y;
- var angle: Number = Math.atan2(mouseY - b.y, mouseX - b.x);
- xArray.push(15 * Math.cos(angle));
- yArray.push(15 * Math.sin(angle));
- }
- stage.addEventListener(MouseEvent.MOUSE_DOWN, dFun);
- function dFun(evt: MouseEvent): void {
- b.gotoAndStop(5);
- if (arrowCheck == false) {
- shootCheck = true;
- // arrow
- arrowArray[arrowArray.length - 1].x = b.x;
- arrowArray[arrowArray.length - 1].y = b.y;
- // line for aiming
- al.x = mouseX;
- al.y = mouseY;
- }
- }
- stage.addEventListener(MouseEvent.MOUSE_UP, uFun);
- function uFun(evt: MouseEvent): void {
- if (arrowCheck == false) {
- shootCheck = false;
- arrowCheck = true; // restricts to one arrow on stage
- b.rotation = al.rotation - 180;
- xSpeed = Math.cos((b.rotation - 90) * Math.PI / 180) * (10 * tempNum / 100);
- ySpeed = Math.sin((b.rotation + 90) * Math.PI / 180) * (10 * tempNum / 100);
- al.x = -550;
- }
- }
- stage.addEventListener(MouseEvent.MOUSE_MOVE, moveBow);
- function moveBow(evt:MouseEvent):void{
- b.rotation = Math.atan2(mouseY - b.y, mouseX - b.x) * 180 / Math.PI + 90;
- }
- // functions
- function aimFun(): void {
- if (shootCheck == true) {
- b.rotation = Math.atan2(b.y - mouseY, b.x - mouseX) * 180 / Math.PI - 90;
- // redraw the aim line to reflect the distance the mouse moved
- tempNum = Math.sqrt((al.x - mouseX) * (al.x - mouseX) + (al.y - mouseY) * (al.y - mouseY));
- al.scaleY = tempNum / 100;
- al.rotation = Math.atan2((al.y - mouseY), (al.x - mouseX)) * 180 / Math.PI - 90;
- b.rotation = al.rotation - 180;
- arrowArray[arrowArray.length - 1].rotation = b.rotation;
- }
- }
- /*function shootArrow(): void {
- if (shootCheck == false) {
- arrowCheck = true;
- if (arrowCheck == true) {
- a.y -= ySpeed;
- a.x += xSpeed;
- ySpeed -= 0.5;
- a.rotation = Math.atan2(ySpeed,- xSpeed) * 180 / Math.PI - 90;
- }
- if (a.x > 550 || a.x < 0 || a.y > 400) {
- a.x = -550;
- arrowCheck = false;
- shootCheck = false;
- }
- }
- }*/
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement