Advertisement
Guest User

Untitled

a guest
Jan 5th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  {
  2.     import flash.display.MovieClip;
  3.     import flash.events.Event;
  4.     import flash.events.KeyboardEvent;
  5.     import flash.events.MouseEvent;
  6.     import flash.text.TextField;
  7.     import flash.text.TextFormat;
  8.    
  9.     public class finalGameCode extends MovieClip {
  10.  
  11.         public function finalGameCode() {
  12.            
  13.             //VARIABLES~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14.             var dir:String = "stop";
  15.             var prevDir:String = "down"; //checks the previous/current direction and stores it (used in invisCheck fun)
  16.             //set to "down" because boi is facing down u kno
  17.             var walkCheck:Boolean;
  18.             var mapspeed:Number = 4;
  19.            
  20.             var gameOneOn:Boolean=false; //sets the stage for game 1/establishes that the game can now start
  21.             var gameOneStart:Boolean=false;  //actually makes the game itself start
  22.            
  23.             //ON LOAD~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24.             var m:mapbg = new mapbg();
  25.             addChild(m);
  26.             var mg:mapguideline=new mapguideline();
  27.             addChild(mg);
  28.            
  29.             // R O O M  O N E  ELEMENTS----------------
  30.             var f1:r1flower=new r1flower();
  31.             addChild(f1);
  32.            
  33.             // a painting
  34.            
  35.             // R O O M  T W O ELEMENTS-----------------
  36.             var t2:r2trigger = new r2trigger();
  37.             addChild (t2);
  38.            
  39.             //a couple of desks / canvases
  40.            
  41.             var gbg:gamebg=new gamebg();
  42.             addChild(gbg);
  43.             gbg.x=550/2
  44.             gbg.y=-1000;
  45.            
  46.             //CHARACTER MOVEMENT -----------------
  47.             var a:MovieClip=new MovieClip();
  48.             addChild(a);
  49.            
  50.             var left:leftwalk=new leftwalk;
  51.             a.addChild(left);
  52.             left.x = 550/2;
  53.             left.y = 200;
  54.             left.stop();
  55.             left.visible = false;
  56.            
  57.             var right:rightwalk=new rightwalk;
  58.             a.addChild(right);
  59.             right.x = 550/2;
  60.             right.y= 200;
  61.             right.stop();
  62.             right.visible = false;
  63.            
  64.             var down:downwalk=new downwalk;
  65.             a.addChild(down);
  66.             down.x=550/2;
  67.             down.y=200;
  68.             down.stop();
  69.            
  70.             var up:upwalk=new upwalk;
  71.             a.addChild(up);
  72.             up.x=550/2;
  73.             up.y=200;
  74.             up.stop();
  75.             up.visible = false;
  76.        
  77.             //GAME 1 ELEMENTS =================================
  78.             //game one will be a game where 5 nooses fall at random speeds and you simply have to avoid them as they fall
  79.             //if they happen to hit you, you will have to keep retrying until you can avoid all 5 as they hit the ground
  80.             var nArray:Array = new Array();
  81.             for (var i:Number = 0; i < 7; i++)
  82.             {
  83.                 var n:noose = new noose ();
  84.                 nArray.push(n);
  85.                 addChild(nArray[nArray.length-1]);
  86.                 nArray[nArray.length - 1].x = i * 80;
  87.                 //the array will be off the screen and will only come when the game starts
  88.                 nArray[nArray.length - 1].y -= 50;
  89.                 nArray[nArray.length - 1].x += 40;
  90.             }
  91.             //diff speeds for each noose
  92.             var n1speed:Number=Math.random()*2+10;
  93.             var n2speed:Number=Math.random()*4+10;
  94.             var n3speed:Number=Math.random()*6+10;
  95.             var n4speed:Number=Math.random()*3+10;
  96.             var n5speed:Number=Math.random()*2+15;
  97.             var n6speed:Number=Math.random()*2+10;
  98.             var n7speed:Number=Math.random()*11+10;
  99.            
  100.             var G1t:TextField = new TextField ();
  101.             addChild(G1t);
  102.             //the text will start off the screen and will come when game 1 starts
  103.             G1t.x=55;
  104.             G1t.y=18000;
  105.             G1t.text = "Click to start. Avoid the falling objects. If you are hit, click to try again until you succeed."
  106.             G1t.width = 500;
  107.             G1t.height=200;
  108.             var G1tf:TextFormat = new TextFormat ();
  109.             G1tf.size=12;
  110.             G1tf.color=0xFFFFFF;
  111.             G1t.setTextFormat(G1tf);
  112.            
  113.            
  114.             addEventListener(Event.ENTER_FRAME,mainFun);
  115.             function mainFun (evt:Event)
  116.             {
  117.                 invisCheck(); // constantly checks if invis
  118.                 //directionCommands();
  119.                 //walkIntoWall();
  120.                 G1setStage();
  121.                 G1startGame();
  122.                 G1startOver();
  123.                 G1beatGame();
  124.             }
  125.            
  126.             stage.addEventListener(KeyboardEvent.KEY_DOWN, dFun)
  127.             function dFun(evt:KeyboardEvent):void
  128.             {
  129.                 if (evt.keyCode==39) //RIGHT KEY---------------------
  130.                 {
  131.                     prevDir = "right";
  132.                     right.play();
  133.                     dir = "right"
  134.                    
  135.                     if (gameOneOn==false)
  136.                     {
  137.                     m.x-=mapspeed;
  138.                     mg.x-=mapspeed;
  139.                     f1.x-=mapspeed;
  140.                     t2.x-=mapspeed;
  141.                     }
  142.                     if (gameOneOn==true) a.x+=4;
  143.                 }
  144.                 if (evt.keyCode == 37) //LEFT KEY--------------------
  145.                 {
  146.                     dir = "left";
  147.                     prevDir = "left";
  148.                     left.play();
  149.                    
  150.                     if (gameOneOn==false)
  151.                     {
  152.                     m.x+=mapspeed;
  153.                     mg.x+=mapspeed;
  154.                     f1.x+=mapspeed;
  155.                     t2.x+=mapspeed;
  156.                     }
  157.                     if (gameOneOn==true) a.x-=4;
  158.                 }
  159.                 if (evt.keyCode == 38) // UP KEY--------------------
  160.                 {
  161.                     if (gameOneOn==false)
  162.                     {
  163.                     dir = "up";
  164.                     prevDir = "up";
  165.                     up.play();
  166.                    
  167.                     m.y+=mapspeed;
  168.                     mg.y+=mapspeed;
  169.                     f1.y+=mapspeed;
  170.                     t2.y+=mapspeed;
  171.                     }
  172.                 }
  173.                 if (evt.keyCode == 40) //DOWN KEY------------------------
  174.                 {
  175.                     if (gameOneOn==false)
  176.                     {
  177.                     dir = "down";
  178.                     prevDir = "down";
  179.                     down.play();
  180.                    
  181.                     m.y-=mapspeed;
  182.                     mg.y-=mapspeed;
  183.                     f1.y-=mapspeed;
  184.                     t2.y-=mapspeed;
  185.                     }
  186.                 }
  187.             }
  188.             stage.addEventListener(KeyboardEvent.KEY_UP, uFun)
  189.             function uFun (evt:KeyboardEvent)
  190.             {
  191.                 if (evt.keyCode == 39)
  192.                 {
  193.                     dir = "stop";
  194.                     right.gotoAndStop(1);
  195.                 }
  196.                 if (evt.keyCode == 37)
  197.                 {
  198.                     dir = "stop";
  199.                     left.gotoAndStop(1);
  200.                 }
  201.                 if (evt.keyCode == 38)
  202.                 {
  203.                     dir = "stop";
  204.                     up.gotoAndStop(1);
  205.                 }
  206.                 if (evt.keyCode == 40)
  207.                 {
  208.                     dir = "stop";
  209.                     down.gotoAndStop(1);
  210.                 }
  211.             }
  212.            
  213.             stage.addEventListener(MouseEvent.CLICK, clickFun)
  214.             function clickFun (evt:MouseEvent):void
  215.             {
  216.                 if (gameOneOn==true)
  217.                 {
  218.                     gameOneStart=true;
  219.                 }
  220.             }
  221.            
  222.             // FUNCTIONS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  223.            
  224.             function invisCheck()  //checks what the previous direction is and makes the other directions invisible
  225.             {
  226.                 if (prevDir == "right")
  227.                     {
  228.                         right.visible = true;
  229.                        
  230.                         left.visible = false;
  231.                         up.visible = false;
  232.                         down.visible = false;
  233.                     }
  234.                
  235.                 else if (prevDir == "left")
  236.                     {
  237.                         left.visible= true;
  238.                        
  239.                         right.visible = false;
  240.                         up.visible = false;
  241.                         down.visible = false;
  242.                     }
  243.                
  244.                  else if (prevDir == "up")
  245.                     {
  246.                         up.visible = true;
  247.                        
  248.                         left.visible = false;
  249.                         right.visible = false;
  250.                         down.visible = false;
  251.                     }
  252.                 else if (prevDir == "down")
  253.                     {
  254.                         down.visible = true;
  255.                        
  256.                         left.visible = false;
  257.                         right.visible = false;
  258.                         up.visible = false;
  259.                     }
  260.             }
  261.            
  262.             //function that makes it so the avatar cant walk further if it bumps into any walls
  263.             function walkIntoWall():void
  264.             {
  265.                 if (a.hitTestObject(mg))
  266.                 {
  267.                     trace("hello");
  268.                     if (dir == "right")
  269.                     {
  270.                         //opposite of direction command function
  271.                         m.x+=4;
  272.                         mg.x+=4;
  273.                     }
  274.                     if (dir == "left")
  275.                     {
  276.                         m.x-=4;
  277.                         mg.x-=4;
  278.                     }
  279.                     if (dir == "up")
  280.                     {
  281.                         m.y-=4;
  282.                         mg.y-=4;
  283.                     }
  284.                     if (dir == "down")
  285.                     {
  286.                         m.y+=4;
  287.                         mg.y+=4;
  288.                     }
  289.                 }
  290.             }
  291.            
  292.             function G1setStage():void
  293.             {
  294.                 //if the avatar steps on the trigger tile, game one gets setup
  295.                 if (a.hitTestObject(t2))
  296.                 {
  297.                     gameOneOn=true;
  298.                     gbg.y=200;
  299.                     mapspeed=0;
  300.                     a.y=100;
  301.                     //bring the instruction text onto the stage
  302.                     G1t.y=180;
  303.                 }
  304.             }
  305.            
  306.             function G1startGame():void
  307.             {
  308.                 //if game one is setup and you have clicked, game one is able to start, and the noose begin falling
  309.                 if (gameOneStart==true)
  310.                 {
  311.                     //move the text off the screen
  312.                     G1t.y=180000;
  313.                    
  314.                     for (var i:Number=0; i < nArray.length; i++)
  315.                     {
  316.                         if (i==0) nArray[i].y+=n1speed;
  317.                         if (i==1) nArray[i].y+=n2speed;
  318.                         if (i==2) nArray[i].y+=n3speed;
  319.                         if (i==3) nArray[i].y+=n4speed;
  320.                         if (i==4) nArray[i].y+=n5speed;
  321.                         if (i==5) nArray[i].y+=n6speed;
  322.                         if (i==6) nArray[i].y+=n7speed;
  323.                         //make a hit test object with the person
  324.                     }
  325.                 }
  326.             }
  327.            
  328.             function G1startOver():void
  329.             {
  330.                 for (var i:Number=0; i < nArray.length; i++)
  331.                     {
  332.                         if (nArray[i].hitTestObject(a))
  333.                         {
  334.                             gameOneStart=false
  335.                             nArray[nArray.length-1].y-= 50;
  336.                             a.y=100;
  337.                         }
  338.                     }
  339.                 //if - hit test object with a and nArray elements
  340.                 //-all of the elements of the array go back to the top
  341.                 //-text that says click again to restart
  342.                 //-then when you click it will loop back to g1startgame function
  343.             }
  344.            
  345.             function G1beatGame():void
  346.             {
  347.                 for (var i:Number=0; i < nArray.length; i++)
  348.                     {
  349.                         if (nArray[i].y > 400 && gameOneStart==true)
  350.                         {
  351.                             trace ("hi kill me");
  352.                             gameOneStart=false;
  353.                             gameOneOn=false;
  354.                             a.y=0;
  355.                             gbg.x=-10000;
  356.                             t2.x=-10000;
  357.                         }
  358.                     }
  359.                 //if all of the elements of the array are off the screen then:
  360.                 //-the a returns to a.y returns to 0
  361.                 //-the black screen goes off
  362.                 //-t2 goes off the screen
  363.                 //gameOneStart and GameOneOn = false
  364.             }
  365.            
  366.         }
  367.  
  368.     }
  369.    
  370. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement