Introduction: How to Make a Android Game

Using this Instructable will teach you the basics of how to build an Android app using the Android Studio development environment. As Android devices become increasingly more common, demand for new apps are increasing. Android Studio is an easy to use (and free) development environment to learn on. It's best if one has a working knowledge of the Java programming language for this tutorial because it is the language used by Android. I won't post too much code in this tutorial, so I will assume that you know enough Java to understand or are willing to look up what you don't know. This will take roughly 30-60 minutes, depending on how quickly you are able to download and install Android Studio. After using this tutorial to create your first Android app, you'll be well on your way to a fun new hobby or possibly even a promising career in mobile development.

Step 1: Install Android Studio

1. Go to http://developer.android.com/sdk/index.html to download Android Studio.

2. Use the installer to install Android Studio following its instructions.

Note :

To install Android Studio on Windows, proceed as follows:
1. Launch the .exe file you downloaded.

2. Follow the setup wizard to install Android Studio and any necessary SDK tools.

3. On some Windows systems, the launcher script does not find where the JDK is installed. If you encounter this problem, you need to set an environment variable indicating the correct location.

Select Start menu > Computer > System Properties > Advanced System Properties. Then open Advanced tab > Environment Variables and add a new system variable JAVA_HOME that points to your JDK folder, for example C:\Program Files\Java\jdk1.8.0_77.

Step 2: Make a Simple User Interface Design

Note: you can design your user interfaces whatever you like. It is a simple and useful example.

How to make a simple user interface

1. have four entities which are Main menu, game, pause menu, win & lose menu

2. draw relationships between all entities

3. place a start button, a game title and a background in the main menu interface

4. place the game view in the game interface

5. place a continue button, a main menu button in the pause menu interface

6. place a main menu button and a header text in the win & lose menu

Step 3: Make a Plan, Find Resources, Download Them and Put Them in the Right Place

How to prepare before you start to work

1. make a plan to figure out things based on user interfaces

2. find resources like images and musics on the internet

3. Download all resources.

4. Copy all images and paste them into res\drawable-nodpi folder in android studio.

3. Copy all musics and paste them into new created folder named raw in res folder in android studio.

Note: don't forget to rename all images' name to lowercase.


Step 4: Open a New Project

1. Open Android Studio.

2. Under the "Quick Start" menu, select "Start a new Android Studio project."

3. On the "Create New Project" window that opens, name your project.

4. Note where the project file location is and change it if desired.

5. Make sure on that "Phone and Tablet" is the only box that is checked.

6. If you are planning to test the app on your phone, make sure the minimum SDK is below your phone's operating system level.

7. Select "Blank Activity."

8. Leave all of the Activity name fields as they are.

9. start to code.

Step 5: Create and Code Xml Files

Based on user interfaces i designed, i need to create 6 XML files:

main.xml, game.xml, pause_menu.xml, pause.xml, lose.xml, win.xml.

How to code main.xml (as a example)

In user interfaces, main menu contains a start button, a game title and a background.

Background:

1. create a RelativeLayout named RelativeLayout1 (the base layout)

2. set layout_width="fill_parent" and layout_height="fill_parent" (width and height of the base layout is the size of screen)

3. android:background="@drawable/main_bg" (add background on the base layout)

a game title:

1. create a ImageView named imageView1

2. set layout_width="wrap_content" and layout_height="wrap_content"

(wrap_content:The border of the child view wraps snugly around its own content.)

3. android:src="@drawable/main_title" (add game title image on the RelativeLayout1)

a start button:

1. create another RelativeLayout name RelativeLayout2

( because the start buttom contains a button image and a start text. more importantly)

2. set ID, Width and Height of RelativeLayout2

button image:

1.create a imageView named ing_btn

2. set width and height to match the size of the start button

3. android:src="@drawable/btn" (add a button image on the imageView)

start text:

1. android:id="@+id/text_start" (create a TextView named text_start)

2. set width and height to match the size of the start button

3. android:text="@string/start_game" (create a text box and type a string on it)

You can download give files and copy & paste into appropriate xml file.

Step 6: Create and Code Java Files

Based on user interfaces i designed, i need to create 10 JAVA files:

Background, Barier, Barriermanager, Bonus, Game, GamePanel, MainMenu, MainThread, Ship, TochButton

In game interface, there are many objects such as the ship, bonus coins, barriers and so on

I use the ship as a example to briefly show how to realize functions of the ship

Functions of the ship:

1. create a ship

2. animation of a ship

3. draw a ship

4. update data of a ship

5. bump a ship

How to make a Ship.java file (as a example)

1. Create a ship;

public Ship(Bitmap decodeResource, int x, int y, int screenWidth, int screenheight)

(create a constructor of ship class)

2. animation of a ship;

public void setBoomAnimation(ArrayList animation){

(play images of the ship in rotation and let it looks like an animation)

Note:this function use Bitmap files in constructor of ship class

3. draw a ship

public void draw(Canvas canvas){

(draw images of ship in canvas)

4. update data of a ship

public void update(float dt){

if (death){ else

(update data of ship if the ship did not die)

5. bump a ship

public boolean bump (Point OTL, Point OTR, Point OBR, Point OBL){

(check position of the ship)

You can do it by yourself or you can download give files and copy & paste into appropriate java file.

Step 7: Final Stop: Run It!

Now just connect phone to your PC and click on run application,this will install game into your mobile phone and enjoy it.

Note:This game will work with android moblie phone.