Abstract public classes in Android, reuse common methods for multiple objects

Source: Internet
Author: User
Tags abstract

Today learning how to realize Angry Birds, using jbox2d to build the physical world (this is not the focus of this article, but thank you for this open source thing)

An entity class of an individual object.

Import Org.jbox2d.dynamics.Body;
Import Org.liky.angrybird.util.Globals;
    
    
Import Org.liky.angrybird.util.ImageUtils;
Import Android.graphics.Canvas;
Import Android.graphics.Paint;
    
    
Import Android.graphics.Point;
    
    
public class Bird {private body body;
private float R;
    
    
private int type;
    
    
public Bird (int type) {switch (type) {case 1:r = GLOBALS.PIECE_WIDTH/2; break;} this.type = type;}
    
    
public void Draw (Canvas Canvas, Paint Paint, point nowposition) {canvas.save (); Canvas.rotate ((float) (Body.getangle () * 180/math.pi), body.getposition (). x * globals.rate + nowposition.x, Body.getPos
    
    
Ition (). Y * globals.rate + NOWPOSITION.Y); Canvas.drawbitmap (imageutils.getbirdimg (type), Body.getposition (). x * globals.rate-r + nowposition.x,
    
    
Body.getposition (). Y * globals.rate-r + nowposition.y, paint); if (Globals.birdcenterflag) {//Ensure that the coordinates of the flying bird are in the center of the screen//back to the column page: Http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/nowposition.x = (int)-(Body.getposition (). x * GLOBALS.RATE-GLOBALS.SCREEN_WIDTH/2);
    
    
NOWPOSITION.Y = (int)-(Body.getposition (). Y * globals.rate-globals.screen_height/2); if (nowposition.x > 0) {nowposition.x = 0;} if (Nowposition.y > 0) {nowposition.y = 0;} if (Nowposition.x <- Globals.screen_width) {nowposition.x =-globals.screen_width} if (Nowposition.y <-globals.screen_height) {NowPosi
TION.Y =-globals.screen_height;
} canvas.restore ();
    
    
Public Body GetBody () {return body;}
    
    
public void Setbody {this.body = body; this.body.m_userData = this;}
    
    
public int GetType () {return type;}
    
    
public void SetType (int type) {this.type = type;}
    
    
public float Getr () {return r;}
    
    
public void Setr (float r) {THIS.R = R;} }

Related Article

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.