Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- import openfl.display.Sprite;
- import openfl.events.MouseEvent;
- import openfl.system.System;
- import openfl.text.TextField;
- import openfl.text.TextFieldAutoSize;
- import openfl.text.TextFormat;
- /**
- * ...
- * @author Reka
- */
- class Menu extends Sprite
- {
- private var myTextFormat:TextFormat;
- private var gameTitle:TextField;
- // Clean previous screen and setup the current screen
- public function new()
- {
- super();
- removeChildren(); // Clean previous screen
- mainMenu();
- }
- // Setup the current screen
- public function mainMenu()
- {
- // Setup a default text format
- myTextFormat = new TextFormat("_sans", 14, 0xAA2023, true);
- // Add the neccessary elements
- addTitle();
- addPlayGame();
- addHallOfFame();
- addQuit();
- }
- // Adds the Game's Title
- function addTitle()
- {
- var titleFormat:TextFormat = new TextFormat("_sans", 20, 0xAA2023, true);
- gameTitle = new TextField();
- gameTitle.autoSize = TextFieldAutoSize.LEFT;
- gameTitle.defaultTextFormat = titleFormat;
- gameTitle.text = "Escape!";
- gameTitle.x = 400 - (gameTitle.width / 2);
- gameTitle.y = 100;
- addChild(gameTitle);
- }
- // Adds a button to start the gameplay
- function addPlayGame()
- {
- var playGame:TextField = new TextField();
- playGame.autoSize = TextFieldAutoSize.LEFT;
- playGame.defaultTextFormat = myTextFormat;
- playGame.text = "Play Game";
- playGame.x = gameTitle.x;
- playGame.y = gameTitle.y + 100;
- addChild( playGame );
- playGame.addEventListener( MouseEvent.CLICK, start);
- }
- // Adds a button to show hall of fame
- function addHallOfFame()
- {
- var hallOfFame:TextField = new TextField();
- hallOfFame.autoSize = TextFieldAutoSize.LEFT;
- hallOfFame.defaultTextFormat = myTextFormat;
- hallOfFame.text = "Hall of Fame";
- hallOfFame.x = gameTitle.x;
- hallOfFame.y = gameTitle.y + 200;
- addChild( hallOfFame );
- hallOfFame.addEventListener( MouseEvent.CLICK, leaderboard);
- }
- // Adds a button to quit the game
- function addQuit()
- {
- var quitGame:TextField = new TextField();
- quitGame.autoSize = TextFieldAutoSize.LEFT;
- quitGame.defaultTextFormat = myTextFormat;
- quitGame.text = "Quit Game";
- quitGame.x = gameTitle.x;
- quitGame.y = gameTitle.y + 300;
- addChild( quitGame );
- quitGame.addEventListener( MouseEvent.CLICK, quit);
- }
- // Switches to game screen
- function start(evt:MouseEvent)
- {
- removeChildren();
- var gameScreen = new Game();
- addChild(gameScreen);
- }
- // Switches to hall of fame screen
- function leaderboard(evt:MouseEvent)
- {
- removeChildren();
- var gameScreen = new HallofFame();
- addChild(gameScreen);
- }
- // Exits the game
- function quit(evt:MouseEvent)
- {
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement