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;} }