Part 4b – Hello piggy

With the floor raised, it’s time to add our pig.
The pig will be just another Prefab type.

Here’s a placeholder sprite with the right dimensions:

In the PrefabBodyFactory class, we add our pig as such, assuming the above image was saved as pig.png and ends up as such in our PigsFlySpriteSheet.xml file.

Library.Add(PrefabType.Pig, (world, position) => CreateRectangle(world, position, "pig", 0.5f, 0.59f));

Replace the old body creation code with the one below:

Body box1 = PrefabBodyFactory.CreateBody(PrefabType.GrayBox, _world, new Vector2(6.0f, 3.999274f));
Body box2 = PrefabBodyFactory.CreateBody(PrefabType.GrayBox, _world, new Vector2(6.0f, 3.612630f));
Body box3 = PrefabBodyFactory.CreateBody(PrefabType.GrayBox, _world, new Vector2(6.0f, 3.222778f));
Body pig = PrefabBodyFactory.CreateBody(PrefabType.Pig, _world, new Vector2(1.5f, 3.9f));
_projectile = new Projectile(pig);

To obtain these specific Y values, I let the bodies drop from a higher value and waited till they all fell and came at rest. Then it was only a matter of breaking the debugger and looking up these values of each body.

Run the code now and the result will be just like this:

Continue to part 4c – launching the pig.


2 Responses to Part 4b – Hello piggy

  1. Pingback: Part 4 – Three, two, one… launch! « Jo De Greef | Blog

  2. Pingback: Part 4a – Raising the floor « Jo De Greef | Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: