[GAME] Space Lasers - galaxy puzzle saga


#1

Hi,
Let me introduce my new game - Space Lasers - https://itunes.apple.com/app/space-lasers-blast-in-galaxy-puzzle-saga/id944950714

Space Lasers - puzzle with lasers and mirrors. In game there are more than 300 levels that can help you forget about your problems and spend time with pleasure. Use your mind, wit and creative potential to solve difficult puzzles quickly.
The game is divided into several worlds that have from 20 to 30 levels of different complexity and block characteristics (some of them reflect the laser, others reflect and pass it through themselves or teleport to other places etc).




We have use
• SDKBOX
• GameSpark (Backend Development Platform)

  • News
  • Daily challenge
  • Account for user (save progress)

Please check this game. Waiting for your questions and reviews.


#2

Hi, perfect game. How you integrate GamesSpark? I saw sdk for cocos2dx but I can’t find any tutorials.
Thank you for your answer.


#3

Hi!
I didn’t see tutorials too. I use sample:
https://bitbucket.org/gamesparks/gamesparks-cpp-cocos2dx/src/e7f3aa773895?at=master


#4

This post was flagged by the community and is temporarily hidden.


#5

Hi! What platform do you have problems with?


#6

MacOS Sierra 10.12.6
Xcode 9.2
Cocos2dx 3.16
Building for iOS
GameSparksSDK version - 1.1.19.0


#7

Congrats! It looks cool. May I ask some questions in the future to learn from your experiences about cocos. Did you use Cocos Creator?


#8

Copy/Move GameSparks SDK to Classes folder.
Go to Build Settings tab, then find User Header Search Path add
$(SRCROOT)/../Classes/GameSparksSDK/include
Find Other Linker Flags add
-ObjC
-v

Don’t add all SDK folder to your xCode project, you should add ONLY 2 files
GameSparksSDK/src/GameSparksAll.cpp
GameSparksSDK/src/UNIX2003_Fix.c


#9

Thank you!
Yes you can. No, I use cocos2d-x 3.16


#10

Thanks for the help. Can you please tell how do you initialize GS in your cocos2dx project?


#11

This is not a working code and it maybe not be compiled. This is example just for understanding how it works.

GameSparksManager.h

#pragma once

#include "cocos2d.h"

// *GS* includes needed for GameSparks
#include <GameSparks/GS.h>
#include <GameSparks/Cocos2dxPlatform.h>
#include <GameSparks/generated/GSRequests.h>

class GameSparksManager
{
public:
    static GameSparksManager *getInstance();
    static void destroyInstance();

    bool isLogin() { return gsupdater.GS.GetAuthenticated(); }

    void login(const std::string& name, const std::string& pswrd, std::function<void(bool)> callback);
    void logout() { gsupdater.GS.Disconnect(); gsupdater.GS.Reset(); }

    void registration(const std::string& dispaly_name, const std::string& name, const std::string& pswrd, std::function<void(bool)> callback);

    void saveSettings();
    void loadSettings();

    ~GameSparksManager();

private:
    GameSparksManager();
    bool init();

    void onGameSparksAvailable(GameSparks::Core::GS& gsInstance, bool available);

    void authenticationRequest_Response(GameSparks::Core::GS& gsInstance, const GameSparks::Api::Responses::AuthenticationResponse& response);
    void registrationRequest_Response(GameSparks::Core::GS& gsInstance, const GameSparks::Api::Responses::RegistrationResponse& response);
    void accountDetailsRequest_Response(GameSparks::Core::GS& gsInstance, const GameSparks::Api::Responses::AccountDetailsResponse& response);

    void loadSettingsRequest_Response(GameSparks::Core::GS& gsInstance, const GameSparks::Api::Responses::LogEventResponse& response);

    struct GameSparksCocos
    {
        GameSparksCocos(): platform(GS_API_KEY, GS_API_SECRET, true, true)
        {
            GS.Initialise(&platform);
        }
        GameSparks::Core::Cocos2dxPlatform platform;
        GameSparks::Core::GS GS;

        void update(float dt)
        {
            GS.Update(dt);
        }
    };
    GameSparksCocos gsupdater;

    std::function<void(bool)> _auth_callback;
    std::function<void(bool)> _reg_callback;
};

GameSparksManager.cpp

#include "GameSparksManager.h"

USING_NS_CC;

GameSparksManager::GameSparksManager()
{
}

GameSparksManager::~GameSparksManager()
{
}

GameSparksManager *GameSparksManager::getInstance()
{
    if (_GameSparksManager == nullptr)
    {
        _GameSparksManager = new GameSparksManager();
        if (!_GameSparksManager->init())
        {
            delete _GameSparksManager;
            _GameSparksManager = nullptr;
        }
    }
    return _GameSparksManager;
}

GameSparksManager* GameSparksManager::_GameSparksManager = nullptr;

void GameSparksManager::destroyInstance()
{
    CC_SAFE_DELETE(_GameSparksManager);
}

bool GameSparksManager::init()
{
    using namespace GameSparks::Core;
    gsupdater.GS.GameSparksAvailable = std::bind(&GameSparksManager::onGameSparksAvailable, this, std::placeholders::_1, std::placeholders::_2);
    Director::getInstance()->getScheduler()->scheduleUpdate(&gsupdater, 0, false);

    return true;
}

void GameSparksManager::login(const std::string& name, const std::string& pswrd, std::function<void(bool)> callback)
{
    GameSparks::Api::Requests::AuthenticationRequest request(gsupdater.GS);
    request.SetUserName(name);
    request.SetPassword(pswrd);
    request.Send(std::bind(&GameSparksManager::authenticationRequest_Response, this, std::placeholders::_1, std::placeholders::_2));
    _auth_callback = callback;
}

void GameSparksManager::registration(const std::string & dispaly_name, const std::string & name, const std::string & pswrd, std::function<void(bool)> callback)
{
    GameSparks::Api::Requests::RegistrationRequest request(gsupdater.GS);
    request.SetDisplayName(dispaly_name);
    request.SetUserName(name);
    request.SetPassword(pswrd);
    request.Send(std::bind(&GameSparksManager::registrationRequest_Response, this, std::placeholders::_1, std::placeholders::_2));
    _reg_callback = callback;
}

void GameSparksManager::saveSettings()
{
    if (!isLogin())
        return;

    auto json = GameSparks::cJSON_CreateObject();

    auto json_score = GameSparks::cJSON_CreateNumber(PlayersManager::getInstance()->getCurrPlayer()->score);
    GameSparks::cJSON_AddItemReferenceToObject(json, "score", json_score);

    GameSparks::Api::Requests::LogEventRequest request(gsupdater.GS);
    request.SetEventKey("saveMainProgress");
    request.SetEventAttribute("value", json);
    request.Send();
}

void GameSparksManager::loadSettings()
{
    if (!isLogin())
        return;

    GameSparks::Api::Requests::LogEventRequest request(gsupdater.GS);
    request.SetEventKey("loadMainProgress");
    request.Send(std::bind(&GameSparksManager::loadSettingsRequest_Response, this, std::placeholders::_1, std::placeholders::_2));
}

void GameSparksManager::addCoins(int coins)
{
    if (!isLogin())
        return;
    GameSparks::Api::Requests::LogEventRequest request(gsupdater.GS);
    request.SetEventKey("addCoins");
    request.SetEventAttribute("amount", coins);
    request.Send();
}

void GameSparksManager::spendCoins(int coins)
{
    if (!isLogin())
        return;
    GameSparks::Api::Requests::LogEventRequest request(gsupdater.GS);
    request.SetEventKey("spendCoins");
    request.SetEventAttribute("amount", coins);
    request.Send();
}

void GameSparksManager::onGameSparksAvailable(GameSparks::Core::GS& gsInstance, bool available)
{
    cocos2d::log("GameSparks is %s.", (available ? "available" : "not available"));
    GameManager::getInstance();

    if (isLogin())
    {
        GameSparks::Api::Requests::AccountDetailsRequest accountDetailsRequest(gsupdater.GS);
        accountDetailsRequest.Send(std::bind(&GameSparksManager::accountDetailsRequest_Response, this, std::placeholders::_1, std::placeholders::_2));
    }
}

/******************************************************************************************************************************/
/*                                                                                                                            */
/*                                                    RESPONSES                                                               */
/*                                                                                                                            */
/******************************************************************************************************************************/

void GameSparksManager::authenticationRequest_Response(GameSparks::Core::GS& gsInstance, const     GameSparks::Api::Responses::AuthenticationResponse& response)
{
    if (response.GetHasErrors())
    {
        cocos2d::log("something went wrong during the authentication");
        cocos2d::log("%s", response.GetErrors().GetValue().GetJSON().c_str());
        if(_auth_callback)
            _auth_callback(false);
    }
    else
    {
        cocos2d::log("you successfully authenticated to GameSparks with your credentials");
        cocos2d::log("your displayname is %s.", response.GetBaseData().GetString("displayName").GetValue().c_str());

        if (_auth_callback)
            _auth_callback(true);
    }
}

void GameSparksManager::registrationRequest_Response(GameSparks::Core::GS & gsInstance, const GameSparks::Api::Responses::RegistrationResponse & response)
{
    if (response.GetHasErrors())
    {
        cocos2d::log("something went wrong during the registration");
        cocos2d::log("%s", response.GetErrors().GetValue().GetJSON().c_str());
        if (_reg_callback)
            _reg_callback(false);
    }
    else
    {
        cocos2d::log("you successfully registration on GameSparks");
        cocos2d::log("your displayname is %s.", response.GetBaseData().GetString("displayName").GetValue().c_str());

        if (_reg_callback)
            _reg_callback(true);
    }
}

void GameSparksManager::accountDetailsRequest_Response(GameSparks::Core::GS & gsInstance, const GameSparks::Api::Responses::AccountDetailsResponse & response)
{
    if (response.GetHasErrors())
    {
        cocos2d::log("something went wrong during the account details");
        cocos2d::log("%s", response.GetErrors().GetValue().GetJSON().c_str());
    }
    else
    {
        cocos2d::log("you successfully get account details");
        cocos2d::log("your displayname is %s.", response.GetBaseData().GetString("displayName").GetValue().c_str());

        int server_coins = response.GetCurrency1().GetValue();
        GameManager::getInstance()->setCoins(server_coins);
    }
}

void GameSparksManager::loadSettingsRequest_Response(GameSparks::Core::GS & gsInstance, const GameSparks::Api::Responses::LogEventResponse & response)
{
    if (response.GetHasErrors())
    {
        cocos2d::log("something went wrong during loading main settings");
        cocos2d::log("%s", response.GetErrors().GetValue().GetJSON().c_str());
    }
    else
    {
        cocos2d::log("you successfully loading main settings");

        auto empty_settings = response.GetScriptData().GetValue().GetGSDataObject("main_player_saves").GetValue().GetString("empty_settings");
        if (empty_settings.GetValue() == "true")
        {
            return;
        }

        PlayersManager::getInstance()->getCurrPlayer()->score = main_player_saves.GetInt("score").GetValue();
    }
}