Game Development Reference
In-Depth Information
Physics games aren't just a matter of
physics
This section has nothing to do with Box2D, and it's just necessary to allow the player
to launch the bird. So I am explaining what happens here very quickly, in order to go
straight to the point.
Before we start drawing, I want you to know that you can mix physics and non-
physics scripts in your game, just like I am doing now. In this case, player interaction
is not managed by Box2D, which comes into play once the bird is released.
First, we need some more class-level variables:
private var world:b2World;
private var worldScale:Number=30;
private var theBird:Sprite=new Sprite();
private var slingX:int=100;
private var slingY:int=250;
private var slingR:int=75;
theBird is the sprite representing the draggable bird, slingX and slingY are
the coordinates of the center of the sling in pixels, and slingR is the radius of the
draggable area of the sling in pixels.
Now, we need to draw some stuff on the stage. We'll draw the big circle representing
the sling area, and the small circle representing the bird. Also, we are going to add
some listeners to select, draw, and release the bird.
Add the following lines to the Main function:
public function Main() {
world=new b2World(new b2Vec2(0,5),true);
debugDraw();
floor();
brick(402,431,140,36);
brick(544,431,140,36);
brick(342,396,16,32);
brick(604,396,16,32);
brick(416,347,16,130);
brick(532,347,16,130);
brick(474,273,132,16);
brick(474,257,32,16);
brick(445,199,16,130);
brick(503,199,16,130);
brick(474,125,58,16);
 
Search WWH ::




Custom Search