Guest User

Untitled

a guest
Jun 12th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 16.16 KB | None | 0 0
  1. package  
  2. {
  3.    
  4.     import flash.display.MovieClip;
  5.     import flash.events.Event;
  6.     import flash.events.KeyboardEvent;
  7.     import flash.ui.Keyboard;
  8.     import flash.display.Sprite;
  9.     import flash.events.MouseEvent;
  10.     import flash.events.TimerEvent;
  11.     import flash.utils.Timer;
  12.     import flash.sensors.Accelerometer;
  13.    
  14.     public class TrainMain extends MovieClip
  15.  {
  16.  
  17.         // The elements used in this game as the enviroment.
  18.         private var ground1:LGround;
  19.         private var introAni:LIntroAni;
  20.         private var introPlayB:LIntroPlayB;
  21.         private var introInstruB:LIntroInstruB;
  22.         private var instructions:LInstructions;
  23.         private var gameOverPoster:LGameOverPoster;
  24.         private var kittenFodder:LKittenFodder;
  25.         private var forgrunn:LForgrunn;
  26.         private var background1:LBackground1;
  27.         private var togbunn:LTogBunn;
  28.         private var automat:LAutomat;
  29.         private var boxes:LBoxes;
  30.         private var alien:LAlien;
  31.         private var emergency:LEmergency;
  32.         private var nrKittens:LNrkittens;
  33.         private var pillow:LPillow;
  34.         private var zamuel:LZamuel;
  35.         private var barell:LBarell;
  36.         private var alex:LAlex;
  37.         private var loo:LLoo;
  38.        
  39.         //Key pressing E and F
  40.         private var using:Boolean = false;
  41.         private var pewpew:Boolean = false;
  42.         private var kittenL:Boolean = false;
  43.         private var kittenR:Boolean = false;
  44.         private var nextSpawn:Boolean = true;
  45.        
  46.         // Picking the cats up booleans to keep from spam picking!
  47.         private var boxesP:Boolean = true;
  48.         private var emergencyP:Boolean = true;
  49.         private var pillowP:Boolean = true;
  50.         private var zamuelP:Boolean = true;
  51.         private var barellP:Boolean = true;
  52.         private var alexP:Boolean = true;
  53.  
  54.         //Walking
  55.         private var walkL:Boolean=false;
  56.         private var walkR:Boolean=false;
  57.         private var walkU:Boolean=false;
  58.         private var walkD:Boolean=false;
  59.         private var standStill:Boolean=false;
  60.         var Y: Number= 10; //Walking speed
  61.         var S: Number=0.3; //Scaling of the character
  62.         var SZ:Number=1.3; //Scaling the zombies
  63.         var ZS:Number = 2; //Zombie Spawn - number of zombies spawning
  64.        
  65.         //Jumping
  66.         private var gravity:Number = 2;
  67.         private var jumpY:Number = 0;
  68.         private var jumpSpeed:Number = -25;
  69.         private var jumpingNow = false;
  70.         var KFC: Number = 3; // Kitten Fodder Count
  71.        
  72.        
  73.         private var kittenTimer:Number = 0;
  74.            
  75.         //Timer and game over
  76.         private var timer:Timer = new Timer(4000, 1);
  77.         private var timerMonster:Timer = new Timer(30000, 100);
  78.         private var gameOver:Boolean = false;
  79. //      private var monstersInPlay:Boolean = false;
  80.         private var shoot:Boolean = false;
  81.         private var looResett:Boolean = true;
  82.        
  83.         // The character
  84.         private var character:LCharacter;
  85.        
  86.         // Sprite added to make sure I can hid all the elements when the game ends, and make it easier to restart it again as soom as the button is pressed.
  87.         private var trainCart1:Sprite;
  88.         private var forGround:Sprite;
  89.         private var intro:Sprite;
  90.         private var monster:Sprite;
  91.  
  92.  
  93.         public var Monster:Array;
  94.  
  95.    
  96.         public function TrainMain()
  97.         {
  98.            
  99.             // Sprites that contains our items, this makes it easier for the items to move when the character should be moving.
  100.             background1 = new LBackground1();
  101.             addChild(background1);
  102.             background1.x = 1374;
  103.             background1.y = 407;
  104.             background1.play();
  105.            
  106.             trainCart1 = new Sprite();
  107.             addChild(trainCart1);
  108.             trainCart1.x = 0;
  109.             trainCart1.y = 0;
  110.             trainCart1.visible = false;
  111.            
  112.             kittenFodder = new LKittenFodder();
  113.             addChild(kittenFodder);
  114.             kittenFodder.x = 1500;
  115.             kittenFodder.y = 1500;
  116.             kittenFodder.visible = false;
  117.             kittenFodder.scaleX = kittenFodder.scaleY = S;
  118.  
  119.             character= new LCharacter();
  120.             addChild(character);
  121.             character.x = 400;
  122.             character.y = 400
  123.             character.gotoAndStop(1);
  124.             character.scaleX = character.scaleY = S;
  125.  
  126.             monster = new Sprite();
  127.             addChild(monster);
  128.             monster.x = 0;
  129.             monster.y = 0;
  130.             monster.visible = true;
  131.            
  132.             forGround = new Sprite();
  133.             addChild(forGround);
  134.             forGround.x = 0;
  135.             forGround.y = 0;
  136.             forGround.visible = false;
  137.  
  138.             nrKittens = new LNrkittens();
  139.             addChild (nrKittens);
  140.             nrKittens.x = 1160;
  141.             nrKittens.y = 77;
  142.            
  143.             gameOverPoster = new LGameOverPoster();
  144.             addChild(gameOverPoster);
  145.             gameOverPoster.x = 0;
  146.             gameOverPoster.y = 0;
  147.             gameOverPoster.visible = false;
  148.            
  149.             intro = new Sprite();
  150.             addChild(intro);
  151.             intro.x = 0;
  152.             intro.y = 0;
  153.             intro.visible = true;
  154.            
  155.             insideTrainCart1();
  156.             introAndGuide();
  157.  
  158.             stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);
  159.             stage.addEventListener(KeyboardEvent.KEY_UP, onKeyReleased);
  160.             gameOverPoster.addEventListener(MouseEvent.CLICK, resett);
  161.             timerMonster.addEventListener(TimerEvent.TIMER, thingsGettingHarder);
  162.  
  163.  
  164.             Monster = new Array();
  165.            
  166.         }
  167.        
  168.         public function thingsGettingHarder (e:TimerEvent):void
  169.         {
  170.             trace(ZS);
  171.             ZS += 1;
  172.             nextSpawn = true;
  173.             spawnZombie();
  174.         }
  175.        
  176.         public function spawnZombie():void
  177.         {
  178.             var tempMonster:MovieClip = new LZombie();
  179.             tempMonster.x = character.x + 200 + (Math.random() * 600);
  180.             tempMonster.y = 400 + (Math.random() * 150);
  181.             tempMonster.scaleX = tempMonster.scaleY = SZ;
  182.             monster.addChild(tempMonster);
  183.             Monster.push(tempMonster);         
  184.             monster.visible = true;
  185.         }
  186.        
  187.        
  188.         public function onFrameLoop(e:Event):void
  189.         {
  190.             trace (looResett);
  191.            
  192.             if(Monster.length < ZS && nextSpawn == true)
  193.                 spawnZombie();
  194.            
  195.             for (var i:int = 0; i < Monster.length; ++i)
  196.             {
  197.                 if(Monster[i].x > character.x)
  198.                 {
  199.                     Monster[i].x -= 2;
  200.                     Monster[i].scaleX = -1;
  201.                 }
  202.                    
  203.                 if(Monster[i].x < character.x)
  204.                 {
  205.                     Monster[i].x += 2;
  206.                     Monster[i].scaleX = 1;
  207.                 }
  208.                
  209.                 if(Monster[i].y > character.y)
  210.                 {
  211.                     Monster[i].y -= 2;
  212.                 }
  213.                    
  214.                 if(Monster[i].y < character.y)
  215.                 {
  216.                     Monster[i].y += 2;
  217.                 }
  218.             if (Monster[i].hitTestObject(kittenFodder) && Monster[i].visible == true)
  219.                 {
  220.                 Monster[i].visible = false;
  221.                 kittenFodder.visible = false;
  222.                 kittenFodder.x = 1500;
  223.                 ZS += 1;
  224.                 trace(ZS);
  225.                 nextSpawn = false;
  226.                 }
  227.                
  228.             if (character.hitTestPoint(Monster[i].x, Monster[i].y, true) && Monster[i].visible == true && jumpingNow == false)
  229.                 {
  230.                 gameOver = true;
  231.                 }              
  232.             }
  233.        
  234.                    
  235.            
  236.             moving();
  237.             hitTestKittens();
  238.             kittenInPlay();
  239.            
  240.             if (kittenTimer != 0)
  241.             kittenTimer  --;           
  242.            
  243.             if (jumpingNow == true && jumpY < 25 || character.y < 300)
  244.             {
  245.                 character.y += jumpY;
  246.                 jumpY += gravity;
  247.                 character.gotoAndPlay(153);
  248.                
  249.                 if (jumpY == 25)
  250.                 {
  251.                     jumpingNow = false;
  252.                     jumpY = 0;
  253.                     standStill = true;
  254.                    
  255.                     if (character.y < 350 )
  256.                     character.y = 380;
  257.                 }
  258.             }
  259.            
  260. /*          if (gameOver == true)
  261.                 {
  262.                 gameOverPoster.visible = true;
  263.                 }*/
  264.            
  265.             if (ground1.hitTestPoint(character.x,character.y,true) == false)
  266.                 {
  267.                 if (jumpingNow == false)
  268.                     gameOver = true;
  269.                 }
  270.         }
  271.        
  272.        
  273.         //Resett
  274.         public function resett(event:MouseEvent)
  275.         {
  276.             gameOverPoster.visible = false;
  277.             gameOver = false;
  278.            
  279.             trainCart1.x = 0;
  280.             trainCart1.y = 0;
  281.             trainCart1.visible = true;
  282.  
  283.             forGround.x = 0;
  284.             forGround.y = 0;
  285.             forGround.visible = true;
  286.            
  287.             character.x = 400;
  288.             character.y = 400
  289.            
  290.             ZS = 2;
  291.             KFC = 3;
  292.             trace (ZS);
  293.  
  294.             spawnZombie();
  295.  
  296.         }
  297.        
  298.         public function redButton ()
  299.         {
  300.             boxesP = true;
  301.             emergencyP = true;
  302.             pillowP = true;
  303.             zamuelP = true;
  304.             barellP = true;
  305.             alexP = true;
  306.  
  307.             //Resetting the movieClip
  308.             boxes.gotoAndStop(1);
  309.             emergency.gotoAndStop(1);
  310.             barell.gotoAndPlay(1);
  311.             alex.gotoAndStop(1);
  312.  
  313.             ZS = 2;
  314.             trace (ZS);
  315.             KFC += 1;
  316.             Monster.length(2);
  317.        
  318.         }
  319.        
  320.         //InsideTrain
  321.         public function insideTrainCart1()
  322.         {          
  323.             // Ground objects
  324.             alien= new LAlien();
  325.             trainCart1.addChild(alien);
  326.             alien.x = 334;
  327.             alien.y = 340;
  328.             alien.scaleX = alien.scaleY = 0.8;
  329.            
  330.             togbunn= new LTogBunn();
  331.             trainCart1.addChild(togbunn);
  332.             togbunn.x = 845;
  333.             togbunn.y = 700;
  334.             togbunn.scaleX = togbunn.scaleY = 0.8;
  335.            
  336.             ground1= new LGround();
  337.             trainCart1.addChild(ground1);
  338.             ground1.x = 1825;
  339.             ground1.y = 313;
  340.             ground1.scaleX = ground1.scaleY = 0.8;
  341.            
  342.            
  343.             //Extra objects you can interact with
  344.             loo= new LLoo();
  345.             trainCart1.addChild(loo);
  346.             loo.x = 3900;
  347.             loo.y = 385;
  348.             loo.scaleX = loo.scaleY = 1.2;
  349.            
  350.             emergency = new LEmergency();
  351.             trainCart1.addChild(emergency);
  352.             emergency.x = 240;
  353.             emergency.y = 320;
  354.             emergency.gotoAndStop(1);
  355.             emergency.scaleX = emergency.scaleY = 0.4;
  356.            
  357.             zamuel = new LZamuel();
  358.             trainCart1.addChild(zamuel);
  359.             zamuel.x = 1285;
  360.             zamuel.y = 320;
  361.             zamuel.gotoAndStop(1);
  362.             zamuel.scaleX = zamuel.scaleY = 0.6;
  363.  
  364.             alex = new LAlex();
  365.             trainCart1.addChild(alex);
  366.             alex.x = 2425;
  367.             alex.y = 320;
  368.             alex.gotoAndStop(1);
  369.             alex.scaleX = alex.scaleY = 0.6;
  370.  
  371.             automat = new LAutomat();
  372.             trainCart1.addChild(automat);
  373.             automat.x = -200;
  374.             automat.y = 300;
  375.             automat.scaleX = automat.scaleY = 1.2;
  376.            
  377.             pillow = new LPillow();
  378.             trainCart1.addChild(pillow);
  379.             pillow.x = 1105;
  380.             pillow.y = 305;
  381.             pillow.gotoAndStop(1);
  382.             pillow.scaleX = pillow.scaleY = 0.6;
  383.            
  384.             barell = new LBarell();
  385.             trainCart1.addChild(barell);
  386.             barell.x = 3200;
  387.             barell.y = 331;
  388.             barell.gotoAndStop(1);
  389.            
  390.            
  391.             //Infront
  392.             forgrunn = new LForgrunn;
  393.             forGround.addChild (forgrunn);
  394.             forgrunn.x = 1797;
  395.             forgrunn.y = 313;
  396.             forgrunn.scaleX = forgrunn.scaleY = 0.8;
  397.            
  398.             boxes= new LBoxes();
  399.             forGround.addChild(boxes);
  400.             boxes.x = 3600;
  401.             boxes.y = 460;
  402.             boxes.gotoAndStop(1);
  403.         }
  404.        
  405.         //Things inside the cart!! Kitteys
  406.        
  407.         public function hitTestKittens ()
  408.         {
  409.             nrKittens.kittenNr.text = "." + KFC + ".";
  410.            
  411.             if(character.hitTestObject(automat) && using == true)
  412.             {
  413.                looResett = true;
  414.                using = false;
  415.             }
  416.             if (character.hitTestObject(automat) && KFC < 7)
  417.             {
  418.                 KFC += 1;
  419.             }
  420.            
  421.             if (character.hitTestObject(boxes) && using == true && boxesP == true)
  422.             {
  423.                 boxes.play();
  424.                 KFC += 1;
  425.                 using = false;
  426.                 boxesP = false;
  427.             }
  428.  
  429.             if (character.hitTestObject(emergency) && using == true && emergencyP == true)
  430.             {
  431.                 emergency.play();
  432.                 KFC += 1;
  433.                 using = false;
  434.                 emergencyP = false;
  435.             }
  436.             if (character.hitTestObject(pillow) && using == true && pillowP == true)
  437.             {
  438.                 pillow.play();
  439.                 KFC += 1;
  440.                 using = false;
  441.                 pillowP = false;
  442.             }
  443.             if (character.hitTestObject(zamuel) && using == true && zamuelP == true)
  444.             {
  445.                 zamuel.play();
  446.                 using = false;
  447.                 zamuelP = false;
  448.             }
  449.            
  450.             if (character.hitTestObject(barell) && using == true && barellP == true)
  451.             {
  452.                 barell.play();
  453.                 KFC +=1;
  454.                 using = false;
  455.                 barellP = false;
  456.             }
  457.            
  458.             if (character.hitTestObject(alex) && using == true && alexP == true)
  459.             {
  460.                 alex.gotoAndStop(28);
  461.                 KFC +=2;
  462.                 using = false;
  463.                 alexP = false;
  464.             }
  465.            
  466.             if (character.hitTestObject(loo) && using == true && looResett == true)
  467.             {
  468.                 loo.play();
  469.                 using = false;
  470.                 looResett = false;
  471.                 redButton();
  472.             }          
  473.         }
  474.        
  475.         //Keiitens
  476.         public function kittenInPlay()
  477.         {              
  478.             if (kittenR == true)
  479.             {
  480.                 //trace("forward");
  481.             kittenFodder.x += 15;
  482.             kittenL = false;
  483.             }
  484.            
  485.             if (kittenL == true)
  486.             {
  487.             kittenFodder.x -= 15;
  488.             kittenR = false;
  489.             }
  490.             if (kittenTimer == 2)
  491.             {
  492.             kittenFodder.visible = false;
  493.             }
  494.         }
  495.        
  496.         //Monsters!
  497.  
  498.        
  499.         //Monster damage
  500.  
  501.        
  502.         //Intro
  503.         public function introAndGuide()
  504.         {
  505.             introAni = new LIntroAni;
  506.             intro.addChild(introAni);
  507.             introAni.x = 640;
  508.             introAni.y =359;
  509.             introAni.play();
  510.            
  511.             timer.start();
  512.            
  513.             timer.addEventListener(TimerEvent.TIMER, timerListener);
  514.            
  515.             function timerListener (e:TimerEvent):void
  516.             {
  517.                
  518.                 introPlayB = new LIntroPlayB();
  519.                 intro.addChild(introPlayB);
  520.                 introPlayB.x = 680;
  521.                 introPlayB.y = 40;
  522.            
  523.                 introInstruB = new LIntroInstruB();
  524.                 intro.addChild(introInstruB);
  525.                 introInstruB.x = 930;
  526.                 introInstruB.y = 400;
  527.                
  528.                 introPlayB.addEventListener(MouseEvent.CLICK, drawEnviroment);
  529.                 introInstruB.addEventListener(MouseEvent.CLICK, introInstructions);
  530.                
  531.                 function drawEnviroment(event:MouseEvent)
  532.                 {
  533.                     intro.visible = false;
  534.                     trainCart1.visible = true;
  535.                     forGround.visible = true;
  536.                     addEventListener(Event.ENTER_FRAME, onFrameLoop);
  537.                     timerMonster.start();
  538.                 }
  539.                
  540.                 function introInstructions(event:MouseEvent)
  541.                 {
  542.                     intro.visible = false;
  543.                    
  544.                     instructions = new LInstructions();
  545.                     addChild(instructions);
  546.                     instructions.x = 0;
  547.                     instructions.y = 0;
  548.                     instructions.visible = true;
  549.                    
  550.                     introPlayB = new LIntroPlayB();
  551.                     addChild(introPlayB);
  552.                     introPlayB.x = 788;
  553.                     introPlayB.y = 357;
  554.                     introPlayB.visible = true;
  555.                
  556.                     introPlayB.addEventListener(MouseEvent.CLICK, drawEnviroment);
  557.                
  558.                
  559.                     function drawEnviroment(event:MouseEvent)
  560.                     {
  561.                         intro.visible = false;
  562.                         instructions.visible = false;
  563.                         introPlayB.visible = false;
  564.                         trainCart1.visible = true;
  565.                         forGround.visible = true;
  566.                     }
  567.                 }
  568.             }
  569.         }
  570.        
  571.        
  572.         // Walking!
  573.        
  574.         private function moving()
  575.         {  
  576.             if(walkL && trainCart1.x < 660)
  577.                 {
  578.                 standStill=false;
  579.                 trainCart1.x += Y;
  580.                 forGround.x += Y;
  581.                 kittenFodder.x += Y;
  582.                 character.scaleX = -S;
  583.                 for (var i:int = 0; i < Monster.length; ++i)
  584.                     {
  585.                     Monster[i].x +=Y;
  586.                    
  587.                     }
  588.                
  589.                
  590.                 }
  591.             if(walkR && trainCart1.x > -3570)
  592.                 {
  593.                 standStill=false;
  594.                 trainCart1.x  -= Y;
  595.                 forGround.x -= Y;
  596.                 kittenFodder.x -= Y;
  597.                 character.scaleX = S;
  598.                 for (var i:int = 0; i < Monster.length; ++i)
  599.                     {
  600.                     Monster[i].x -=Y;
  601.                    
  602.                     }
  603.                 }
  604.                
  605.             if(walkU && character.y > 387 )
  606.                 {
  607.                 character.play();
  608.                 standStill=false;
  609.                 character.y  -= Y;
  610.                 }
  611.                
  612.             if(walkD && character.y < 480)
  613.                 {
  614.                 character.play();
  615.                 standStill=false;
  616.                 character.y  += Y;
  617.                 }
  618.                
  619.             if(standStill == true && pewpew == false)
  620.                 {
  621.                 character.gotoAndPlay(156);
  622.                 standStill = false;
  623.                 }
  624.         }
  625.        
  626.         //Key Presses
  627.         public function onKeyPressed(e:KeyboardEvent) : void
  628.         {
  629.            
  630.             var key:uint = e.keyCode;
  631.             switch (key)
  632.                 {
  633.                 case Keyboard.SPACE :
  634.                     if (jumpY < 0.1 && character.y > 300)
  635.                         {
  636.                         jumpY = jumpSpeed;
  637.                         jumpingNow = true;
  638.                         }
  639.                     break;
  640.                    
  641.                 case Keyboard.LEFT:
  642.                     if (walkL == false && pewpew == false)
  643.                     {
  644.                     walkL=true;
  645.                     character.gotoAndPlay(1);
  646.                     }
  647.                     break;
  648.    
  649.                 case Keyboard.RIGHT:
  650.                     if (walkR == false && pewpew == false)
  651.                     {
  652.                     walkR=true;
  653.                     character.gotoAndPlay(1);
  654.                     }
  655.                     break;
  656.    
  657.                 case Keyboard.UP:
  658.                     walkU=true;
  659.                     break;
  660.    
  661.                 case Keyboard.DOWN:
  662.                     walkD=true;
  663.                     break;
  664.                    
  665.                    
  666.                 case Keyboard.E:
  667.                     using = true;
  668.                     break;
  669.                 case Keyboard.F:
  670.                
  671.                     if (kittenTimer == 0 && KFC > 0)
  672.                     {
  673.                    
  674.                    
  675.                     KFC --;
  676.                     pewpew = true;
  677.                     shoot = true;
  678.                     character.gotoAndPlay(108);
  679.  
  680.                     kittenFodder.x = character.x;
  681.                     kittenFodder.y = character.y - 85
  682.                     kittenFodder.visible = true;
  683.                     kittenTimer = 80;
  684.                    
  685.                     kittenFodder.gotoAndPlay(1);
  686.                    
  687.                     //trace ("Kitten Finder: " + kittenFodder.x + ", " + kittenFodder.y);
  688.                     if (character.scaleX == S)
  689.                     {
  690.                         kittenR = true;
  691.                         kittenL = false;
  692.                     }
  693.                    
  694.                     if (character.scaleX == -S)
  695.                     {
  696.                         kittenR = false;
  697.                         kittenL = true;
  698.                     }
  699.                     }
  700.                     break;
  701.                 }
  702.                
  703.            
  704.         }
  705.        
  706.         public function onKeyReleased(e:KeyboardEvent) : void
  707.         {
  708.             character.gotoAndStop(1);
  709.            
  710.                 var key:uint = e.keyCode;
  711.                 switch (key)
  712.                 {
  713.                 case Keyboard.LEFT:
  714.                     walkL=false;
  715.                     standStill=true;
  716.                 break;
  717.                
  718.                 case Keyboard.RIGHT:
  719.                     walkR=false;
  720.                     standStill=true;
  721.                 break;
  722.                
  723.                 case Keyboard.UP:
  724.                     walkU=false;
  725.                     standStill=true;
  726.                 break;
  727.                
  728.                 case Keyboard.DOWN:
  729.                     walkD=false;
  730.                     standStill=true;
  731.                 break;
  732.                 case Keyboard.E:
  733.                     using = false;
  734.                     break;
  735.                 case Keyboard.F:
  736.                     pewpew = false;
  737.                     break;
  738.                 }
  739.         }
  740.                
  741.  }
  742. }
Add Comment
Please, Sign In to add comment