Wednesday, December 25, 2013

How To Make Simple Game In Android

How To Make Simple Game In Android

This Tutorial Explains about how to make simple game in android, In the recent market these andorid game are hiitng great, As these game are getting compulsory to developers to learn how to develop games in android.In this Tutorial lets see some basic simple game to build in android,

First and foremost to develop games in android OS, we have to know abou ANDEngine, its a 2dimensional android game development library based engine, With this engine we can develop 2d based games like shooting games, puzzle games, racing games and soo on...

Before to develop the game with this engine you must have some basic knowledge on Andengine and Java development and some patience.If not please go to the below link to get an idea about this engine.


Now we see how to build a sample shooting game in android OS using AND engine.
Theme of the game : Its a simpe game, a ball should collect all the diamonds and stars and navigate the ball using accelerometer sensrors in the mobile, and avoid hitting with the enemy balls.

Basic view of the game : 


Start : You should make all the environment ready like ECLIPSE(IDE), Integrated with ANDROID SDK, and also ANDENGINE, if you don't have download it from HERE

Now Let's see how to write a code for this game, Please note i am not writing all the code here, these are main snippets which are lill bit tricky,You can download total souce below 
As we know the first and formost document class going to be main.java,
Here you can see this code in the main class, 

Main.java:

public class GameLogicController extends BaseGameActivity 
implements IAccelerometerListener
{
                 public PlayerProfileManager playerProfileManager; 
                 public LevelController levelController;
                 private Camera camera;
                 protected PhysicsWorld mPhysicsWorld;
                 public Texture mTexture;
                 public TextureRegion enemyTextureRegion;
                 private float mGravityX;
                 private float mGravityY;
                 private final Vector2 mTempVector = new Vector2();
                 public TiledTextureRegion mCircleFaceTextureRegion;
                 private RepeatingSpriteBackground mGrassBackground;
                 private Sound mGameOverSound;
                 and soo on..
}
Here BaseGameActivity is the main class in the ANDENGINE , anyways you would have known about the IAccelerometerListener, it is used for iterating accelerator sensors in the mobile device, after this youw must load a Load engine class, and you can also place an animated sprite which can available only in that engine

public class Player extends AnimatedSprite   {
...
@Override
protected void onManagedUpdate(final float pSecondsElapsed) {
super.onManagedUpdate(pSecondsElapsed);
onBeforePositionChanged();
}

private boolean onBeforePositionChanged(){
//speed up
if(frameCount < 2){
frameCount++;
return true;
}
frameCount = 0;
int enemyListSize = levelController.getEnemyList().size();
for(int i = 0; i < enemyListSize; i++)
if(this.collidesWith(levelController.getEnemyList().get(i)))
{
levelController.callbackCollisionEnemy();
return false;
}
for(int i = 0; i < levelController.getGoodsList().size(); i++)
if(this.collidesWith(levelController.getGoodsList().get(i)))
{
levelController.callbackCollisionGoods(i);
return false;
}

for(int i = 0; i < levelController.getEndPointList().size(); i++)
if(this.collidesWith(levelController.getEndPointList().get(i)))
{
levelController.callbackCollisionWithEndPoint();
return false;
}
return true;
    }
...

Like here we can add running animations,and some animated images using this class file
You can find FULLSOURCE CODE HERE

As from the above tutorial i hope you feel that , developing games in android is not too tuff to handle..so Have practice like this games and can build your dream game..All the best

tags : How To Make Simple Game In Android, Android Games, Develop games in Android, android tutorials, Java, Mobile, Intermediate, Android, JDK, Game, Phone, Android, Mobile Development, Free source code, tutorials, Android development tutorials