Overview
- - This game written in Java programming language;
- - uses free library LibGdx;
- - game includes 14 images, 3 sounds;
- - AdMob banner integrated;
To run this project, you need Eclipse+ADT installed in your system and also Java Development Kit. All of these products are free. You can download Eclipse+ADT at http://developer.android.com/sdk/index.html You can download Java Development Kit at http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html Installing these products are as simple as installing other software. You can also view this video on Youtube: https://www.youtube.com/watch?v=Q1Od7_6FDY0 After installing Eclipse and JDK, you must import the project to Eclipse.
Import project to Eclipse
Unzip your downloaded game to any folder you like.
- In Eclipse, go to "File->Import". "Import" window should appear. Expand the
"General" folder, choose "Existing Projects into Workspace" and click "Next" button". - Check the "Copy projects into workspace", then click "Browse" button in the "Select root directory" text field.
- Navigate to your unzipped "BirdAdventure" path. Two projects should appear - "birdadventure-android" and "birdadventure-core". Click "Finish" button.
To run project, right click on "birdadventure-android", then select "Run->Android Application". You can run game on an Android Virtual Device (AVD) or on the real device connected by USB cable.
Some Things You Want to Configure
Main files for your customisation are AndroidLauncher.java (which is in "birdadventure-android/src" folder) and GameScreen.java (which is in "birdadventure-core/src" folder) AndroidLauncher.java- contains information about your AdMob unit ID GameScreen.java- contains main game logic. In AndroidLauncher.java, find these lines //set your ad unit id here
adView.setAdUnitId("YOUR_UNIT_ID");
Change string YOUR_UNIT_ID to your AdMob Unit ID. You must have registered AdMob account. If you have not, register one at www.admob.com/register. After registering, add the application and copy your AdMob Unit ID.Implementing AdMob
I assume you already have AdMob account. if no, register one at www.admob.com/register
- To use AdMob, you must integrate Google Play services into your IDE. In "Eclipse", go to "Window->Android SDK Manager".
- Expand "Extras" and check "Google Play Services", then click "Install packages" button.
- After succesfull downloading, go to "File->Import", expand "Android" folder, choose "Existing Android Code Into Workspace" and click "Next". Check the "Copy projects into workspace". Click "Browse" button and navigate to your SDK path (for example, "C:/adt_eclipse/sdk") then navigate to "extras/google/google_play_services/libproject".
- "google_play_services_lib" should appear, click "Finish".
- Right click in "birdadventure-android" in your Package Explorer, choose "Properties".
- In "Android" tab, click "Add" button in "Library" field. Then choose just added "google_play_services_lib".
Running AdMob in test mode
Add your Ad unit ID to the code
adView.setAdUnitId("YOUR_UNIT_ID");
While developing application it is useful to run AdMob in test mode. To do so, it is already code added to the AndroidLauncher.java AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("xxx")
.build();
in addTestDevice("xxx") replace the "xxx" value with your device hashed id. To do so, follow these steps:- Run application in android device.
- In LogCat, find info "To get test ads on this device, call adRequest.addTestDevice("0123456789ABCDEF")"
- Select this line, press Ctrl+C to copy this, paste into your code and delete all the message, but leave your hashed id.
- After that, run application again. If all done correct after about two minutes AdMob banner should appear.
AdRequest adRequest = new AdRequest.Builder().build();Showing and Hiding AdMob Banner
BirdGame.myRequestHandler.showAds(false) - hides AdMob. This used in main GameScreen.java to hide banner while gameplay;
BirdGame.myRequestHandler.showAds(true) - shows AdMob. This used in StartScreen.java and in GameoverScreen.java. Remember, it could take some time when showing banner first time.
Changing Game Variables
In GameScreen.java find and change these values:
gameSpeed - influences on obstacle_speed, bonus speed and parallax scrolling speed. If game speed is low, there are much easier to play, because less reaction is required to avoid obstacles and collect items. During gameplay gameSpeed is increased. This value is controlled by max_gameSpeed, but you can change its values.
obstacle_distance - determines how far obstacles will be generated from each other. If this value is too low, obstacles will be generated more often, and with gameSpeed it determines game difficulty. This value is controlled by min_distance, so obstacle_distance cannot be lower than min_distance, for example, it cannot be zero. (But you can change this)
obstacles_passed - when new obstacle created, obstacle_passed increases. When it greater than 10, gameSpeed increases and obstacle_distance decreases.
bird_speed - how fast bird moves up and down
bonus_distance - determines how far bonuses will be generated from each other. Less value generates more bonuses
How To Change Title of the Game
Find "birdadventure-android/res/values/strings.xml" and change "Bird Adventure" to your title. This title will appear in android device, when game is installed.
How To Change Sounds
Sounds are in "birdadventure-android/assets/sounds" folder. Replace them to your own sounds.
How To Change Graphics
Graphics files are in "Assets Source" folder. There are two subfolders - "PNG" and "EPS". "PNG" contains raster PNG files, "EPS" contains vector files. EPS files can be edited by free Inkscape software - www.inkscape.org PNG can be edited by free GIMP software - www.gimp.org After editing, all the graphics must be in PNG format and must be packed by gdx-texturepacker tool.
This tool is available for free download at https://code.google.com/p/libgdx-texturepacker-gui/ Here also you can find documentation for this tool, but it is easy to use. Simple download and launch this tool. Click "New pack", enter name (I have used "items"). Locate directory with all your images, locate output directory, fill the file name of the packed file ("I have used items.pack") and press "Pack'em all" button. Then copy "items.png" and "items.pack" from output directory to your "birdadventure-android/assets/images" Publishing Your App
Before publishing, change the package name in AndroidManifest.xml, which is in "birdadventure-android" folder.
To export to apk file, go to "File->Export". "Export" window should appear. Expand "Android" folder, select "Export Android Application" and click "Next" button.
Project Structure
Game code consists of two projects -- birdadvenute-android
- birdadventure-core
IActivityRequestHandler.java is a helper class used for show or hide AdMob;
Constants.java is a helper class which contains game constants, such as Viewport width and height
This is game life cycle:
- BirdGame.java - initializes the game. It contains reference to the AdMob handler, loads TextureAtlas, creates game font and creates StartScreen.
- StartScreen.java - Shows AdMob, loads its background image and wait for player touches the screen. When player touches the screen, it loads GameScreen.
- GameScreen.java - main game action goes here. There are a lot of code here. GameScreen uses:
- Bird.java to initialize player's bird;
- BonusItem.java to generate bonus items;
- Obstacle.java to generate obstacles
When bird collides with obstacle, GameScreen creates new GameoverScreen - GameoverScreen shows gameover background, displays score and shows AdMob banner.
Free Source Code DOWNLOAD HERE

0 Response to "Bird Adventure Android Source Code"
Posting Komentar