Guest User

Untitled

a guest
Jan 12th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package{
  2.     import flash.display.MovieClip;
  3.     import playerio.*
  4.     import flash.text.TextField;
  5.     import flash.text.TextFieldType;
  6.     import flash.events.KeyboardEvent;
  7.     import flash.text.TextFormat;
  8.     import flash.net.FileReference;
  9.     import flash.net.URLRequest;
  10.     import flash.events.Event;
  11.     import flash.events.ProgressEvent;
  12.     import flash.display.Loader;
  13.     import flash.utils.ByteArray;
  14.     import flash.display.DisplayObject;
  15.     import flash.events.MouseEvent;
  16.     import flash.utils.Timer;
  17.     import flash.events.TimerEvent;
  18.     import flash.text.Font;
  19.     import flash.filters.GlowFilter;
  20.     import flash.media.SoundChannel;
  21.     import flash.media.SoundTransform;
  22.    
  23.     public class MyCode extends MovieClip{
  24.        
  25.         //Lobby related variables
  26.         private var MessageAmount:int = 0;
  27.         private var LobbyGameArray:Array = new Array();
  28.         private var LobbyGameDetails:Array = new Array();
  29.         private var CreatedGames:uint = 0;
  30.         private var SelectLight:MovieClip = new MovieClip();
  31.         private var SelectLightIndex:uint = 0;
  32.         private var RoomName:String = "Main";
  33.         private var CurrentGameSelected:uint = 0;
  34.         private var CurrentGame:String = "Chatroom";
  35.         private var RefreshButton = new RefreshButtonClass();
  36.         private var RefreshList:Boolean = false;
  37.         private var CurrentAmount:int = 0;
  38.         private var CurrentDescription:String = "";
  39.         private var CurrentHoster:String = "None";
  40.         private var Coop:Boolean = true;
  41.         private var MaxPlayers:int = 0;
  42.         private var SearchGameTimer:Timer = new Timer(2000);
  43.        
  44.         //Game Window variables
  45.         private var GameName:TextField = new TextField();
  46.         private var GameWindow:MovieClip = new MovieClip();
  47.         private var GameTab:MovieClip = new MovieClip();
  48.         private var CloseGame:MovieClip = new MovieClip();
  49.         private var DraggingGame:Boolean = false;
  50.        
  51.         //Lobby Window variables
  52.         private var CreateGameButton:MovieClip = new MovieClip();
  53.         private var LobbyTitle:TextField = new TextField();
  54.         private var CreateGameText:TextField = new TextField();
  55.         private var OptionBox:MovieClip = new MovieClip();
  56.         private var OptionTitle:TextField = new TextField();
  57.         private var JoinGameButton:MovieClip = new MovieClip();
  58.         private var CreateJoinText:TextField = new TextField();
  59.         private var MaxPlayersOptionText:TextField = new TextField();
  60.         private var MaxPlayersText:TextField = new TextField();
  61.        
  62.         //Create Game Window variables
  63.         private var DescriptionText:TextField = new TextField();
  64.         private var GameOptionText:TextField = new TextField();
  65.         private var GameNameText:TextField = new TextField();
  66.         private var AttachedWindowObjects:Array = new Array();
  67.         private var AttachedWindowObjectsX:Array = new Array();
  68.         private var AttachedWindowObjectsY:Array = new Array();
  69.         private var WindowTab:MovieClip = new MovieClip();
  70.         private var DraggingWindow:Boolean = false;
  71.         private var CloseWindow:MovieClip = new MovieClip();
  72.         private var CreateInGameButton:MovieClip = new MovieClip();
  73.         private var CreateButtonTextInGame:TextField = new TextField();
  74.         private var MapTypeText:TextField = new TextField();
  75.         private var MapTypeOptionBox:MovieClip = new MovieClip();
  76.         private var GameCoopText:TextField = new TextField();
  77.         private var GameCompText:TextField = new TextField();
  78.         private var SecondMapOptionBox:MovieClip = new MovieClip();
  79.        
  80.         //Meeting Chat variables
  81.         private var StartGameButton:MovieClip = new MovieClip();
  82.         private var StartGameText:TextField = new TextField();
  83.         private var JoiningGame:Boolean = false;
  84.         private var BeginWaiting:Timer = new Timer(5000);
  85.         private var LobbyButton = new LobbyButtonClass();
  86.         private var RejoinChat:Boolean = false;
  87.        
  88.         //Connecting Window variables
  89.         private var ConnectingBox:MovieClip = new MovieClip();
  90.         private var ConnectingTab:MovieClip = new MovieClip();
  91.         private var ConnectingText:TextField = new TextField();
  92.         private var JoiningLobby:Boolean = false;
  93.        
  94.         //Message Box Window variables
  95.         private var MessageBox:MovieClip = new MovieClip();
  96.         private var TheMessageText:TextField = new TextField();
  97.         private var MessageButton:MovieClip = new MovieClip();
  98.         private var MessageButtonText:TextField = new TextField();
  99.        
  100.         //Main Game related variables
  101.         private var PauseGame:Boolean = true;
  102.         private var RunningTimers:Array = new Array();
  103.        
  104.         //Text related variables
  105.         private var myFont:Font = new Rexlia();
  106.        
  107.         //Money related variables
  108.         private var MoneyDisplay:TextField = new TextField();
  109.        
  110.         //Music related variables
  111.         private var gameMusic:GameMusic = new GameMusic();
  112.         private var FadeMusic:Boolean = false;
  113.         private var MusicVolume:Number = 1;
  114.         private var MusicChannel:SoundChannel = new SoundChannel();
  115.         private var MusicTransform:SoundTransform = new SoundTransform();
  116.        
  117.         //Special related variables
  118.         private var KeyCombination:Timer = new Timer(5000);
  119.         private var CombinationKeys:Array = new Array(65, 51, 83, 49, 56, 57);
  120.         private var NextKey:int = 0;
  121.         private var GodModeOnTimer:Timer = new Timer(5000);
  122.         private var GodModeOnKeys:Array = new Array(71, 79, 68, 77, 79, 68, 69, 79, 78);
  123.         private var NextKey2:int = 0;
  124.         private var GodModeOffTimer:Timer = new Timer(5000);
  125.         private var GodModeOffKeys:Array = new Array(71, 79, 68, 77, 79, 68, 69, 79, 70, 70);
  126.         private var NextKey3:int = 0;
  127.        
  128.         private var friendsClass:FriendsClass = new FriendsClass();
  129.         private var loginClass:LoginClass = new LoginClass();
  130.         private var menuClass:MenuClass = new MenuClass();
  131.         private var menuProfileClass:MenuProfileClass = new MenuProfileClass();
  132.         private var manageEnemyClass:ManageEnemyClass = new ManageEnemyClass();
  133.         private var particleClass:ParticleClass = new ParticleClass();
  134.         private var spellClass:SpellClass = new SpellClass();
  135.         private var enemyClass:EnemyClass = new EnemyClass();
  136.         private var shipClass:ShipClass = new ShipClass();
  137.         private var upgradesClass:UpgradesClass = new UpgradesClass();
  138.         private var debuggerClass:DebuggerClass = new DebuggerClass();
  139.        
  140.         public function MyCode(){
  141.             stop();
  142.            
  143.             stage.addChild(menuProfileClass);
  144.             stage.addChild(friendsClass);
  145.             stage.addChild(loginClass);
  146.             stage.addChild(menuClass);
  147.             stage.addChild(manageEnemyClass);
  148.             stage.addChild(particleClass);
  149.             stage.addChild(spellClass);
  150.             stage.addChild(enemyClass);
  151.             stage.addChild(shipClass);
  152.             stage.addChild(upgradesClass);
  153.             stage.addChild(debuggerClass);
  154.            
  155.             debuggerClass.CreateEvents();
  156.            
  157.             MenuClass.friendsClass = friendsClass;
  158.             MenuClass.menuProfileClass = menuProfileClass;
  159.            
  160.             ManageEnemyClass.particleClass = particleClass;
  161.             ManageEnemyClass.enemyClass = enemyClass;
  162.             ManageEnemyClass.upgradesClass = upgradesClass;
  163.             ManageEnemyClass.spellClass = spellClass;
  164.            
  165.             stage.addChild(MenuClass.TitleBackground);
  166.             MenuClass.TitleBackground.alpha = .2;
  167.            
  168.             CreateGame();
  169.         }
  170.        
  171.         private function SearchingGameAgain(Event:TimerEvent){
  172.             SearchGameTimer.reset();
  173.             SearchGameTimer.stop();
  174.             PlayerIOConnect();
  175.         }
  176.        
  177.         private function PlayerIOConnect():void{
  178.             PlayerIO.connect(
  179.                 stage,                              //Referance to stage
  180.                 "buddynet-q5uh09yhu0ff3oesqokcw",           //Game id (Get your own at playerio.com)
  181.                 "public",                           //Connection id, default is public
  182.                 AccountDetailsClass.Username,                       //Username
  183.                 "",                                 //User auth. Can be left blank if authentication is disabled on connection
  184.                 null,                               //Current PartnerPay partner.
  185.                 handleConnect,                      //Function executed on successful connect
  186.                 handleError                         //Function executed if we recive an error
  187.             );  
  188.         }
  189.        
  190.         private function handleConnect(client:Client):void{
  191.             trace("Sucessfully connected to player.io");
  192.            
  193.             //Set developmentsever (Comment out to connect to your server online)
  194.             //client.multiplayer.developmentServer = "localhost:8184";
  195.            
  196.             if (MenuClass.SearchUser){
  197.                 MenuClass.SearchUser = false;
  198.                
  199.                 client.bigDB.loadMyPlayerObject(function(myDBObject:DatabaseObject):void{
  200.                     if (myDBObject.Password == undefined){
  201.                         AccountDetailsClass.Username = AccountDetailsClass.StoreUsername;
  202.                         MenuClass.ReConnect = true;
  203.                     }else{
  204.                         AccountDetailsClass.Username = AccountDetailsClass.StoreUsername;
  205.                         MenuClass.ReConnectFriend = true;
  206.                     }
  207.                    
  208.                     PlayerIOConnect();
  209.                 })
  210.             }else if (MenuClass.ReConnect || MenuClass.ReConnectFriend){
  211.                 //Create pr join the room test
  212.                 client.multiplayer.createJoinRoom(
  213.                     RoomName,                               //Room id. If set to null a random roomid is used
  214.                     "MyCode",                           //The game type started on the server
  215.                     true,                               //Should the room be visible in the lobby?
  216.                     {},                                 //Room data. This data is returned to lobby list. Variabels can be modifed on the server
  217.                     {},                                 //User join data
  218.                     handleJoin,                         //Function executed on successful joining of the room
  219.                     handleError                         //Function executed if we got a join error
  220.                 );
  221.             }else if (RoomName == "Main"){
  222.                 client.bigDB.loadMyPlayerObject(function(myDBObject:DatabaseObject):void{
  223.                     CurrentAmount = myDBObject.GameAmount;
  224.                    
  225.                     if (myDBObject.Friends != undefined){
  226.                         FriendsClass.Friends = myDBObject.Friends;
  227.                     }
  228.                    
  229.                     var PasswordReceived = myDBObject.Password;
  230.                    
  231.                     if (PasswordReceived != undefined){
  232.                         PasswordReceived = PasswordReceived.toUpperCase();
  233.                     }
  234.                    
  235.                     if (PasswordReceived == undefined && LoginClass.LoggingIn){
  236.                         RemoveConnectingBox();
  237.                         loginClass.CreateLogin();
  238.                         CreateMessageBox("Error: Username or password does not exist");
  239.                         LoginClass.ErrorEncounted = true;
  240.                     }else if (PasswordReceived != AccountDetailsClass.Password && LoginClass.LoggingIn && PasswordReceived != undefined){
  241.                         RemoveConnectingBox();
  242.                         loginClass.CreateLogin();
  243.                         CreateMessageBox("Error: Incorrect Password!");
  244.                         LoginClass.ErrorEncounted = true;
  245.                     }else if (PasswordReceived != undefined && !LoginClass.LoggingIn){
  246.                         RemoveConnectingBox();
  247.                         loginClass.CreateLogin();
  248.                         CreateMessageBox("Error: Username has already been taken");
  249.                         LoginClass.ErrorEncounted = true;
  250.                     }else{
  251.                         AccountDetailsClass.Level = myDBObject.Level;
  252.                         AccountDetailsClass.Money = myDBObject.Money;
  253.                         AccountDetailsClass.XP = myDBObject.XP;
  254.                        
  255.                         //Create pr join the room test
  256.                         client.multiplayer.createJoinRoom(
  257.                             RoomName,                               //Room id. If set to null a random roomid is used
  258.                             "MyCode",                           //The game type started on the server
  259.                             true,                               //Should the room be visible in the lobby?
  260.                             {},                                 //Room data. This data is returned to lobby list. Variabels can be modifed on the server
  261.                             {},                                 //User join data
  262.                             handleJoin,                         //Function executed on successful joining of the room
  263.                             handleError                         //Function executed if we got a join error
  264.                         );
  265.                     }
  266.                 })
  267.             }else{
  268.                 if (RoomName.substring(0, 6) == "Info: "){
  269.                     client.bigDB.loadMyPlayerObject(function(myDBObject:DatabaseObject):void{
  270.                         if (myDBObject.GameNames == ""){
  271.                             PlayerIOConnect();
  272.                         }else{
  273.                             RemoveConnectingBox();
  274.                             menuClass.RemoveMenu();
  275.                             MenuClass.TimeSearcher.stop();
  276.                             MenuClass.TimeSearched = 0;
  277.                            
  278.                             var AmountOfGames:int = 0;
  279.                             var GameNameClone:String = myDBObject.GameNames + ",";
  280.                             var GameNameLength:int = GameNameClone.length;
  281.                            
  282.                             trace("Game Names: " + myDBObject.GameNames);
  283.                            
  284.                             for (var i:uint = 0; i < GameNameLength; i++){
  285.                                 if (GameNameClone.substring(i, i+1) == ","){
  286.                                     GameNameClone = GameNameClone.substring(i+1, GameNameClone.length);
  287.                                     AmountOfGames++;
  288.                                     i = 0;
  289.                                 }
  290.                             }
  291.                            
  292.                             GameNameClone = myDBObject.GameNames + ",";
  293.                            
  294.                             trace("There are currently " + AmountOfGames + " games open at the moment.");
  295.                            
  296.                             var CurrentGameNumber:Number = (-Math.floor(Math.random() * (1 - (AmountOfGames+1))) + 1)-1;
  297.                            
  298.                             trace("You will be joining game " + CurrentGameNumber);
  299.                            
  300.                             var JoiningGame:String = "";
  301.                            
  302.                             for (var j:uint = 0; j < AmountOfGames; j++){
  303.                                 trace(GameNameClone.indexOf(","));
  304.                                 if (GameNameClone.indexOf(",") != -1){
  305.                                     trace("it made it? :P");
  306.                                     if (j+1 == CurrentGameNumber){
  307.                                         trace("Made it past again :D");
  308.                                         JoiningGame = GameNameClone.substring(0, GameNameClone.indexOf(","));
  309.                                         trace(JoiningGame);
  310.                                         break;
  311.                                     }
  312.                                     GameNameClone = GameNameClone.substring(GameNameClone.indexOf(",")+1, GameNameClone.length);
  313.                                 }
  314.                             }
  315.                            
  316.                             trace("Joining " + JoiningGame + "'s Room!");
  317.                            
  318.                             CreateConnectingBox("Found game! Joining Game.\nHoster: " + JoiningGame);
  319.                             AccountDetailsClass.Username = AccountDetailsClass.StoreUsername;
  320.                             RoomName = "Room: " + myDBObject.GameNames.substring(0, myDBObject.GameNames.indexOf(","));
  321.                             CurrentGame = RoomName;
  322.                             SearchGameTimer.start();
  323.                             CurrentHoster = myDBObject.GameNames.substring(0, myDBObject.GameNames.indexOf(","));
  324.                         }
  325.                     })
  326.                 }else{
  327.                     //Create pr join the room test
  328.                     client.multiplayer.createJoinRoom(
  329.                         RoomName,                               //Room id. If set to null a random roomid is used
  330.                         "MyCode",                           //The game type started on the server
  331.                         true,                               //Should the room be visible in the lobby?
  332.                         {},                                 //Room data. This data is returned to lobby list. Variabels can be modifed on the server
  333.                         {},                                 //User join data
  334.                         handleJoin,                         //Function executed on successful joining of the room
  335.                         handleError                         //Function executed if we got a join error
  336.                     );
  337.                 }
  338.             }
  339.         }
  340.        
  341.        
  342.         private function handleJoin(connection:Connection):void{
  343.             trace("Sucessfully connected to the multiplayer server");
  344.            
  345.             debuggerClass.DebugMessage(AccountDetailsClass.Username + " just joined the room: " + RoomName);
  346.            
  347.             ConnectionClass.TheConnection = connection;
  348.            
  349.             if (MenuClass.ReConnect){
  350.                 RemoveConnectingBox();
  351.                
  352.                 FriendsClass.GreyScreen.graphics.clear();
  353.                
  354.                 FriendsClass.GreyScreen.graphics.lineStyle(1, 0x333333);
  355.                 FriendsClass.GreyScreen.graphics.beginFill(0x999999);
  356.                
  357.                 FriendsClass.GreyScreen.graphics.lineTo(850, 0);
  358.                 FriendsClass.GreyScreen.graphics.lineTo(850, 650);
  359.                 FriendsClass.GreyScreen.graphics.lineTo(0, 650);
  360.                 FriendsClass.GreyScreen.graphics.lineTo(0, 0);
  361.                
  362.                 FriendsClass.GreyScreen.alpha = .4;
  363.            
  364.                 stage.addChild(FriendsClass.GreyScreen);
  365.                
  366.                 friendsClass.RemoveAddFriendBox();
  367.                 CreateMessageBox("Error: Username does not exist.");
  368.                 MenuClass.ReConnect = false;
  369.             }else if (MenuClass.ReConnectFriend){
  370.                 RemoveConnectingBox();
  371.                 MenuClass.ReConnectFriend = false;
  372.                 connection.send("AddFriend", FriendsClass.FriendInput.text.toUpperCase());
  373.             }else if (MenuClass.JoiningMenu){
  374.                 RemoveConnectingBox();
  375.                 menuClass.CreateMenu();
  376.                 MenuClass.JoiningMenu = false;
  377.                 if (!LoginClass.LoggingIn){
  378.                     connection.send("RegisterUser", AccountDetailsClass.Username, AccountDetailsClass.Password);
  379.                 }
  380.             }else if (RejoinChat){
  381.                 ShipClass.WaitingTime = 15;
  382.                 ShipClass.ChoosingShipArray = [];
  383.                 RemoveConnectingBox();
  384.                 CreateShipMenu();
  385.                 ChatClass.ChatBox.text = "";
  386.                 ChatClass.ChatText.text = "";
  387.                 ChatClass.ChatUsers.text = "";
  388.                 connection.send("ChatMessage", AccountDetailsClass.Username + " Just joined the chat.", AccountDetailsClass.Username);
  389.                 connection.send("MyInfo", AccountDetailsClass.Username, CurrentGame);
  390.                
  391.                 RejoinChat = false;
  392.                 EnemyClass.StageEnd = false;
  393.                 PauseGame = true;
  394.                 ShipClass.WaitingChat = true;
  395.                 MusicVolume = 1;
  396.                 RemoveConnectingBox();
  397.                 menuClass.CreateMenu();
  398.             }else if (CurrentGame.substring(0, 6) == "Room: "){
  399.                 RemoveConnectingBox();
  400.                 CreateChat();
  401.                 ChatClass.ChatBox.text = "";
  402.                 ChatClass.ChatText.text = "";
  403.                 connection.send("ChatMessage", AccountDetailsClass.Username + " Just joined the game.", AccountDetailsClass.Username);
  404.                 connection.send("MyInfo", AccountDetailsClass.Username, CurrentGame);
  405.                
  406.                 if (AccountDetailsClass.Username == CurrentHoster){
  407.                     CreateStartGameButton();
  408.                 }
  409.                 connection.send("SendHostInfo", CurrentHoster, CurrentGame, Coop);
  410.             }else if (CurrentGame.substring(0, 6) == "Game: " || ShipClass.WaitingChat){
  411.                 RemoveConnectingBox();
  412.                 CreateConnectingBox("Waiting for other players");
  413.                 CreateInGameChat("ChatText");
  414.                 ChatClass.ChatBox.text = "";
  415.                 ChatClass.ChatText.text = "";
  416.                
  417.                 BeginWaiting.addEventListener(TimerEvent.TIMER, PlayersHaveJoined);
  418.                 BeginWaiting.start();
  419.             }
  420.             RefreshList = false;
  421.            
  422.             //Add disconnect listener
  423.             connection.addDisconnectHandler(handleDisconnect);
  424.                    
  425.             //Add listener for messages of the type "hello"
  426.             connection.addMessageHandler("ChatMessage", function(m:Message, TextMessage:String, TheUsername:String){
  427.                 if (CurrentGame.substring(0, 6) == "Game: " && TextMessage.substring(TheUsername.length+3, TheUsername.length+4) == "/"){
  428.                     var Recordp:uint = 0;
  429.                     var FoundP:Boolean = false;
  430.                    
  431.                     for (var p:uint = 0; p < ShipClass.ShipArray.length; p++){
  432.                         if (TheUsername == ShipClass.ShipArray[p].Username){
  433.                             Recordp = p;
  434.                             FoundP = true;
  435.                         }
  436.                     }
  437.                    
  438.                     switch((TextMessage.toUpperCase()).substring(TheUsername.length+3, TextMessage.length)){
  439.                         case "/ACTIVATE1":
  440.                         if (FoundP){
  441.                             ShipClass.ShipArray[Recordp].alpha = 0;
  442.                         }
  443.                         ShipClass.Ship.alpha = 0;
  444.                         break;
  445.                         case "/ACTIVATE2":
  446.                         if (FoundP){
  447.                             ShipClass.ShipArray[Recordp].alpha = 1;
  448.                         }
  449.                         ShipClass.Ship.alpha = 1;
  450.                         break;
  451.                         case "/ACTIVATE3":
  452.                         if (FoundP){
  453.                             ShipClass.ShipArray[Recordp].Fill = 0x000000;
  454.                             ShipClass.ShipArray[Recordp].Outline = 0xFFFFFF;
  455.                             ShipClass.ShipArray[Recordp].DarkOutline = 0xFFFFFF;
  456.                             ShipClass.ShipArray[Recordp].BackColour = 0x000000;
  457.                         }
  458.                         ShipClass.ShipFill = 0x000000;
  459.                         ShipClass.ShipOutline = 0xFFFFFF;
  460.                         ShipClass.ShipDarkOutline = 0xFFFFFF;
  461.                         ShipClass.BackShipColour = 0x000000;
  462.                         break;
  463.                         case "/ACTIVATE4":
  464.                         if (FoundP){
  465.                             ShipClass.ShipArray[Recordp].Fill = 0xFF0000;
  466.                             ShipClass.ShipArray[Recordp].Outline = 0xFFFFFF;
  467.                             ShipClass.ShipArray[Recordp].DarkOutline = 0xFF0000;
  468.                             ShipClass.ShipArray[Recordp].BackColour = 0xFF0000;
  469.                         }
  470.                         ShipClass.ShipFill = 0xFF0000;
  471.                         ShipClass.ShipOutline = 0xFFFFFF;
  472.                         ShipClass.ShipDarkOutline = 0xFF0000;
  473.                         ShipClass.BackShipColour = 0xFF0000;
  474.                         break;
  475.                     }
  476.                 }else{
  477.                     var OriginScroll = ChatClass.ChatText.scrollV;
  478.                    
  479.                     var Time;
  480.                     if (TextMessage.indexOf("[") != -1){
  481.                         var myDate:Date = new Date();
  482.                        
  483.                         var Hours = myDate.getHours();
  484.                         var Minutes = myDate.getMinutes();
  485.                        
  486.                         if (Hours > 12){
  487.                             Hours = Hours-12;
  488.                         }else if (Hours == 0){
  489.                             Hours = 12;
  490.                         }
  491.                        
  492.                         if (Minutes < 10){
  493.                             var prevMins = Minutes;
  494.                             Minutes = "0";
  495.                             Minutes += prevMins;
  496.                         }
  497.                        
  498.                         Time = Hours + ":" + Minutes;
  499.                     }else{
  500.                         Time = "";
  501.                     }
  502.                    
  503.                     if (CurrentGame.substring(0, 6) == "Game: "){
  504.                         ChatClass.ChatText.appendText(TextMessage + "\n");
  505.                     }else{
  506.                         ChatClass.ChatText.appendText(Time + " " + TextMessage + "\n");
  507.                     }
  508.                    
  509.                     if (CurrentGame.substring(0, 6) != "Game: "){
  510.                         MessageAmount++;
  511.                        
  512.                         if (OriginScroll >= MessageAmount-26){
  513.                             ChatClass.ChatText.scrollV = MessageAmount;
  514.                         }else{
  515.                             ChatClass.ChatText.scrollV = OriginScroll;
  516.                         }
  517.                     }
  518.                 }
  519.             })
  520.            
  521.             //Add message listener for users joining the room
  522.             connection.addMessageHandler("UserJoined", function(m:Message, userid:uint){
  523.                 trace("Player with the userid", userid, "just joined the room");
  524.                 friendsClass.UpdateFriendsList(FriendsClass.Friends);
  525.                
  526.                 if (!ChatClass.UserJoinedGame){
  527.                     if (CurrentGame.substring(0, 6) == "Game: " || CurrentGame.substring(0, 6) == "Room: "){
  528.                         connection.send("ChatMessage", AccountDetailsClass.Username + " just joined BuddyNet", AccountDetailsClass.Username);
  529.                     }
  530.                     ChatClass.UserJoinedGame = true;
  531.                 }
  532.             })
  533.            
  534.             //Add message listener for users leaving the room
  535.             connection.addMessageHandler("UserLeft", function(m:Message, userid:uint, LeftUsername:String){
  536.                 trace("Player with the userid", userid, "just left the room");
  537.                 if (CurrentGame.substring(0, 6) == "Game: " || CurrentGame.substring(0, 6) == "Room: "){
  538.                     connection.send("ChatMessage", LeftUsername + " left the game.", LoginClass.Username);
  539.                 }
  540.                
  541.                 connection.send("SendLobbyDetails");
  542.             })
  543.            
  544.             connection.addMessageHandler("MyInfo", function(m:Message, ListofUsers:String){
  545.                 FriendsClass.OnlineUsers = [];
  546.                 ChatClass.ChatUsers.text = "";
  547.                
  548.                 for (var j:uint = 0; j < 50; j++){
  549.                     if (ListofUsers.indexOf("*") != -1){
  550.                         FriendsClass.OnlineUsers.push(ListofUsers.substring(0, ListofUsers.indexOf("*")));
  551.                         ListofUsers = ListofUsers.substring(ListofUsers.indexOf("*")+1, ListofUsers.length);
  552.                        
  553.                         ChatClass.ChatUsers.appendText(" - " + FriendsClass.OnlineUsers[FriendsClass.OnlineUsers.length-1] + "\n");
  554.                     }else{
  555.                         break;
  556.                     }
  557.                 }
  558.                
  559.                 friendsClass.UpdateFriendsList(FriendsClass.Friends);
  560.             })
  561.            
  562.             connection.addMessageHandler("AddFriend", function(m:Message, NewFriendList:String){
  563.                 FriendsClass.Friends = NewFriendList;
  564.                
  565.                 friendsClass.UpdateFriendsList(FriendsClass.Friends);
  566.                 friendsClass.RemoveAddFriendBox();
  567.                
  568.                 CreateMessageBox("Friend added!");
  569.             })
  570.            
  571.             connection.addMessageHandler("StartGame", function(m:Message, TheGameName:String, TheHoster:String, RealGameName:String){
  572.                 FriendsClass.OnlineUsers = [];
  573.                 if (TheGameName == "Game: Awesome"){
  574.                     RoomName = "Game: " + RealGameName;
  575.                     CurrentGame = "Game: " + RealGameName;
  576.                     CurrentHoster = TheHoster;
  577.                    
  578.                     connection.disconnect();
  579.                     PlayerIOConnect();
  580.                    
  581.                     stage.removeChild(ChatClass.ChatBox);
  582.                     stage.removeChild(ChatClass.ChatText);
  583.                     stage.removeChild(ChatClass.ChatUsers);
  584.                     stage.removeChild(ChatClass.ChatBoxFill);
  585.                     stage.removeChild(ChatClass.ChatTextFill);
  586.                     stage.removeChild(ChatClass.ChatUsersFill);
  587.                    
  588.                     for (var j:uint = 0; j < ShipClass.ChoosingShipArray.length; j++){
  589.                         stage.removeChild(ShipClass.ChoosingShipArray[j]);
  590.                     }
  591.                     ShipClass.ChoosingShipArray = [];
  592.                    
  593.                     stage.removeChild(ShipClass.DisplayWaitingTime);
  594.                     stage.removeChild(ShipClass.ShipColourBox);
  595.                     stage.removeChild(ShipClass.ShipChooser);
  596.                    
  597.                     CreateConnectingBox("Starting Game");
  598.                 }else{
  599.                     RemoveChat();
  600.                     CreateShipMenu();
  601.                 }
  602.             })
  603.            
  604.             connection.addMessageHandler("GameJoin", function(m:Message, TheUsername:String, ColourOutline:int, ColourFill:int, ColourDarkOutline:int){
  605.                 if (TheUsername != AccountDetailsClass.Username){
  606.                     CreateNewShip(TheUsername, ColourOutline, ColourFill, ColourDarkOutline);
  607.                 }
  608.             })
  609.            
  610.             connection.addMessageHandler("SavedGame", function(m:Message){
  611.                 RemoveConnectingBox();
  612.                 CreateConnectingBox("Joining Room...");
  613.                 AccountDetailsClass.Username = AccountDetailsClass.StoreUsername;
  614.                 RoomName = "Room: " + AccountDetailsClass.Username;
  615.                 CurrentGame = RoomName;
  616.                 connection.disconnect();
  617.                 PlayerIOConnect();
  618.             })
  619.            
  620.             connection.addMessageHandler("DestroyEnemy", function(m:Message, TheEnemy:String){
  621.                 for (var j:uint = 0; j < EnemyClass.EnemyArray.length; j++){
  622.                     if (EnemyClass.EnemyArray[j].name == TheEnemy){
  623.                         EnemyClass.EnemyArray[j].Health = -999;
  624.                         break;
  625.                     }
  626.                 }
  627.             })
  628.            
  629.             connection.addMessageHandler("SendMovements", function(m:Message, TheUsername:String, X:int, Y:int, speedx:int){
  630.                 var Recordj:int = 0;
  631.                
  632.                 for (var j:uint = 0; j < ShipClass.ShipArray.length; j++){
  633.                     if (ShipClass.ShipArray[j].Username == TheUsername && TheUsername != LoginClass.Username){
  634.                         ShipClass.ShipArray[j].x = X;
  635.                         ShipClass.ShipArray[j].y = Y;
  636.                         Recordj = j;
  637.                        
  638.                         particleClass.CreateTrail(ShipClass.ShipArray[j].DarkOutline, "PlayerThrust", ShipClass.ShipArray[j].x, ShipClass.ShipArray[j].y);
  639.                     }
  640.                 }
  641.                
  642.                 ShipClass.TheSpeedX[Recordj] = speedx;
  643.             })
  644.            
  645.             connection.addMessageHandler("CreateBullet", function(m:Message, TheUsername:String, X:int, Y:int, extrashots:int, TheBulletType:String){
  646.                 var Recordj:int = 0;
  647.                
  648.                 for (var j:uint = 0; j < ShipClass.ShipArray.length; j++){
  649.                     if (ShipClass.ShipArray[j].Username == TheUsername && TheUsername != AccountDetailsClass.Username){
  650.                         ShipClass.ShipArray[j].x = X;
  651.                         ShipClass.ShipArray[j].y = Y;
  652.                         Recordj = j;
  653.                     }
  654.                 }
  655.                
  656.                 if (TheUsername != AccountDetailsClass.Username){
  657.                     CreateBullet(extrashots, ShipClass.ShipArray[Recordj].x, ShipClass.ShipArray[Recordj].y, TheBulletType);
  658.                 }
  659.             })
  660.            
  661.             connection.addMessageHandler("StartMainGame", function(m:Message){
  662.                 BeginWaiting.stop();
  663.                
  664.                 StartMainGame();
  665.             })
  666.            
  667.             connection.addMessageHandler("HealAllies", function(m:Message, HealHealth:int){
  668.                 if (HealthClass.Health+100 > HealthClass.MaxHealth){
  669.                     HealthClass.Health = HealthClass.MaxHealth;
  670.                 }else{
  671.                     HealthClass.Health = HealthClass.Health+100;
  672.                 }
  673.                
  674.                 particleClass.CreateText(ShipClass.Ship.x,ShipClass. Ship.y, 12, "+" + HealHealth, 0x00FF00, 30, "Scroll");
  675.                
  676.                 for (var j:uint = 0; j < ShipClass.ShipArray.length; j++){
  677.                     particleClass.CreateText(ShipClass.ShipArray[j].x, ShipClass.ShipArray[j].y, 12, "+" + HealHealth, 0x00FF00, 30, "Scroll");
  678.                 }
  679.             })
  680.            
  681.             connection.addMessageHandler("DestroyUpgrade", function(m:Message, UpgradeName:String, CollectUsername:String){
  682.                 for (var j:uint = 0; j < UpgradesClass.UpgradesArray.length; j++){
  683.                     if (UpgradesClass.UpgradesArray[j].name == UpgradeName){
  684.                         if (AccountDetailsClass.Username == CollectUsername){
  685.                             switch (UpgradesClass.UpgradesArray[j].Type){
  686.                                 case "Lightning":
  687.                                 ShipClass.FireRate -= 50;
  688.                                 if (ShipClass.FireRate <= 250){
  689.                                     ShipClass.FireRate = 250;
  690.                                 }
  691.                                 ResetBulletTime(ShipClass.FireRate);
  692.                                 particleClass.CreateText(ShipClass.Ship.x, ShipClass.Ship.y, 15, "+ Bullet Rate Increased!", 0xFF0000, 30, "Scroll");
  693.                                 break;
  694.                                 case "Health":
  695.                                 HealthClass.Health = HealthClass.MaxHealth;
  696.                                 particleClass.CreateText(ShipClass.Ship.x, ShipClass.Ship.y, 15, "+ Health!", 0x00FF00, 30, "Scroll");
  697.                                 break;
  698.                                 case "GoldBullet":
  699.                                 ShipClass.BulletType = "GoldBullet";
  700.                                 particleClass.CreateText(ShipClass.Ship.x, ShipClass.Ship.y, 15, "+ Golden Bullets", 0x00FF00, 30, "Scroll");
  701.                                 break;
  702.                                 case "BlueBullet":
  703.                                 ShipClass.BulletType = "BlueBullet";
  704.                                 particleClass.CreateText(ShipClass.Ship.x, ShipClass.Ship.y, 15, "+ Diamond Penetration!", 0x00FF00, 30, "Scroll");
  705.                                 break;
  706.                                 case "ExtraShot":
  707.                                 if (ShipClass.ShipArray.ExtraShots <= 3){
  708.                                     ShipClass.ShipArray.ExtraShots += 2;
  709.                                 }
  710.                                 if (ShipClass.ShipArray.ExtraShots >= 5){
  711.                                     ShipClass.ShipArray.ExtraShots = 4;
  712.                                 }
  713.                                 particleClass.CreateText(ShipClass.Ship.x, ShipClass.Ship.y, 20, "MULTISHOT!!", 0xFF0000, 50, "Scroll");
  714.                                 break;
  715.                                 case "GreenBullet":
  716.                                 ShipClass.BulletType = "GreenBullet";
  717.                                 particleClass.CreateText(ShipClass.Ship.x, ShipClass.Ship.y, 15, "+ Squiggle Laser", 0x00FF00, 30, "Scroll");
  718.                                 break;
  719.                                 case "PlasmaBullet":
  720.                                 ShipClass.BulletType = "PlasmaBullet";
  721.                                 particleClass.CreateText(ShipClass.Ship.x, ShipClass.Ship.y, 15, "+ Plasma Bullet", 0xFFFFFF, 30, "Scroll");
  722.                                 break;
  723.                                 case "EvilPlasmaBullet":
  724.                                 ShipClass.BulletType = "EvilPlasmaBullet";
  725.                                 particleClass.CreateText(ShipClass.Ship.x, ShipClass.Ship.y, 15, "+ Dark Plasma Bullet", 0xFF0000, 30, "Scroll");
  726.                                 break;
  727.                                 case "ForkBullet":
  728.                                 ShipClass.BulletType = "ForkBullet";
  729.                                 particleClass.CreateText(ShipClass.Ship.x, ShipClass.Ship.y, 15, "+ Lightning Shock!!", 0xFFFFFF, 30, "Scroll");
  730.                                 break;
  731.                                 case "ArrowBullet":
  732.                                 ShipClass.BulletType = "ArrowBullet";
  733.                                 particleClass.CreateText(ShipClass.Ship.x, ShipClass.Ship.y, 15, "+ Speeding Arrow Bullet", 0x00FF00, 30, "Scroll");
  734.                                 break;
  735.                             }
  736.                         }
  737.                        
  738.                         if (UpgradesClass.UpgradesArray[j].stage != null){
  739.                             stage.removeChild(UpgradesClass.UpgradesArray[j]);
  740.                         }
  741.                         UpgradesClass.UpgradesArray.splice(j, 1);
  742.                     }
  743.                 }
  744.             })
  745.            
  746.             connection.addMessageHandler("CreateUpgrade", function(m:Message, UpgradeName:String, X:int, Y:int, UpgradeType:String, TheUsername:String){
  747.                 if (AccountDetailsClass.Username != TheUsername){
  748.                     switch (UpgradeType){
  749.                         case "Lightning":
  750.                         upgradesClass.CreateLightningUpgrade(X, Y, UpgradeName);
  751.                         UpgradesClass.UpgradesCreated++;
  752.                         break;
  753.                         case "Health":
  754.                         upgradesClass.CreateHealthUpgrade(X, Y, UpgradeName);
  755.                         UpgradesClass.UpgradesCreated++;
  756.                         break;
  757.                         case "GoldBullet":
  758.                         upgradesClass.CreateGoldenUpgrade(X, Y, UpgradeName);
  759.                         UpgradesClass.UpgradesCreated++;
  760.                         break;
  761.                         case "BlueBullet":
  762.                         upgradesClass.CreateBlueUpgrade(X, Y, UpgradeName);
  763.                         UpgradesClass.UpgradesCreated++;
  764.                         break;
  765.                         case "ExtraShot":
  766.                         upgradesClass.CreateExtraShotUpgrade(X, Y, UpgradeName);
  767.                         UpgradesClass.UpgradesCreated++;
  768.                         break;
  769.                         case "GreenBullet":
  770.                         upgradesClass.CreateGreenUpgrade(X, Y, UpgradeName);
  771.                         UpgradesClass.UpgradesCreated++;
  772.                         break;
  773.                         case "PlasmaBullet":
  774.                         upgradesClass.CreatePlasmaUpgrade(X, Y, UpgradeName);
  775.                         UpgradesClass.UpgradesCreated++;
  776.                         break;
  777.                         case "EvilPlasmaBullet":
  778.                         upgradesClass.CreateEvilPlasmaUpgrade(X, Y, UpgradeName);
  779.                         UpgradesClass.UpgradesCreated++;
  780.                         break;
  781.                         case "ForkBullet":
  782.                         upgradesClass.CreateForkUpgrade(X, Y, UpgradeName);
  783.                         UpgradesClass.UpgradesCreated++;
  784.                         break;
  785.                         case "ArrowBullet":
  786.                         upgradesClass.CreateArrowUpgrade(X, Y, UpgradeName);
  787.                         UpgradesClass.UpgradesCreated++;
  788.                         break;
  789.                     }
  790.                 }
  791.             })
  792.            
  793.             //Listen to all messages using a private function
  794.             connection.addMessageHandler("*", handleMessages)
  795.            
  796.         }
  797.        
  798.         private function handleMessages(m:Message){
  799.             trace("Recived the message", m)
  800.         }
  801.        
  802.         private function handleDisconnect():void{
  803.             trace("Disconnected from server")
  804.         }
  805.        
  806.         private function handleError(error:PlayerIOError):void{
  807.             trace("got",error)
  808.             gotoAndStop(3);
  809.         }
  810.        
  811.         private function CreateGame():void{
  812.             CreateEvents();
  813.             loginClass.CreateLogin();
  814.         }
  815.        
  816.         private function StartMainGame():void{
  817.             CurrentGame = RoomName;
  818.             ConnectionClass.TheConnection.send("MyInfo", AccountDetailsClass.Username, CurrentGame, ShipClass.ShipOutline, ShipClass.ShipFill, ShipClass.ShipDarkOutline);
  819.             RemoveConnectingBox();
  820.             ConnectionClass.Connected = true;
  821.            
  822.             CreateMainGame();
  823.         }
  824.        
  825.         private function PlayersHaveJoined(Timer:TimerEvent){
  826.             ConnectionClass.TheConnection.send("StartMainGame");
  827.            
  828.             BeginWaiting.stop();
  829.         }
  830.        
  831.         private function CreateChat():void{
  832.             stage.addChild(ChatClass.ChatBoxFill);
  833.            
  834.             ChatClass.ChatBoxFill.x = 50;
  835.             ChatClass.ChatBoxFill.y = 500;
  836.            
  837.             ChatClass.ChatBoxFill.graphics.lineStyle(1, 0x333333);
  838.             ChatClass.ChatBoxFill.graphics.beginFill(0x999999);
  839.            
  840.             ChatClass.ChatBoxFill.graphics.lineTo(600, 0);
  841.             ChatClass.ChatBoxFill.graphics.lineTo(600, 20);
  842.             ChatClass.ChatBoxFill.graphics.lineTo(0, 20);
  843.             ChatClass.ChatBoxFill.graphics.lineTo(0, 0);
  844.            
  845.             stage.addChild(ChatClass.ChatTextFill);
  846.            
  847.             ChatClass.ChatTextFill.x = 50;
  848.             ChatClass.ChatTextFill.y = 100;
  849.            
  850.             ChatClass.ChatTextFill.graphics.lineStyle(1, 0x333333);
  851.             ChatClass.ChatTextFill.graphics.beginFill(0x999999);
  852.            
  853.             ChatClass.ChatTextFill.graphics.lineTo(600, 0);
  854.             ChatClass.ChatTextFill.graphics.lineTo(600, 400);
  855.             ChatClass.ChatTextFill.graphics.lineTo(0, 400);
  856.             ChatClass.ChatTextFill.graphics.lineTo(0, 0);
  857.            
  858.             stage.addChild(ChatClass.ChatUsersFill);
  859.            
  860.             ChatClass.ChatUsersFill.x = 650;
  861.             ChatClass.ChatUsersFill.y = 100;
  862.            
  863.             ChatClass.ChatUsersFill.graphics.lineStyle(1, 0x333333);
  864.             ChatClass.ChatUsersFill.graphics.beginFill(0x999999);
  865.            
  866.             ChatClass.ChatUsersFill.graphics.lineTo(120, 0);
  867.             ChatClass.ChatUsersFill.graphics.lineTo(120, 420);
  868.             ChatClass.ChatUsersFill.graphics.lineTo(0, 420);
  869.             ChatClass.ChatUsersFill.graphics.lineTo(0, 0);
  870.            
  871.             stage.addChild(ChatClass.ChatBox);
  872.            
  873.             ChatClass.ChatBox.embedFonts = true;
  874.            
  875.             var NameProperties:TextFormat = new TextFormat();
  876.             NameProperties.font = myFont.fontName;
  877.            
  878.             ChatClass.ChatBox.defaultTextFormat = NameProperties;
  879.            
  880.             var TextGlowFilter2 = new GlowFilter(0x000000, 1, 5, 5, .5, 1, false, false);
  881.             ChatClass.ChatBox.filters = [TextGlowFilter2];
  882.            
  883.             ChatClass.ChatBox.x = 50;
  884.             ChatClass.ChatBox.y = 500;
  885.            
  886.             ChatClass.ChatBox.width = 600;
  887.             ChatClass.ChatBox.height = 20;
  888.            
  889.             ChatClass.ChatBox.border = true;
  890.             ChatClass.ChatBox.type = TextFieldType.INPUT;
  891.             ChatClass.ChatBox.textColor = 0x000000;
  892.            
  893.             stage.addChild(ChatClass.ChatText);
  894.            
  895.             ChatClass.ChatText.embedFonts = true;
  896.            
  897.             var NameProperties2:TextFormat = new TextFormat();
  898.             NameProperties2.font = myFont.fontName;
  899.            
  900.             ChatClass.ChatText.defaultTextFormat = NameProperties2;
  901.            
  902.             var TextGlowFilter = new GlowFilter(0x000000, 1, 5, 5, .5, 1, false, false);
  903.             ChatClass.ChatText.filters = [TextGlowFilter];
  904.            
  905.             ChatClass.ChatText.x = 50;
  906.             ChatClass.ChatText.y = 100;
  907.            
  908.             ChatClass.ChatText.width = 600;
  909.             ChatClass.ChatText.height = 400;
  910.            
  911.             ChatClass.ChatText.border = true;
  912.             ChatClass.ChatText.textColor = 0x000000;
  913.             ChatClass.ChatText.multiline = true;
  914.             ChatClass.ChatText.wordWrap = true;
  915.            
  916.             stage.addChild(ChatClass.ChatUsers);
  917.            
  918.             ChatClass.ChatUsers.embedFonts = true;
  919.            
  920.             var NameProperties3:TextFormat = new TextFormat();
  921.             NameProperties3.font = myFont.fontName;
  922.            
  923.             ChatClass.ChatUsers.defaultTextFormat = NameProperties3;
  924.            
  925.             var TextGlowFilter3 = new GlowFilter(0x000000, 1, 5, 5, .5, 1, false, false);
  926.             ChatClass.ChatUsers.filters = [TextGlowFilter3];
  927.            
  928.             ChatClass.ChatUsers.x = 650;
  929.             ChatClass.ChatUsers.y = 100;
  930.            
  931.             ChatClass.ChatUsers.width = 120;
  932.             ChatClass.ChatUsers.height = 420;
  933.            
  934.             ChatClass.ChatUsers.border = true;
  935.            
  936.             ChatClass.ChatUsers.text = "Loading User List...";
  937.             ChatClass.ChatUsers.textColor = 0x000000;
  938.            
  939.             LobbyButton = new LobbyButtonClass();
  940.            
  941.             stage.addChild(LobbyButton);
  942.            
  943.             LobbyButton.x = 50;
  944.             LobbyButton.y = 600;
  945.         }
  946.        
  947.         private function CreateShipMenu():void{
  948.             ChatClass.ChatBoxFill.graphics.clear();
  949.             ChatClass.ChatTextFill.graphics.clear();
  950.             ChatClass.ChatUsersFill.graphics.clear();
  951.            
  952.             var AlignX:int = 250;
  953.             var AlignY:int = -130;
  954.            
  955.             stage.addChild(ChatClass.ChatBoxFill);
  956.            
  957.             ChatClass.ChatBoxFill.x = 250-AlignX;
  958.             ChatClass.ChatBoxFill.y = 500-AlignY;
  959.            
  960.             ChatClass.ChatBoxFill.graphics.lineStyle(1, 0x333333);
  961.             ChatClass.ChatBoxFill.graphics.beginFill(0x999999);
  962.            
  963.             ChatClass.ChatBoxFill.graphics.lineTo(300, 0);
  964.             ChatClass.ChatBoxFill.graphics.lineTo(300, 20);
  965.             ChatClass.ChatBoxFill.graphics.lineTo(0, 20);
  966.             ChatClass.ChatBoxFill.graphics.lineTo(0, 0);
  967.            
  968.             stage.addChild(ChatClass.ChatTextFill);
  969.            
  970.             ChatClass.ChatTextFill.x = 250-AlignX;
  971.             ChatClass.ChatTextFill.y = 300-AlignY;
  972.            
  973.             ChatClass.ChatTextFill.graphics.lineStyle(1, 0x333333);
  974.             ChatClass.ChatTextFill.graphics.beginFill(0x999999);
  975.            
  976.             ChatClass.ChatTextFill.graphics.lineTo(300, 0);
  977.             ChatClass.ChatTextFill.graphics.lineTo(300, 200);
  978.             ChatClass.ChatTextFill.graphics.lineTo(0, 200);
  979.             ChatClass.ChatTextFill.graphics.lineTo(0, 0);
  980.            
  981.             stage.addChild(ChatClass.ChatUsersFill);
  982.            
  983.             ChatClass.ChatUsersFill.x = 550-AlignX;
  984.             ChatClass.ChatUsersFill.y = 300-AlignY;
  985.            
  986.             ChatClass.ChatUsersFill.graphics.lineStyle(1, 0x333333);
  987.             ChatClass.ChatUsersFill.graphics.beginFill(0x999999);
  988.            
  989.             ChatClass.ChatUsersFill.graphics.lineTo(60, 0);
  990.             ChatClass.ChatUsersFill.graphics.lineTo(60, 220);
  991.             ChatClass.ChatUsersFill.graphics.lineTo(0, 220);
  992.             ChatClass.ChatUsersFill.graphics.lineTo(0, 0);
  993.            
  994.             stage.addChild(ChatClass.ChatBox);
  995.            
  996.             ChatClass.ChatBox.embedFonts = true;
  997.            
  998.             var NameProperties:TextFormat = new TextFormat();
  999.             NameProperties.font = myFont.fontName;
  1000.            
  1001.             ChatClass.ChatBox.defaultTextFormat = NameProperties;
  1002.            
  1003.             var TextGlowFilter2 = new GlowFilter(0x000000, 1, 5, 5, .5, 1, false, false);
  1004.             ChatClass.ChatBox.filters = [TextGlowFilter2];
  1005.            
  1006.             ChatClass.ChatBox.x = 250-AlignX;
  1007.             ChatClass.ChatBox.y = 500-AlignY;
  1008.            
  1009.             ChatClass.ChatBox.width = 300;
  1010.             ChatClass.ChatBox.height = 20;
  1011.            
  1012.             ChatClass.ChatBox.border = true;
  1013.             ChatClass.ChatBox.type = TextFieldType.INPUT;
  1014.             ChatClass.ChatBox.textColor = 0x000000;
  1015.            
  1016.             stage.addChild(ChatClass.ChatText);
  1017.            
  1018.             ChatClass.ChatText.embedFonts = true;
  1019.            
  1020.             var NameProperties2:TextFormat = new TextFormat();
  1021.             NameProperties2.font = myFont.fontName;
  1022.            
  1023.             ChatClass.ChatText.defaultTextFormat = NameProperties2;
  1024.            
  1025.             var TextGlowFilter = new GlowFilter(0x000000, 1, 5, 5, .5, 1, false, false);
  1026.             ChatClass.ChatText.filters = [TextGlowFilter];
  1027.            
  1028.             ChatClass.ChatText.x = 250-AlignX;
  1029.             ChatClass.ChatText.y = 300-AlignY;
  1030.            
  1031.             ChatClass.ChatText.width = 300;
  1032.             ChatClass.ChatText.height = 200;
  1033.            
  1034.             ChatClass.ChatText.border = true;
  1035.             ChatClass.ChatText.textColor = 0x000000;
  1036.             ChatClass.ChatText.multiline = true;
  1037.             ChatClass.ChatText.wordWrap = true;
  1038.            
  1039.             stage.addChild(ChatClass.ChatUsers);
  1040.            
  1041.             ChatClass.ChatUsers.embedFonts = true;
  1042.            
  1043.             var NameProperties3:TextFormat = new TextFormat();
  1044.             NameProperties3.font = myFont.fontName;
  1045.            
  1046.             ChatClass.ChatUsers.defaultTextFormat = NameProperties3;
  1047.            
  1048.             var TextGlowFilter3 = new GlowFilter(0x000000, 1, 5, 5, .5, 1, false, false);
  1049.             ChatClass.ChatUsers.filters = [TextGlowFilter3];
  1050.            
  1051.             ChatClass.ChatUsers.x = 550-AlignX;
  1052.             ChatClass.ChatUsers.y = 300-AlignY;
  1053.            
  1054.             ChatClass.ChatUsers.width = 60;
  1055.             ChatClass.ChatUsers.height = 220;
  1056.            
  1057.             ChatClass.ChatUsers.border = true;
  1058.            
  1059.             ChatClass.ChatUsers.textColor = 0x000000;
  1060.            
  1061.             stage.addChild(ShipClass.ShipColourBox);
  1062.            
  1063.             ShipClass.ShipColourBox.graphics.lineStyle(1, 0x333333);
  1064.             ShipClass.ShipColourBox.graphics.beginFill(0x999999);
  1065.            
  1066.             ShipClass.ShipColourBox.graphics.moveTo(100, 100);
  1067.             ShipClass.ShipColourBox.graphics.lineTo(700, 100);
  1068.             ShipClass.ShipColourBox.graphics.lineTo(700, 400);
  1069.             ShipClass.ShipColourBox.graphics.lineTo(100, 400);
  1070.             ShipClass.ShipColourBox.graphics.lineTo(100, 100);
  1071.            
  1072.             CreateModelShip(200, 150, 0x002002, 0x00FF16, 0x006B03);
  1073.             CreateModelShip(300, 150, 0x660033, 0xFF33CC, 0x990066);
  1074.             CreateModelShip(400, 150, 0xFF6600, 0xFF9900, 0xFF6600);
  1075.             CreateModelShip(500, 150, 0x000099, 0x0000FF, 0x000066);
  1076.             CreateModelShip(600, 150, 0xCCCC00, 0xFFFF00, 0x999900);
  1077.            
  1078.             ShipClass.ShipOutline = 0x002002;
  1079.             ShipClass.ShipFill = 0x00FF16;
  1080.             ShipClass.ShipDarkOutline = 0x006B03;
  1081.            
  1082.             stage.addChild(ShipClass.ShipChooser);
  1083.            
  1084.             ShipClass.ShipChooser.graphics.lineStyle(1, 0x333333);
  1085.             ShipClass.ShipChooser.graphics.beginFill(0x0000FF, .2);
  1086.            
  1087.             ShipClass.ShipChooser.graphics.lineTo(65, 0);
  1088.             ShipClass.ShipChooser.graphics.lineTo(65, 65);
  1089.             ShipClass.ShipChooser.graphics.lineTo(0, 65);
  1090.             ShipClass.ShipChooser.graphics.lineTo(0, 0);
  1091.            
  1092.             ShipClass.ShipChooser.x = ShipClass.ChoosingShipArray[0].x-22;
  1093.             ShipClass.ShipChooser.y = ShipClass.ChoosingShipArray[0].y-18;
  1094.            
  1095.             ShipClass.SecondDisplayTimer.addEventListener(TimerEvent.TIMER, SecondDisplay);
  1096.             ShipClass.SecondDisplayTimer.start();
  1097.            
  1098.             stage.addChild(ShipClass.DisplayWaitingTime);
  1099.            
  1100.             ShipClass.DisplayWaitingTime.embedFonts = true;
  1101.            
  1102.             var NameProperties4:TextFormat = new TextFormat();
  1103.             NameProperties4.font = myFont.fontName;
  1104.             NameProperties4.size = 15;
  1105.             NameProperties4.bold = true;
  1106.            
  1107.             ShipClass.DisplayWaitingTime.defaultTextFormat = NameProperties4;
  1108.            
  1109.             ShipClass.DisplayWaitingTime.x = 300;
  1110.             ShipClass.DisplayWaitingTime.y = 50;
  1111.            
  1112.             ShipClass.DisplayWaitingTime.width = 400;
  1113.             ShipClass.DisplayWaitingTime.height = 50;
  1114.            
  1115.             ShipClass.DisplayWaitingTime.text = "15 Seconds until the game starts";
  1116.             ShipClass.DisplayWaitingTime.textColor = 0xFFFFFF;
  1117.         }
  1118.        
  1119.         private function SecondDisplay(Timer:TimerEvent){
  1120.             if (ShipClass.WaitingTime <= 0 && AccountDetailsClass.Username == CurrentHoster){
  1121.                 ShipClass.SecondDisplayTimer.stop();
  1122.                 ConnectionClass.TheConnection.send("StartGame", "Game: Awesome", CurrentHoster, CurrentGame);
  1123.             }else{
  1124.                 ShipClass.SecondDisplayTimer.reset();
  1125.                 ShipClass.SecondDisplayTimer.start();
  1126.                
  1127.                 if (ShipClass.WaitingTime > 0){
  1128.                     ShipClass.WaitingTime--;
  1129.                 }
  1130.                 ShipClass.DisplayWaitingTime.text = ShipClass.WaitingTime + " Seconds until the game starts";
  1131.             }
  1132.         }
  1133.        
  1134.         private function CreateModelShip(X:int, Y:int, ColourOutline:int, ColourFill:int, DarkOutlineColour:int){
  1135.             var NewShip:MovieClip = new MovieClip();
  1136.            
  1137.             NewShip.x = X;
  1138.             NewShip.y = Y;
  1139.            
  1140.             var distanceX:Number = 0;
  1141.            
  1142.             NewShip.graphics.clear();
  1143.  
  1144.  
  1145.            
  1146.             NewShip.graphics.lineStyle(1, ColourOutline, .5);
  1147.             NewShip.graphics.beginFill(ColourFill, .5);
  1148.            
  1149.             //Creating the basic shape of the NewShip
  1150.             NewShip.graphics.lineTo(25-distanceX, 0-distanceX);
  1151.             NewShip.graphics.lineTo(55-distanceX, 25-distanceX);
  1152.             NewShip.graphics.lineTo(-25+distanceX, 25+distanceX);
  1153.             NewShip.graphics.lineTo(0, 0);
  1154.            
  1155.             //Creating shading to the back of the NewShip
  1156.             NewShip.graphics.beginFill(DarkOutlineColour, .4);
  1157.             NewShip.graphics.lineStyle(1, DarkOutlineColour, .4);
  1158.             NewShip.graphics.moveTo(-20+distanceX, 20+distanceX);
  1159.             NewShip.graphics.lineTo(50-distanceX, 20-distanceX);
  1160.             NewShip.graphics.lineTo(55-distanceX, 25-distanceX);
  1161.             NewShip.graphics.lineTo(-25+distanceX, 25+distanceX);
  1162.            
  1163.             //Creating Back model of the NewShip
  1164.             NewShip.graphics.beginFill(0x930000);
  1165.             NewShip.graphics.lineStyle(1, ColourOutline, .8);
  1166.             NewShip.graphics.moveTo(55-distanceX, 25-distanceX);
  1167.             NewShip.graphics.lineTo(55-distanceX, 32-distanceX);
  1168.             NewShip.graphics.lineTo(-25+distanceX, 32+distanceX);
  1169.             NewShip.graphics.lineTo(-25+distanceX, 25+distanceX);
  1170.            
  1171.             //Creating the right missle on the NewShip
  1172.             NewShip.graphics.beginFill(ColourFill, .5);
  1173.             NewShip.graphics.lineStyle(1, ColourOutline, .5);
  1174.             NewShip.graphics.moveTo(33-distanceX, 5-distanceX);
  1175.             NewShip.graphics.lineTo(50-distanceX, 5-distanceX);
  1176.             NewShip.graphics.lineTo(55-distanceX, 25-distanceX);
  1177.             NewShip.graphics.lineTo(33-distanceX, 5-distanceX);
  1178.        
  1179.             //Creating the left missle on the NewShip
  1180.             NewShip.graphics.beginFill(ColourFill, .5);
  1181.             NewShip.graphics.lineStyle(1, ColourOutline, .5);
  1182.             NewShip.graphics.moveTo(-4, 5);
  1183.             NewShip.graphics.lineTo(-21+distanceX, 5+distanceX);
  1184.             NewShip.graphics.lineTo(-26+distanceX, 25+distanceX);
  1185.             NewShip.graphics.lineTo(-4, 5);
  1186.            
  1187.             NewShip.scaleX = .7;
  1188.             NewShip.scaleY = .7;
  1189.            
  1190.             stage.addChild(NewShip);
  1191.            
  1192.             ShipClass.ChoosingShipArray.push(NewShip);
  1193.            
  1194.             ShipClass.ChoosingShipArray[ShipClass.ChoosingShipArray.length-1].Outline = ColourOutline;
  1195.             ShipClass.ChoosingShipArray[ShipClass.ChoosingShipArray.length-1].Fill = ColourFill;
  1196.             ShipClass.ChoosingShipArray[ShipClass.ChoosingShipArray.length-1].DarkOutline = DarkOutlineColour;
  1197.         }
  1198.        
  1199.         private function CreateEvents():void{
  1200.             this.addEventListener(Event.ENTER_FRAME, EnterFrameFunction);
  1201.             stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyIsDown);
  1202.             stage.addEventListener(MouseEvent.MOUSE_DOWN, MouseIsDown);
  1203.             stage.addEventListener(MouseEvent.MOUSE_UP, MouseIsUp);
  1204.             KeyCombination.addEventListener(TimerEvent.TIMER, StartCombination);
  1205.             GodModeOnTimer.addEventListener(TimerEvent.TIMER, GodModeOnStart);
  1206.             GodModeOffTimer.addEventListener(TimerEvent.TIMER, GodModeOffStart);
  1207.             SearchGameTimer.addEventListener(TimerEvent.TIMER, SearchingGameAgain);
  1208.         }
  1209.        
  1210.         private function StartCombination(Timer:TimerEvent){
  1211.             KeyCombination.reset();
  1212.             KeyCombination.stop();
  1213.             NextKey = 0;
  1214.         }
  1215.        
  1216.         private function GodModeOnStart(Timer:TimerEvent){
  1217.             GodModeOnTimer.reset();
  1218.             GodModeOnTimer.stop();
  1219.             NextKey2 = 0;
  1220.         }
  1221.        
  1222.         private function GodModeOffStart(Timer:TimerEvent){
  1223.             GodModeOffTimer.reset();
  1224.             GodModeOffTimer.stop();
  1225.             NextKey3 = 0;
  1226.         }
  1227.        
  1228.         private function KeyIsDown(ev:KeyboardEvent){
  1229.             //ToBeRemoved
  1230.             if (ev.keyCode == 39){
  1231.                 if (CurrentGame.substring(0, 6) == "Room: "){
  1232.                     ShipClass.WaitingTime = 0;
  1233.                 }
  1234.             }
  1235.             //ToBeRemovedEnd
  1236.            
  1237.             if (ev.keyCode == 13){
  1238.                 if (ConnectionClass.Connected){
  1239.                     if (stage.focus == ChatClass.ChatBox){
  1240.                         SendMessage();
  1241.                     }
  1242.                     if (CurrentGame != "Chatroom"){
  1243.                         if (CurrentGame.substring(0, 6) == "Game: "){
  1244.                             if (ChatClass.ChatVisible){
  1245.                                 if (ChatClass.ChatBox.text != ""){
  1246.                                     SendMessage();
  1247.                                 }
  1248.                                 stage.focus = stage;
  1249.                                 stage.removeChild(ChatClass.ChatBox);
  1250.                                 ChatClass.ChatVisible = false;
  1251.                             }else{
  1252.                                 CreateInGameChat("ChatBox");
  1253.                                 ChatClass.ChatVisible = true;
  1254.                             }
  1255.                         }else if (CurrentGame.substring(0, 6) == "Room: " && ChatClass.ChatBox.text != ""){
  1256.                             SendMessage();
  1257.                         }
  1258.                     }else if (ChatClass.ChatBox.text != ""){
  1259.                         SendMessage();
  1260.                     }
  1261.                 }
  1262.             }
  1263.            
  1264.             if (CurrentGame.substring(0, 6) == "Game: " && !ChatClass.ChatVisible){
  1265.                 if (NextKey >= CombinationKeys.length-1){
  1266.                     NextKey = 0;
  1267.                     KeyCombination.reset();
  1268.                     KeyCombination.stop();
  1269.                     HealthClass.Health = HealthClass.MaxHealth;
  1270.                 }
  1271.                
  1272.                 if (ev.keyCode == CombinationKeys[NextKey]){
  1273.                     KeyCombination.start();
  1274.                     NextKey++;
  1275.                 }else{
  1276.                     NextKey = 0;
  1277.                     KeyCombination.reset();
  1278.                     KeyCombination.stop();
  1279.                 }
  1280.             }
  1281.            
  1282.             if (CurrentGame.substring(0, 6) == "Game: " && !ChatClass.ChatVisible){
  1283.                 if (NextKey2 >= GodModeOnKeys.length-1){
  1284.                     NextKey2 = 0;
  1285.                     GodModeOnTimer.reset();
  1286.                     GodModeOnTimer.stop();
  1287.                     HealthClass.Invincible = true;
  1288.                 }
  1289.                
  1290.                 if (ev.keyCode == GodModeOnKeys[NextKey2]){
  1291.                     GodModeOnTimer.start();
  1292.                     NextKey2++;
  1293.                 }else{
  1294.                     NextKey2 = 0;
  1295.                     GodModeOnTimer.reset();
  1296.                     GodModeOnTimer.stop();
  1297.                 }
  1298.             }
  1299.            
  1300.             if (CurrentGame.substring(0, 6) == "Game: " && !ChatClass.ChatVisible){
  1301.                 if (NextKey3 >= GodModeOffKeys.length-1){
  1302.                     NextKey3 = 0;
  1303.                     GodModeOffTimer.reset();
  1304.                     GodModeOffTimer.stop();
  1305.                     HealthClass.Invincible = false;
  1306.                 }
  1307.                
  1308.                 if (ev.keyCode == GodModeOffKeys[NextKey3]){
  1309.                     GodModeOffTimer.start();
  1310.                     NextKey3++;
  1311.                 }else{
  1312.                     NextKey3 = 0;
  1313.                     GodModeOffTimer.reset();
  1314.                     GodModeOffTimer.stop();
  1315.                 }
  1316.             }
  1317.            
  1318.             if (CurrentGame.substring(0, 6) == "Game: "){
  1319.                 switch(ev.keyCode){
  1320.                     case 49:
  1321.                     if (HealthClass.Mana >= 20){
  1322.                         if (SpellClass.CastSpell){
  1323.                             stage.removeChild(SpellClass.CastingScroll);
  1324.                             stage.removeChild(SpellClass.CastingBar);
  1325.                             stage.removeChild(SpellClass.CastingText);
  1326.                         }
  1327.                         spellClass.CreateCastingBar("Casting Heal Allies");
  1328.                         SpellClass.CastSpell = true;
  1329.                         SpellClass.CastingTime = .1;
  1330.                         SpellClass.CurrentSpell = "Heal";
  1331.                        
  1332.                         spellClass.CreateCastingCircles(5, 0x00FF00);
  1333.                     }
  1334.                     break;
  1335.                     case 50:
  1336.                     if (HealthClass.Mana >= 100){
  1337.                         if (SpellClass.CastSpell){
  1338.                             stage.removeChild(SpellClass.CastingScroll);
  1339.                             stage.removeChild(SpellClass.CastingBar);
  1340.                             stage.removeChild(SpellClass.CastingText);
  1341.                         }
  1342.                         spellClass.CreateCastingBar("Casting Laser Nuke");
  1343.                         SpellClass.CastSpell = true;
  1344.                         SpellClass.CastingTime = .02;
  1345.                         SpellClass.CurrentSpell = "ThunderArea";
  1346.                        
  1347.                         spellClass.CreateCastingCircles(10, 0x0000FF);
  1348.                     }
  1349.                     break;
  1350.                     case 51:
  1351.                     if (HealthClass.Mana >= 65){
  1352.                         if (SpellClass.CastSpell){
  1353.                             stage.removeChild(SpellClass.CastingScroll);
  1354.                             stage.removeChild(SpellClass.CastingBar);
  1355.                             stage.removeChild(SpellClass.CastingText);
  1356.                         }
  1357.                         spellClass.CreateCastingBar("Casting Holy Shield");
  1358.                         SpellClass.CastSpell = true;
  1359.                         SpellClass.CastingTime = .2;
  1360.                         SpellClass.CurrentSpell = "HolyShield";
  1361.                        
  1362.                         spellClass.CreateCastingCircles(7, 0xFFFFFF);
  1363.                     }
  1364.                     break;
  1365.                 }
  1366.             }
  1367.         }
  1368.        
  1369.         private function SendMessage():void{
  1370.             var NameAccepted = "";
  1371.             for (var i:uint = 0; i < FriendsClass.OnlineUsers.length; i++){
  1372.                 if (ChatClass.ChatBox.text == "/UFST:" + FriendsClass.OnlineUsers[i]){
  1373.                     NameAccepted = FriendsClass.OnlineUsers[i];
  1374.                     break;
  1375.                 }
  1376.             }
  1377.            
  1378.             if (ChatClass.ChatBox.text == "/usersOnline"){
  1379.                 var AllUsers:String = "";
  1380.                
  1381.                 for (var c:uint = 0; c < FriendsClass.OnlineUsers.length; c++){
  1382.                     AllUsers += FriendsClass.OnlineUsers[c];
  1383.                    
  1384.                     if (c != FriendsClass.OnlineUsers.length-1){
  1385.                         AllUsers += ", ";
  1386.                     }
  1387.                 }
  1388.                
  1389.                 ConnectionClass.TheConnection.send("ChatMessage", AllUsers, AccountDetailsClass.Username);
  1390.             }else{
  1391.                 if (ChatClass.ChatBox.text.substring(0, 3) == "/me"){
  1392.                     ConnectionClass.TheConnection.send("ChatMessage", AccountDetailsClass.Username + ChatClass.ChatBox.text.substring(3, ChatClass.ChatBox.length), AccountDetailsClass.Username);
  1393.                 }else{
  1394.                     ConnectionClass.TheConnection.send("ChatMessage", "[" + AccountDetailsClass.Username + "] " + ChatClass.ChatBox.text, AccountDetailsClass.Username);
  1395.                 }
  1396.                 ChatClass.ChatBox.text = "";
  1397.             }
  1398.         }
  1399.        
  1400.         private function LogIn(TheMessage:String):void{
  1401.             AccountDetailsClass.Username = LoginClass.EnterName.text.toUpperCase();
  1402.             AccountDetailsClass.Password = LoginClass.EnterPassword.text.toUpperCase();
  1403.             PlayerIOConnect();
  1404.             ConnectionClass.Connected = true;
  1405.             loginClass.RemoveLogin();
  1406.             CreateConnectingBox(TheMessage);
  1407.            
  1408.             for (var j:uint = 0; j < ChatClass.ModList.length; j++){
  1409.                 if (LoginClass.EnterName.text == ChatClass.ModList[j]){
  1410.                     ChatClass.Mod = true;
  1411.                     break;
  1412.                 }
  1413.             }
  1414.         }
  1415.        
  1416.         private function RandomNumber(Small:int, Big:int){
  1417.             var TheRandomNumber:int = Math.floor(Math.random() * (Small - Big)) + Small;
  1418.             return TheRandomNumber;
  1419.         }
  1420.        
  1421.         private function SearchingTime(Event:TimerEvent){
  1422.             MenuClass.TimeSearcher.reset();
  1423.             MenuClass.TimeSearcher.start();
  1424.             MenuClass.TimeSearched++;
  1425.            
  1426.             var CurrentTime:String = "";
  1427.            
  1428.             if (MenuClass.TimeSearched == 60){
  1429.                 MenuClass.TimeSearched = 100;
  1430.             }
  1431.            
  1432.             switch(MenuClass.TimeSearched){
  1433.                 case 160:
  1434.                 MenuClass.TimeSearched = 200;
  1435.                 break;
  1436.                 case 260:
  1437.                 MenuClass.TimeSearched = 300;
  1438.                 break;
  1439.                 case 360:
  1440.                 MenuClass.TimeSearched = 400;
  1441.                 break;
  1442.                 case 460:
  1443.                 MenuClass.TimeSearched = 500;
  1444.                 break;
  1445.                 case 560:
  1446.                 MenuClass.TimeSearched = 600;
  1447.                 break;
  1448.                 case 660:
  1449.                 MenuClass.TimeSearched = 700;
  1450.                 break;
  1451.                 case 760:
  1452.                 MenuClass.TimeSearched = 800;
  1453.                 break;
  1454.                 case 860:
  1455.                 MenuClass.TimeSearched = 900;
  1456.                 break;
  1457.                 case 960:
  1458.                 MenuClass.TimeSearched = 1000;
  1459.                 break;
  1460.                 case 1600:
  1461.                 MenuClass.TimeSearched = 2000;
  1462.                 break;
  1463.                 case 2600:
  1464.                 MenuClass.TimeSearched = 3000;
  1465.                 break;
  1466.                 case 3600:
  1467.                 MenuClass.TimeSearched = 4000;
  1468.                 break;
  1469.                 case 4600:
  1470.                 MenuClass.TimeSearched = 5000;
  1471.                 break;
  1472.                 case 5600:
  1473.                 MenuClass.TimeSearched = 6000;
  1474.                 break;
  1475.                 case 6600:
  1476.                 MenuClass.TimeSearched = 7000;
  1477.                 break;
  1478.                 case 7600:
  1479.                 MenuClass.TimeSearched = 8000;
  1480.                 break;
  1481.                 case 8600:
  1482.                 MenuClass.TimeSearched = 9000;
  1483.                 break;
  1484.                 case 9600:
  1485.                 MenuClass.TimeSearched = 10000;
  1486.                 break;
  1487.             }
  1488.            
  1489.             if (MenuClass.TimeSearched == 600){
  1490.                 MenuClass.TimeSearched = 1000;
  1491.             }
  1492.            
  1493.             switch(String(MenuClass.TimeSearched).length){
  1494.                    case 1:
  1495.                    CurrentTime = "00:0" + String(MenuClass.TimeSearched);
  1496.                    break;
  1497.                    case 2:
  1498.                    CurrentTime = "00:" + String(MenuClass.TimeSearched);
  1499.                    break;
  1500.                    case 3:
  1501.                    CurrentTime = "0" + String(MenuClass.TimeSearched).substring(0, 1) + ":" + String(MenuClass.TimeSearched).substring(1, 2) + String(MenuClass.TimeSearched).substring(2, 3);
  1502.                    break;
  1503.                    case 4:
  1504.                    CurrentTime = String(MenuClass.TimeSearched).substring(0, 1) + String(MenuClass.TimeSearched).substring(1, 2) + ":" + String(MenuClass.TimeSearched).substring(2, 3) + String(MenuClass.TimeSearched).substring(3, 4);
  1505.                    break;
  1506.             }
  1507.             ConnectingText.text = "Searching for game...\nCurrent time searched: " + CurrentTime;
  1508.         }
  1509.        
  1510.         private function MouseIsDown(Event:MouseEvent){
  1511.             if (LoginClass.RegisterButton.hitTestPoint(stage.mouseX, stage.mouseY)){
  1512.                 if (LoginClass.RegisterText.text == "Done"){
  1513.                     if (LoginClass.EnterName.text != "Please enter your desired username" && LoginClass.EnterPassword.text != "Please enter your desired password"){
  1514.                         if (LoginClass.EnterName.text == ""){
  1515.                             CreateMessageBox("Error: Please type in your desired username");
  1516.                         }else if (LoginClass.EnterPassword.text == ""){
  1517.                             CreateMessageBox("Error: Please type in your desired password");
  1518.                         }else{
  1519.                             LoginClass.LoggingIn = false;
  1520.                             LogIn("Registering Account...");
  1521.                         }
  1522.                     }else{
  1523.                         if (LoginClass.RegisterText.text == "Done"){
  1524.                             CreateMessageBox("Error: Please type in desired username and password");
  1525.                         }
  1526.                     }
  1527.                 }else{
  1528.                     LoginClass.RegisterPage = true;
  1529.                     LoginClass.StaticEnterName.text = "Register for Titan's Nebula";
  1530.                     LoginClass.RegisterText.text = "Done";
  1531.                     LoginClass.EnterName.text = "Please enter your desired username";
  1532.                     LoginClass.EnterPassword.text = "Please enter your desired password";
  1533.                     LoginClass.EnterName.textColor = 0x9F9F9F;
  1534.                     LoginClass.EnterPassword.textColor = 0x9F9F9F;
  1535.                     LoginClass.EnterPassword.displayAsPassword = false;
  1536.                     loginClass.CreateBackButton();
  1537.                     loginClass.CreateBackButtonText();
  1538.                    
  1539.                     stage.removeChild(LoginClass.LoginButton);
  1540.                     stage.removeChild(LoginClass.LoginButtonText);
  1541.                 }
  1542.             }
  1543.            
  1544.             if (MenuClass.GameChooseJoin.hitTestPoint(stage.mouseX, stage.mouseY)){
  1545.                 CreateConnectingBox("Searching for game...\nCurrent time searched: 00:00");
  1546.                 MenuClass.TimeSearcher.addEventListener(TimerEvent.TIMER, SearchingTime);
  1547.                 MenuClass.TimeSearcher.start();
  1548.                 ConnectionClass.TheConnection.disconnect();
  1549.                 RoomName = "Info: " + AccountDetailsClass.Username;
  1550.                 CurrentGame = "Info: " + AccountDetailsClass.Username;
  1551.                 AccountDetailsClass.StoreUsername = AccountDetailsClass.Username;
  1552.                 AccountDetailsClass.Username = "StoreGameBot2000";
  1553.                 PlayerIOConnect();
  1554.             }
  1555.            
  1556.             if (FriendsClass.AddFriendsButton.hitTestPoint(stage.mouseX, stage.mouseY) && FriendsClass.FriendInputButton.stage == null){
  1557.                 friendsClass.CreateAddFriendBox();
  1558.             }
  1559.            
  1560.             if (FriendsClass.FriendInputButton.hitTestPoint(stage.mouseX, stage.mouseY)){
  1561.                 if (FriendsClass.Friends.indexOf(FriendsClass.FriendInput.text.toUpperCase()) != -1){
  1562.                     CreateMessageBox("You've already added " + FriendsClass.FriendInput.text.toUpperCase());
  1563.                 }else if (FriendsClass.FriendInput.text == ""){
  1564.                     CreateMessageBox("Error: Please type in a username");
  1565.                 }else{
  1566.                     ConnectionClass.TheConnection.disconnect();
  1567.                     AccountDetailsClass.StoreUsername = AccountDetailsClass.Username;
  1568.                     AccountDetailsClass.Username = FriendsClass.FriendInput.text.toUpperCase();
  1569.                     PlayerIOConnect();
  1570.                     CreateConnectingBox("Adding friend...");
  1571.                     MenuClass.SearchUser = true;
  1572.                 }
  1573.             }
  1574.            
  1575.             if (MenuClass.GameChooseCreate.hitTestPoint(stage.mouseX, stage.mouseY)){
  1576.                 menuClass.RemoveMenu();
  1577.                 CreateConnectingBox("Creating game...");
  1578.                 ConnectionClass.TheConnection.disconnect();
  1579.                 RoomName = "Crte: " + AccountDetailsClass.Username;
  1580.                 CurrentGame = "Crte: " + AccountDetailsClass.Username;
  1581.                 AccountDetailsClass.StoreUsername = AccountDetailsClass.Username;
  1582.                 AccountDetailsClass.Username = "StoreGameBot2000";
  1583.                 PlayerIOConnect();
  1584.                 CurrentHoster = AccountDetailsClass.StoreUsername;
  1585.             }
  1586.            
  1587.             if (!MenuClass.GameChooseBox.hitTestPoint(stage.mouseX, stage.mouseY) && MenuClass.GameChooseBox.stage != null){
  1588.                 menuClass.RemoveGameChooseBox();
  1589.             }
  1590.            
  1591.             if (MenuClass.PlayButton.hitTestPoint(stage.mouseX, stage.mouseY)){
  1592.                 menuClass.CreateGameChoose();
  1593.             }
  1594.            
  1595.             if (LoginClass.LoginButton.hitTestPoint(stage.mouseX, stage.mouseY)){
  1596.                 if (LoginClass.EnterName.text != "Please enter your username" && LoginClass.EnterPassword.text != "Please enter your password"){
  1597.                     if (LoginClass.EnterName.text == ""){
  1598.                         CreateMessageBox("Error: Please enter your username in the text field");
  1599.                     }else if (LoginClass.EnterPassword.text == ""){
  1600.                         CreateMessageBox("Error: Please enter your password in the text field");
  1601.                     }else{
  1602.                         LoginClass.LoggingIn = true;
  1603.                         LogIn("Logging In...");
  1604.                     }
  1605.                 }else{
  1606.                     CreateMessageBox("Error: Please type in your username and password");
  1607.                 }
  1608.             }
  1609.            
  1610.             if (LoginClass.BackButton.hitTestPoint(stage.mouseX, stage.mouseY)){
  1611.                 LoginClass.RegisterPage = false;
  1612.                 LoginClass.StaticEnterName.text = "Login to your Titan's Nebula Account";
  1613.                 LoginClass.RegisterText.text = "Register";
  1614.                 LoginClass.EnterName.text = "Please enter your username";
  1615.                 LoginClass.EnterPassword.text = "Please enter your password";
  1616.                 LoginClass.EnterPassword.displayAsPassword = false;
  1617.                 LoginClass.EnterName.textColor = 0x9F9F9F;
  1618.                 LoginClass.EnterPassword.textColor = 0x9F9F9F;
  1619.                
  1620.                 stage.removeChild(LoginClass.BackButton);
  1621.                 stage.removeChild(LoginClass.BackText);
  1622.                
  1623.                 loginClass.CreateLoginButton();
  1624.                 loginClass.CreateLoginButtonText();
  1625.             }
  1626.            
  1627.             if (MessageButton.hitTestPoint(stage.mouseX, stage.mouseY)){
  1628.                 RemoveMessageBox();
  1629.             }
  1630.            
  1631.             if (CloseWindow.hitTestPoint(stage.mouseX, stage.mouseY)){
  1632.                 RemoveConnectingBox();
  1633.             }
  1634.            
  1635.             if (CreateInGameButton.hitTestPoint(stage.mouseX, stage.mouseY) && GameNameText.text != "" && DescriptionText.text != "" && MaxPlayersText.text != ""){
  1636.                 RoomName = "Room: " + GameNameText.text;
  1637.                 CurrentDescription = DescriptionText.text;
  1638.                 CurrentGame = "Room: " + RoomName;
  1639.                 MaxPlayers = int(MaxPlayersText.text);
  1640.                 RemoveConnectingBox();
  1641.                 CurrentHoster = AccountDetailsClass.Username;
  1642.                 ConnectionClass.TheConnection.send("CreateGame", CurrentGame, CurrentDescription, AccountDetailsClass.Username, CurrentAmount+1, Coop, MaxPlayers, 0);
  1643.             }
  1644.            
  1645.             for (var p:uint = 0; p < ShipClass.ChoosingShipArray.length; p++){
  1646.                 if (ShipClass.ChoosingShipArray[p].hitTestPoint(stage.mouseX, stage.mouseY)){
  1647.                     ShipClass.ShipChooser.graphics.clear();
  1648.                    
  1649.                     ShipClass.ShipChooser.graphics.lineStyle(1, 0x333333);
  1650.                     ShipClass.ShipChooser.graphics.beginFill(0x0000FF, .2);
  1651.                    
  1652.                     ShipClass.ShipChooser.graphics.lineTo(65, 0);
  1653.                     ShipClass.ShipChooser.graphics.lineTo(65, 65);
  1654.                     ShipClass.ShipChooser.graphics.lineTo(0, 65);
  1655.                     ShipClass.ShipChooser.graphics.lineTo(0, 0);
  1656.                    
  1657.                     ShipClass.ShipChooser.x = ShipClass.ChoosingShipArray[p].x-22;
  1658.                     ShipClass.ShipChooser.y = ShipClass.ChoosingShipArray[p].y-18;
  1659.                    
  1660.                     ShipClass.ShipOutline = ShipClass.ChoosingShipArray[p].Outline;
  1661.                     ShipClass.ShipFill = ShipClass.ChoosingShipArray[p].Fill;
  1662.                     ShipClass.ShipDarkOutline = ShipClass.ChoosingShipArray[p].DarkOutline;
  1663.                 }
  1664.             }
  1665.            
  1666.             if (JoinGameButton.hitTestPoint(stage.mouseX, stage.mouseY)){
  1667.                 RoomName = LobbyGameDetails[CurrentGameSelected];
  1668.                 CurrentGame = RoomName;
  1669.                 CurrentHoster = LobbyGameDetails[CurrentGameSelected+2];
  1670.                 CurrentDescription = LobbyGameDetails[CurrentGameSelected+1];
  1671.                 Coop = LobbyGameDetails[CurrentGameSelected+3];
  1672.                 ConnectionClass.TheConnection.send("SendLobbyDetails");
  1673.                 JoiningGame = true;
  1674.             }
  1675.            
  1676.             if (StartGameButton.hitTestPoint(stage.mouseX, stage.mouseY) && FriendsClass.OnlineUsers.length > 0){
  1677.                 ConnectionClass.TheConnection.send("StartGame", RoomName, CurrentHoster, RoomName);
  1678.             }
  1679.            
  1680.             if (LobbyButton.hitTestPoint(stage.mouseX, stage.mouseY) && LobbyButton.stage != null){
  1681.                 RemoveChat();
  1682.                 ConnectionClass.TheConnection.disconnect();
  1683.                 PlayerIOConnect();
  1684.                 CurrentGame = "Lobby1";
  1685.                 RoomName = "Lobby1";
  1686.                 CreateConnectingBox("Rejoining Lobby...");
  1687.                 MenuClass.JoiningMenu = true;
  1688.             }
  1689.            
  1690.             if (MapTypeOptionBox.hitTestPoint(stage.mouseX, stage.mouseY)){
  1691.                 MapTypeOptionBox.graphics.clear();
  1692.                 MapTypeOptionBox.graphics.lineStyle(1, 0x333333);
  1693.                 MapTypeOptionBox.graphics.beginFill(0x999999);
  1694.                
  1695.                 MapTypeOptionBox.graphics.lineTo(40, 0);
  1696.                 MapTypeOptionBox.graphics.lineTo(40, 25);
  1697.                 MapTypeOptionBox.graphics.lineTo(0, 25);
  1698.                 MapTypeOptionBox.graphics.lineTo(0, 0);
  1699.                
  1700.                 MapTypeOptionBox.graphics.lineStyle(1, 0x333333);
  1701.                 MapTypeOptionBox.graphics.beginFill(0x000000);
  1702.                
  1703.                 MapTypeOptionBox.graphics.moveTo(5, 5);
  1704.                 MapTypeOptionBox.graphics.lineTo(35, 5);
  1705.                 MapTypeOptionBox.graphics.lineTo(35, 20);
  1706.                 MapTypeOptionBox.graphics.lineTo(5, 20);
  1707.                 MapTypeOptionBox.graphics.lineTo(5, 5);
  1708.                
  1709.                 SecondMapOptionBox.graphics.clear();
  1710.                 SecondMapOptionBox.graphics.lineStyle(1, 0x333333);
  1711.                 SecondMapOptionBox.graphics.beginFill(0x999999);
  1712.                
  1713.                 SecondMapOptionBox.graphics.lineTo(40, 0);
  1714.                 SecondMapOptionBox.graphics.lineTo(40, 25);
  1715.                 SecondMapOptionBox.graphics.lineTo(0, 25);
  1716.                 SecondMapOptionBox.graphics.lineTo(0, 0);
  1717.                
  1718.                 Coop = true;
  1719.             }
  1720.            
  1721.             if (SecondMapOptionBox.hitTestPoint(stage.mouseX, stage.mouseY)){
  1722.                 SecondMapOptionBox.graphics.clear();
  1723.                 SecondMapOptionBox.graphics.lineStyle(1, 0x333333);
  1724.                 SecondMapOptionBox.graphics.beginFill(0x999999);
  1725.                
  1726.                 SecondMapOptionBox.graphics.lineTo(40, 0);
  1727.                 SecondMapOptionBox.graphics.lineTo(40, 25);
  1728.                 SecondMapOptionBox.graphics.lineTo(0, 25);
  1729.                 SecondMapOptionBox.graphics.lineTo(0, 0);
  1730.                
  1731.                 SecondMapOptionBox.graphics.lineStyle(1, 0x333333);
  1732.                 SecondMapOptionBox.graphics.beginFill(0x000000);
  1733.                
  1734.                 SecondMapOptionBox.graphics.moveTo(5, 5);
  1735.                 SecondMapOptionBox.graphics.lineTo(35, 5);
  1736.                 SecondMapOptionBox.graphics.lineTo(35, 20);
  1737.                 SecondMapOptionBox.graphics.lineTo(5, 20);
  1738.                 SecondMapOptionBox.graphics.lineTo(5, 5);
  1739.                
  1740.                 MapTypeOptionBox.graphics.clear();
  1741.                 MapTypeOptionBox.graphics.lineStyle(1, 0x333333);
  1742.                 MapTypeOptionBox.graphics.beginFill(0x999999);
  1743.                
  1744.                 MapTypeOptionBox.graphics.lineTo(40, 0);
  1745.                 MapTypeOptionBox.graphics.lineTo(40, 25);
  1746.                 MapTypeOptionBox.graphics.lineTo(0, 25);
  1747.                 MapTypeOptionBox.graphics.lineTo(0, 0);
  1748.                
  1749.                 Coop = false;
  1750.             }
  1751.            
  1752.             if (!HealthClass.Reviving && !PauseGame){
  1753.                 ShipClass.Shooting = true;
  1754.                 ShipClass.BulletTimer.start();
  1755.             }
  1756.         }
  1757.        
  1758.         private function MouseIsUp(Event:MouseEvent){
  1759.             DraggingGame = false;
  1760.             DraggingWindow = false;
  1761.            
  1762.             if (!PauseGame){
  1763.                 ShipClass.Shooting = false;
  1764.                 ShipClass.BulletTimer.reset();
  1765.                 ShipClass.BulletTimer.stop();
  1766.             }
  1767.         }
  1768.        
  1769.         private function EnterFrameFunction(event:Event){
  1770.             if (SpellClass.CastSpell){
  1771.                 SpellClass.CastingScroll.scaleX += SpellClass.CastingTime;
  1772.                
  1773.                 for (var g:uint = 0; g < SpellClass.CastingCircleArray.length; g++){
  1774.                     if (g > SpellClass.CastingCircleArray.length/2){
  1775.                         SpellClass.CastingCircleArray[g].degrees = SpellClass.CastingCircleArray[g].degrees + 20;
  1776.                     }else{
  1777.                         SpellClass.CastingCircleArray[g].degrees = SpellClass.CastingCircleArray[g].degrees - 20;
  1778.                     }
  1779.                     var radians = SpellClass.CastingCircleArray[g].degrees * Math.PI / 180;
  1780.                     SpellClass.CastingCircleArray[g].x += Math.sin(radians) * SpellClass.CastingCircleArray[g].radius;
  1781.                     SpellClass.CastingCircleArray[g].y += Math.cos(radians) * SpellClass.CastingCircleArray[g].radius;
  1782.                    
  1783.                     SpellClass.CastingCircleArray[g].alpha -= SpellClass.CastingTime;
  1784.                    
  1785.                     particleClass.CreateTrail(SpellClass.CastingCircleArray[g].Colour, "PlayerThrust", SpellClass.CastingCircleArray[g].x, SpellClass.CastingCircleArray[g].y);
  1786.                 }
  1787.                
  1788.                 if (SpellClass.CastingScroll.scaleX >= 1){
  1789.                     SpellClass.CastingScroll.scaleX = 0;
  1790.                     stage.removeChild(SpellClass.CastingScroll);
  1791.                     stage.removeChild(SpellClass.CastingBar);
  1792.                     stage.removeChild(SpellClass.CastingText);
  1793.                     spellClass.CreateSpell(SpellClass.CurrentSpell);
  1794.                     SpellClass.CurrentSpell = "";
  1795.                     SpellClass.CastSpell = false;
  1796.                    
  1797.                     for (var d:uint = SpellClass.CastingCircleArray.length-1; d > -1; d--){
  1798.                         stage.removeChild(SpellClass.CastingCircleArray[d]);
  1799.                         SpellClass.CastingCircleArray.splice(d, 1);
  1800.                     }
  1801.                 }
  1802.             }
  1803.            
  1804.             if (SpellClass.ThunderSpellTimer.running){
  1805.                 SpellClass.NewLine.graphics.clear();
  1806.             }
  1807.            
  1808.             if (!PauseGame && !RejoinChat){
  1809.                 particleClass.CreateStars();
  1810.                                
  1811.                 ManageGameStatements();
  1812.                 ManageBulletLoop();
  1813.                 manageEnemyClass.ManageEnemyBulletLoop();
  1814.                 ManageParticleLoop();
  1815.                 ManageTrailLoop();
  1816.                 ManageTextLoop();
  1817.                 ManageStarLoop();
  1818.                 ManageUpgradesLoop();
  1819.                 manageEnemyClass.ManageEnemyLoop();
  1820.                
  1821.                 if (!HealthClass.Reviving){
  1822.                     if (stage.mouseX <= 850 || ShipClass.Ship.x <= 850){
  1823.                         if (stage.mouseX >= 0 || ShipClass.Ship.x >= 0){
  1824.                             if (stage.mouseY >= 0 || ShipClass.Ship.y >= 0){
  1825.                                 if (stage.mouseY <= 650 || ShipClass.Ship.y <= 650){
  1826.                                     MoveShip();
  1827.                                 }
  1828.                             }
  1829.                         }
  1830.                     }
  1831.                     particleClass.CreateTrail(ShipClass.ShipDarkOutline, "Thrust", 0, 0);
  1832.                 }
  1833.                
  1834.                 for (var b:uint = 0; b < ShipClass.ShipArray.length; b++){
  1835.                     if (ShipClass.ShipArray[b] != AccountDetailsClass.Username){
  1836.                         MovePlayerShip(b, ShipClass.TheSpeedX[b]);
  1837.                     }
  1838.                 }
  1839.             }
  1840.            
  1841.             if (CurrentGame.substring(0, 6) == "Game: "){
  1842.                 MoneyDisplay.text = String(AccountDetailsClass.Money);
  1843.                
  1844.                 MenuClass.TheBackground.y += 12;
  1845.                
  1846.                 if (MenuClass.TheBackground.y > 1400){
  1847.                     MenuClass.TheBackground.y = 20;
  1848.                 }
  1849.                
  1850.                 if (HealthClass.Mana < HealthClass.MaxMana){
  1851.                     HealthClass.Mana += .2;
  1852.                 }
  1853.                 HealthClass.ManaScroll.scaleX = (HealthClass.Mana/HealthClass.MaxMana);
  1854.                 HealthClass.HealthScroll.scaleX = (HealthClass.Health/HealthClass.MaxHealth);
  1855.             }
  1856.            
  1857.             if (FadeMusic){
  1858.                 MusicTransform.volume = MusicVolume;
  1859.                 MusicChannel.soundTransform = MusicTransform;
  1860.                
  1861.                 MusicVolume -= .02;
  1862.                
  1863.                 if (MusicVolume <= 0){
  1864.                     FadeMusic = false;
  1865.                 }
  1866.             }
  1867.            
  1868.             var LoginBoxText:String = "";
  1869.             var PasswordBoxText:String = "";
  1870.                
  1871.             if (LoginClass.RegisterPage){
  1872.                 LoginBoxText = "Please enter your desired username";
  1873.                 PasswordBoxText = "Please enter your desired password";
  1874.             }else{
  1875.                 LoginBoxText = "Please enter your username";
  1876.                 PasswordBoxText = "Please enter your password";
  1877.             }
  1878.            
  1879.             if (stage.focus != LoginClass.EnterName && LoginClass.EnterName.text == ""){
  1880.                 LoginClass.EnterName.text = LoginBoxText;
  1881.                 LoginClass.EnterName.textColor = 0x9F9F9F;
  1882.                 LoginClass.EnterName.maxChars = 200;
  1883.             }else if (stage.focus == LoginClass.EnterName){
  1884.                 if (LoginClass.EnterName.text == LoginBoxText){
  1885.                     LoginClass.EnterName.text = "";
  1886.                     LoginClass.EnterName.textColor = 0x000000;
  1887.                     LoginClass.EnterName.maxChars = 15;
  1888.                 }
  1889.             }
  1890.            
  1891.             if (stage.focus != LoginClass.EnterPassword && LoginClass.EnterPassword.text == ""){
  1892.                 LoginClass.EnterPassword.text = PasswordBoxText;
  1893.                 LoginClass.EnterPassword.textColor = 0x9F9F9F;
  1894.                 LoginClass.EnterPassword.maxChars = 200;
  1895.                 LoginClass.EnterPassword.displayAsPassword = false;
  1896.             }else if (stage.focus == LoginClass.EnterPassword){
  1897.                 if (LoginClass.EnterPassword.text == PasswordBoxText){
  1898.                     LoginClass.EnterPassword.text = "";
  1899.                     LoginClass.EnterPassword.textColor = 0x000000;
  1900.                     LoginClass.EnterPassword.maxChars = 20;
  1901.                     LoginClass.EnterPassword.displayAsPassword = true;
  1902.                 }
  1903.             }
  1904.            
  1905.             if (FriendsClass.FriendInput.stage != null){
  1906.                 if (stage.focus != FriendsClass.FriendInput && FriendsClass.FriendInput.text == ""){
  1907.                     FriendsClass.FriendInput.text = "Type in your friend's name";
  1908.                     FriendsClass.FriendInput.textColor = 0x333333;
  1909.                     FriendsClass.FriendInput.maxChars = 200;
  1910.                 }else if (stage.focus == FriendsClass.FriendInput){
  1911.                     if (FriendsClass.FriendInput.text == "Type in your friend's name"){
  1912.                         FriendsClass.FriendInput.text = "";
  1913.                         FriendsClass.FriendInput.textColor = 0x000000;
  1914.                         FriendsClass.FriendInput.maxChars = 20;
  1915.                     }
  1916.                 }
  1917.             }
  1918.            
  1919.             for (var p:uint = 0; p < FriendsClass.MouseOverGlowArray.length; p++){
  1920.                 if (FriendsClass.MouseOverGlowArray[p] != null){
  1921.                     if (FriendsClass.MouseOverGlowArray[p].hitTestPoint(stage.mouseX, stage.mouseY)){
  1922.                         var ButtonGlowFilter = new GlowFilter(FriendsClass.ColourGlowArray[p], 1, 10, 10, 1, 1, false, false);
  1923.                         FriendsClass.MouseOverGlowArray[p].filters = [ButtonGlowFilter];
  1924.                     }else{
  1925.                         FriendsClass.MouseOverGlowArray[p].filters = [];
  1926.                     }
  1927.                 }
  1928.             }
  1929.         }
  1930.        
  1931.         private function RemoveConnectingBox():void{
  1932.             if (FriendsClass.GreyScreen.stage != null){
  1933.                 stage.removeChild(FriendsClass.GreyScreen);
  1934.             }
  1935.             if (ConnectingBox.stage != null){
  1936.                 stage.removeChild(ConnectingBox);
  1937.             }
  1938.             if (ConnectingText.stage != null){
  1939.                 stage.removeChild(ConnectingText);
  1940.             }
  1941.            
  1942.             FriendsClass.GreyScreen.graphics.clear();
  1943.             ConnectingBox.graphics.clear();
  1944.             ConnectingText.text = "";
  1945.         }
  1946.        
  1947.         private function CreateConnectingBox(ConnectMessage):void{
  1948.             FriendsClass.GreyScreen.graphics.clear();
  1949.             ConnectingBox.graphics.clear();
  1950.            
  1951.             FriendsClass.GreyScreen.graphics.lineStyle(1, 0x333333);
  1952.             FriendsClass.GreyScreen.graphics.beginFill(0x999999);
  1953.            
  1954.             FriendsClass.GreyScreen.graphics.lineTo(850, 0);
  1955.             FriendsClass.GreyScreen.graphics.lineTo(850, 650);
  1956.             FriendsClass.GreyScreen.graphics.lineTo(0, 650);
  1957.             FriendsClass.GreyScreen.graphics.lineTo(0, 0);
  1958.            
  1959.             FriendsClass.GreyScreen.alpha = .5;
  1960.            
  1961.             stage.addChild(FriendsClass.GreyScreen);
  1962.            
  1963.             ConnectingBox.graphics.lineStyle(1, 0x333333);
  1964.             ConnectingBox.graphics.beginFill(0x999999);
  1965.            
  1966.             ConnectingBox.graphics.lineTo(250, 0);
  1967.             ConnectingBox.graphics.lineTo(250, 100);
  1968.             ConnectingBox.graphics.lineTo(0, 100);
  1969.             ConnectingBox.graphics.lineTo(0, 0);
  1970.            
  1971.             ConnectingBox.x = 300;
  1972.             ConnectingBox.y = 150;
  1973.            
  1974.             ConnectingBox.alpha = .8;
  1975.            
  1976.             stage.addChild(ConnectingBox);
  1977.  
  1978.             stage.addChild(ConnectingText);
  1979.            
  1980.             ConnectingText.embedFonts = true;
  1981.            
  1982.             var NameProperties:TextFormat = new TextFormat();
  1983.             NameProperties.font = myFont.fontName;
  1984.             NameProperties.align = "center";
  1985.            
  1986.             ConnectingText.defaultTextFormat = NameProperties;
  1987.            
  1988.             ConnectingText.x = 180;
  1989.             ConnectingText.y = 180;
  1990.            
  1991.             ConnectingText.width = 500;
  1992.             ConnectingText.height = 50;
  1993.            
  1994.             ConnectingText.selectable = false;
  1995.             ConnectingText.text = ConnectMessage;
  1996.         }
  1997.        
  1998.         private function CreateMessageBox(TheMessage):void{
  1999.             MessageBox.graphics.clear();
  2000.             MessageButton.graphics.clear();
  2001.            
  2002.             if (FriendsClass.GreyScreen.stage == null){
  2003.                 FriendsClass.GreyScreen.graphics.clear();
  2004.                            
  2005.                 FriendsClass.GreyScreen.graphics.lineStyle(1, 0x333333);
  2006.                 FriendsClass.GreyScreen.graphics.beginFill(0x999999);
  2007.                
  2008.                 FriendsClass.GreyScreen.graphics.lineTo(850, 0);
  2009.                 FriendsClass.GreyScreen.graphics.lineTo(850, 650);
  2010.                 FriendsClass.GreyScreen.graphics.lineTo(0, 650);
  2011.                 FriendsClass.GreyScreen.graphics.lineTo(0, 0);
  2012.                
  2013.                 FriendsClass.GreyScreen.alpha = .5;
  2014.                
  2015.                 stage.addChild(FriendsClass.GreyScreen);
  2016.             }
  2017.            
  2018.             MessageBox.graphics.lineStyle(1, 0x333333);
  2019.             MessageBox.graphics.beginFill(0x999999);
  2020.            
  2021.             MessageBox.graphics.lineTo(250, 0);
  2022.             MessageBox.graphics.lineTo(250, 150);
  2023.             MessageBox.graphics.lineTo(0, 150);
  2024.             MessageBox.graphics.lineTo(0, 0);
  2025.            
  2026.             MessageBox.x = 300;
  2027.             MessageBox.y = 150;
  2028.            
  2029.             MessageBox.alpha = .8;
  2030.            
  2031.             stage.addChild(MessageBox);
  2032.  
  2033.             stage.addChild(TheMessageText);
  2034.            
  2035.             TheMessageText.embedFonts = true;
  2036.            
  2037.             var NameProperties:TextFormat = new TextFormat();
  2038.             NameProperties.font = myFont.fontName;
  2039.             NameProperties.align = "center";
  2040.            
  2041.             TheMessageText.defaultTextFormat = NameProperties;
  2042.            
  2043.             TheMessageText.x = 320;
  2044.             TheMessageText.y = 180;
  2045.            
  2046.             TheMessageText.width = 200;
  2047.             TheMessageText.height = 200;
  2048.            
  2049.             TheMessageText.selectable = false;
  2050.             TheMessageText.text = TheMessage;
  2051.             TheMessageText.multiline = true;
  2052.             TheMessageText.wordWrap = true;
  2053.            
  2054.             MessageButton.graphics.lineStyle(1, 0x333333);
  2055.             MessageButton.graphics.beginFill(0x999999);
  2056.            
  2057.             MessageButton.graphics.lineTo(75, 0);
  2058.             MessageButton.graphics.lineTo(75, 25);
  2059.             MessageButton.graphics.lineTo(0, 25);
  2060.             MessageButton.graphics.lineTo(0, 0);
  2061.            
  2062.             MessageButton.x = 430;
  2063.             MessageButton.y = 260;
  2064.            
  2065.             MessageButton.alpha = .8;
  2066.            
  2067.             stage.addChild(MessageButton);
  2068.            
  2069.             FriendsClass.MouseOverGlowArray[3] = MessageButton;
  2070.             FriendsClass.ColourGlowArray[3] = 0xD2C400;
  2071.            
  2072.             stage.addChild(MessageButtonText);
  2073.            
  2074.             MessageButtonText.embedFonts = true;
  2075.            
  2076.             var NameProperties2:TextFormat = new TextFormat();
  2077.             NameProperties2.font = myFont.fontName;
  2078.            
  2079.             MessageButtonText.defaultTextFormat = NameProperties2;
  2080.            
  2081.             MessageButtonText.x = 450;
  2082.             MessageButtonText.y = 265;
  2083.            
  2084.             MessageButtonText.width = 500;
  2085.             MessageButtonText.height = 25;
  2086.            
  2087.             MessageButtonText.selectable = false;
  2088.             MessageButtonText.text = "Ok";
  2089.         }
  2090.        
  2091.         private function RemoveMessageBox():void{
  2092.             if (FriendsClass.GreyScreen.stage != null){
  2093.                 stage.removeChild(FriendsClass.GreyScreen);
  2094.             }
  2095.             stage.removeChild(MessageBox);
  2096.             stage.removeChild(TheMessageText);
  2097.             stage.removeChild(MessageButton);
  2098.             stage.removeChild(MessageButtonText);
  2099.             FriendsClass.GreyScreen.graphics.clear();
  2100.             MessageBox.graphics.clear();
  2101.             MessageButton.graphics.clear();
  2102.             TheMessageText.text = "";
  2103.             MessageButton.text = "";
  2104.         }
  2105.        
  2106.         private function CreateInGameChat(Amount:String):void{
  2107.             if (Amount != "ChatText"){
  2108.                 stage.addChild(ChatClass.ChatBox);
  2109.                
  2110.                 ChatClass.ChatBox.embedFonts = true;
  2111.                
  2112.                 var NameProperties:TextFormat = new TextFormat();
  2113.                 NameProperties.font = myFont.fontName;
  2114.                
  2115.                 ChatClass.ChatBox.defaultTextFormat = NameProperties;
  2116.                
  2117.                 ChatClass.ChatBox.x = 20;
  2118.                 ChatClass.ChatBox.y = 600;
  2119.                
  2120.                 ChatClass.ChatBox.width = 200;
  2121.                 ChatClass.ChatBox.height = 20;
  2122.                
  2123.                 ChatClass.ChatBox.border = true;
  2124.                 ChatClass.ChatBox.borderColor = 0xFFFFFF;
  2125.  
  2126.                 ChatClass.ChatBox.type = TextFieldType.INPUT;
  2127.                 ChatClass.ChatBox.textColor = 0xFFFFFF;
  2128.                 stage.focus = ChatClass.ChatBox;
  2129.             }
  2130.            
  2131.             if (Amount != "ChatBox"){
  2132.                 stage.addChild(ChatClass.ChatText);
  2133.                
  2134.                 ChatClass.ChatText.embedFonts = true;
  2135.                
  2136.                 var NameProperties2:TextFormat = new TextFormat();
  2137.                 NameProperties2.font = myFont.fontName;
  2138.                
  2139.                 ChatClass.ChatText.defaultTextFormat = NameProperties2;
  2140.                
  2141.                 ChatClass.ChatText.x = 620;
  2142.                 ChatClass.ChatText.y = 520;
  2143.                
  2144.                 ChatClass.ChatText.width = 200;
  2145.                 ChatClass.ChatText.height = 400;
  2146.                
  2147.                 ChatClass.ChatText.border = false;
  2148.                 ChatClass.ChatText.selectable = false;
  2149.                 ChatClass.ChatText.multiline = true;
  2150.                 ChatClass.ChatText.wordWrap = true;
  2151.                 ChatClass.ChatText.textColor = 0xFFFFFF;
  2152.             }
  2153.         }
  2154.        
  2155.         private function RemoveChat():void{
  2156.             stage.removeChild(ChatClass.ChatBox);
  2157.             stage.removeChild(ChatClass.ChatText);
  2158.             stage.removeChild(ChatClass.ChatUsers);
  2159.             stage.removeChild(ChatClass.ChatBoxFill);
  2160.             stage.removeChild(ChatClass.ChatTextFill);
  2161.             stage.removeChild(ChatClass.ChatUsersFill);
  2162.             if (AccountDetailsClass.Username == CurrentHoster){
  2163.                 stage.removeChild(StartGameButton);
  2164.                 stage.removeChild(StartGameText);
  2165.                 StartGameButton.graphics.clear();
  2166.             }
  2167.             stage.removeChild(LobbyButton);
  2168.             LobbyButton = new MovieClip();
  2169.             ChatClass.ChatBox.text = "";
  2170.             ChatClass.ChatText.text = "";
  2171.         }
  2172.        
  2173.         private function CreateStartGameButton():void{
  2174.             StartGameButton.graphics.lineStyle(1, 0x333333);
  2175.             StartGameButton.graphics.beginFill(0x999999);
  2176.            
  2177.             StartGameButton.graphics.lineTo(100, 0);
  2178.             StartGameButton.graphics.lineTo(100, 40);
  2179.             StartGameButton.graphics.lineTo(0, 40);
  2180.             StartGameButton.graphics.lineTo(0, 0);
  2181.            
  2182.             StartGameButton.x = 540;
  2183.             StartGameButton.y = 450;
  2184.            
  2185.             StartGameButton.alpha = .8;
  2186.            
  2187.             stage.addChild(StartGameButton);
  2188.  
  2189.             stage.addChild(StartGameText);
  2190.            
  2191.             StartGameText.embedFonts = true;
  2192.            
  2193.             var NameProperties3:TextFormat = new TextFormat();
  2194.             NameProperties3.font = myFont.fontName;
  2195.            
  2196.             StartGameText.defaultTextFormat = NameProperties3;
  2197.            
  2198.             StartGameText.x = 555;
  2199.             StartGameText.y = 455;
  2200.            
  2201.             StartGameText.width = 100;
  2202.             StartGameText.height = 25;
  2203.            
  2204.             StartGameText.selectable = false;
  2205.             StartGameText.text = "Start Game";
  2206.         }
  2207.        
  2208.         private function CreateMainGame():void{
  2209.             trace("Creating Game");
  2210.             stage.removeChild(MenuClass.BigPicture);
  2211.             trace("Removed BigPicture");
  2212.             stage.addChild(MenuClass.TheBackground);
  2213.             trace("Created TheBackground");
  2214.            
  2215.             DrawShip();
  2216.             trace("DrewShip");
  2217.             CreateHealthBar();
  2218.             trace("Created Health Bar");
  2219.             CreateManaBar();
  2220.             trace("Created Mana Bar");
  2221.             CreateSpellsBox("Heal", 50, 600);
  2222.             CreateSpellsBox("ThunderArea", 130, 600);
  2223.             CreateSpellsBox("HolyShield", 200, 600);
  2224.             trace("Created Spell Boxes");
  2225.             CreateGameEvents();
  2226.             trace("Created Game Events");
  2227.             particleClass.CreateText(200, 150, 30, "Prepare yourself for Wave 1", 0xA10097, 80, "Nothing");
  2228.             particleClass.CreateText(250, 200, 30, WaveClass.WaveNames[WaveClass.CurrentWave], 0xFFFFFF, 50, "Nothing");
  2229.             trace("Created Text");
  2230.             CreateMoneyText();
  2231.             trace("Created Money Text");
  2232.            
  2233.             MusicChannel = gameMusic.play(0, 99);
  2234.             MusicTransform.volume = 1;
  2235.             MusicChannel.soundTransform = MusicTransform;
  2236.            
  2237.             PauseGame = false;
  2238.             ShipClass.WaitingChat = false;
  2239.            
  2240.             stage.addChild(SpellClass.NewLine);
  2241.             CreateInGameChat("ChatText");
  2242.         }
  2243.        
  2244.         private function CreateGameEvents():void{
  2245.             EnemyClass.EnemyTimer.addEventListener(TimerEvent.TIMER, EnemyTimerComplete);
  2246.             ShipClass.BulletTimer.addEventListener(TimerEvent.TIMER, ShootBullet);
  2247.             HealthClass.ReviveTimer.addEventListener(TimerEvent.TIMER, ReviveShip);
  2248.             HealthClass.FlashTimer.addEventListener(TimerEvent.TIMER, FlashTimerComplete);
  2249.             ShipClass.MovementTimer.addEventListener(TimerEvent.TIMER, SendMovementConnections);
  2250.             WaveClass.NextWaveTimer.addEventListener(TimerEvent.TIMER, NextWave);
  2251.             EnemyClass.EndOfStageTimer.addEventListener(TimerEvent.TIMER, EndStage);
  2252.             WaveClass.NextWaveTimer.start();
  2253.             ShipClass.MovementTimer.start();
  2254.         }
  2255.        
  2256.         private function EndStage(Event:TimerEvent){
  2257.             EnemyClass.EndOfStageTimer.reset();
  2258.             EnemyClass.EndOfStageTimer.stop();
  2259.            
  2260.             stage.addChild(MenuClass.TitleBackground);
  2261.             MenuClass.TitleBackground.alpha = .2;
  2262.            
  2263.             EnemyClass.StageEnd = true;
  2264.             RejoinChat = true;
  2265.             ShipClass.MovementTimer.stop();
  2266.             EnemyClass.EnemyTimer.stop();
  2267.             ShipClass.BulletTimer.stop();
  2268.             HealthClass.ReviveTimer.stop();
  2269.             HealthClass.FlashTimer.stop();
  2270.             WaveClass.NextWaveTimer.stop();
  2271.             RemoveMainGame();
  2272.             RoomName = "Room: " + RoomName.substring(7, RoomName.length);
  2273.             CurrentGame = "Room: " + RoomName.substring(7, RoomName.length);
  2274.             CreateConnectingBox("Rejoining Chat...");
  2275.             ConnectionClass.TheConnection.disconnect();
  2276.             PlayerIOConnect();
  2277.         }
  2278.        
  2279.         private function RemoveMainGame():void{
  2280.             for (var j:int = ParticleClass.StarsArray.length-1; j > -1; j--){
  2281.                 stage.removeChild(ParticleClass.StarsArray[j]);
  2282.                 ParticleClass.StarsArray.splice(j, 1);
  2283.             }
  2284.            
  2285.             for (var i:int = EnemyClass.EnemyArray.length-1; i > -1; i--){
  2286.                 stage.removeChild(EnemyClass.EnemyArray[i]);
  2287.                 EnemyClass.EnemyArray.splice(i, 1);
  2288.             }
  2289.            
  2290.             for (var c:int = ShipClass.ShipArray.length-1; c > -1; c--){
  2291.                 stage.removeChild(ShipClass.ShipArray[c]);
  2292.                 ShipClass.ShipArray.splice(c, 1);
  2293.             }
  2294.            
  2295.             for (var l:int = ShipClass.BulletArray.length-1; l > -1; l--){
  2296.                 stage.removeChild(ShipClass.BulletArray[l]);
  2297.                 ShipClass.BulletArray.splice(l, 1);
  2298.             }
  2299.            
  2300.             for (var p:int = EnemyClass.EnemyBulletArray.length-1; p > -1; p--){
  2301.                 stage.removeChild(EnemyClass.EnemyBulletArray[p]);
  2302.                 EnemyClass.EnemyBulletArray.splice(p, 1);
  2303.             }
  2304.            
  2305.             for (var t:int = ParticleClass.TrailArray.length-1; t > -1; t--){
  2306.                 stage.removeChild(ParticleClass.TrailArray[t]);
  2307.                 ParticleClass.TrailArray.splice(t, 1);
  2308.             }
  2309.            
  2310.             for (var n:int = ParticleClass.TextArray.length-4; n > -1; n -= 4){
  2311.                 stage.removeChild(ParticleClass.TextArray[n]);
  2312.                 ParticleClass.TextArray.splice(n, 4);
  2313.             }
  2314.            
  2315.             stage.removeChild(ShipClass.Ship);
  2316.             stage.removeChild(MoneyDisplay);
  2317.             stage.removeChild(HealthClass.HealthScroll);
  2318.             stage.removeChild(HealthClass.HealthBar);
  2319.             stage.removeChild(MenuClass.TheBackground);
  2320.         }
  2321.        
  2322.         private function MoveShip():void{
  2323.             ShipClass.SpeedX = (stage.mouseX-ShipClass.Ship.x-12)/ShipClass.ShipSpeed;
  2324.             ShipClass.SpeedY = (stage.mouseY-ShipClass.Ship.y-12)/ShipClass.ShipSpeed/2;
  2325.            
  2326.             if (ShipClass.SpeedX >= ShipClass.maxSpeed){
  2327.                 ShipClass.SpeedX = ShipClass.maxSpeed;
  2328.             }
  2329.            
  2330.             if (ShipClass.SpeedY >= ShipClass.maxSpeed){
  2331.                 ShipClass.SpeedY = ShipClass.maxSpeed;
  2332.             }
  2333.            
  2334.             if (ShipClass.SpeedX <= -ShipClass.maxSpeed){
  2335.                 ShipClass.SpeedX = -ShipClass.maxSpeed;
  2336.             }
  2337.            
  2338.             if (ShipClass.SpeedY <= -ShipClass.maxSpeed){
  2339.                 ShipClass.SpeedY = -ShipClass.maxSpeed;
  2340.             }
  2341.            
  2342.             if (!SpellClass.CastSpell){
  2343.                 ShipClass.Ship.x += ShipClass.SpeedX;
  2344.                 ShipClass.Ship.y += ShipClass.SpeedY;
  2345.             }
  2346.            
  2347.             var distanceX:Number = 0;
  2348.             var dx = ShipClass.Ship.x-stage.mouseX;
  2349.            
  2350.             distanceX = Math.round(Math.sqrt((dx*dx)))/5-2;
  2351.            
  2352.             if (stage.mouseX >= ShipClass.Ship.x){
  2353.                 if (distanceX >= 20){
  2354.                     distanceX = 20;
  2355.                 }
  2356.             }else{
  2357.                 if (distanceX >= 10){
  2358.                     distanceX = 10;
  2359.                 }
  2360.             }
  2361.            
  2362.             if (SpellClass.CastSpell){
  2363.                 distanceX = 0;
  2364.                 ShipClass.SpeedX = 0;
  2365.             }
  2366.            
  2367.             ShipClass.Ship.graphics.clear();
  2368.            
  2369.             ShipClass.Ship.graphics.lineStyle(2, ShipClass.ShipOutline);
  2370.             ShipClass.Ship.graphics.beginFill(ShipClass.ShipFill, 1-Math.abs(ShipClass.SpeedX)/40);
  2371.            
  2372.             if (stage.mouseX <= ShipClass.Ship.x){
  2373.                 //Creating the basic shape of the ship
  2374.                 ShipClass.Ship.graphics.lineTo(25-distanceX, 0-distanceX);
  2375.                 ShipClass.Ship.graphics.lineTo(55-distanceX, 25-distanceX);
  2376.                 ShipClass.Ship.graphics.lineTo(-25+distanceX, 25+distanceX);
  2377.                 ShipClass.Ship.graphics.lineTo(0, 0);
  2378.                
  2379.                 //Creating shading to the back of the ship
  2380.                 ShipClass.Ship.graphics.beginFill(ShipClass.ShipDarkOutline, .8);
  2381.                 ShipClass.Ship.graphics.lineStyle(1, ShipClass.ShipDarkOutline, .8);
  2382.                 ShipClass.Ship.graphics.moveTo(-20+distanceX, 20+distanceX);
  2383.                 ShipClass.Ship.graphics.lineTo(50-distanceX, 20-distanceX);
  2384.                 ShipClass.Ship.graphics.lineTo(55-distanceX, 25-distanceX);
  2385.                 ShipClass.Ship.graphics.lineTo(-25+distanceX, 25+distanceX);
  2386.                
  2387.                 //Creating Back model of the ship
  2388.                 ShipClass.Ship.graphics.beginFill(ShipClass.BackShipColour, 1-Math.abs(ShipClass.SpeedX)/40);
  2389.                 ShipClass.Ship.graphics.lineStyle(1, ShipClass.ShipOutline, .8);
  2390.                 ShipClass.Ship.graphics.moveTo(55-distanceX, 25-distanceX);
  2391.                 ShipClass.Ship.graphics.lineTo(55-distanceX, 32-distanceX);
  2392.                 ShipClass.Ship.graphics.lineTo(-25+distanceX, 32+distanceX);
  2393.                 ShipClass.Ship.graphics.lineTo(-25+distanceX, 25+distanceX);
  2394.                
  2395.                 //Creating the right missle on the ship
  2396.                 ShipClass.Ship.graphics.beginFill(ShipClass.ShipFill, .8);
  2397.                 ShipClass.Ship.graphics.lineStyle(1, ShipClass.ShipOutline, 1-ShipClass.SpeedX/40);
  2398.                 ShipClass.Ship.graphics.moveTo(33-distanceX, 5-distanceX);
  2399.                 ShipClass.Ship.graphics.lineTo(50-distanceX, 5-distanceX);
  2400.                 ShipClass.Ship.graphics.lineTo(55-distanceX, 25-distanceX);
  2401.                 ShipClass.Ship.graphics.lineTo(33-distanceX, 5-distanceX);
  2402.                
  2403.                 //Creating the left missle on the ship
  2404.                 ShipClass.Ship.graphics.beginFill(ShipClass.ShipFill, 1-ShipClass.SpeedX/25);
  2405.                 ShipClass.Ship.graphics.lineStyle(1, ShipClass.ShipOutline, 1-ShipClass.SpeedX/25);
  2406.                 ShipClass.Ship.graphics.moveTo(-4, 5);
  2407.                 ShipClass.Ship.graphics.lineTo(-21+distanceX, 5+distanceX);
  2408.                 ShipClass.Ship.graphics.lineTo(-26+distanceX, 25+distanceX);
  2409.                 ShipClass.Ship.graphics.lineTo(-4, 5);
  2410.             }else{
  2411.                 distanceX = distanceX/1.8;
  2412.                 //Creating the left missle on the ship
  2413.                 ShipClass.Ship.graphics.beginFill(ShipClass.ShipFill, 1-Math.abs(ShipClass.SpeedX)/40);
  2414.                 ShipClass.Ship.graphics.lineStyle(1, ShipClass.ShipOutline, .8);
  2415.                 ShipClass.Ship.graphics.moveTo(-4+distanceX, 5-distanceX/2);
  2416.                 ShipClass.Ship.graphics.lineTo(-21+distanceX, 5-distanceX/2);
  2417.                 ShipClass.Ship.graphics.lineTo(-26+distanceX, 25-distanceX/2);
  2418.                 ShipClass.Ship.graphics.lineTo(-4+distanceX, 5-distanceX/2);
  2419.                
  2420.                 //Creating the basic shape of the ship
  2421.                 ShipClass.Ship.graphics.lineStyle(2, ShipClass.ShipOutline);
  2422.                 ShipClass.Ship.graphics.beginFill(ShipClass.ShipFill, 1-ShipClass.SpeedX/40);
  2423.                 ShipClass.Ship.graphics.moveTo(0, 0);
  2424.                 ShipClass.Ship.graphics.lineTo(25-distanceX, 0+distanceX);
  2425.                 ShipClass.Ship.graphics.lineTo(55-distanceX, 25+distanceX);
  2426.                 ShipClass.Ship.graphics.lineTo(-25+distanceX, 25-distanceX);
  2427.                 ShipClass.Ship.graphics.lineTo(0, 0);
  2428.                
  2429.                 //Creating shading to the back of the ship
  2430.                 ShipClass.Ship.graphics.beginFill(ShipClass.ShipDarkOutline, .8);
  2431.                 ShipClass.Ship.graphics.lineStyle(1, ShipClass.ShipDarkOutline, .8);
  2432.                 ShipClass.Ship.graphics.moveTo(-20+distanceX, 20-distanceX);
  2433.                 ShipClass.Ship.graphics.lineTo(50-distanceX, 20+distanceX);
  2434.                 ShipClass.Ship.graphics.lineTo(55-distanceX, 25+distanceX);
  2435.                 ShipClass.Ship.graphics.lineTo(-25+distanceX, 25-distanceX);
  2436.                
  2437.                 //Creating Back model of the ship
  2438.                 ShipClass.Ship.graphics.beginFill(ShipClass.BackShipColour, 1-ShipClass.SpeedX/40);
  2439.                 ShipClass.Ship.graphics.lineStyle(1, ShipClass.ShipOutline, .8);
  2440.                 ShipClass.Ship.graphics.moveTo(55-distanceX, 25+distanceX);
  2441.                 ShipClass.Ship.graphics.lineTo(55-distanceX, 32+distanceX);
  2442.                 ShipClass.Ship.graphics.lineTo(-25+distanceX, 32-distanceX);
  2443.                 ShipClass.Ship.graphics.lineTo(-25+distanceX, 25-distanceX);
  2444.                
  2445.                 //Creating the right missle on the ship
  2446.                 ShipClass.Ship.graphics.beginFill(ShipClass.ShipFill, 1-ShipClass.SpeedX/50);
  2447.                 ShipClass.Ship.graphics.lineStyle(1, ShipClass.ShipOutline, 1-ShipClass.SpeedX/50);
  2448.                 ShipClass.Ship.graphics.moveTo(33-distanceX, 5+distanceX);
  2449.                 ShipClass.Ship.graphics.lineTo(50-distanceX, 5+(distanceX*2));
  2450.                 ShipClass.Ship.graphics.lineTo(55-distanceX, 25+distanceX);
  2451.                 ShipClass.Ship.graphics.lineTo(33-distanceX, 5+distanceX);
  2452.             }
  2453.            
  2454.             ShipClass.Ship.scaleX = .7;
  2455.             ShipClass.Ship.scaleY = .7;
  2456.         }
  2457.        
  2458.         private function DrawShip():void{
  2459.             ShipClass.Ship.graphics.lineStyle(1, 0x00BD30);
  2460.            
  2461.             ShipClass.Ship.graphics.lineTo(25, 0);
  2462.             ShipClass.Ship.graphics.lineTo(55, 25);
  2463.             ShipClass.Ship.graphics.lineTo(-25, 25);
  2464.             ShipClass.Ship.graphics.lineTo(0, 0);
  2465.            
  2466.             stage.addChild(ShipClass.Ship);
  2467.            
  2468.             ShipClass.Ship.x = 300;
  2469.             ShipClass.Ship.y = 300;
  2470.         }
  2471.        
  2472.         private function CreateNewShip(TheUsername:String, ColourOutline:int, ColourFill:int, ColourDarkOutline:int):void{
  2473.             var ship:MovieClip = new MovieClip();
  2474.            
  2475.             ship.graphics.lineStyle(1, 0x00BD30);
  2476.            
  2477.             ship.graphics.lineTo(25, 0);
  2478.             ship.graphics.lineTo(55, 25);
  2479.             ship.graphics.lineTo(-25, 25);
  2480.             ship.graphics.lineTo(0, 0);
  2481.            
  2482.             stage.addChild(ship);
  2483.            
  2484.             ship.x = 300;
  2485.             ship.y = 300;
  2486.            
  2487.             ShipClass.ShipArray.push(ship);
  2488.             ShipClass.ShipArray[ShipClass.ShipArray.length-1].Username = TheUsername;
  2489.             ShipClass.ShipArray[ShipClass.ShipArray.length-1].Outline = ColourOutline;
  2490.             ShipClass.ShipArray[ShipClass.ShipArray.length-1].Fill = ColourFill;
  2491.             ShipClass.ShipArray[ShipClass.ShipArray.length-1].DarkOutline = ColourDarkOutline;
  2492.         }
  2493.        
  2494.         private function CreateBullet(Bunches:uint, X:int, Y:int, TheBulletType:String):void{
  2495.             trace("Creating Bullet");
  2496.             var Bullet:MovieClip = new MovieClip();
  2497.             var BulletGlowFilter;
  2498.             var BulletGlowFilter2;
  2499.            
  2500.             switch (TheBulletType){
  2501.                 case "RedLaser":
  2502.                 BulletGlowFilter = new GlowFilter(0xFF0000, 1, 10, 10, 1, 1, false, false);
  2503.                 Bullet.filters = [BulletGlowFilter];
  2504.                
  2505.                 Bullet.graphics.lineStyle(2, 0xFF0000);
  2506.                 Bullet.graphics.lineTo(0, 20);
  2507.                 break;
  2508.                 case "GoldBullet":
  2509.                 BulletGlowFilter = new GlowFilter(0xA87800, 1, 10, 10, 1, 1, false, false);
  2510.                 BulletGlowFilter2 = new GlowFilter(0xFFCC33, 1, 15, 15, 4, 1, true, false);
  2511.                 Bullet.filters = [BulletGlowFilter];
  2512.                
  2513.                 Bullet.graphics.lineStyle(2, 0xA87800);
  2514.                 Bullet.graphics.lineTo(5, 0);
  2515.                 Bullet.graphics.lineTo(5, 25);
  2516.                 Bullet.graphics.lineTo(0, 25);
  2517.                 Bullet.graphics.lineTo(0, 0);
  2518.                 break;
  2519.                 case "BlueBullet":
  2520.                 BulletGlowFilter = new GlowFilter(0x0006C2, 1, 10, 10, 1, 1, false, false);
  2521.                 Bullet.filters = [BulletGlowFilter];
  2522.                
  2523.                 Bullet.graphics.lineStyle(2, 0x0006C2);
  2524.                 Bullet.graphics.beginFill(0x0008E9);
  2525.                 Bullet.graphics.lineTo(5, 15);
  2526.                 Bullet.graphics.lineTo(10, 0);
  2527.                 Bullet.graphics.lineTo(5, -15);
  2528.                 Bullet.graphics.lineTo(0, 0);
  2529.                 break;
  2530.                 case "GreenBullet":
  2531.                 BulletGlowFilter = new GlowFilter(0x00FF00, 1, 10, 10, 2, 1, false, false);
  2532.                 Bullet.filters = [BulletGlowFilter];
  2533.                
  2534.                 Bullet.graphics.lineStyle(1, 0x00FF00);
  2535.                 Bullet.graphics.lineTo(5, 2.5);
  2536.                 Bullet.graphics.lineTo(0, 5);
  2537.                 Bullet.graphics.lineTo(5, 7.5);
  2538.                 Bullet.graphics.lineTo(0, 10);
  2539.                 Bullet.graphics.lineTo(5, 12.5);
  2540.                 Bullet.graphics.lineTo(0, 15);
  2541.                 Bullet.graphics.lineTo(5, 17.5);
  2542.                 Bullet.graphics.lineTo(0, 20);
  2543.                 break;
  2544.                 case "PlasmaBullet":
  2545.                 BulletGlowFilter = new GlowFilter(0xFFFFCC, 1, 10, 10, 2, 1, false, false);
  2546.                 BulletGlowFilter2 = new GlowFilter(0x990099, 1, 10, 10, 2, 1, true, false);
  2547.                 Bullet.filters = [BulletGlowFilter2, BulletGlowFilter];
  2548.                
  2549.                 Bullet.graphics.lineStyle(1, 0xFFFFCC);
  2550.                 Bullet.graphics.beginFill(0xFFFFCC);
  2551.                 Bullet.graphics.drawCircle(0, 0, 5);
  2552.                 break;
  2553.                 case "EvilPlasmaBullet":
  2554.                 BulletGlowFilter = new GlowFilter(0x000000, 1, 10, 10, 2, 1, true, false);
  2555.                 BulletGlowFilter2 = new GlowFilter(0xFF0000, 1, 10, 10, 4, 1, false, false);
  2556.                 Bullet.filters = [BulletGlowFilter, BulletGlowFilter2];
  2557.                
  2558.                 Bullet.graphics.lineStyle(1, 0x000000);
  2559.                 Bullet.graphics.beginFill(0xFFFFFF);
  2560.                 Bullet.graphics.drawCircle(0, 0, 5);
  2561.                 break;
  2562.                 case "ForkBullet":
  2563.                 BulletGlowFilter = new GlowFilter(0x0000FF, 1, 10, 10, 4, 1, false, false);
  2564.                 Bullet.filters = [BulletGlowFilter];
  2565.                
  2566.                 Bullet.graphics.lineStyle(1, 0x00CCFF);
  2567.                 Bullet.graphics.lineTo(5, 3);
  2568.                 Bullet.graphics.lineTo(5, 8);
  2569.                 Bullet.graphics.lineTo(10, 11);
  2570.                 Bullet.graphics.lineTo(10, 16);
  2571.                 Bullet.graphics.lineTo(15, 19);
  2572.                 Bullet.graphics.lineTo(15, 24);
  2573.                 Bullet.graphics.lineTo(15, 19);
  2574.                 Bullet.graphics.lineTo(20, 16);
  2575.                 Bullet.graphics.lineTo(20, 11);
  2576.                 Bullet.graphics.lineTo(25, 8);
  2577.                 Bullet.graphics.lineTo(25, 3);
  2578.                 Bullet.graphics.lineTo(30, 0);
  2579.                
  2580.                 Bullet.rotation = 180;
  2581.                 break;
  2582.                 case "ArrowBullet":
  2583.                 BulletGlowFilter = new GlowFilter(0x9900CC, 1, 10, 10, 1, 1, false, false);
  2584.                 Bullet.filters = [BulletGlowFilter];
  2585.                
  2586.                 Bullet.graphics.lineStyle(1, 0x9900CC);
  2587.                 Bullet.graphics.beginFill(0xFF0000);
  2588.                 Bullet.graphics.lineTo(5, 10);
  2589.                 Bullet.graphics.lineTo(2, 13);
  2590.                 Bullet.graphics.lineTo(6, 20);
  2591.                 Bullet.graphics.lineTo(-6, 20);
  2592.                 Bullet.graphics.lineTo(-2, 13);
  2593.                 Bullet.graphics.lineTo(-5, 10);
  2594.                 Bullet.graphics.lineTo(0, 0);
  2595.                 break;
  2596.             }
  2597.            
  2598.             stage.addChild(Bullet);
  2599.            
  2600.             ShipClass.BulletArray.push(Bullet);
  2601.             ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginX = ShipClass.SpeedX/1.8;
  2602.             ShipClass.BulletArray[ShipClass.BulletArray.length-1].Trail = ShipClass.BulletType;
  2603.            
  2604.             if (ShipClass.SpeedY <= -1){
  2605.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed = 20;
  2606.             }else{
  2607.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed = 15;
  2608.             }
  2609.            
  2610.             if (ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed < 15){
  2611.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed = 15;
  2612.             }
  2613.            
  2614.             switch (TheBulletType){
  2615.                 case "GoldBullet":
  2616.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed = ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed*2;
  2617.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Damage = 5;
  2618.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Rotation = 0;
  2619.                 break;
  2620.                 case "BlueBullet":
  2621.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed = ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed*2;
  2622.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Damage = 5;
  2623.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Penetrate = true;
  2624.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Rotation = 0;
  2625.                 break;
  2626.                 case "GreenBullet":
  2627.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed = ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed/2;
  2628.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Damage = 20;
  2629.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Rotation = -25;
  2630.                 break;
  2631.                 case "PlasmaBullet":
  2632.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed = ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed*2.5;
  2633.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Damage = 8;
  2634.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Rotation = 0;
  2635.                 break;
  2636.                 case "EvilPlasmaBullet":
  2637.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed = ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed*2;
  2638.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Damage = 10;
  2639.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Rotation = 0;
  2640.                 break;
  2641.                 case "ForkBullet":
  2642.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Damage = 6;
  2643.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Rotation = 20;
  2644.                 break;
  2645.                 case "RedLaser":
  2646.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Damage = 5;
  2647.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Rotation = 0;
  2648.                 break;
  2649.                 case "ArrowBullet":
  2650.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed = ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginSpeed*2;
  2651.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Damage = 8;
  2652.                 ShipClass.BulletArray[ShipClass.BulletArray.length-1].Rotation = 0;
  2653.                 break;
  2654.             }
  2655.            
  2656.             var ShiftY:uint = 0;
  2657.             switch(ShipClass.Position){
  2658.                 case 40:
  2659.                 ShipClass.Position = -15;
  2660.                
  2661.                 if (Bunches >= 1){
  2662.                     ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginX -= 2*Bunches;
  2663.                 }
  2664.                 break;
  2665.                 case -15:
  2666.                 ShipClass.Position = 40;
  2667.                 if (Bunches >= 1){
  2668.                     ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginX += 2*Bunches;
  2669.                 }
  2670.                 break;
  2671.             }
  2672.            
  2673.             Bullet.rotation += ShipClass.BulletArray[ShipClass.BulletArray.length-1].OriginX*2;
  2674.            
  2675.             Bullet.x = X+ShipClass.Position+(Math.floor(Math.random() * (0 - 5)) + 0)-(Math.floor(Math.random() * (0 - 5)) + 0);
  2676.             Bullet.y = Y+Math.abs(ShipClass.SpeedX)-ShiftY;
  2677.         }
  2678.        
  2679.         private function CreateEnemy(ThePosition:uint, X:int, Y:int, BossMode:Boolean, EnemyType:String):void{
  2680.             var Enemy:MovieClip = new MovieClip();
  2681.             Enemy.graphics.clear();
  2682.            
  2683.             var ListOfColours:Array = new Array("0xFF0000", "0xD700FF", "0x2E00FF", "0x00FF17",
  2684.                                                 "0xFFFC00", "0xFF7E00");
  2685.             var EnemyColour:int = Math.floor(Math.random() * (ListOfColours.length - 0)) + 0;
  2686.            
  2687.             if (EnemyType == "F"){
  2688.                 EnemyColour = 0;
  2689.             }
  2690.             Enemy.graphics.lineStyle(1, ListOfColours[EnemyColour]);
  2691.            
  2692.             var EnemyStructure:Array = new Array(0, 0, 0, 0, 0, 0, 0, 0,
  2693.                                                  0, 0, 0, 0, 0, 0, 0, 0,
  2694.                                                  0, 0, 0, 0, 0, 0, 0, 0,
  2695.                                                  0, 0, 0, 0, 0, 0, 0, 0,
  2696.                                                  0, 0, 0, 0, 0, 0, 0, 0);
  2697.            
  2698.             if (WaveClass.WaveArray[WaveClass.CurrentWave-1].substring(0, 1) == "B" && BossMode){
  2699.                 EnemyStructure = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2700.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2701.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2702.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2703.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2704.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2705.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2706.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2707.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2708.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2709.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2710.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2711.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2712.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2713.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2714.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2715.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2716.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2717.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2718.                                     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  2719.             }
  2720.            
  2721.             var Column:uint = 1;
  2722.             var StructureString:String = "";
  2723.             var MaxColumn:uint = 4;
  2724.             var MaxColumns:uint = 5;
  2725.             var PlaceRate:uint = 50;
  2726.            
  2727.             if (EnemyType == "B" && BossMode){
  2728.                 MaxColumn = 16;
  2729.                 MaxColumns = 20;
  2730.                 PlaceRate = 80;
  2731.             }
  2732.            
  2733.             for (var j:uint = 0; j < EnemyStructure.length-1; j++){
  2734.                 if (Column <= MaxColumn){
  2735.                     var RandomCircle = (Math.floor(Math.random() * (100 - 0)) + 0);
  2736.                     if (RandomCircle >= PlaceRate){
  2737.                         EnemyStructure[j] = " ";
  2738.                     }
  2739.                    
  2740.                     StructureString += String(EnemyStructure[j]);
  2741.                    
  2742.                     Column++;
  2743.                 }else{
  2744.                     Column = 1;
  2745.                     for (var i:uint = 0; i < (EnemyStructure.length/MaxColumns)/2; i++){
  2746.                         EnemyStructure[j+i] = String(EnemyStructure[j-i]);
  2747.                         StructureString += String(EnemyStructure[j+i]);
  2748.                     }
  2749.                     StructureString += "\n";
  2750.                     j += 3;
  2751.                 }
  2752.             }
  2753.            
  2754.             var EnemyPoints:Array = new Array();
  2755.            
  2756.             Column = 1;
  2757.             var MaxRows = 8;
  2758.            
  2759.             if (EnemyType == "B" && BossMode){
  2760.                 MaxRows = 32;
  2761.             }
  2762.            
  2763.             for (var c:uint = 0; c < EnemyStructure.length-1; c++){
  2764.                 if (EnemyStructure[c] != " "){
  2765.                     EnemyPoints.push(Column*10);
  2766.                     EnemyPoints.push((Math.ceil((c+1)/MaxRows))*10);
  2767.                     EnemyPoints.push(110-(Column*10));
  2768.                     EnemyPoints.push((Math.ceil((c+1)/MaxRows))*10);
  2769.                 }
  2770.                
  2771.                 if (Column <= MaxRows-1){
  2772.                     Column++;
  2773.                 }else{
  2774.                     Column = 1;
  2775.                 }
  2776.             }
  2777.            
  2778.             for (var t:uint = 0; t < EnemyPoints.length; t += 2){
  2779.                 Enemy.graphics.beginFill(ListOfColours[EnemyColour], .5);
  2780.                 Enemy.graphics.moveTo(EnemyPoints[t], EnemyPoints[t+1]);
  2781.                 Enemy.graphics.lineTo(EnemyPoints[t]+10, EnemyPoints[t+1]);
  2782.                 Enemy.graphics.lineTo(EnemyPoints[t]+10, EnemyPoints[t+1]+10);
  2783.                 Enemy.graphics.lineTo(EnemyPoints[t], EnemyPoints[t+1]+10);
  2784.                 Enemy.graphics.lineTo(EnemyPoints[t], EnemyPoints[t+1]);
  2785.                 Enemy.graphics.beginFill(ListOfColours[EnemyColour], 1);
  2786.                 Enemy.graphics.lineTo(EnemyPoints[t]+10, EnemyPoints[t+1]);
  2787.                 Enemy.graphics.lineTo(EnemyPoints[t]+10, EnemyPoints[t+1]+4);
  2788.                 Enemy.graphics.lineTo(EnemyPoints[t], EnemyPoints[t+1]+4);
  2789.                 Enemy.graphics.lineTo(EnemyPoints[t], EnemyPoints[t+1]);
  2790.             }
  2791.            
  2792.             stage.addChild(Enemy);
  2793.            
  2794.             EnemyClass.EnemyArray.push(Enemy);
  2795.             EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Speed = 5;
  2796.             EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Health = 5;
  2797.             EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Colour = ListOfColours[EnemyColour];
  2798.             EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Points = EnemyPoints;
  2799.             EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Degrees = 0;
  2800.             EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].BulletTimer = 0;
  2801.             EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Rate = Math.floor(Math.random() * (120 - 50)) + 50;
  2802.            
  2803.             switch (EnemyClass.Sideways){
  2804.                 case 5:
  2805.                 EnemyClass.Sideways = -5;
  2806.                 break;
  2807.                 case -5:
  2808.                 EnemyClass.Sideways = 5;
  2809.                 break;
  2810.             }
  2811.            
  2812.             if (EnemyType == "D"){
  2813.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Sideways = EnemyClass.Sideways;
  2814.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Diagonal = true;
  2815.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].OriginY = WaveClass.Rows;
  2816.             }else if (EnemyType == "C" || EnemyType == "S"){
  2817.                 if (WaveClass.StackedNumbers >= 5){
  2818.                     switch (EnemyClass.DiagonalSideways){
  2819.                         case 5:
  2820.                         EnemyClass.DiagonalSideways = -5;
  2821.                         break;
  2822.                         case -5:
  2823.                         EnemyClass.DiagonalSideways = 5;
  2824.                         break;
  2825.                     }
  2826.                 }
  2827.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Sideways = EnemyClass.DiagonalSideways;
  2828.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Spin = true;
  2829.             }
  2830.            
  2831.             var position:int = 0;
  2832.            
  2833.             if (EnemyClass.Sideways == 5){
  2834.                 position = 100;
  2835.             }else{
  2836.                 position = 500;
  2837.             }
  2838.            
  2839.             if (EnemyType == "C" && WaveClass.StackedNumbers >= 5){
  2840.                 position = Math.floor(Math.random() * (300 - 0)) + 200;
  2841.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].OriginX = position;
  2842.                 WaveClass.StackedNumbers = 0;
  2843.                 WaveClass.StoredPosition = position;
  2844.             }else{
  2845.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].OriginX = WaveClass.StoredPosition;
  2846.                 WaveClass.StackedNumbers++;
  2847.             }
  2848.            
  2849.             if (EnemyType == "B" && BossMode){
  2850.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].OriginX = 350;
  2851.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].BossMode = true;
  2852.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Health = 500;
  2853.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Sideways = -5;
  2854.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].SpawnEnemies = 0;
  2855.                 position = 350;
  2856.             }
  2857.            
  2858.             if (EnemyType == "F"){
  2859.                 position = ThePosition;
  2860.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].OriginX = position;
  2861.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Sideways = 0;
  2862.             }
  2863.            
  2864.             if (EnemyType == "S"){
  2865.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].RestrictSpinX = true;
  2866.             }
  2867.            
  2868.             Enemy.x = position;
  2869.             Enemy.y = -50;
  2870.            
  2871.             if (X != 0){
  2872.                 Enemy.x = X;
  2873.                 Enemy.y = Y;
  2874.                
  2875.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].OriginX = 0;
  2876.                 EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].OriginY = 0;
  2877.                
  2878.                 if (EnemyType == "Mindless"){
  2879.                     EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].Mindless = true;
  2880.                 }
  2881.             }
  2882.            
  2883.             Enemy.scaleX -= .6;
  2884.             Enemy.scaleY -= .6;
  2885.            
  2886.             EnemyClass.EnemiesCreated++;
  2887.             EnemyClass.EnemyArray[EnemyClass.EnemyArray.length-1].name = "Enemy" + EnemyClass.EnemiesCreated;
  2888.         }
  2889.        
  2890.         private function EnemyTimerComplete(Timer:TimerEvent){
  2891.             if (WaveClass.CurrentWave-1 >= WaveClass.WaveArray.length){
  2892.                 EnemyClass.EnemyTimer.stop();
  2893.                 EnemyClass.EndOfStageTimer.start();
  2894.                 FadeMusic = true;
  2895.                 MusicVolume = 1;
  2896.             }else{
  2897.                 var AddZero:String = "0";
  2898.                 if (WaveClass.WaveArray[WaveClass.CurrentWave-1].substring(0, 1) == "B"){
  2899.                     AddZero = "";
  2900.                 }
  2901.                
  2902.                 if (EnemyClass.EnemyCounter <= int(WaveClass.WaveArray[WaveClass.CurrentWave-1].substring(1, 2) + AddZero)){
  2903.                     if (WaveClass.WaveArray[WaveClass.CurrentWave-1].substring(0, 1) == "F"){
  2904.                         for (var j:uint = 0; j < 8; j++){
  2905.                             if (WaveClass.WaveArray[WaveClass.CurrentWave-1].substring(0, 1) == "B"){
  2906.                                 CreateEnemy((j*80)+50, 0, 0, true, WaveClass.WaveArray[WaveClass.CurrentWave-1].substring(0, 1));
  2907.                             }else{
  2908.                                 CreateEnemy((j*80)+50, 0, 0, false, WaveClass.WaveArray[WaveClass.CurrentWave-1].substring(0, 1));
  2909.                             }
  2910.                         }
  2911.                     }else{
  2912.                         if (WaveClass.WaveArray[WaveClass.CurrentWave-1].substring(0, 1) == "B"){
  2913.                             CreateEnemy(0, 0, 0, true, WaveClass.WaveArray[WaveClass.CurrentWave-1].substring(0, 1));
  2914.                         }else{
  2915.                             CreateEnemy(0, 0, 0, false, WaveClass.WaveArray[WaveClass.CurrentWave-1].substring(0, 1));
  2916.                         }
  2917.                     }
  2918.                     EnemyClass.EnemyCounter++;
  2919.                 }else if (EnemyClass.EnemyArray.length == 0 && !WaveClass.NextWaveTimer.running){
  2920.                     WaveClass.NextWaveTimer.start();
  2921.                     if (WaveClass.WaveArray[WaveClass.CurrentWave].substring(0, 1) == "B"){
  2922.                         particleClass.CreateText(200, 200, 30, "Deltoidicus has awoken!", 0xFF0000, 80, "Nothing");
  2923.                         CreateEnemyHealthBar();
  2924.                     }else{
  2925.                         particleClass.CreateText(200, 150, 30, "Get ready for Wave " + String(WaveClass.CurrentWave+1), 0xA10097, 80, "Nothing");
  2926.                         particleClass.CreateText(200, 200, 30, WaveClass.WaveNames[WaveClass.CurrentWave], 0xFFFFFF, 50, "Nothing");
  2927.                     }
  2928.                 }
  2929.                 EnemyClass.EnemyTimer.reset();
  2930.                 EnemyClass.EnemyTimer.start();
  2931.             }
  2932.         }
  2933.        
  2934.         private function ShootBullet(Timer:TimerEvent){
  2935.             if (!HealthClass.Reviving && ShipClass.Shooting && !RejoinChat && !PauseGame && !SpellClass.CastSpell){
  2936.                 for (var j:uint = 0; j < ShipClass.ExtraShots; j++){
  2937.                     CreateBullet(j, ShipClass.Ship.x, ShipClass.Ship.y, ShipClass.BulletType);
  2938.                     ConnectionClass.TheConnection.send("CreateBullet", AccountDetailsClass.Username, ShipClass.Ship.x, ShipClass.Ship.y, j, ShipClass.BulletType);
  2939.                 }
  2940.                 ShipClass.BulletTimer.reset();
  2941.                 ShipClass.BulletTimer.start();
  2942.             }
  2943.         }
  2944.        
  2945.         private function NextWave(Timer:TimerEvent){
  2946.             WaveClass.NextWaveTimer.reset();
  2947.             WaveClass.NextWaveTimer.stop();
  2948.             WaveClass.CurrentWave++;
  2949.             EnemyClass.EnemyCounter = 0;
  2950.             WaveClass.RowAmount = 0;
  2951.             WaveClass.Rows = 0;
  2952.            
  2953.             if (WaveClass.WaveArray[WaveClass.CurrentWave-1].substring(0, 1) == "C"){
  2954.                 ResetEnemyTime(400);
  2955.             }else if (WaveClass.WaveArray[WaveClass.CurrentWave-1].substring(0, 1) == "S"){
  2956.                 ResetEnemyTime(100);
  2957.             }else if (WaveClass.WaveArray[WaveClass.CurrentWave-1].substring(0, 1) == "F"){
  2958.                 ResetEnemyTime(2000);
  2959.             }else{
  2960.                 ResetEnemyTime(200);
  2961.             }
  2962.         }
  2963.        
  2964.         private function ResetEnemyTime(SpawnRate:uint):void{
  2965.             var enemyTimer:Timer = new Timer(SpawnRate);
  2966.             EnemyClass.EnemyTimer.removeEventListener(TimerEvent.TIMER, EnemyTimerComplete);
  2967.             EnemyClass.EnemyTimer = enemyTimer;
  2968.             EnemyClass.EnemyTimer.addEventListener(TimerEvent.TIMER, EnemyTimerComplete);
  2969.             EnemyClass.ResetSpawnTime = true;
  2970.             EnemyClass.EnemyTimer.start();
  2971.         }
  2972.        
  2973.         private function ResetBulletTime(SpawnRate:uint):void{
  2974.             ShipClass.BulletTimer = new Timer(SpawnRate);
  2975.             ShipClass.BulletTimer.removeEventListener(TimerEvent.TIMER, ShootBullet);
  2976.             ShipClass.BulletTimer = ShipClass.BulletTimer;
  2977.             ShipClass.BulletTimer.addEventListener(TimerEvent.TIMER, ShootBullet);
  2978.             EnemyClass.ResetSpawnTime = true;
  2979.             ShipClass.BulletTimer.start();
  2980.         }
  2981.        
  2982.         private function ManageBulletLoop():void{
  2983.             for (var j:uint = 0; j < ShipClass.BulletArray.length; j++){
  2984.                 ShipClass.BulletArray[j].x += ShipClass.BulletArray[j].OriginX;
  2985.                 ShipClass.BulletArray[j].y -= ShipClass.BulletArray[j].OriginSpeed;
  2986.                
  2987.                 ShipClass.BulletArray[j].rotation += ShipClass.BulletArray[j].Rotation;
  2988.                
  2989.                 if (ShipClass.BulletArray[j].y <= -50){
  2990.                     stage.removeChild(ShipClass.BulletArray[j]);
  2991.                     ShipClass.BulletArray.splice(j, 1);
  2992.                 }
  2993.             }
  2994.         }
  2995.        
  2996.         private function ManageParticleLoop():void{
  2997.             for (var l:uint = 0; l < ParticleClass.ParticleArray.length; l++){
  2998.                 ParticleClass.ParticleArray[l].x += ParticleClass.ParticleArray[l].OriginX;
  2999.                 ParticleClass.ParticleArray[l].y += ParticleClass.ParticleArray[l].OriginY;
  3000.                
  3001.                 if (ParticleClass.ParticleArray[l].y <= -50){
  3002.                     stage.removeChild(ParticleClass.ParticleArray[l]);
  3003.                     ParticleClass.ParticleArray.splice(l, 1);
  3004.                     break;
  3005.                 }else if (ParticleClass.ParticleArray[l].y >= 650){
  3006.                     stage.removeChild(ParticleClass.ParticleArray[l]);
  3007.                     ParticleClass.ParticleArray.splice(l, 1);
  3008.                     break;
  3009.                 }else if (ParticleClass.ParticleArray[l].x <= 0){
  3010.                     stage.removeChild(ParticleClass.ParticleArray[l]);
  3011.                     ParticleClass.ParticleArray.splice(l, 1);
  3012.                     break;
  3013.                 }else if (ParticleClass.ParticleArray[l].x >= 850){
  3014.                     stage.removeChild(ParticleClass.ParticleArray[l]);
  3015.                     ParticleClass.ParticleArray.splice(l, 1);
  3016.                     break;
  3017.                 }
  3018.                
  3019.                 ParticleClass.ParticleArray[l].ParticleTimer += 2;
  3020.                
  3021.                 particleClass.CreateTrail(ParticleClass.ParticleArray[l].Colour, "Explosion", ParticleClass.ParticleArray[l].x, ParticleClass.ParticleArray[l].y);
  3022.                
  3023.                 ParticleClass.ParticleArray[l].alpha = 1-ParticleClass.ParticleArray[l].ParticleTimer/100;
  3024.                
  3025.                 if (ParticleClass.ParticleArray[l].ParticleTimer >= 50){
  3026.                     stage.removeChild(ParticleClass.ParticleArray[l]);
  3027.                     ParticleClass.ParticleArray.splice(l, 1);
  3028.                 }
  3029.             }
  3030.         }
  3031.        
  3032.         private function ManageTrailLoop():void{
  3033.             for (var i:uint = 0; i < ParticleClass.TrailArray.length; i++){
  3034.                 ParticleClass.TrailArray[i].x += (Math.floor(Math.random() * (0 - 2)) + 0)-(Math.floor(Math.random() * (0 - 2)) + 0);
  3035.                 ParticleClass.TrailArray[i].y -= (Math.floor(Math.random() * (0 - 5)) + 0)-2;
  3036.                
  3037.                 if (WaveClass.NextWaveTimer.running){
  3038.                     ParticleClass.TrailArray[i].alpha -= .02;
  3039.                 }else{
  3040.                     ParticleClass.TrailArray[i].alpha -= .1;
  3041.                 }
  3042.                
  3043.                 if (ParticleClass.TrailArray[i].alpha <= 0){
  3044.                     stage.removeChild(ParticleClass.TrailArray[i]);
  3045.                     ParticleClass.TrailArray.splice(i, 1);
  3046.                 }
  3047.             }
  3048.         }
  3049.        
  3050.         private function ManageTextLoop():void{
  3051.             for (var i:uint = 0; i < ParticleClass.TextArray.length; i += 4){
  3052.                 if (ParticleClass.TextArray[i+1] >= ParticleClass.TextArray[i+2]){
  3053.                     ParticleClass.TextArray[i].alpha -= .1;
  3054.                 }else{
  3055.                     ParticleClass.TextArray[i+1] = ParticleClass.TextArray[i+1] + 1;
  3056.                 }
  3057.                
  3058.                 if (ParticleClass.TextArray[i+3] == "Scroll"){
  3059.                     ParticleClass.TextArray[i].y -= 2;
  3060.                 }
  3061.                
  3062.                 if (ParticleClass.TextArray[i].alpha <= 0){
  3063.                     stage.removeChild(ParticleClass.TextArray[i]);
  3064.                     ParticleClass.TextArray.splice(i, 4);
  3065.                 }
  3066.             }
  3067.         }
  3068.        
  3069.         private function ManageStarLoop():void{
  3070.             for (var c:uint = 0; c < ParticleClass.StarsArray.length; c++){
  3071.                 if (WaveClass.NextWaveTimer.running){
  3072.                     ParticleClass.StarsArray[c].y += 30;
  3073.                 }else{
  3074.                     ParticleClass.StarsArray[c].y += 15;
  3075.                 }
  3076.                
  3077.                 if (ParticleClass.StarsArray[c].y >= 600){
  3078.                     stage.removeChild(ParticleClass.StarsArray[c]);
  3079.                     ParticleClass.StarsArray.splice(c, 1);
  3080.                 }
  3081.             }
  3082.         }
  3083.        
  3084.         private function ManageUpgradesLoop():void{
  3085.             for (var c:uint = 0; c < UpgradesClass.UpgradesArray.length; c++){
  3086.                 if (UpgradesClass.UpgradesArray[c].stage != null){
  3087.                     UpgradesClass.UpgradesArray[c].y += 5;
  3088.                    
  3089.                     if (UpgradesClass.UpgradesArray[c].y >= 600 && !UpgradesClass.UpgradesArray[c].hitTestObject(ShipClass.Ship)){
  3090.                         stage.removeChild(UpgradesClass.UpgradesArray[c]);
  3091.                         UpgradesClass.UpgradesArray.splice(c, 1);
  3092.                         break;
  3093.                     }
  3094.                    
  3095.                     if (UpgradesClass.UpgradesArray[c].hitTestObject(ShipClass.Ship)){
  3096.                         ConnectionClass.TheConnection.send("DestroyUpgrade", UpgradesClass.UpgradesArray[c].name, AccountDetailsClass.Username);
  3097.                         stage.removeChild(UpgradesClass.UpgradesArray[c]);
  3098.                         break;
  3099.                     }
  3100.                 }
  3101.             }
  3102.         }
  3103.        
  3104.         private function ManageGameStatements():void{
  3105.             if (WaveClass.RowAmount >= WaveClass.MaxRow){
  3106.                 WaveClass.Rows += 30;
  3107.                 WaveClass.RowAmount = 0;
  3108.             }
  3109.            
  3110.             if (HealthClass.Health <= 0 && !HealthClass.Reviving){
  3111.                 HealthClass.Reviving = true;
  3112.                 HealthClass.ReviveTimer.start();
  3113.                 stage.removeChild(ShipClass.Ship);
  3114.                 HealthClass.Health = 0;
  3115.                 trace("STOPPING TIMER 1");
  3116.                 ShipClass.BulletTimer.stop();
  3117.                 ShipClass.Shooting = false;
  3118.             }
  3119.         }
  3120.        
  3121.         private function CreateHealthBar():void{
  3122.             HealthClass.HealthBar.graphics.lineStyle(1, 0xFFFFFF);
  3123.            
  3124.             HealthClass.HealthBar.graphics.lineTo(150, 0);
  3125.             HealthClass.HealthBar.graphics.lineTo(150, 17);
  3126.             HealthClass.HealthBar.graphics.lineTo(0, 17);
  3127.             HealthClass.HealthBar.graphics.lineTo(0, 0);
  3128.            
  3129.             HealthClass.HealthScroll.graphics.lineStyle(1, 0xFFFFFF);
  3130.             HealthClass.HealthScroll.graphics.beginFill(0x00FF25);
  3131.            
  3132.             HealthClass.HealthScroll.graphics.lineTo(140, 0);
  3133.             HealthClass.HealthScroll.graphics.lineTo(140, 7);
  3134.             HealthClass.HealthScroll.graphics.lineTo(0, 7);
  3135.             HealthClass.HealthScroll.graphics.lineTo(0, 0);
  3136.            
  3137.             stage.addChild(HealthClass.HealthBar);
  3138.             stage.addChild(HealthClass.HealthScroll);
  3139.            
  3140.             HealthClass.HealthBar.x = 5;
  3141.             HealthClass.HealthBar.y = 5;
  3142.            
  3143.             HealthClass.HealthScroll.x = 10;
  3144.             HealthClass.HealthScroll.y = 10;
  3145.         }
  3146.        
  3147.         private function CreateManaBar():void{
  3148.             HealthClass.ManaBar.graphics.lineStyle(1, 0xFFFFFF);
  3149.            
  3150.             HealthClass.ManaBar.graphics.lineTo(150, 0);
  3151.             HealthClass.ManaBar.graphics.lineTo(150, 17);
  3152.             HealthClass.ManaBar.graphics.lineTo(0, 17);
  3153.             HealthClass.ManaBar.graphics.lineTo(0, 0);
  3154.            
  3155.             HealthClass.ManaScroll.graphics.lineStyle(1, 0xFFFFFF);
  3156.             HealthClass.ManaScroll.graphics.beginFill(0x0000FF);
  3157.            
  3158.             HealthClass.ManaScroll.graphics.lineTo(140, 0);
  3159.             HealthClass.ManaScroll.graphics.lineTo(140, 7);
  3160.             HealthClass.ManaScroll.graphics.lineTo(0, 7);
  3161.             HealthClass.ManaScroll.graphics.lineTo(0, 0);
  3162.            
  3163.             stage.addChild(HealthClass.ManaBar);
  3164.             stage.addChild(HealthClass.ManaScroll);
  3165.            
  3166.             HealthClass.ManaBar.x = 5;
  3167.             HealthClass.ManaBar.y = 22;
  3168.            
  3169.             HealthClass.ManaScroll.x = 10;
  3170.             HealthClass.ManaScroll.y = 27;
  3171.         }
  3172.        
  3173.         public function EndThunderSpell(Event:TimerEvent){
  3174.             SpellClass.ThunderSpellTimer.reset();
  3175.             SpellClass.ThunderSpellTimer.stop();
  3176.             SpellClass.NewLine.graphics.clear();
  3177.         }
  3178.        
  3179.         public function EndShieldSpell(Event:TimerEvent){
  3180.             SpellClass.ShieldTimer.reset();
  3181.             SpellClass.ShieldTimer.stop();
  3182.             HealthClass.FlashTimer.stop();
  3183.            
  3184.             HealthClass.Invincible = false;
  3185.             ShipClass.ShipOutline = SpellClass.OriginalShipOutline;
  3186.         }
  3187.        
  3188.         private function CreateSpellsBox(Type:String, X:int, Y:int){
  3189.             switch(Type){
  3190.                 case "ThunderArea":
  3191.                 SpellClass.ThunderSpellTimer.addEventListener(TimerEvent.TIMER, EndThunderSpell);
  3192.                 var TheLightningIcon:LightningIcon = new LightningIcon();
  3193.                 stage.addChild(TheLightningIcon);
  3194.                 TheLightningIcon.width = 60;
  3195.                 TheLightningIcon.height = 40;
  3196.                
  3197.                 TheLightningIcon.x = X;
  3198.                 TheLightningIcon.y = Y;
  3199.                
  3200.                 SpellClass.SpellsArray.push(TheLightningIcon);
  3201.                 break;
  3202.                 case "HolyShield":
  3203.                 SpellClass.ShieldTimer.addEventListener(TimerEvent.TIMER, EndShieldSpell);
  3204.                 var TheShieldIcon:ShieldIcon = new ShieldIcon();
  3205.                 stage.addChild(TheShieldIcon);
  3206.                 TheShieldIcon.width = 60;
  3207.                 TheShieldIcon.height = 40;
  3208.                
  3209.                 TheShieldIcon.x = X;
  3210.                 TheShieldIcon.y = Y;
  3211.                
  3212.                 SpellClass.SpellsArray.push(TheShieldIcon);
  3213.                 break;
  3214.                 case "Heal":
  3215.                 var TheHealIcon:HealIcon = new HealIcon();
  3216.                 stage.addChild(TheHealIcon);
  3217.                 TheHealIcon.width = 60;
  3218.                 TheHealIcon.height = 40;
  3219.                
  3220.                 TheHealIcon.x = X;
  3221.                 TheHealIcon.y = Y;
  3222.                
  3223.                 SpellClass.SpellsArray.push(TheHealIcon);
  3224.                 break;
  3225.             }
  3226.            
  3227.             SpellClass.SpellsArray[SpellClass.SpellsArray.length-1].Type = Type;
  3228.         }
  3229.        
  3230.         private function ReviveShip(Timer:TimerEvent){
  3231.             if (!HealthClass.Invincible){
  3232.                 DrawShip();
  3233.                 HealthClass.ReviveTimer.reset();
  3234.                 HealthClass.ReviveTimer.start();
  3235.                 HealthClass.Reviving = false;
  3236.                 HealthClass.Health = HealthClass.MaxHealth;
  3237.                 HealthClass.Invincible = true;
  3238.                 HealthClass.FlashTimer.start();
  3239.             }else{
  3240.                 HealthClass.Invincible = false;
  3241.                 HealthClass.ReviveTimer.stop();
  3242.                 HealthClass.FlashTimer.stop();
  3243.                 ShipClass.Ship.alpha = 1;
  3244.                 HealthClass.Reviving = false;
  3245.             }
  3246.         }
  3247.        
  3248.         private function FlashTimerComplete(Timer:TimerEvent){
  3249.             HealthClass.FlashTimer.reset();
  3250.             HealthClass.FlashTimer.start();
  3251.            
  3252.             if (HealthClass.Flashing){
  3253.                 HealthClass.Flashing = false;
  3254.                 ShipClass.Ship.alpha = 1;
  3255.             }else{
  3256.                 HealthClass.Flashing = true;
  3257.                 ShipClass.Ship.alpha = .1;
  3258.             }
  3259.         }
  3260.        
  3261.         private function CreateEnemyHealthBar():void{
  3262.             EnemyClass.EnemyHealthBar.graphics.lineStyle(1, 0xFFFFFF);
  3263.            
  3264.             EnemyClass.EnemyHealthBar.graphics.lineTo(150, 0);
  3265.             EnemyClass.EnemyHealthBar.graphics.lineTo(150, 25);
  3266.             EnemyClass.EnemyHealthBar.graphics.lineTo(0, 25);
  3267.             EnemyClass.EnemyHealthBar.graphics.lineTo(0, 0);
  3268.            
  3269.             EnemyClass.EnemyHealthScroll.graphics.lineStyle(1, 0xFFFFFF);
  3270.             EnemyClass.EnemyHealthScroll.graphics.beginFill(0xFF0000);
  3271.            
  3272.             EnemyClass.EnemyHealthScroll.graphics.lineTo(140, 0);
  3273.             EnemyClass.EnemyHealthScroll.graphics.lineTo(140, 15);
  3274.             EnemyClass.EnemyHealthScroll.graphics.lineTo(0, 15);
  3275.             EnemyClass.EnemyHealthScroll.graphics.lineTo(0, 0);
  3276.            
  3277.             stage.addChild(EnemyClass.EnemyHealthBar);
  3278.             stage.addChild(EnemyClass.EnemyHealthScroll);
  3279.            
  3280.             EnemyClass.EnemyHealthBar.x = 680;
  3281.             EnemyClass.EnemyHealthBar.y = 5;
  3282.            
  3283.             EnemyClass.EnemyHealthScroll.x = 690;
  3284.             EnemyClass.EnemyHealthScroll.y = 10;
  3285.         }
  3286.        
  3287.         private function SendMovementConnections(Timer:TimerEvent){
  3288.             ShipClass.MovementTimer.reset();
  3289.             ShipClass.MovementTimer.start();
  3290.            
  3291.             ConnectionClass.TheConnection.send("SendMovements", AccountDetailsClass.Username, ShipClass.Ship.x, ShipClass.Ship.y, stage.mouseX);
  3292.         }
  3293.        
  3294.         private function MovePlayerShip(ShipNumber:int, speedx:int):void{
  3295.             var distanceX:Number = 0;
  3296.            
  3297.             ShipClass.ShipArray[ShipNumber].graphics.clear();
  3298.            
  3299.             ShipClass.ShipArray[ShipNumber].graphics.lineStyle(2, ShipClass.ShipArray[ShipNumber].Outline);
  3300.             ShipClass.ShipArray[ShipNumber].graphics.beginFill(ShipClass.ShipArray[ShipNumber].Fill, 1-Math.abs(distanceX)/40);
  3301.            
  3302.             if (speedx <= ShipClass.ShipArray[ShipNumber].x){
  3303.                 //Creating the basic shape of the ship
  3304.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(25-distanceX, 0-distanceX);
  3305.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(55-distanceX, 25-distanceX);
  3306.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-25+distanceX, 25+distanceX);
  3307.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(0, 0);
  3308.                
  3309.                 //Creating shading to the back of the ship
  3310.                 ShipClass.ShipArray[ShipNumber].graphics.beginFill(ShipClass.ShipArray[ShipNumber].DarkOutline, .8);
  3311.                 ShipClass.ShipArray[ShipNumber].graphics.lineStyle(1, ShipClass.ShipArray[ShipNumber].DarkOutline, .8);
  3312.                 ShipClass.ShipArray[ShipNumber].graphics.moveTo(-20+distanceX, 20+distanceX);
  3313.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(50-distanceX, 20-distanceX);
  3314.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(55-distanceX, 25-distanceX);
  3315.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-25+distanceX, 25+distanceX);
  3316.                
  3317.                 //Creating Back model of the ship
  3318.                 ShipClass.ShipArray[ShipNumber].graphics.beginFill(ShipClass.ShipArray[ShipNumber].BackColour, 1-Math.abs(distanceX)/40);
  3319.                 ShipClass.ShipArray[ShipNumber].graphics.lineStyle(1, ShipClass.ShipArray[ShipNumber].Outline, .8);
  3320.                 ShipClass.ShipArray[ShipNumber].graphics.moveTo(55-distanceX, 25-distanceX);
  3321.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(55-distanceX, 32-distanceX);
  3322.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-25+distanceX, 32+distanceX);
  3323.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-25+distanceX, 25+distanceX);
  3324.                
  3325.                 //Creating the right missle on the ship
  3326.                 ShipClass.ShipArray[ShipNumber].graphics.beginFill(ShipClass.ShipArray[ShipNumber].Fill, .8);
  3327.                 ShipClass.ShipArray[ShipNumber].graphics.lineStyle(1, ShipClass.ShipArray[ShipNumber].Outline, 1-distanceX/40);
  3328.                 ShipClass.ShipArray[ShipNumber].graphics.moveTo(33-distanceX, 5-distanceX);
  3329.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(50-distanceX, 5-distanceX);
  3330.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(55-distanceX, 25-distanceX);
  3331.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(33-distanceX, 5-distanceX);
  3332.                
  3333.                 //Creating the left missle on the ship
  3334.                 ShipClass.ShipArray[ShipNumber].graphics.beginFill(ShipClass.ShipArray[ShipNumber].Fill, 1-distanceX/25);
  3335.                 ShipClass.ShipArray[ShipNumber].graphics.lineStyle(1, ShipClass.ShipArray[ShipNumber].Outline, 1-distanceX/25);
  3336.                 ShipClass.ShipArray[ShipNumber].graphics.moveTo(-4, 5);
  3337.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-21+distanceX, 5+distanceX);
  3338.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-26+distanceX, 25+distanceX);
  3339.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-4, 5);
  3340.             }else{
  3341.                 distanceX = distanceX/1.8;
  3342.                 //Creating the left missle on the ship
  3343.                 ShipClass.ShipArray[ShipNumber].graphics.beginFill(ShipClass.ShipArray[ShipNumber].Fill, 1-Math.abs(distanceX)/40);
  3344.                 ShipClass.ShipArray[ShipNumber].graphics.lineStyle(1, ShipClass.ShipArray[ShipNumber].Outline, .8);
  3345.                 ShipClass.ShipArray[ShipNumber].graphics.moveTo(-4+distanceX, 5-distanceX/2);
  3346.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-21+distanceX, 5-distanceX/2);
  3347.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-26+distanceX, 25-distanceX/2);
  3348.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-4+distanceX, 5-distanceX/2);
  3349.                
  3350.                 //Creating the basic shape of the ship
  3351.                 ShipClass.ShipArray[ShipNumber].graphics.lineStyle(2, ShipClass.ShipArray[ShipNumber].Outline);
  3352.                 ShipClass.ShipArray[ShipNumber].graphics.beginFill(ShipClass.ShipArray[ShipNumber].Fill, 1-distanceX/40);
  3353.                 ShipClass.ShipArray[ShipNumber].graphics.moveTo(0, 0);
  3354.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(25-distanceX, 0+distanceX);
  3355.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(55-distanceX, 25+distanceX);
  3356.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-25+distanceX, 25-distanceX);
  3357.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(0, 0);
  3358.                
  3359.                 //Creating shading to the back of the ship
  3360.                 ShipClass.ShipArray[ShipNumber].graphics.beginFill(ShipClass.ShipArray[ShipNumber].DarkOutline, .8);
  3361.                 ShipClass.ShipArray[ShipNumber].graphics.lineStyle(1, ShipClass.ShipArray[ShipNumber].DarkOutline, .8);
  3362.                 ShipClass.ShipArray[ShipNumber].graphics.moveTo(-20+distanceX, 20-distanceX);
  3363.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(50-distanceX, 20+distanceX);
  3364.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(55-distanceX, 25+distanceX);
  3365.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-25+distanceX, 25-distanceX);
  3366.                
  3367.                 //Creating Back model of the ship
  3368.                 ShipClass.ShipArray[ShipNumber].graphics.beginFill(ShipClass.ShipArray[ShipNumber].BackColour, 1-distanceX/40);
  3369.                 ShipClass.ShipArray[ShipNumber].graphics.lineStyle(1, ShipClass.ShipArray[ShipNumber].Outline, .8);
  3370.                 ShipClass.ShipArray[ShipNumber].graphics.moveTo(55-distanceX, 25+distanceX);
  3371.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(55-distanceX, 32+distanceX);
  3372.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-25+distanceX, 32-distanceX);
  3373.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(-25+distanceX, 25-distanceX);
  3374.                
  3375.                 //Creating the right missle on the ship
  3376.                 ShipClass.ShipArray[ShipNumber].graphics.beginFill(ShipClass.ShipArray[ShipNumber].Fill, 1-distanceX/50);
  3377.                 ShipClass.ShipArray[ShipNumber].graphics.lineStyle(1, ShipClass.ShipArray[ShipNumber].Outline, 1-distanceX/50);
  3378.                 ShipClass.ShipArray[ShipNumber].graphics.moveTo(33-distanceX, 5+distanceX);
  3379.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(50-distanceX, 5+(distanceX*2));
  3380.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(55-distanceX, 25+distanceX);
  3381.                 ShipClass.ShipArray[ShipNumber].graphics.lineTo(33-distanceX, 5+distanceX);
  3382.             }
  3383.            
  3384.             ShipClass.ShipArray[ShipNumber].scaleX = .7;
  3385.             ShipClass.ShipArray[ShipNumber].scaleY = .7;
  3386.         }
  3387.        
  3388.         private function CreateMoneyText():void{
  3389.             stage.addChild(MoneyDisplay);
  3390.            
  3391.             MoneyDisplay.embedFonts = true;
  3392.            
  3393.             var NameProperties:TextFormat = new TextFormat();
  3394.             NameProperties.font = myFont.fontName;
  3395.            
  3396.             MoneyDisplay.defaultTextFormat = NameProperties;
  3397.            
  3398.             MoneyDisplay.x = 760;
  3399.             MoneyDisplay.y = 30;
  3400.            
  3401.             MoneyDisplay.width = 500;
  3402.             MoneyDisplay.height = 25;
  3403.            
  3404.             MoneyDisplay.selectable = false;
  3405.             MoneyDisplay.text = String(AccountDetailsClass.Money);
  3406.             MoneyDisplay.textColor = 0xFFD200;
  3407.         }
  3408.     }
  3409. }
Add Comment
Please, Sign In to add comment