• Sponsored Links

Step 10 : Step by Step libGDX Tutorial : Understand basics of Game

Share this :

Step 10 : Step by Step libGDX Tutorial : Understand basics of Game

Environment is all set and we are ready to start the Game development . I hope you guys have already played this game downloaded on your android or Desktop and you understand what is this game all about and have noticed what are the various components in the game like :

  1. Loading Screen
  2. Menu Screen
  3. Play screen
  4. How to Play Screen
  5. Bird
  6. Pipes
  7. Score
  8. Ground
  9. Bird changes colour whenever we start a new Game
  10. Pipes change colour after each score increase
  11. Bird is killed whenever it touches any Pipe or Ground or Sky
  12. Game Over State
  13. High Score
  14. Medals according to high score
  15. Play again Button

If you haven't played the game yet , Play it first so you understand all these components as mentioned above . Download links are shared in previous Tutorials but i will mention it once again

Download Desktop Version

Download Android Version @Google Play Store Search using Brisky Bird or VersionPB @ Play Store

Ok lets understand some basic terms about the game like :

Game State

A Game state is the state of a game i.e. for example A Game can be in Menu State , Pause State , Play State , Resume State , Game Over State etc . So in our Game we have :

Splash State : State which we see as soon as the game is started

Menu State : This state comes after Splash State is end and it gives us 2 options

  1. See How to play Game by tapping on How to Play Game Button
  2. Tap on any where else on the game except on How to Play Button to Start playing the Game

How to Play Game State : This State basically tells how to play the game in a simple text

Play State : In this state we play the game and do most of the tasks our game does like

  1. Controlling the Bird
  2. Bird Jumping whenever we Tap
  3. See pipes coming and how pipes move towards the bird etc

Game Over State : This state comes whenever the bird is killed .

We will discuss each of the state in more details in next sections for now we must just understand which state is which in the Game .

Game World

Game world is a large world , like in our game  Brisky Bird it can have pipes , bird , surroundings and more different components at different point of times depending on the situation of the game But we will show user only a small part of the full game world and we will do that by using Camera

Camera

Camera has a view port i.e. Only a rectangular area i.e. a specific height and width and it shows that only that height and width of our game world to user at any point of the game

Basic Game Lib

It has 2 main parts

  1. Update Method : It does all the calculations in order for render method to draw pictures on the screen . it includes methods like :
    1. bird jumping  : which calculates gravity i.e. move the bird down when there is no tap and move the bird up when there is a tap , Calculates birds positions etc
    2. Adjust Pipes positions
    3. Scoring Logic and so on
  2. Render Method : Its only purpose is to draw things on the screen . It takes objects on the game world and draws it on the screen

I am sure above points are all clear , lets start doing the basic changes to our code and lets see what changes it makes to our default game code

  • Create a new package in our core package named States under com.versionpb.briskybird package

    Create Package States

    Create Package States

  • Inside States create a new abstract java Class called State
    Create Class State

    Create Class State

    Create Abstract Class

    Create Abstract Class

  • Open the class BriksyDemo and lets create some global variables for width , height and Title for our game as below
    In BriksyDemo Class add followinng three lines just below public class BriksyDemo extends ApplicationAdapter {
    public static final int WIDTH = 480;
    public static final int HEIGHT = 800;
    public static final String TITLE = "Briksy Bird Demo";

    Set Height and Width of Screen

    Set Height and Width of Screen

Lets open DesktopLauncher.java under BriskyBird-desktop package and lets set config to have these global parameters
Enter below 3 lines under LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.width = BriksyDemo.WIDTH ;
config.height = BriksyDemo.HEIGHT;
config.title = BriksyDemo.TITLE;

Add config to DesktopLauncher

Add config to DesktopLauncher

  • Execute Code for Desktop and we will see width , height and title of our default screen is changed .

    Title width and height changed

    Title width and height changed

  • Full Code after changes for Desktop Launcher.java and BriskyDemo.java is as below :

DesktopLauncher.java


package com.versionpb.briskybird.desktop;

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.versionpb.briskybird.BriksyDemo;

public class DesktopLauncher {
public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.width = BriksyDemo.WIDTH ;
config.height = BriksyDemo.HEIGHT;
config.title = BriksyDemo.TITLE;
new LwjglApplication(new BriksyDemo(), config);
}
}

BriksyDemo.java


package com.versionpb.briskybird;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class BriksyDemo extends ApplicationAdapter {
public static final int WIDTH = 480;
public static final int HEIGHT = 600;
public static final String TITLE = "Briksy Bird Demo";
SpriteBatch batch;
Texture img;

@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
}

@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

23 − = 21