Thursday, July 31, 2014

Adding Chartboost to LibGDX games

Chartboost is a way of monetizing mobile gaming applications. In this article, I'm writing down the steps I followed to get Charboost SDK running on a LibGDX based Android game. 

The very first task we have to do is signing up for Chartboost by creating an account in their website. Then we can move into our dashboard where we can create a new app. Since our Android app is still not published into Google Play the only information we need to fill are (1) Platform name which is Android in our case, (2) App nickname which we fill with our app name, (3) App orientation which was portrait in my case, (4) Test mode which we set to 'enabled'. Now click the 'Done' button and note down the App ID and App Signature which we need later in our apps source code. Now, move into the 'Publish' menu and from their, click on the 'Add Campaign' -> 'Publish in the Network' option. Set a name for the campaign and select our app from the Android platform. Now click on the 'Save' button.

Now our configurations from the Chartboost dashboard side is ready. It's time to prepare our LibGDX game source code to use Chartboost. On this, the first thing we have to do is downloading latest Chartboost SDK from here. Go through the following steps to prepare our LibGDX source code to use Chartboost.

(1) Extract the downloaded Chartboost SDK ZIP folder to somewhere in the file system. Copy the chartboost.jar file, chartboost.jar.properties file and doc folder into the libs folder of the Android project in Eclipse. Those are the components which are useful to our project.

(2) Add a new interface called 'ActionResolver' into our LibGDX main project. The content of the 'ActionResolver' interface would be as follows. 

1
2
3
4
public interface ActionResolver {

 public void showChartBoostInterstitial(); 
}

(3) Make the Android projects MainActivity.java to implement that interface. Now put the following codes in the specified locations inside the Main Activity.

Inside OnCreate function:
// make sure to add the correct app ID and app signature from the Chartboost site.

1
2
3
4
5
6
7
 // Configure Chartboost
 this.cb = Chartboost.sharedChartboost();
 // temporary from my account
 String appId = "53d8b2ae8xxxxxxxxxxxxxxxxx";
 // temporary from my account
 String appSignature = "2c37f8f3380259b3efxxxxxxxxxxxxxxxxx";
 this.cb.onCreate(this, appId, appSignature, null);

Inside OnStart() function:

1
2
3
4
5
6
@Override
public void onStart() {
 super.onStart();  
 this.cb.onStart(this);     
 this.cb.showInterstitial(); 
}

Inside OnStop() function:

1
2
3
4
5
@Override
public void onStop(){
        super.onStop();
 this.cb.onStop(this); 
}

Inside OnDestroy() function:

1
2
3
4
5
6
@Override
public void onDestroy() {

        this.cb.onDestroy(this);   
 super.onDestroy();   
}

Inside OnBackPressed() function:

1
2
3
4
5
6
7
8
@Override
public void onBackPressed() {  
 
    if (this.cb.onBackPressed()) 
        return; 
    else 
        super.onBackPressed(); 
}

The function which was defined in the interface. We have to implement it here.


1
2
3
4
5
@Override
public void showChartBoostInterstitial() {
    
    this.cb.showInterstitial();
}

(4) Our ActionResolver interfaces' function implementation is inside the MainActivity of the Android project. To be able to call it from somewhere inside our LibGDX main project, we need to have access to the main activity instance within the main project. The way to do it is to pass the main activity instance as 'this' into the constructor of the initial class in the main libGDX project. The constructor of that class must be modified to accept an ActionResolver object. By doing so, we get the capability show Interstitials within our game whenever necessary by calling the ActionResolvers' showChartBoostInterstitial() function.

Now, building and running the LibGDX android project should show up Interstitials for testing purpose.

Sunday, July 27, 2014

Finished Reading Digital Fortress :)

Few days ago, I finished reading the book Digital Fortress by Dan Brown. It was a book which didn't let me take a rest in the middle of reading. Every chapter, every page leads to a huge curiosity on whats going to happen next and how they will overcome it. Surely, Digital Fortress is a really good thriller book for everybody. Besides the good part of the book, I have some comments on its content from a technical point of view. I agree to the fact that a book for a common reader can not contain most accurate technical details of something described inside the book. That's totally OK because that's not a research paper but instead a novel. However my curious mind mostly got attracted to the technical details and tried to reason why things happen like that and why they didn't do that in some other way.

The most obvious question which came into my mind is related to the invention of the Internet. DARPA (Defense Advanced Research Project Agency) started to build such a distributed system mainly due to security concerns from physical attacks on a centralized command and control center or a data center right? Finally it evolved into the Internet what we see today with a huge potential in commercial and social applications. Even today, distributed systems are the way to face any threats of losing a single point in a system without losing the functionality. The attack can come physically or through the network but we can face it when we have the functionality distributed over the network.

In the book Digital Fortress, one question that bothered me so much was, why this TRANSLTR happened to be a single super computer which does the whole code breaking work. Due to it's centralized architecture, it faced both physical and network threats. When the cooling mechanism went down, they were about to lose the whole code breaking system. That means even an accurately targeted missile into this building of TRANSLTR machine can completely blow off whole code breaking capabilities. In the mean time, network based attacks also targets this centralized system.

The second question is completely related to it. Why the data-bank is not distributed. They should have done that because it appears like the data-bank is a more critical component that this TRANSLTR thing. If these guys store the ballistic missile launch codes, identities of foreign spies, different information related to military installments outside US soil, etc, this is critical. In the mean time, TRANSLTR had access to this centralized data-bank without having to go through some firewall protection. This is a very bad design. They had a firewall for their code breaking machine but not in between their main storage and TRANSLTR inside the same premises apparently.

There's another question which sometimes made me angry while reading. TRANSLTRs functionalities and its daily tasks are transparent to many people. OKay, a cipher text is inserted into the code breaking system and it is taking hours whithout being able to decrypt it. So, what? Every Tom Dick and Harry started to be aware of it. Maintaining the system as technicians and also as people who manage its financial costs is a one thing. Code breaking and national security is another thing. In the Digital Fortress book, many people who have different jobs to do, started to interrupt the work of cryptographers and question the ongoing processes of the code breaking system. It is true that at the end, those who questioned the things were right. However it doesn't justify the security threat of exposing the cryptographic tasks to those who do some other jobs.

Anyway at the end, everything got solved beautifully and had some romantic moments such as David proposing from Spain over the network to Susan at the NSA main data-bank control room or somewhere. Digital Fortress is a nice thriller book which I read after a long time. I think I should find more books from Dan Brown and read in the future.

~***********~

Saturday, July 26, 2014

My Daily GIT Command Sequence

As a user of GIT repositories, everyday I'm checking out the source code from the repository, make changes, and finally submit it to the repository again at the end of the day. This has become a part of my daily work routine. Unless I have encountered some new requirement, most of the days these are the sequence of GIT commands which I issue daily.

I start working by moving into the local working copy of a project through the command line and checking out the source code.

git checkout

Then I start working on the source code. I will be adding new files, deleting files and modifying the existing ones. If I implemented something significant, or if the day is over before I finish working on something, its a time to push my modifications into the remote repository. This is the command sequence for ending my daily work on a repository.

git add *

git commit -a

git push origin remote_branch_name

Occasionally, I come across many different requirements such as cloning a new repository, creating new branches, etc which require a different set of commands. However its very rarely. Most of the cases, the above set of commands do the job for me.

Thursday, July 17, 2014

Hands on MongoDB for Ubuntu 12.04 LTS

While I was working on TikiriDB database abstraction for wireless sensor networks (WSN), a big argument we had is about SQL and NoSQL. Even though the argument is about database abstractions for WSN, not exactly about database management systems for conventional information systems, it was the first time I heard about this new concept, NoSQL. Since then, I have been working on many projects but didn't get a chance to work closely with any NoSQL database system. After a long time, that long awaited moment arrived.
 
As a very popular NoSQL database system, MongoDB is something which I could not avoid. While working on some project, I came across it and had to install and work with it in my Ubuntu platform. To to leave a note about it, I decided to write about how I installed it and moved around the database system to explore. Since my platform is Ubuntu 12.04, the installation process is pretty straightforward. Everything can be accomplished from the command line. So, issue the following commands to install MongoDB.
 
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' |  sudo tee /etc/apt/sources.list.d/mongodb.list

sudo apt-get update

sudo apt-get install mongodb-org
 
 
At the end we can start the MongoDB server from the following command.
 
sudo service mongod start
 

 Now, we can play with the database using a command line client. By default with the database installation we are getting a client called mongo. Start it by typing that command name on the terminal and you should face the query prompt of the mongo client. We can list the current databases by issuing 'show dbs' command on the terminal. Among the output, there should be a database called 'local' by default. Lets move into it by issuing the command 'use local' and after that typing 'db' will confirm that we are in the 'local'.

Inside a MongoDB database such as this 'local' database, there are items called 'Collections' which resemble 'Tables' in a SQL database. Now, we can check what are the collections in this 'local' database by issuing the command 'show collections'. In my system, the only two collections in this database are 'startup_log' and 'system.indexes'. If we want to see the data in one of these collections, we can use find() function in the following way.

db.startup_log.find()

It should list down the contents in this collection which are lot of configuration information of the MongoDB database installation on my platform. This is all for now. More things about MongoDB can be learned from the official MongoDB documentation.

Tuesday, July 15, 2014

Alt+Tab issue in Ubuntu 12.04 with GNOME Classic

As a heavy user of GNU/Linux I always loved the good old appearance of GNOME desktop environment. When the fancy looking Unity interface started to appear in recent versions of Ubuntu, I had to use the GNOME Classic version and I used it together with Clearlooks-Phenix theme since I loved the good old clearlooks theme too. However, Ubuntu 12.04 LTS is facing a trouble with the Alt+Tab keyboard shortcut which we use for switching between windows so rapidly. It appears to be a bug as I found in the web but there is a workaround. This is how I overcame the issue after finding the solution from a forum.

We need Compiz-Config-Settings-Manager for this task. Install it by issuing the following commands in the terminal.

sudo apt-get update

sudo apt-get install compizconfig-settings-manager

After the installation, run the command ccsm on the terminal to start this advanced application. There, under the window management tab, you can find a check box called Static Application Switcher which you should check. Then, Alt+Tab combination for switching between windows should work immediately.


References:

[1] A bug report

[2] A forum question


Tuesday, July 1, 2014

Shoot The Flurry !! :-)

Due to the vast dominance of hand-held devices such as Smartphones and Tabs, the role of PC based applications have moved onto the hand-held device platforms. Gaming applications are no exception. As one of the most popular mobile platforms, Android device users has a huge variety of Games available to select. Since, hand-held devices tend to stay with the user almost all the time from the moment he/she wake up in the morning till the day is done at night, mobile games are within the reach of a user always.

Shoot The Flurry is a completely new mobile game for the Android platform which comes with a new concept. Aligning with the recent trend among mobile game players to choose games with very simplistic ideas, Shoot The Flurry gives a maximum experience. In this game, you are provided with metal balls which move around a wooden wheel in a circular path. When you tap anywhere on the screen, a metal ball escapes from the wheel and flies in a linear direction. In the meantime, balloons of various colors falls down over the screen continuously. Your task is to hit as much balloons as possible to collect your score. Every hit on a balloon earns you a point. When you miss a balloon, you loose a life value which is a rare resource since you have only limited life values.

With beautiful graphics and smooth game play, Shoot The Flurry brings you the joy of playing a completely new game absolutely for no cost. The developer behind Shoot The Flurry is a small team of creative and talented guys from Sri Lanka. Starting from a completely new game concept, they evolved it into a beautiful game as you now see as Shoot The Flurry. It's built on top of an advanced game engine which enables the compatibility of the game to various Android platforms. Even though the game currently comes with just three game play levels, the developers are planning to release more levels with more attractive features in the coming future. Moreover, Shoot The Flurry will not be limited to Android platform as it will come for your iPhone very soon.

Get it on Google Play:
https://www.facebook.com/ShootTheFlurry

Enjoy Shooting The Flurry !!!