Keksicle

Menu

Aug 17th, 2017
486
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package;
  2.  
  3. import openfl.display.Sprite;
  4. import openfl.events.MouseEvent;
  5. import openfl.system.System;
  6. import openfl.text.TextField;
  7. import openfl.text.TextFieldAutoSize;
  8. import openfl.text.TextFormat;
  9.  
  10. /**
  11.  * ...
  12.  * @author Reka
  13.  */
  14. class Menu extends Sprite
  15. {
  16.     private var myTextFormat:TextFormat;
  17.     private var gameTitle:TextField;
  18.    
  19.     // Clean previous screen and setup the current screen
  20.     public function new()
  21.     {
  22.         super();
  23.        
  24.         removeChildren();   // Clean previous screen
  25.         mainMenu();
  26.     }
  27.    
  28.     // Setup the current screen
  29.     public function mainMenu()
  30.     {
  31.         // Setup a default text format
  32.         myTextFormat = new TextFormat("_sans", 14, 0xAA2023, true);
  33.        
  34.         // Add the neccessary elements
  35.         addTitle();
  36.         addPlayGame();
  37.         addHallOfFame();
  38.         addQuit();
  39.     }
  40.    
  41.     // Adds the Game's Title
  42.     function addTitle()
  43.     {
  44.         var titleFormat:TextFormat = new TextFormat("_sans", 20, 0xAA2023, true);
  45.         gameTitle = new TextField();
  46.         gameTitle.autoSize = TextFieldAutoSize.LEFT;
  47.         gameTitle.defaultTextFormat = titleFormat;
  48.         gameTitle.text = "Escape!";
  49.         gameTitle.x = 400 - (gameTitle.width / 2);
  50.         gameTitle.y = 100;
  51.         addChild(gameTitle);
  52.     }
  53.    
  54.     // Adds a button to start the gameplay
  55.     function addPlayGame()
  56.     {
  57.         var playGame:TextField = new TextField();
  58.         playGame.autoSize = TextFieldAutoSize.LEFT;
  59.         playGame.defaultTextFormat = myTextFormat;
  60.         playGame.text = "Play Game";
  61.         playGame.x = gameTitle.x;
  62.         playGame.y = gameTitle.y + 100;
  63.         addChild( playGame );
  64.         playGame.addEventListener( MouseEvent.CLICK, start);
  65.     }
  66.    
  67.     // Adds a button to show hall of fame
  68.     function addHallOfFame()
  69.     {
  70.         var hallOfFame:TextField = new TextField();
  71.         hallOfFame.autoSize = TextFieldAutoSize.LEFT;
  72.         hallOfFame.defaultTextFormat = myTextFormat;
  73.         hallOfFame.text = "Hall of Fame";
  74.         hallOfFame.x = gameTitle.x;
  75.         hallOfFame.y = gameTitle.y + 200;
  76.         addChild( hallOfFame );
  77.         hallOfFame.addEventListener( MouseEvent.CLICK, leaderboard);
  78.     }
  79.    
  80.     // Adds a button to quit the game
  81.     function addQuit()
  82.     {
  83.         var quitGame:TextField = new TextField();
  84.         quitGame.autoSize = TextFieldAutoSize.LEFT;
  85.         quitGame.defaultTextFormat = myTextFormat;
  86.         quitGame.text = "Quit Game";
  87.         quitGame.x = gameTitle.x;
  88.         quitGame.y = gameTitle.y + 300;
  89.         addChild( quitGame );
  90.         quitGame.addEventListener( MouseEvent.CLICK, quit);
  91.     }
  92.    
  93.     // Switches to game screen
  94.     function start(evt:MouseEvent)
  95.     {
  96.         removeChildren();
  97.         var gameScreen = new Game();
  98.         addChild(gameScreen);
  99.     }
  100.    
  101.     // Switches to hall of fame screen
  102.     function leaderboard(evt:MouseEvent)
  103.     {
  104.         removeChildren();
  105.         var gameScreen = new HallofFame();
  106.         addChild(gameScreen);
  107.     }
  108.    
  109.     // Exits the game
  110.     function quit(evt:MouseEvent)
  111.     {
  112.         System.exit(0);
  113.     }
  114. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×