aboutsummaryrefslogtreecommitdiff
path: root/source/shared
diff options
context:
space:
mode:
Diffstat (limited to 'source/shared')
-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
6 files changed, 200 insertions, 0 deletions
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("");
+ }
+}