aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--.gitignore46
-rw-r--r--.vscode/extensions.json6
-rw-r--r--.vscode/launch.json21
-rw-r--r--.vscode/settings.json13
-rw-r--r--.vscode/tasks.json13
-rw-r--r--Project.xml84
-rw-r--r--assets/data/data-goes-here.txt0
-rw-r--r--assets/images/images-go-here.txt0
-rw-r--r--assets/images/space_bg.pngbin0 -> 10980 bytes
-rw-r--r--assets/music/music-goes-here.txt0
-rw-r--r--assets/sounds/sounds-go-here.txt0
-rw-r--r--hxformat.json15
-rw-r--r--source/AssetPaths.hx4
-rw-r--r--source/Main.hx13
-rw-r--r--source/PlayState.hx33
-rw-r--r--source/screens/LeaderBoardState.hx74
-rw-r--r--source/screens/MenuState.hx31
-rw-r--r--source/screens/RegisterPlayerState.hx27
-rw-r--r--source/shared/PlayerSave.hx37
-rw-r--r--source/shared/ScoreBoard.hx54
-rw-r--r--source/shared/Types.hx25
-rw-r--r--source/shared/UIBackground.hx14
-rw-r--r--source/shared/UserNamePopup.hx57
-rw-r--r--source/shared/Utils.hx13
24 files changed, 580 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f3c021a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,46 @@
+# Prerequisites
+*.d
+
+# Object files
+*.o
+*.ko
+*.obj
+*.elf
+
+# Linker output
+*.ilk
+*.map
+*.exp
+
+# Precompiled Headers
+*.gch
+*.pch
+
+# Libraries
+*.lib
+*.a
+*.la
+*.lo
+
+# Shared objects (inc. Windows DLLs)
+*.dll
+*.so
+*.so.*
+*.dylib
+
+# Executables
+*.exe
+*.out
+*.app
+*.i*86
+*.x86_64
+*.hex
+
+# Debug files
+*.dSYM/
+*.su
+*.idb
+*.pdb
+
+# Build Folders
+export/ \ No newline at end of file
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
new file mode 100644
index 0000000..89e20ed
--- /dev/null
+++ b/.vscode/extensions.json
@@ -0,0 +1,6 @@
+{
+ "recommendations": [
+ "openfl.lime-vscode-extension",
+ "redhat.vscode-xml"
+ ]
+}
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..5e9a7a1
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,21 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Build + Debug",
+ "type": "lime",
+ "request": "launch"
+ },
+ {
+ "name": "Debug",
+ "type": "lime",
+ "request": "launch",
+ "preLaunchTask": null
+ },
+ {
+ "name": "Macro",
+ "type": "haxe-eval",
+ "request": "launch"
+ }
+ ]
+}
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..4c1a0e9
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,13 @@
+{
+ "search.exclude": {
+ "export/**/*.hx": true
+ },
+ "[haxe]": {
+ "editor.formatOnSave": true,
+ "editor.formatOnPaste": true,
+ "editor.codeActionsOnSave": {
+ "source.sortImports": true
+ }
+ },
+ "haxe.enableExtendedIndentation": true
+} \ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644
index 0000000..16a7764
--- /dev/null
+++ b/.vscode/tasks.json
@@ -0,0 +1,13 @@
+{
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "type": "lime",
+ "command": "test",
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ }
+ }
+ ]
+}
diff --git a/Project.xml b/Project.xml
new file mode 100644
index 0000000..fd79d2e
--- /dev/null
+++ b/Project.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project xmlns="http://lime.software/project/1.0.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://lime.software/project/1.0.2 http://lime.software/xsd/project-1.0.2.xsd">
+
+ <!-- _________________________ Application Settings _________________________ -->
+
+ <app title="LeaderBoardTest" file="LeaderBoardTest" main="Main" version="0.0.1" company="HaxeFlixel" />
+
+ <!--The flixel preloader is not accurate in Chrome. You can use it regularly if you embed the swf into a html file
+ or you can set the actual size of your file manually at "FlxPreloaderBase-onUpdate-bytesTotal"-->
+ <app preloader="flixel.system.FlxPreloader" />
+
+ <!--Minimum without FLX_NO_GAMEPAD: 11.8, without FLX_NO_NATIVE_CURSOR: 11.2-->
+ <set name="SWF_VERSION" value="11.8" />
+
+ <!-- ____________________________ Window Settings ___________________________ -->
+
+ <!--These window settings apply to all targets-->
+ <window width="640" height="480" fps="60" background="#000000" hardware="true" vsync="false" />
+
+ <!--HTML5-specific-->
+ <window if="html5" resizable="false" />
+
+ <!--Desktop-specific-->
+ <window if="desktop" orientation="landscape" fullscreen="false" resizable="true" />
+
+ <!--Mobile-specific-->
+ <window if="mobile" orientation="landscape" fullscreen="true" width="0" height="0" />
+
+ <!-- _____________________________ Path Settings ____________________________ -->
+
+ <set name="BUILD_DIR" value="export" />
+ <source path="source" />
+ <assets path="assets" />
+
+ <!-- _______________________________ Libraries ______________________________ -->
+
+ <haxelib name="flixel" />
+
+ <!--In case you want to use the addons package-->
+ <haxelib name="flixel-addons" />
+
+ <!--In case you want to use the ui package-->
+ <haxelib name="flixel-ui" />
+
+ <!--In case you want to use nape with flixel-->
+ <!--<haxelib name="nape-haxe4" />-->
+
+ <!-- ______________________________ Haxedefines _____________________________ -->
+
+ <!--Enable the Flixel core recording system-->
+ <!--<haxedef name="FLX_RECORD" />-->
+
+ <!--Disable the right and middle mouse buttons-->
+ <!--<haxedef name="FLX_NO_MOUSE_ADVANCED" />-->
+
+ <!--Disable the native cursor API on Flash-->
+ <!--<haxedef name="FLX_NO_NATIVE_CURSOR" />-->
+
+ <!--Optimise inputs, be careful you will get null errors if you don't use conditionals in your game-->
+ <haxedef name="FLX_NO_MOUSE" if="mobile" />
+ <haxedef name="FLX_NO_KEYBOARD" if="mobile" />
+ <haxedef name="FLX_NO_TOUCH" if="desktop" />
+ <!--<haxedef name="FLX_NO_GAMEPAD" />-->
+
+ <!--Disable the Flixel core sound tray-->
+ <!--<haxedef name="FLX_NO_SOUND_TRAY" />-->
+
+ <!--Disable the Flixel sound management code-->
+ <!--<haxedef name="FLX_NO_SOUND_SYSTEM" />-->
+
+ <!--Disable the Flixel core focus lost screen-->
+ <!--<haxedef name="FLX_NO_FOCUS_LOST_SCREEN" />-->
+
+ <!--Disable the Flixel core debugger. Automatically gets set whenever you compile in release mode!-->
+ <haxedef name="FLX_NO_DEBUG" unless="debug" />
+
+ <!--Enable this for Nape release builds for a serious peformance improvement-->
+ <haxedef name="NAPE_RELEASE_BUILD" unless="debug" />
+
+ <!-- _________________________________ Custom _______________________________ -->
+
+ <!--Place custom nodes like icons here (higher priority to override the HaxeFlixel icon)-->
+</project>
diff --git a/assets/data/data-goes-here.txt b/assets/data/data-goes-here.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/assets/data/data-goes-here.txt
diff --git a/assets/images/images-go-here.txt b/assets/images/images-go-here.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/assets/images/images-go-here.txt
diff --git a/assets/images/space_bg.png b/assets/images/space_bg.png
new file mode 100644
index 0000000..4032c6f
--- /dev/null
+++ b/assets/images/space_bg.png
Binary files differ
diff --git a/assets/music/music-goes-here.txt b/assets/music/music-goes-here.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/assets/music/music-goes-here.txt
diff --git a/assets/sounds/sounds-go-here.txt b/assets/sounds/sounds-go-here.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/assets/sounds/sounds-go-here.txt
diff --git a/hxformat.json b/hxformat.json
new file mode 100644
index 0000000..66cb386
--- /dev/null
+++ b/hxformat.json
@@ -0,0 +1,15 @@
+{
+ "lineEnds": {
+ "leftCurly": "both",
+ "rightCurly": "both",
+ "objectLiteralCurly": {
+ "leftCurly": "after"
+ }
+ },
+ "sameLine": {
+ "ifElse": "next",
+ "doWhile": "next",
+ "tryBody": "next",
+ "tryCatch": "next"
+ }
+}
diff --git a/source/AssetPaths.hx b/source/AssetPaths.hx
new file mode 100644
index 0000000..db7ef44
--- /dev/null
+++ b/source/AssetPaths.hx
@@ -0,0 +1,4 @@
+package;
+
+@:build(flixel.system.FlxAssets.buildFileReferences("assets", true))
+class AssetPaths {}
diff --git a/source/Main.hx b/source/Main.hx
new file mode 100644
index 0000000..efa0e2d
--- /dev/null
+++ b/source/Main.hx
@@ -0,0 +1,13 @@
+package;
+
+import flixel.FlxGame;
+import openfl.display.Sprite;
+
+class Main extends Sprite
+{
+ public function new()
+ {
+ super();
+ addChild(new FlxGame(0, 0, PlayState));
+ }
+}
diff --git a/source/PlayState.hx b/source/PlayState.hx
new file mode 100644
index 0000000..593c32f
--- /dev/null
+++ b/source/PlayState.hx
@@ -0,0 +1,33 @@
+package;
+
+import flixel.FlxG;
+import flixel.FlxState;
+import flixel.util.FlxSave;
+import screens.MenuState;
+import screens.RegisterPlayerState;
+import shared.PlayerSave;
+
+class PlayState extends FlxState
+{
+ var saveData:FlxSave = new FlxSave();
+
+ override public function create()
+ {
+ super.create();
+ saveData.bind("PlayerSaveObj");
+ if (saveData.data.playerSaveObj == null)
+ {
+ FlxG.switchState(new RegisterPlayerState());
+ }
+ else
+ {
+ PlayerSave.instance.setPlayerData(saveData.data.playerSaveObj.name, saveData.data.playerSaveObj.guid);
+ FlxG.switchState(new MenuState());
+ }
+ }
+
+ override public function update(elapsed:Float)
+ {
+ super.update(elapsed);
+ }
+}
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());
+ }
+ }
+}
diff --git a/source/shared/PlayerSave.hx b/source/shared/PlayerSave.hx
new file mode 100644
index 0000000..298eca6
--- /dev/null
+++ b/source/shared/PlayerSave.hx
@@ -0,0 +1,37 @@
+package shared;
+
+class PlayerSave
+{
+ public static final instance:PlayerSave = new PlayerSave();
+
+ @:isVar public var name(get, set):String;
+ @:isVar public var guid(get, set):String;
+
+ private function new() {}
+
+ public function setPlayerData(_name:String, _name:String)
+ {
+ this.name = _name;
+ this.guid = _name;
+ }
+
+ function set_name(name:String):String
+ {
+ return this.name = name;
+ }
+
+ public function get_name()
+ {
+ return name;
+ }
+
+ function set_guid(guid:String):String
+ {
+ return this.guid = guid;
+ }
+
+ public function get_guid()
+ {
+ return guid;
+ }
+}
diff --git a/source/shared/ScoreBoard.hx b/source/shared/ScoreBoard.hx
new file mode 100644
index 0000000..f91ae34
--- /dev/null
+++ b/source/shared/ScoreBoard.hx
@@ -0,0 +1,54 @@
+package shared;
+
+import haxe.Http;
+import haxe.Json;
+import shared.Types.ScoreBoardData;
+
+class ScoreBoard
+{
+ var scoreBoardSecret:String = '8lykk7evgka9JqFzCs_C-QSBPeydJIUEa_vSuoSRJYJQ';
+ var scoreBoardPublicId:String = '6144ce1e8f40bb0e285c6d95';
+ var scoreBoardSetUrl:String;
+ var baseUrl:String = 'http://dreamlo.com';
+
+ public function new()
+ {
+ this.scoreBoardSetUrl = '$baseUrl/lb/$scoreBoardSecret/add';
+ }
+
+ public function setScore(name:String, guid:String, score:Int)
+ {
+ var scoreUrl:String = '$scoreBoardSetUrl/$guid/$score/0/$name';
+ var request:Http = new Http(scoreUrl);
+ trace(scoreUrl);
+ // request.onData = function(data)
+ // {
+ // trace(data);
+ // }
+
+ request.onError = function(error)
+ {
+ trace(error);
+ }
+ request.request(false);
+ }
+
+ public function getScores():ScoreBoardData
+ {
+ var scoresUrl:String = '$baseUrl/lb/$scoreBoardPublicId/json';
+ var request:Http = new Http(scoresUrl);
+ request.onData = function(data)
+ {
+ // trace(data);
+ }
+
+ request.onError = function(error)
+ {
+ trace(error);
+ }
+ request.request(false);
+
+ var response = request.responseBytes;
+ return Json.parse(response.toString());
+ }
+}
diff --git a/source/shared/Types.hx b/source/shared/Types.hx
new file mode 100644
index 0000000..3faad76
--- /dev/null
+++ b/source/shared/Types.hx
@@ -0,0 +1,25 @@
+package shared;
+
+typedef Entry =
+{
+ var date:String;
+ var name:String;
+ var score:String;
+ var seconds:String;
+ var text:String;
+}
+
+typedef LeaderBoard =
+{
+ var entry:Array<Entry>;
+}
+
+typedef DreamLo =
+{
+ var leaderboard:LeaderBoard;
+}
+
+typedef ScoreBoardData =
+{
+ var dreamlo:DreamLo;
+}
diff --git a/source/shared/UIBackground.hx b/source/shared/UIBackground.hx
new file mode 100644
index 0000000..de3b4c9
--- /dev/null
+++ b/source/shared/UIBackground.hx
@@ -0,0 +1,14 @@
+package shared;
+
+import flixel.FlxSprite;
+import flixel.util.FlxColor;
+
+class UIBackground extends FlxSprite
+{
+ public function new(x:Float = 0, y:Float = 0, width:Int, height:Int, color:FlxColor)
+ {
+ super(x, y);
+ makeGraphic(width, height, color);
+ alpha = 0.5;
+ }
+}
diff --git a/source/shared/UserNamePopup.hx b/source/shared/UserNamePopup.hx
new file mode 100644
index 0000000..81e7129
--- /dev/null
+++ b/source/shared/UserNamePopup.hx
@@ -0,0 +1,57 @@
+package shared;
+
+import flixel.FlxG;
+import flixel.FlxObject;
+import flixel.FlxSprite;
+import flixel.addons.ui.FlxInputText;
+import flixel.addons.ui.FlxUIGroup;
+import flixel.graphics.FlxGraphic;
+import flixel.group.FlxGroup.FlxTypedGroup;
+import flixel.text.FlxText;
+import flixel.ui.FlxButton;
+import flixel.util.FlxColor;
+import flixel.util.FlxSave;
+
+class UserNamePopup extends FlxTypedGroup<FlxSprite>
+{
+ var popupWidth:Int = 200;
+ var popupHeight:Int = 100;
+ var pX:Float = 0;
+ var pY:Float = 0;
+ var textFieldWidth = 150;
+ var textFieldHeight = 8;
+ var txtInput:FlxInputText;
+ var playerSave:FlxSave;
+
+ public function new(OnClick:PlayerSave->Void)
+ {
+ super();
+ this.playerSave = new FlxSave();
+ this.playerSave.bind("PlayerSaveObj");
+ this.pX = (FlxG.width / 2) - (this.popupWidth / 2);
+ this.pY = (FlxG.height / 2) - (popupHeight / 2);
+ var inputTextX = this.pX + (this.popupWidth / 2) - (this.textFieldWidth / 2);
+ var inputTextY = this.pY + (this.popupHeight / 2) - this.textFieldHeight;
+ var uiBackground:UIBackground = new UIBackground(this.pX, this.pY, this.popupWidth, this.popupHeight, FlxColor.PURPLE);
+ var label:FlxText = new FlxText(inputTextX, inputTextY - 20, 100, "Enter Your Name");
+ var enterGameBut = new FlxButton(inputTextX + textFieldWidth / 2 - 4, inputTextY + 20, "Enter Game", onEnterGame.bind(this, OnClick));
+ this.txtInput = new FlxInputText(inputTextX, inputTextY, this.textFieldWidth, "", this.textFieldHeight);
+ txtInput.backgroundColor = FlxColor.PURPLE;
+ txtInput.color = FlxColor.WHITE;
+ add(uiBackground);
+ add(label);
+ add(txtInput);
+ add(enterGameBut);
+ }
+
+ function onEnterGame(event, OnClick)
+ {
+ FlxG.camera.shake(0.05);
+ var guid = Utils.Guid();
+ PlayerSave.instance.setPlayerData(this.txtInput.text, guid);
+ this.playerSave.data.playerSaveObj = PlayerSave.instance;
+ this.playerSave.flush();
+ OnClick(PlayerSave.instance);
+ trace(OnClick);
+ }
+}
diff --git a/source/shared/Utils.hx b/source/shared/Utils.hx
new file mode 100644
index 0000000..3f924ed
--- /dev/null
+++ b/source/shared/Utils.hx
@@ -0,0 +1,13 @@
+package shared;
+
+import haxe.Timer;
+import lime.tools.GUID;
+
+class Utils
+{
+ public static function Guid()
+ {
+ var guid = GUID.seededUuid(Date.now().toString());
+ return guid.split("{").join("").split("}").join("");
+ }
+}