Guest User

Untitled

a guest
Apr 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package  {
  2.    
  3.     import flash.display.MovieClip;
  4.     import flash.display.Sprite;
  5.     import flash.events.KeyboardEvent;
  6.     import flash.events.Event;
  7.     import flash.ui.Keyboard;
  8.     import flash.text.TextField;
  9.    
  10.     public class obli7main extends MovieClip{
  11.        
  12.         private var ute:Sprite;
  13.         private var inne:Sprite;
  14.        
  15.         private var sun:Sprite = new Sprite();
  16.        
  17.         private var hus:Hus;
  18.         private var forgrundUte:LForgrundUte;
  19.         private var bakgrundUte:LBakgrundUte;
  20.         private var fjell:LFjell
  21.         private var doer:LDoer;
  22.         private var haantak:LHaantak;
  23.         private var himmel:LHimmel;
  24.         private var wc3:LWc3; //karakter
  25.        
  26.         private var blomst1:LBlomst1;
  27.         private var blomst2:LBlomst2;
  28.         private var blomst3:LBlomst3;
  29.         private var rom:LRom;
  30.        
  31.         var Score:int;
  32.         var scoretext: TextField = new TextField();
  33.        
  34.  
  35.         const L:int = 0;                    // Left
  36.         const W:int = 550;                  // Width   
  37.         const T:int = 0;                    // Top
  38.         const H:int = 400;                  // Height
  39.         const R:int = L+W;                  // Right
  40.         const B:int = T+H;
  41.         var   S:Number = 0.3;                // skalering av karakter
  42.    
  43.        
  44.         public function obli7main()
  45.         {
  46.             inne = new Sprite();
  47.             addChild(inne);
  48.             inne.x = 0;
  49.             inne.y = 0;
  50.             inne.visible = false;
  51.            
  52.            
  53.             ute = new Sprite();
  54.             addChild(ute);
  55.             ute.x = 0;
  56.             ute.y = 0;
  57.            
  58.             leggTilObjektInne();
  59.             leggTilObjektUte();
  60.            
  61.             wc3 = new LWc3(); //karakter
  62.             wc3.x = 275;
  63.             wc3.y = 260;
  64.             wc3.gotoAndStop(1);
  65.             addChild(wc3);                 
  66.             wc3.scaleX = wc3.scaleY = S;
  67.            
  68.            
  69.             leggTilLyttereUte();
  70.             leggTilLyttereInne();
  71.            
  72.             scoretext.width = 200;
  73.             scoretext.text = "Score: 0";
  74.             addChild (scoretext) ;
  75.             scoretext.x =  50;
  76.             scoretext.y =  40;
  77.             scoretext.textColor = 0xffffff;
  78.  
  79.         }
  80.        
  81.         public function onFrameLoop(e:Event) : void
  82.         {      
  83.                 wc3.stop();
  84.                
  85.                 plukkBlomster();
  86.                
  87.                if (ute.visible && blomst1.visible == false && blomst2.visible == false && blomst3.visible == false)
  88.                     lyttPaaDoer();
  89.                //trace(wc3.x);     
  90.         }
  91.  
  92.         private function plukkBlomster()
  93.         {
  94.            if (blomst1.visible == true && ute.visible && wc3.hitTestObject( blomst1 ))
  95.            {
  96.                blomst1.visible = false ;
  97.                addScore();
  98.            }
  99.             if (blomst2.visible == true && ute.visible && wc3.hitTestObject( blomst2 ))
  100.             {
  101.                 blomst2.visible = false ;
  102.                 addScore();
  103.             }
  104.                
  105.             if (blomst3.visible == true && ute.visible && wc3.hitTestObject( blomst3 ))
  106.             {
  107.                 blomst3.visible = false ;
  108.                 addScore();
  109.             }
  110.         }
  111.         private function addScore()
  112.         {
  113.             trace ("hit");
  114.             Score = Score +1
  115.             trace ("Score: " + Score);
  116.             scoretext.text = "Score: 0" + Score;
  117.         }
  118.        
  119.         private function leggTilObjektUte()
  120.        {
  121.             himmel = new LHimmel();
  122.             ute.addChild(himmel);
  123.            
  124.             fjell = new LFjell();
  125.             ute.addChild(fjell);
  126.             fjell.X = 50;
  127.             fjell.Y = 330;
  128.  
  129.             bakgrundUte = new LBakgrundUte();
  130.             ute.addChild(bakgrundUte);
  131.             bakgrundUte.X = bakgrundUte.width/2;
  132.             bakgrundUte.Y = bakgrundUte.height/2
  133.            
  134.             forgrundUte = new LForgrundUte();
  135.             ute.addChild(forgrundUte);
  136.             forgrundUte.x = forgrundUte.width/2;
  137.             forgrundUte.y = B - forgrundUte.height/2;
  138.            
  139.             sun.graphics.beginFill(0x0FFFF99);
  140.             sun.graphics.drawCircle(210, 90, 50);
  141.             sun.graphics.endFill();
  142.             ute.addChild(sun);
  143.        
  144.             hus = new Hus();
  145.             ute.addChild(hus);
  146.             hus.x = 155;
  147.             hus.y = 310;
  148.             hus.scaleX = hus.scaleY = 1.5;
  149.            
  150.             blomst1= new LBlomst1();
  151.             ute.addChild(blomst1);
  152.             blomst1.x = 390;
  153.             blomst1.y = 310;
  154.             blomst1.scaleX = blomst1.scaleY = 1
  155.            
  156.             blomst2= new LBlomst2();
  157.             ute.addChild(blomst2);
  158.             blomst2.x = 30;
  159.             blomst2.y = 330;
  160.             blomst2.scaleX = blomst2.scaleY = 1
  161.            
  162.             blomst3= new LBlomst3();
  163.             ute.addChild(blomst3);
  164.             blomst3.x = 450;
  165.             blomst3.y = 330;
  166.             blomst3.scaleX = blomst3.scaleY = 1
  167.            
  168.  
  169.  
  170.            
  171.             //doer=new Ldoer();
  172. //          ute.addChild(doer);
  173. //          doer.x=128;
  174. //          doer.y=260;
  175. //          doer.scaleX = doer.scaleY = 1.5;
  176. //         
  177. //          haantak= new LHaantak();
  178. //          ute.addChild(haantak);
  179. //          haantak.x=100;
  180. //          haantak.y= 267;
  181. //          haantak.scaleX = haantak.scaleY = 1.5;
  182.        }
  183.  
  184.         public function onKeyPressed(e:KeyboardEvent) : void
  185.         {
  186.            
  187.             if (e.keyCode == Keyboard.LEFT)
  188.             {
  189.                 wc3.scaleX = -S;
  190.                 if(wc3.x > 0)
  191.                 {0
  192.                     wc3.x = wc3.x - 5;
  193.                     wc3.play();
  194.                 }
  195.             }
  196.             else if (e.keyCode == Keyboard.RIGHT)
  197.             {
  198.                 wc3.scaleX = S;
  199.                 wc3.x = wc3.x + 5;
  200.                 wc3.play();
  201.             }
  202.           }
  203.        
  204.        private function leggTilLyttereUte()
  205.        
  206.        {
  207.             stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);  
  208.             //stage.addEventListener(KeyboardEvent.KEY_UP, onkeyReleased);  
  209.             stage.addEventListener(Event.ENTER_FRAME, onFrameLoop);        
  210.        
  211.        }
  212.        
  213.        private function leggTilLyttereInne()
  214.          
  215.        {
  216.            
  217.             //stage.addEventListener(Event.ENTER_FRAME, onFrameLoop);          
  218.        
  219.        }
  220.        
  221.         private function lyttPaaDoer()
  222.         {
  223.             if (wc3.hitTestObject(hus.doer.haantak) && blomst1.visible == false && blomst2.visible == false && blomst3.visible == false )
  224.             {
  225.                 if (hus.doer.haantak.rotationZ >-60)
  226.                     hus.doer.haantak.rotationZ--;
  227.                    
  228.                 else if (hus.doer.haantak.rotationZ==-60 && hus.doer.rotationY<55)
  229.                     hus.doer.rotationY ++;
  230.                    
  231.                    
  232.                     else
  233.                     {
  234.                        
  235.                     inne.visible = true;
  236.                     S = 0.5 ;
  237.                     wc3.scaleX = wc3.scaleY = S;
  238.                     ute.visible = false;
  239.                     }
  240.         }
  241. //      public function onKeyboardMove(me:KeyboardEvent): void
  242.         //{
  243. //         
  244. //         
  245. //                 
  246. //              //else
  247. //         
  248. //          }
  249.         }
  250.        
  251.         private function leggTilObjektInne()
  252.         {
  253.             rom = new LRom();
  254.             //rom.width = 600;
  255. //          rom.height = 400;
  256.             inne.addChild(rom);
  257.             rom.scaleX = 0.8 ;
  258.             rom.scaleY = 0.94;
  259.         }
  260.  
  261.      }
  262.    }
Add Comment
Please, Sign In to add comment