aboutsummaryrefslogtreecommitdiff
path: root/source/screens
diff options
context:
space:
mode:
authorIndrajith K L2021-09-22 10:10:50 +0530
committerIndrajith K L2021-09-22 10:10:50 +0530
commit9abd235ed2b9a5c80d5e63d6187d69e9317c2f0d (patch)
tree5a7618d359c216a9a24ff73e2bdc3550e9d03080 /source/screens
downloadLeaderboardTest-9abd235ed2b9a5c80d5e63d6187d69e9317c2f0d.tar.gz
LeaderboardTest-9abd235ed2b9a5c80d5e63d6187d69e9317c2f0d.tar.bz2
LeaderboardTest-9abd235ed2b9a5c80d5e63d6187d69e9317c2f0d.zip
* Initial Commit
* Leaderboard Implementation for dreamlo * FlxSave for Player Data * GUID Generation for Unique User
Diffstat (limited to 'source/screens')
-rw-r--r--source/screens/LeaderBoardState.hx74
-rw-r--r--source/screens/MenuState.hx31
-rw-r--r--source/screens/RegisterPlayerState.hx27
3 files changed, 132 insertions, 0 deletions
diff --git a/source/screens/LeaderBoardState.hx b/source/screens/LeaderBoardState.hx
new file mode 100644
index 0000000..67f726e
--- /dev/null
+++ b/source/screens/LeaderBoardState.hx
@@ -0,0 +1,74 @@
+package screens;
+
+import flixel.FlxG;
+import flixel.FlxState;
+import flixel.addons.ui.FlxUIGroup;
+import flixel.addons.ui.FlxUIList;
+import flixel.addons.ui.FlxUIRegion;
+import flixel.addons.ui.FlxUIText;
+import flixel.text.FlxText;
+import flixel.ui.FlxButton;
+import flixel.util.FlxColor;
+import shared.PlayerSave;
+import shared.ScoreBoard;
+import shared.Types.Entry;
+import shared.Types.ScoreBoardData;
+
+class LeaderBoardState extends FlxState
+{
+ var scoreBoardList:FlxUIList;
+ var previousState:FlxState;
+
+ public function new()
+ {
+ super();
+ var scoreLabel:FlxText = new FlxText(FlxG.width / 2 - 50, 10, "Leaderboard", 13);
+ scoreLabel.borderSize = 1;
+ scoreLabel.borderColor = FlxColor.PURPLE;
+ scoreLabel.borderQuality = 1;
+ scoreLabel.borderStyle = FlxTextBorderStyle.OUTLINE;
+ scoreBoardList = new FlxUIList(FlxG.width / 2 - 100, 70, [], 300, 300, "More");
+ scoreBoardList.loadGraphic(AssetPaths.space_bg__png);
+ var backButton:FlxButton = new FlxButton(FlxG.width / 2 - 40, 410, "Back", onBackButtonClick);
+ add(scoreLabel);
+ add(scoreBoardList);
+ add(backButton);
+ getScores();
+ }
+
+ override public function create()
+ {
+ super.create();
+ }
+
+ private function getScores()
+ {
+ var scoreboard:ScoreBoard = new ScoreBoard();
+ var scoresData:ScoreBoardData = scoreboard.getScores();
+ trace(scoresData.dreamlo.leaderboard);
+ if (scoresData.dreamlo.leaderboard != null)
+ {
+ var scores:Array<Entry> = scoresData.dreamlo.leaderboard.entry;
+ for (i in 0...400)
+ {
+ scores.push(scores[0]);
+ }
+ for (score in scores)
+ {
+ var widgetGroup:FlxUIGroup = new FlxUIGroup(0, 0);
+ var nameTxt:FlxUIText = new FlxUIText(0, 0, 100, '${score.text}', 11);
+ var scoreTxt:FlxUIText = new FlxUIText(100, 0, 100, '${score.score}', 11);
+ nameTxt.alignment = FlxTextAlign.LEFT;
+ scoreTxt.alignment = FlxTextAlign.RIGHT;
+ widgetGroup.add(nameTxt);
+ widgetGroup.add(scoreTxt);
+ scoreBoardList.add(widgetGroup);
+ }
+ }
+ }
+
+ private function onBackButtonClick()
+ {
+ FlxG.switchState(new MenuState());
+ }
+}
diff --git a/source/screens/MenuState.hx b/source/screens/MenuState.hx
new file mode 100644
index 0000000..9f4deda
--- /dev/null
+++ b/source/screens/MenuState.hx
@@ -0,0 +1,31 @@
+package screens;
+
+import flixel.FlxG;
+import flixel.FlxState;
+import flixel.ui.FlxButton;
+import shared.PlayerSave;
+
+class MenuState extends FlxState
+{
+ public function new()
+ {
+ super();
+ var playButton = new FlxButton(FlxG.width / 2 - 40, FlxG.height / 2, "Play", onPlayButtonPressed);
+ var leaderBoardButton = new FlxButton(FlxG.width / 2 - 40, FlxG.width / 2 + 30, "Leaderboard", onLeaderBoardButtonPressed);
+ add(playButton);
+ add(leaderBoardButton);
+ trace(PlayerSave.instance.guid);
+ }
+
+ override public function create()
+ {
+ super.create();
+ }
+
+ function onPlayButtonPressed() {}
+
+ function onLeaderBoardButtonPressed()
+ {
+ FlxG.switchState(new LeaderBoardState());
+ }
+}
diff --git a/source/screens/RegisterPlayerState.hx b/source/screens/RegisterPlayerState.hx
new file mode 100644
index 0000000..e50d3d1
--- /dev/null
+++ b/source/screens/RegisterPlayerState.hx
@@ -0,0 +1,27 @@
+package screens;
+
+import flixel.FlxG;
+import flixel.FlxSprite;
+import flixel.FlxState;
+import shared.PlayerSave;
+import shared.UserNamePopup;
+
+class RegisterPlayerState extends FlxState
+{
+ override public function create()
+ {
+ super.create();
+ var bg = new FlxSprite(0, 0, AssetPaths.space_bg__png);
+ var popup = new UserNamePopup(OnSave);
+ add(bg);
+ add(popup);
+ }
+
+ function OnSave(data:PlayerSave)
+ {
+ if (data != null)
+ {
+ FlxG.switchState(new MenuState());
+ }
+ }
+}