Archive for the ‘xna’ Category

Gamerservices component

May 25, 2012

I have been having an awful time deploying my application. It seems I have a reference to gamerservices in my code which means my game will only deploy to an XNA development machine. You would think this restriction would not be in XNA. There is alot to be said for flash or HTML 5 games. No deployment or distribution issues . Never had this issue with my flixel game herding monkies

Advertisements

Diygamer

May 17, 2012

 

Still on  holiday in Indonesia, my TV is the sun tinted window looking at a junction in the village, my wife is out on the motorbike leaving her niece to school. My mother in law is putting our son to bed and today I used the internet to book our  last nite staying in a hotel with ac attached to a shopping mall.

It’s amazing what you can do without including video games…TV..cinema but saying that i am thinking where I can advertise and put my freeware game Boo Boo Birds up for download. Sites include Diygamer and tigsource but I don’ think that is updated often.

Dynamic Body Types and Static Body Types

May 17, 2012
Technorati Tags: ,,,

In Box2D ( Farseer) you can create Dynamic and Static Body Types. This is not to be confused with the isStatic property, the isStatic property is for an object which does not move, you use this property for Static obstacles in a game.

A Dynamic Body  Type is an object which can for example have objects attached to it. In my game Boo Boo Birds you anchor bomb blades to the player bird . On declaring the player bird set it to dynamic

body.BodyType = BodyType.Dynamic;

 

To link another object to this object when it for example collides with the object then do the following

agent.currRopeJoint = new RopeJoint(fixtureA.Body, fixtureB.Body, ConvertUnits.ToSimUnits(fixtureA.Body.Position), ConvertUnits.ToSimUnits(fixtureB.Body.Position));
agent.currRopeJoint.MaxLength = 0.4f;
agent.currRopeJoint.CollideConnected = false;

agent.currFixture = fixtureA;
agent.myFixture = fixtureB;
world.AddJoint(agent.currRopeJoint);

Then to remove the object so that it drops to the ground

if (currRopeJoint != null)
  {
                      world.RemoveJoint(currRopeJoint);
                      currRopeJoint = null;
                      bvertset = false;
}

You can vary the distance the object is connected to the other object by changing a parameter. It is also advisabe to ensure the the NotCollides parameter is set to each object so it does not collide with the object it is attached to.

This has been done earlier on with the following statement in the first example of the code

currRopeJoint.CollideConnected

Aiming at Player in Farseer (Box2D)

May 17, 2012

This is done by using the Raycast function in Box2D. You cast a ray between the enemy and the player. If it collides with an object then it will enter the function. At this stage you can examine the object or fixture it has hit by looking at the userdata attribute to see if you are seeing the ground first before the player. In which case do not fire.

This firing function fires at the last location the enemy was at, you can offset this to fire a bit in front but again you need to analyse where the player is. It was easier for me just to have more than one firing enemy. That way the player is being fired at from different locations so one of the shots should hit.

world.RayCast((f, p, n, fr) =>
                                {
                                    if (fr < minfraction)
                                    {
                                        minfraction = fr;
                                        closestfixture = f;
                                        return -1;
                                    }
                                    else
                                        return -1;
                                    }, dicEnemy[pair.Key].body.Position, agent.body.Position);

As you can see a ray is cast from each enemy towards the player. Below is the code where you examone the fixture and calculate the distance

if (closestfixture != null && (String)closestfixture.Body.UserData != "Ground")
   {
        dicEnemy[pair.Key].bTarget = true;
        double a = Math.Pow(agent.body.LinearVelocity.X, 2) + Math.Pow(agent.body.LinearVelocity.Y, 2) – Math.Pow(dicEnemy[pair.Key].ProjectTileSpeed, 2);
        double b = 2 * (agent.body.LinearVelocity.X * (agent.Position.X – dicEnemy[pair.Key].Position.X) + agent.body.LinearVelocity.Y * (agent.Position.Y – dicEnemy[pair.Key].Position.Y));
        double c = Math.Pow(agent.Position.X – dicEnemy[pair.Key].Position.X, 2) + Math.Pow(agent.Position.Y – dicEnemy[pair.Key].Position.Y, 2);
        double disc = Math.Pow(b, 2) – 4 * a * c;
        double t2 = (-b – Math.Sqrt(Math.Abs(disc))) / (2 * a);

 

That radians code listed below calculates the angle at which the missile should be fired.

 

Vector2 aimSpot = agent.Position + agent.body.LinearVelocity * (float)ConvertUnits.ToSimUnits(Math.Abs(t2));

                                      float radians = (float)Math.Atan2(aimSpot.X – dicEnemy[pair.Key].Position.X, aimSpot.Y – dicEnemy[pair.Key].Position.Y);

Below is a full listing of the code

world.RayCast((f, p, n, fr) =>
   {
    if (fr < minfraction)
    {
       minfraction = fr;
       closestfixture = f;
       return -1;
    }
    else
       return -1;
    }, dicEnemy[pair.Key].body.Position, agent.body.Position);
    //  if (closestfixture != null && (String)closestfixture.UserData != "Ground")
    if (closestfixture != null && (String)closestfixture.Body.UserData != "Ground")
    {
        dicEnemy[pair.Key].bTarget = true;
        double a = Math.Pow(agent.body.LinearVelocity.X, 2) + Math.Pow(agent.body.LinearVelocity.Y, 2) – Math.Pow(dicEnemy[pair.Key].ProjectTileSpeed, 2);
        double b = 2 * (agent.body.LinearVelocity.X * (agent.Position.X – dicEnemy[pair.Key].Position.X) + agent.body.LinearVelocity.Y * (agent.Position.Y – dicEnemy[pair.Key].Position.Y));
        double c = Math.Pow(agent.Position.X – dicEnemy[pair.Key].Position.X, 2) + Math.Pow(agent.Position.Y – dicEnemy[pair.Key].Position.Y, 2);
        double disc = Math.Pow(b, 2) – 4 * a * c;
        double t2 = (-b – Math.Sqrt(Math.Abs(disc))) / (2 * a);
        Vector2 aimSpot = agent.Position + agent.body.LinearVelocity * (float)ConvertUnits.ToSimUnits(Math.Abs(t2));
        float radians = (float)Math.Atan2(aimSpot.X – dicEnemy[pair.Key].Position.X, aimSpot.Y – dicEnemy[pair.Key].Position.Y);
        Vector2 distancevect = aimSpot – dicEnemy[pair.Key].Position;
        if (aimSpot.X – dicEnemy[pair.Key].Position.X < 0)
              dicEnemy[pair.Key].bleft = true;
              float aimdistance = distancevect.Length();

              if (dicEnemy[pair.Key].bhit==false && dicEnemy[pair.Key].body != null && currValue.bshoot.Equals(true) && (aimdistance < 7))
              {
                 /* Missile Code goes here */
                 shoteffect.play()

Youtube Video off BooBoo Birds

April 14, 2012

 

Video of my 2D Physics XNA Game is up on the below link. I aim to get a download link of this freeware game up next month .

 

 

Tools for XNA Development

March 7, 2012

gleed2d

1.gleed2d for the level editor. Even includes some code to reading XML

farseer

2. Farseer. XNA implementation of box2d. This will do your collision detection for you, helps with doing line of sight and of course physics

inkscape

gimp

3. Inkscape and gimp. Inkscape is easy to draw with awns gimp great for editing

4.

visual studio express 2010

Great compared to oracle dev environments