diff --git a/Arcade/FlxPongApi/Project.xml b/Arcade/FlxPongApi/Project.xml
index 7d6b9184b..72d78a056 100644
--- a/Arcade/FlxPongApi/Project.xml
+++ b/Arcade/FlxPongApi/Project.xml
@@ -37,10 +37,10 @@
-
+
-
+
diff --git a/Arcade/FlxPongApi/source/Main.hx b/Arcade/FlxPongApi/source/Main.hx
index b3d857db2..d1c7c7bbd 100644
--- a/Arcade/FlxPongApi/source/Main.hx
+++ b/Arcade/FlxPongApi/source/Main.hx
@@ -1,5 +1,7 @@
package;
+import flixel.addons.api.gamejolt.FlxGameJoltRequest;
+import flixel.FlxG;
import flixel.FlxGame;
import openfl.display.Sprite;
@@ -9,5 +11,6 @@ class Main extends Sprite
{
super();
addChild(new FlxGame(450, 150, MenuState));
+ FlxG.signals.postUpdate.add(() -> new FlxGameJoltRequest(SESSION_PING(true)).send(true));
}
}
diff --git a/Arcade/FlxPongApi/source/MenuState.hx b/Arcade/FlxPongApi/source/MenuState.hx
index 8f92d0e3c..e8711bf70 100644
--- a/Arcade/FlxPongApi/source/MenuState.hx
+++ b/Arcade/FlxPongApi/source/MenuState.hx
@@ -1,13 +1,13 @@
package;
+import flixel.addons.ui.FlxUIInputText;
+import flixel.addons.api.gamejolt.*;
+import flixel.addons.api.FlxGameJolt as OldGameJolt;
import flash.display.BitmapData;
import flash.display.Sprite;
-import flash.text.TextFieldType;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
-import flixel.addons.api.FlxGameJolt;
-import flixel.addons.text.FlxTextField;
import flixel.group.FlxGroup;
import flixel.text.FlxText;
import openfl.utils.ByteArray;
@@ -35,28 +35,36 @@ class MenuState extends FlxState
var _login:Button;
var _apiCurrentPage:Int;
var _mainMenuTime:Float = 0.0;
- var _input1:FlxTextField;
- var _input2:FlxTextField;
+ var _input1:FlxUIInputText;
+ var _input2:FlxUIInputText;
var _imageDisplay:FlxSprite;
-
+
static inline function API_TEST_BUTTONS():Array>
{
- return [
- ["fetchUser", "authUser", "openSession", "pingSession"],
- ["closeSession", "fetchTrophy", "addTrophy", "fetchScore"],
- ["addScore", "getTables", "fetchData", "setData"],
- ["updateData", "removeData", "getAllKeys", "resetUser"],
- ["fetchTrophyImage", "fetchAvatarImage", "username", "usertoken"],
- ["isQuickPlay", "isEmbeddedFlash"]
- ];
+ var row:Array = [];
+ var rows:Array> = [];
+
+ for (button in FlxGameJoltRequestType.getConstructors())
+ {
+ row.push(button);
+ if (row.length >= 4)
+ {
+ rows.push(row);
+ row = [];
+ }
+ }
+ if (row.length > 0)
+ rows.push(row);
+
+ return rows;
}
-
+
override public function create():Void
{
Reg.genColors();
FlxG.cameras.bgColor = Reg.lite;
Reg.level = 1;
-
+
#if FLX_MOUSE
var mouseSprite:Sprite = new Sprite();
mouseSprite.graphics.beginFill(Reg.dark, 1);
@@ -64,70 +72,70 @@ class MenuState extends FlxState
mouseSprite.graphics.lineTo(20, 20);
mouseSprite.graphics.lineTo(0, 27.5);
mouseSprite.graphics.endFill();
-
+
// using .show( mouseSprite ) doesn't work, so we convert it to bitmapdata
-
+
var mouseData:BitmapData = new BitmapData(20, 30, true, 0);
mouseData.draw(mouseSprite);
FlxG.mouse.load(mouseData);
FlxG.mouse.visible = true;
#end
-
+
// The background emitter, connection info, version, and blurb are always present.
-
+
var em:Emitter = new Emitter(Std.int(FlxG.width / 2), Std.int(FlxG.height / 2), 4);
-
+
_connection = new FlxText(1, 1, FlxG.width, "Connecting to GameJolt...");
_connection.color = Reg.med_lite;
-
+
var info:FlxText = new FlxText(0, FlxG.height - 14, FlxG.width,
"FlxPong is a demo of HaxeFlixel & FlxGameJolt, which interacts with the GameJolt API.");
info.color = Reg.med_lite;
info.alignment = CENTER;
-
+
var ver:FlxText = new FlxText(0, 0, FlxG.width, Reg.VERSION);
ver.color = Reg.med_lite;
ver.alignment = RIGHT;
-
+
add(em);
add(_connection);
add(info);
add(ver);
-
+
// Set up the "main" screen/buttons.
-
+
_main = new FlxGroup();
-
+
var title:FlxText = new FlxText(0, 20, FlxG.width, "FlxPong!", 16);
title.color = Reg.med_dark;
title.alignment = CENTER;
-
+
var play:Button = new Button(0, 50, "Play!", playCallback);
Reg.quarterX(play, 2);
-
+
_login = new Button(0, 50, "Log in", switchMenu, 60);
Reg.quarterX(_login, 3);
_login.visible = false;
_login.active = false;
-
+
var test:Button = new Button(0, 80, "API Functions", switchMenu);
Reg.quarterX(test, 1);
-
+
var high:Button = new Button(0, 80, "High Scores", scoresCallback);
Reg.quarterX(high, 2);
-
+
var mine:Button = new Button(0, 80, "My Scores", mineCallback);
Reg.quarterX(mine, 3);
-
+
var source:Button = new Button(0, 110, "FlxGameJolt Source", sourceCallback, 120);
Reg.quarterX(source, 1);
-
+
var hf:Button = new Button(0, 110, "HaxeFlixel.com", hfCallback);
Reg.quarterX(hf, 2);
-
+
var doc:Button = new Button(0, 110, "GameJolt API Doc", docCallback, 120);
Reg.quarterX(doc, 3);
-
+
_main.add(title);
_main.add(play);
_main.add(_login);
@@ -137,72 +145,72 @@ class MenuState extends FlxState
_main.add(source);
_main.add(hf);
_main.add(doc);
-
+
// End main group.
-
+
// Set up the "high scores" screen.
-
+
_highScores = new FlxGroup();
-
+
// End high scores.
-
+
// Set up the API test screen.
-
+
_apiTest = new FlxGroup();
-
+
var xpos:Int = 2;
var ypos:Array = [20, 42, 64, 86, 108, 130];
var buttonwidth:Int = 100;
-
+
// Set up the pages of this screen.
-
+
_apiPages = [];
_apiCurrentPage = 0;
-
+
for (i in 0...API_TEST_BUTTONS().length)
{
_apiPages.push(new FlxGroup());
-
+
var button1:Button;
var button2:Button;
var button3:Button;
var button4:Button;
-
+
if (API_TEST_BUTTONS()[i][0] != null)
{
button1 = new Button(xpos, ypos[0], API_TEST_BUTTONS()[i][0], apiCallback, buttonwidth);
_apiPages[i].add(button1);
}
-
+
if (API_TEST_BUTTONS()[i][1] != null)
{
button2 = new Button(xpos, ypos[1], API_TEST_BUTTONS()[i][1], apiCallback, buttonwidth);
_apiPages[i].add(button2);
}
-
+
if (API_TEST_BUTTONS()[i][2] != null)
{
button3 = new Button(xpos, ypos[2], API_TEST_BUTTONS()[i][2], apiCallback, buttonwidth);
_apiPages[i].add(button3);
}
-
+
if (API_TEST_BUTTONS()[i][3] != null)
{
button4 = new Button(xpos, ypos[3], API_TEST_BUTTONS()[i][3], apiCallback, buttonwidth);
_apiPages[i].add(button4);
}
-
+
_apiPages[i].visible = false;
_apiPages[i].active = false;
}
-
+
// We do want to see the first page, once apiTest is added
-
+
_apiPages[0].visible = true;
_apiPages[0].active = true;
-
+
// Add elements aside from the per-screen buttons
-
+
var prev:Button = new Button(xpos, ypos[4], "<<", testMove, Std.int(buttonwidth / 2 - xpos / 2));
var next:Button = new Button(Std.int(prev.x + prev.width + 2), ypos[4], ">>", testMove, Std.int(buttonwidth / 2 - xpos / 2));
var testSpace:PongSprite = new PongSprite(xpos + buttonwidth + xpos, ypos[0], FlxG.width - (xpos + buttonwidth + xpos * 2), ypos[4] + 20 - ypos[0],
@@ -212,66 +220,65 @@ class MenuState extends FlxState
_imageDisplay = new FlxSprite(testSpace.x + 5, testSpace.y + 5);
_imageDisplay.visible = false;
var exit:Button = new Button(Std.int(testSpace.x + testSpace.width - 40), Std.int(testSpace.y + testSpace.height - 20), "Back", switchMenu, 40);
-
+
// Add everything to this screen
-
+
for (g in _apiPages)
{
_apiTest.add(g);
}
-
+
_apiTest.add(prev);
_apiTest.add(next);
_apiTest.add(testSpace);
_apiTest.add(_return);
_apiTest.add(_imageDisplay);
_apiTest.add(exit);
-
+
_apiTest.active = false;
_apiTest.visible = false;
-
+
// End API test.
-
+
// Login screen
-
+
_loginGroup = new FlxGroup();
-
- var instruct:FlxText = new FlxText(0, 50, FlxG.width, "Log in to GameJolt to get trophies and stuff:");
+
+ var instruct:FlxText = new FlxText(0, 40, FlxG.width, "Log in to GameJolt to get trophies and stuff:");
instruct.alignment = CENTER;
instruct.color = Reg.med_dark;
-
- var word1:FlxText = new FlxText(0, 70, 60, "Username:");
- var word2:FlxText = new FlxText(0, 90, 60, "Token:");
+
+ var word1:FlxText = new FlxText(0, 60, 60, "Username:");
+ var word2:FlxText = new FlxText(0, 85, 60, "Token:");
Reg.quarterX(word1, 1);
Reg.quarterX(word2, 1);
word1.color = word2.color = Reg.med_dark;
-
- _input1 = new FlxTextField(0, 70, 240, " ");
- _input2 = new FlxTextField(0, 90, 240, " ");
+
+ _input1 = new FlxUIInputText(0, word1.y + (word1.height / 2), 150, "");
+ _input2 = new FlxUIInputText(0, word2.y + (word2.height / 2), 150, "");
Reg.quarterX(_input1, 3);
Reg.quarterX(_input2, 3);
- _input2.color = _input1.color = Reg.med_lite;
- _input2.textField.selectable = _input1.textField.selectable = true;
- _input2.textField.multiline = _input1.textField.multiline = false;
- _input2.textField.wordWrap = _input1.textField.wordWrap = false;
- _input2.textField.maxChars = _input1.textField.maxChars = 30;
+ _input1.color = _input2.color = Reg.med_lite;
+ _input1.y -= _input1.height / 2;
+ _input2.y -= _input2.height / 2;
+ _input1.maxLength = 30;
+ _input2.maxLength = 7;
#if flash
- _input2.textField.restrict = _input1.textField.restrict = "A-Za-z0-9_";
+ _input2.textField.restrict = "A-Za-z0-9";
#end
- _input2.textField.type = _input1.textField.type = TextFieldType.INPUT;
-
+
var input1bg:PongSprite = new PongSprite(Std.int(_input1.x), Std.int(_input1.y), Std.int(_input1.width - 40), Std.int(_input1.height + 4), Reg.dark);
var input2bg:PongSprite = new PongSprite(Std.int(_input2.x), Std.int(_input2.y), Std.int(_input2.width - 40), Std.int(_input2.height + 4), Reg.dark);
-
+
#if desktop
_input1.height = input1bg.height;
_input2.height = input2bg.height;
#end
-
+
var trylogin:Button = new Button(0, 110, "Log in", loginCallback);
Reg.quarterX(trylogin, 2);
var back:Button = new Button(400, 108, "Back", switchMenu, 40);
-
+
_loginGroup.add(word1);
_loginGroup.add(word2);
_loginGroup.add(input1bg);
@@ -281,56 +288,64 @@ class MenuState extends FlxState
_loginGroup.add(instruct);
_loginGroup.add(trylogin);
_loginGroup.add(back);
-
+
_loginGroup.active = false;
_loginGroup.visible = false;
-
+
// End Login.
-
+
_allScreens = new FlxGroup();
_allScreens.add(_main);
_allScreens.add(_apiTest);
_allScreens.add(_loginGroup);
-
+
add(_allScreens);
-
+
em.start(false);
-
+
// Load the privatekey data as a bytearray.
-
+
var ba:ByteArray = new MyPrivateKey();
-
+
// If we're already initialized (which would happen on returning from the playstate), we don't need to run init().
// If we're not initialized, call init() using the game ID and the private key, which is converted to a string
// with .readUTFBytes( ba.length ). The ba.length ensures that the ByteArray will be read from beginning to end
// and then stop; otherwise, there would be an error when the end of the ByteArray was reached.
-
- if (!FlxGameJolt.initialized)
- {
- FlxGameJolt.init(19975, ba.readUTFBytes(ba.length), true, null, null, initCallback);
- }
- else
+
+ FlxGameJolt.gameID = 19975;
+ FlxGameJolt.gameKey = ba.readUTFBytes(ba.length);
+
+ var open_session = new FlxGameJoltRequest(BATCH(false, false, [SESSION_CHECK, SESSION_OPEN]));
+ open_session.onComplete.add(function(res)
{
- _connection.text = "Welcome back to the main menu, " + FlxGameJolt.username + "!";
- }
-
+ if (res.responses[0].success)
+ {
+ _connection.text = "Welcome back to the main menu, " + FlxGameJolt.username + "!";
+ return;
+ }
+
+ initCallback(res.responses[1].success);
+ });
+ open_session.onError.add((_) -> initCallback(false));
+ open_session.send(false);
+
super.create();
}
-
+
override public function update(elapsed:Float):Void
{
_mainMenuTime += elapsed;
-
+
#if FLX_KEYBOARD
if (FlxG.keys.justPressed.ENTER && _loginGroup.visible)
{
loginCallback("Login");
}
#end
-
+
super.update(elapsed);
}
-
+
#if debug
function colorCallback(Name:String):Void
{
@@ -338,32 +353,32 @@ class MenuState extends FlxState
FlxG.switchState(MenuState.new);
}
#end
-
+
function playCallback(Name:String):Void
{
FlxG.switchState(PlayState.new);
}
-
+
function hfCallback(Name:String):Void
{
FlxG.openURL("http://www.haxeflixel.com");
}
-
+
function sourceCallback(Name:String):Void
{
FlxG.openURL("https://github.com/HaxeFlixel/flixel-addons/blob/master/flixel/addons/api/FlxGameJolt.hx");
}
-
+
function docCallback(Name:String):Void
{
FlxG.openURL("http://gamejolt.com/api/doc/game/");
}
-
+
function scoresCallback(Name:String):Void
{
// stuff
}
-
+
function switchMenu(Name:String):Void
{
if (_loginGroup.visible)
@@ -371,124 +386,125 @@ class MenuState extends FlxState
_input1.text = " ";
_input2.text = " ";
}
-
+
for (g in _allScreens)
{
g.visible = false;
g.active = false;
}
-
+
if (Name == "Back")
{
_main.visible = true;
_main.active = true;
}
-
+
if (Name == "API Functions")
{
_apiTest.visible = true;
_apiTest.active = true;
}
-
+
if (Name == "Log in")
{
_loginGroup.visible = true;
_loginGroup.active = true;
}
}
-
+
function loginCallback(Name:String):Void
{
+ FlxGameJolt.username = _input1.text.trim();
+ FlxGameJolt.usertoken = _input2.text.trim();
+
_connection.text = "Attempting to log in...";
- FlxGameJolt.authUser(_input1.text.trim(), _input2.text.trim(), initCallback);
+ var login_request = new FlxGameJoltRequest(SESSION_OPEN);
+ login_request.onComplete.add(res -> initCallback(res.success));
+ login_request.onError.add((_) -> initCallback(false));
+ login_request.send(false);
}
-
+
function mineCallback(Name:String):Void {}
-
+
+ @:access(flixel.addons.api.gamejolt.FlxGameJolt.usertoken)
function apiCallback(Name:String):Void
{
_imageDisplay.visible = false;
_return.text = "Sending " + Name + " request to GameJolt...";
-
+
+ var request:Null = null;
+
switch (Name)
{
- case "fetchUser":
- FlxGameJolt.fetchUser(0, FlxGameJolt.username, [], apiReturn);
- case "authUser":
- FlxGameJolt.authUser(FlxGameJolt.username, FlxGameJolt.usertoken, authReturn);
- case "openSession":
- FlxGameJolt.openSession(apiReturn);
- case "pingSession":
- FlxGameJolt.pingSession(true, apiReturn);
- case "closeSession":
- FlxGameJolt.closeSession(apiReturn);
- case "fetchTrophy":
- FlxGameJolt.fetchTrophy(0, apiReturn);
- case "addTrophy":
- FlxGameJolt.addTrophy(5079, apiReturn);
- case "fetchScore":
- FlxGameJolt.fetchScore(10, apiReturn);
- case "addScore":
- FlxGameJolt.addScore(Std.string(Math.round(_mainMenuTime)) + "secondsinmenu", Math.round(_mainMenuTime), 0, false, null, "FlxPongRox",
- apiReturn);
- case "getTables":
- FlxGameJolt.getTables(apiReturn);
- case "fetchData":
- FlxGameJolt.fetchData("testkey", true, apiReturn);
- case "setData":
- FlxGameJolt.setData("testkey", "IheartBACON", true, apiReturn);
- case "updateData":
- FlxGameJolt.updateData("testkey", "append", "andSAUSAGE", true, apiReturn);
- case "removeData":
- FlxGameJolt.removeData("testkey", true, apiReturn);
- case "getAllKeys":
- FlxGameJolt.getAllKeys(true, apiReturn);
- case "resetUser":
- FlxGameJolt.resetUser(FlxGameJolt.username, FlxGameJolt.usertoken, authReturn);
- case "fetchTrophyImage":
- FlxGameJolt.fetchTrophyImage(5072, apiImageReturn);
- case "fetchAvatarImage":
- FlxGameJolt.fetchAvatarImage(apiImageReturn);
- case "username":
- _return.text = "User name: " + FlxGameJolt.username;
- case "usertoken":
- _return.text = "User token: " + FlxGameJolt.usertoken;
- case "isQuickPlay":
- _return.text = "Was FlxPong loaded via Quick Play? Status: " + FlxGameJolt.isQuickPlay;
- case "isEmbeddedFlash":
- _return.text = "Was FlxPong loaded as embedded Flash on GameJolt? Status: " + FlxGameJolt.isEmbeddedFlash;
+ case "BATCH":
+ request = new FlxGameJoltRequest(BATCH(false, false, [USER_AUTH, SESSION_CHECK]));
+ case "USER_AUTH":
+ request = new FlxGameJoltRequest(USER_AUTH);
+ case "SESSION_OPEN":
+ request = new FlxGameJoltRequest(SESSION_OPEN);
+ case "SESSION_PING":
+ request = new FlxGameJoltRequest(SESSION_PING(true));
+ case "SESSION_CLOSE":
+ request = new FlxGameJoltRequest(SESSION_CLOSE);
+ case "SESSION_CHECK":
+ request = new FlxGameJoltRequest(SESSION_CHECK);
+ case "TROPHIES_ADD":
+ request = new FlxGameJoltRequest(TROPHIES_ADD(5079));
+ case "TROPHIES_REMOVE":
+ request = new FlxGameJoltRequest(TROPHIES_REMOVE(5079));
+ case "TROPHIES_FETCH":
+ request = new FlxGameJoltRequest(TROPHIES_FETCH(5079));
+ case "SCORES_FETCH":
+ request = new FlxGameJoltRequest(SCORES_FETCH(false));
+ case "SCORES_ADD":
+ var s = Math.round(_mainMenuTime);
+ request = new FlxGameJoltRequest(SCORES_ADD('${s}secondsinmenu', s, "FlxPongRox"));
+ case "SCORES_TABLES":
+ request = new FlxGameJoltRequest(SCORES_TABLES);
+ case "SCORES_GETRANK":
+ request = new FlxGameJoltRequest(SCORES_GETRANK(Math.round(_mainMenuTime)));
+ case "DATA_FETCH":
+ request = new FlxGameJoltRequest(DATA_FETCH("testkey", true));
+ case "DATA_SET":
+ request = new FlxGameJoltRequest(DATA_SET("testkey", "IheartBACON", true));
+ case "DATA_UPDATE":
+ request = new FlxGameJoltRequest(DATA_UPDATE("testkey", Append("andSAUSAGE"), true));
+ case "DATA_REMOVE":
+ request = new FlxGameJoltRequest(DATA_REMOVE("testkey", true));
+ case "DATA_GETKEYS":
+ request = new FlxGameJoltRequest(DATA_GETKEYS(true));
+ case "FRIENDS":
+ request = new FlxGameJoltRequest(FRIENDS);
+ case "TIME":
+ request = new FlxGameJoltRequest(TIME);
+ /*
+ case "username":
+ _return.text = "User name: " + FlxGameJolt.username;
+ case "usertoken":
+ _return.text = "User token: " + FlxGameJolt.usertoken;
+ */
default:
_return.text = "Sorry, there was an error. :(";
}
- }
-
- function apiReturn(ReturnMap:Map):Void
- {
- _return.text = "Received from GameJolt:\n" + ReturnMap.toString();
- }
-
- function apiImageReturn(Bits:BitmapData):Void
- {
- _return.text = "";
- _imageDisplay.loadGraphic(Bits);
- _imageDisplay.visible = true;
- }
-
- function authReturn(Success:Bool):Void
- {
- _return.text = "The user authentication returned: " + Success;
-
- if (!Success)
+
+ if (request != null)
{
- _return.text += ". This is probably because the user is already authenticated! You can use resetUser() to authenticate a new user.";
+ request.onComplete.add(apiReturn);
+ request.onError.add(err -> apiReturn({success: false, message: err}));
+ request.send(false);
}
}
-
+
+ function apiReturn(ReturnMap:FlxGameJoltResponse):Void
+ {
+ _return.text = 'Received from GameJolt:\n${ReturnMap}';
+ }
+
function testMove(Name:String):Void
{
_apiPages[_apiCurrentPage].visible = false;
_apiPages[_apiCurrentPage].active = false;
-
+
if (Name.charCodeAt(0) == 60)
{
_apiCurrentPage--;
@@ -497,17 +513,17 @@ class MenuState extends FlxState
{
_apiCurrentPage++;
}
-
+
if (_apiCurrentPage < 0)
_apiCurrentPage = _apiPages.length - 1;
-
+
if (_apiCurrentPage > _apiPages.length - 1)
_apiCurrentPage = 0;
-
+
_apiPages[_apiCurrentPage].visible = true;
_apiPages[_apiCurrentPage].active = true;
}
-
+
function initCallback(Result:Bool):Void
{
if (_connection != null)
@@ -518,21 +534,19 @@ class MenuState extends FlxState
{
_connection.text = "Successfully connected to GameJolt! Hi " + FlxGameJolt.username + "!";
}
-
- FlxGameJolt.addTrophy(5072);
-
+
+ new FlxGameJoltRequest(TROPHIES_ADD(5072)).send(false);
+
if (_login.visible)
{
_login.visible = false;
_login.active = false;
}
-
+
if (_loginGroup.visible == true)
{
switchMenu("Back");
}
-
- // FlxGameJolt.fetchAvatarImage( avatarCallback );
}
else
{
@@ -545,10 +559,4 @@ class MenuState extends FlxState
}
}
}
-
- public function createToast(ReturnMap:Dynamic):Void
- {
- var toast:Toast = new Toast(ReturnMap.get("id"));
- add(toast);
- }
}
diff --git a/Arcade/FlxPongApi/source/PlayState.hx b/Arcade/FlxPongApi/source/PlayState.hx
index 4b9703d54..47c048836 100644
--- a/Arcade/FlxPongApi/source/PlayState.hx
+++ b/Arcade/FlxPongApi/source/PlayState.hx
@@ -1,6 +1,7 @@
package;
-import flixel.addons.api.FlxGameJolt;
+import flixel.addons.api.gamejolt.FlxGameJoltRequest;
+import flixel.addons.api.gamejolt.FlxGameJolt;
import flixel.FlxG;
import flixel.FlxState;
import flixel.group.FlxGroup;
@@ -13,7 +14,7 @@ class PlayState extends FlxState
public var ball:Ball;
public var emitterGroup:FlxTypedGroup;
public var collidables:FlxGroup;
-
+
var _obstacles:FlxTypedGroup;
var _centerText:FlxText;
var _player:Player;
@@ -21,35 +22,35 @@ class PlayState extends FlxState
var _enemy:Enemy;
var _enemyBullets:Emitter;
var _paused:Bool = false;
-
+
override public function create():Void
{
Reg.PS = this;
FlxG.cameras.bgColor = Reg.lite;
-
+
#if FLX_MOUSE
FlxG.mouse.visible = false;
#end
-
+
_debris = new Emitter(FlxG.width, 0, 2, Reg.med_lite);
_debris.height = FlxG.height;
_debris.velocity.set(Reg.level * -10, -10, Reg.level * -1, 10);
-
+
_player = new Player();
-
+
_enemy = new Enemy();
-
+
ball = new Ball();
-
+
emitterGroup = new FlxTypedGroup(5);
_obstacles = new FlxTypedGroup(10);
newObstacle();
-
+
_centerText = new FlxText(0, 0, FlxG.width, "");
_centerText.alignment = CENTER;
_centerText.color = Reg.med_dark;
_centerText.y = Std.int((FlxG.height - _centerText.height) / 2);
-
+
add(_debris);
add(emitterGroup);
add(_player);
@@ -57,33 +58,33 @@ class PlayState extends FlxState
add(ball);
add(_obstacles);
add(_centerText);
-
+
collidables = new FlxGroup();
-
+
var topWall = new PongSprite(0, -2, FlxG.width, 2, Reg.dark);
var bottomWall = new PongSprite(0, FlxG.height, FlxG.width, 2, Reg.dark);
topWall.moves = false;
bottomWall.moves = false;
topWall.immovable = true;
bottomWall.immovable = true;
-
+
collidables.add(_obstacles);
collidables.add(topWall);
collidables.add(bottomWall);
collidables.add(_player);
collidables.add(_enemy);
-
+
_debris.start(false);
-
- FlxGameJolt.addTrophy(5071);
-
+
+ new FlxGameJoltRequest(TROPHIES_ADD(5071)).send(false);
+
super.create();
-
+
ball.init();
_player.init();
_enemy.init();
}
-
+
override public function update(elapsed:Float):Void
{
#if FLX_KEYBOARD
@@ -96,26 +97,26 @@ class PlayState extends FlxState
FlxG.switchState(MenuState.new);
}
#end
-
+
if (_paused)
return;
-
+
_player.y = FlxMath.bound(FlxG.mouse.y, 0, FlxG.height - _player.height);
-
+
if (ball.alive)
{
if (ball.x > FlxG.width)
{
ball.kill();
_enemy.kill();
+
+ _centerText.text = "Nice! Moving on to level " + (Reg.level - 1) + "!";
+ new FlxGameJoltRequest(SCORES_ADD('${Reg.level} enemies destroyed', Reg.level, 20599)).send(false);
Reg.level++;
- _centerText.text = "Nice! Moving on to level " + Reg.level + "!";
-
- FlxGameJolt.addScore((Reg.level - 1) + " enemies destroyed", Reg.level - 1, 20599);
-
+
new FlxTimer().start(4, newEnemy, 1);
}
-
+
if (ball.x < 0)
{
ball.kill();
@@ -124,10 +125,10 @@ class PlayState extends FlxState
new FlxTimer().start(4, endGame, 1);
}
}
-
+
super.update(elapsed);
}
-
+
public function newEnemy(f:FlxTimer):Void
{
_centerText.text = "";
@@ -136,7 +137,7 @@ class PlayState extends FlxState
ball.reset(FlxG.width / 2, FlxG.height / 2);
newObstacle();
}
-
+
public function newObstacle():Void
{
var obs:PongSprite = _obstacles.recycle(PongSprite, function()
@@ -147,7 +148,7 @@ class PlayState extends FlxState
obs.velocity.y = FlxG.random.float(-10, 10);
obs.immovable = true;
}
-
+
function endGame(f:FlxTimer):Void
{
FlxG.switchState(MenuState.new);
diff --git a/Arcade/FlxPongApi/source/Toast.hx b/Arcade/FlxPongApi/source/Toast.hx
deleted file mode 100644
index 979848df9..000000000
--- a/Arcade/FlxPongApi/source/Toast.hx
+++ /dev/null
@@ -1,68 +0,0 @@
-package;
-
-import flash.display.BitmapData;
-import flixel.FlxG;
-import flixel.FlxSprite;
-import flixel.group.FlxSpriteGroup;
-import flixel.text.FlxText;
-import flixel.tweens.FlxTween;
-import flixel.addons.api.FlxGameJolt;
-import flixel.util.FlxTimer;
-
-class Toast extends FlxSpriteGroup
-{
- static inline var WIDTH:Int = 105;
- static inline var HEIGHT:Int = 115;
-
- var _name:String;
- var _id:Int;
- var _had:String;
-
- /**
- * Just a handy class to unlock a trophy, and provide visual notification of such to the player.
- *
- * @param TrophyID
- */
- public function new(TrophyID:Int)
- {
- super(FlxG.width, FlxG.height - HEIGHT - 10);
- _id = TrophyID;
- // FlxGameJolt.addTrophy( TrophyID, fetchImage );
- FlxGameJolt.fetchTrophy(_id, setUpTrophy);
- }
-
- function setUpTrophy(Return:Map):Void
- {
- _name = Return.get("title");
- FlxGameJolt.fetchTrophyImage(_id, awardTrophy);
- }
-
- function awardTrophy(bd:BitmapData):Void
- {
- var bg:PongSprite = new PongSprite(0, 0, WIDTH, HEIGHT, Reg.dark);
- var top:FlxText = new FlxText(0, -2, WIDTH, "Trophy Get!");
- top.color = Reg.med_lite;
- top.alignment = CENTER;
- var img:FlxSprite = new FlxSprite(Math.round((WIDTH - 75) / 2), 16, bd);
- var bottom:FlxText = new FlxText(0, HEIGHT - 23, WIDTH - 1, _name);
- bottom.color = Reg.lite;
- bottom.alignment = CENTER;
-
- add(bg);
- add(img);
- add(top);
- add(bottom);
-
- FlxTween.linearMotion(this, this.x, this.y, this.x - WIDTH - 10, this.y, 1);
- new FlxTimer().start(6, removeThis, 1);
- }
-
- function removeThis(t:FlxTimer):Void
- {
- visible = false;
- active = false;
- exists = false;
- alive = false;
- destroy();
- }
-}