Android game flabby Bird (UP)

Source: Internet
Author: User

1. Write in the previous words:

Once inadvertently found a resource on the Csdn "Android high imitation Flappy Bird source code", download down run, the effect is very good, then go in a look at the code, obediently, good things ah, the whole game frame very nice, this is actually a very good game frame, for the general game , we are all able to use directly oh. However, the only regret is this Android master, do not know why only the source code, not a good write a blog detailed introduction of their own this game.


2. Flappy Bird Game effect:



3.flappy Bird Game Key class: 1. Some of the game's tool classes:


(1) FileManager Class ----This class is mainly to save the game's highest score

(2) SoundPlayer class ----Music playing class

(3) Constants Class -------The Constant collection class in the program, mainly dealing with some invariant constants

(4) The config class-------------configuration class, which is primarily a configurable variable in the program, is important because many of the important configuration parameters, such as channel variables for the game, can be configured in this class.


2. The basic elements of the game class:



The basic elements of the flabby Bird game include the floor (Ground), the Bird (Bird), the obstacle (Column). They all have a base class (Gameobject), the following details about the Gameobject (later will be attached to the source code):

For the next game element, the first is his width (obj_width), the High (obj_height), the display position (obj_x,obj_y,obj_mid_x,obj_mid_y), and for the animated element, another parameter is The current picture (Currentframe), the method of initializing the picture (Initbitmap ()), releasing the Resource Method (release ()), displaying its own method (Drawself (canvas canvas)), and a key The method of dynamic stepping Change (step ()).


3. The game scene class-----Baseview



Flabby bird game scenarios include load scenes (Loadingview) and the main game scene (MainView), all scenes have a scene base class (Baseview ), the following detailed introduction of Baseview (later will be attached to the source code):

For the game scene, the first is the game background Scale (Scalex,scaley), this is mainly to deal with the game background. The method of initializing the picture (Initbitmap ()), releasing the Resource Method (release ()), plotting the scene's method (Drawself ()), and a method (run ()) to run the critical thread (threads)--- This method is primarily a thread that performs dynamic operations . Since the game scene class is inherited from the Surfaceview class, in the surfacecreated method, we typically perform initialization and startup threading operations, in surfacedestroyed method, we typically perform a resource release operation.



1----Gameobject class:

Import Android.content.res.resources;import Android.graphics.canvas;import Android.graphics.paint;import Android.graphics.rect;public Abstract class Gameobject {protected int currentframe;//current animation frame protected float obj_x;// Object upper left corner coordinate protected float obj_y;protected Float obj_mid_x;//Object Center horizontal axis protected float obj_mid_y;//Object Center ordinate protected float obj _width;//object width protected Float obj_height;//object height protected Resources resources;protected Paint paint;public gameobject ( Resources Resources) {this.resources = Resources;paint = new paint ();} Object motion Logic public abstract void step ();//drawing method public abstract void drawself (canvas canvas);//Initialize as slice resource public abstract void Initbitmap ();//Release picture resource public abstract void release ();p ublic void Setobjx (float x) {this.obj_x = x;} public float GETOBJX () {return this.obj_x;} public void Setobjy (float y) {this.obj_y = y;} public float Getobjy () {return this.obj_y;} public void Setobjmidx (float x) {this.obj_mid_x = x;} public float Getobjmidx () {return this.obj_mid_x;} public void Setobjmidy (FloaT y) {this.obj_mid_y = y;} public float Getobjmidy () {return this.obj_mid_y;} public void Setobjwidth (float w) {this.obj_width = W;} public float Getobjwidth () {return this.obj_width;} public void Setobjheight (float h) {this.obj_height = h;} public float Getobjheight () {return this.obj_height;}}


2----Baseview class:

Import Liqiang.flybird.mainactivity;import Liqiang.flybird.config.constants;import Liqiang.flybird.util.soundplayer;import Android.content.context;import Android.graphics.canvas;import Android.graphics.paint;import Android.view.surfaceholder;import Android.view.surfaceholder.callback;import Android.view.surfaceview;public class Baseview extends Surfaceview implements Callback, Runnable {protected float ScaleX ;//Background image scaling protected float scaley;protected mainactivity mainactivity;protected soundplayer soundplayer;protected Canvas canvas;//Canvas Object protected Paint paint;//Brush Object protected Surfaceholder sfh;protected thread thread;//painting thread protected The Boolean threadflag;//tag thread runs//constructor public Baseview (context context, SoundPlayer SoundPlayer) {super (context); This.mainactivity = (mainactivity) Context;this.soundplayer = SOUNDPLAYER;THIS.SFH = This.getholder (); This.sfh.addCallback (this); this.paint = new Paint ();} Thread Run method @overridepublic void Run () {}//Initialize picture resource public void Initbitmap () {}//release picture resource public void reLease () {}//drawing method public void Drawself () {}//view changed method @overridepublic void Surfacechanged (Surfaceholder arg0, int arg1, int a RG2, int arg3) {}//view created method @overridepublic void surfacecreated (Surfaceholder arg0) {constants.screen_width = This.getwidth (); Constants.screen_height = This.getheight (); this.threadflag = true;} Method of view Destruction @overridepublic void surfacedestroyed (Surfaceholder arg0) {This.threadflag = false;} public void Setthreadflag (Boolean threadflag) {this.threadflag = Threadflag;}}



Source:


Resources:

1. Android High imitation Flappy Bird source code

http://download.csdn.net/detail/qiang66666ok/7175747


Android game flabby Bird (UP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.