How to Make Android 2D car game Tutorial 1

Java and Libgdx tutorial android 2D car game #1



Hello Welcome to the very first tutorial of our Android 2D car game
series in this tutorial we will just define a few constants that will be
needed into our game. Before we can create a complete game we need
first to define our application window and how big is our world for our object
to interact with, so to begin we create an application window with the
size of WIDTH = 480f; and HEIGHT = 800f; so the display will be
portrait in every mobile device…this width and height will define the
the window for our game, the next attribute will be the HUD_WIDTH &
HUD_HEIGHT, these two attributes will be used to create a window or screen to display our Score and life of the player and will pass this as a parameter into our viewport with camera parameter as well. then finally the next attribute will be the size of our
Game World, which will be the WORLD_WIDTH=6f; WORLD_HEIGHT=10f; remember to always focus on world units when creating your game and not in a pixel as this will lead you in a complex way so always use world unit for an accurate result.
Then the other attribute that we declare will be the WORLD_CENTER_X
= WORLD_WIDTH/2f, WORLD_CENTER_Y=WORLD_HEIGHT/2f and
again this is float type, Now some of you may ask what these two
attributes use, well we need this when we are going to debug our
the world during the development process and we will need this to get the
center of our world using the CameraHelper Class that will be created in
In the next lesson, the other attributes are the following:

================================================================
ATTRIBUTES DESCRIPTION
================================================================

BODY_RADIUS= This will be used for collision detection later on we will
draw shapes with ShapeRenderer class And assign A Math Circle to implement Collision.

PLAYER_SIZE = Will be the size of our player

ENEMY_RADIUS = The body radius of our enemy used also for
collision detection.

ENEMY_SIZE = The respective size of our enemy.

ENEMY_AMBULANCE_TIME = The time that will be used to check
whether it's a time to respawn our ambulance object.

ENEMY_POLICE_SPAWN_TIME = The time used to check the right time to
respawn our Police car

ENEMY_TRUCK_SPAWN_TIME =The time used to check the right time to
respawn our Truck car

ENEMY_BLACKVIPER_SPAWN_TIME = The time used to check the right
time to respawn our Truck car

ENEMY_TAXI_SPAWN_TIME = The time used to check the right
time to respawn our Taxi car

ENEMY_VAN_SPAWN_TIME = The time used to check the right
time to respawn our Van car

SCORE_TIMER = The timer used to check when we should add
value to our Score each frame

DIFFICULTY_MEDIUM = A constant value that is defined in Enum class
use for adding difficulty medium level in our game

DIFFICULTY_EASY = A constant value that is defined in Enum class
use for adding difficulty easy level in our game

DIFFICULTY_HARD = A constant value that is defined in the Enum class
use for adding difficulty hard level in our game

PLAYER_LIFE = The life of our Player when the game starts

CODES:
package config;
public class GameConfig {
public static final float WIDTH = 480;
public static final float HEIGHT = 800;
public static final float HUD_WIDTH = 480;
public static final float HUD_HEIGHT = 800;
public static final float WORLD_WIDTH = 6f;
public static final float WORLD_HEIGHT =10f;
public static final float WORD_CENTER_X = WORLD_WIDTH/2f;
public static final float WORLD_CENTER_Y = WORLD_HEIGHT/2f;
public static final float BODY_RADIUS = 0.3f;
public static final float PLAYER_SIZE = 1;
public static final float ENEMY_RADIUS = 0.3f;
public static final float ENEMY_SIZE = 1;
public static final float ENEMY_AMBULANCE_TIME = 2f;
public static final float ENEMY_POLICE_SPAWN_TIME = 3f;
public static final float ENEMY_TRUCK_SPAWN_TIME = 1f;
public static final float ENEMY_BLACKVIPER_SPAWN_TIME = 2f;
public static final float ENEMY_TAXI_SPAWN_TIME = 4f;
public static final float ENEMY_VAN_SPAWN_TIME = 5f;
public static final int PLAYER_LIFE = 3;
public static final float SCORE_TIMER = 1f;
public static final float DIFFICULTY_MEDIUM = 0.08f;
public static final float DIFFICULTY_EASY = 0.04f;
public static final float DIFFICULTY_HARD = 0.20f;
private GameConfig(){}
}



Post a Comment

0 Comments