Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package;
- import openfl.Lib;
- import openfl.display.Sprite;
- import openfl.text.TextField;
- import openfl.text.TextFormat;
- import openfl.text.TextFieldAutoSize;
- import openfl.events.MouseEvent;
- /**
- * ...
- * @author Reka
- */
- class HallofFame extends Sprite
- {
- private var myTextFormat:TextFormat;
- // Clean previous screen and setup the current screen
- public function new()
- {
- super();
- removeChildren(); // Clean up previous screen
- hallofame();
- }
- // Setup the current screen
- function hallofame()
- {
- // Setup a default text format
- myTextFormat = new TextFormat("_sans", 14, 0xAA2023, true);
- // Add the neccessary elements
- addLeaderboard();
- goBacktoMenu();
- }
- // Get leaderboard scores and get them displayed
- function addLeaderboard()
- {
- var scores = Database.GetScores();
- var scoreCount = 0;
- for (score in scores)
- {
- addScore(scoreCount, score.playerName, score.playerScore);
- scoreCount += 1;
- }
- }
- // Displays a single leaderboard score
- function addScore(scoreID:Int, name:String, score:Int)
- {
- // Rank
- var textRank = new TextField();
- textRank.defaultTextFormat = myTextFormat;
- textRank.selectable = false;
- textRank.text = Std.string(scoreID + 1);
- textRank.x = 10;
- textRank.y = 100 + (scoreID * 30);
- addChild( textRank );
- // Player Name
- var textName = new TextField();
- textName.defaultTextFormat = myTextFormat;
- textName.selectable = false;
- textName.text = name;
- textName.width = 320;
- textName.x = 50;
- textName.y = 100 + (scoreID * 30);
- addChild( textName );
- // Player Score
- var textScore = new TextField();
- textScore.defaultTextFormat = myTextFormat;
- textScore.selectable = false;
- textScore.text = Std.string(score);
- textScore.x = 400;
- textScore.y = 100 + (scoreID * 30);
- addChild( textScore );
- }
- // a function for a button to take the player back to the main menu
- function goBacktoMenu()
- {
- var buttonText:TextField = new TextField();
- buttonText.autoSize = TextFieldAutoSize.LEFT; //position button to the left
- buttonText.defaultTextFormat = myTextFormat;
- buttonText.text = "Back to Menu"; //displays text on button
- buttonText.x = 50; //positions button on screen with coordinates
- buttonText.y = 50;
- addChild( buttonText ); //adds the button itself
- buttonText.addEventListener( MouseEvent.CLICK, backtoMenu); //makes button respond to clicking by redirecting player to menu
- }
- // a function for a button to take the player back to the main menu
- function backtoMenu(evt:MouseEvent)
- {
- removeChildren();
- var newScreen = new Menu();
- addChild(newScreen);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement