Gertboard Motor Test

April 28, 2013

Well I have been running through the test programs for my gertboard and they all seem straightforward. There are a few snags you can hit even using the manual.

The manual has lots of wiring diagrams but it does not clearly explain you need to put the 3V jumper on to fully enable the buttons and leds. Secondly for the motor test it does not fully explain the type of external power source you need. I initially had a 2 AA battery pack as used on the adafruit example. This did not produce enough voltage to power the motor through the gertboard (it did power when the battery was hooked direct to the 3V motor)
A 9V PP3 battery is required to power the 3V motor on the motor test program.

Advertisements

Torchlight2 Item DB

April 6, 2013

I have been working on an ASP.Net MVC EF Application that allows you to explore, query and analyse that Item and Gem Data in the TorchLight 2 Game. I thought it would be an interesting project that would allow me to compare ASP.Net MVC with Ruby on Rails and more importantly Oracle Applications Express 4.1, a tool that I use reasonably often at work.

I have to admit I have found ASP.Net in the past not that interesting especially compared to classic ASP, the whole Web Forms concept seemed to be too custom and too dependent on clicking in controls, seemed too ActiveX or VB6.

ASP.Net MVC does give you complete control of the code, you can use many open source controls and the Microsoft specific HTML helpers are generally useful although the Ajax Helpers are a bit too restrictive you are far better just writing it yourself in Javascript at least that way you can debug it. The Entity Framework does a good job of replicating Ruby on Rails ActiveRecord Framework although I found defining the relationships through the Model a bit awkward, it’s simply an annotation in Ruby on Rails. Now as I have an existing database (I had to pull the Item/Gem data out of Torchlight 2 I  could not use the Code First Method) so that may be one reason but again it was easy to use Ruby on Rails annotation to define how things are mapped.

Saying that Visual Studio Express 2012 is much nicer than the gedit environment I used on my netbook for Ruby on Rails. Git Integration is nice however I could not use it well with AppHarbour, in fact Git Integration in the Express version seems quite awkward, how you rollback from within Visual Studio seemed impossible

I used the Windows 8 Github add on and that worked seemlessly with AppHarbor and AppHarbor is free unlike Azure which is free for 3 months. Should have realised that going the way Microsoft charges you even to play online with XBox ;). Also another nice think with AppHarbor, once I had my connections set up I could easily copy my databases across though that might be to do with Sql Server Management tools.

So my Torchlight 2 Application, what does it consist of. Well firstly the home screen.

Image

As you can see it is all fairly standard from here you can explore the search for specific items/weapns, there is also a couple of Wizards which advise use the best use of a gem and the best use of the weapons.

You can also Explore through the Item Database

Below is a screenshot of searching through the Item database

Image

Below is a screen of the Gem Wizard where it give advice on their best use.

Image

Below is a screen of the Item Detail Screen

 

 

Below is a screen of the Best Weapon Use Screen

 

Screen of the Explore Items Screen

Image

There are quite a few screens, they all make use of Partial Paging, Ajax and the Entity Framework, You do not have to log into the application except if you want to add Items to the basket. I have not done anymore with this and probably won’t, I have a raspberry pi and gertboard to play with.

Do feel like doing a post comparing ASP.Net MVC with Oracle Applications Express 4.1, comparing Models, Views, Controllers, ModelViews and separating out database code into separate classes is kindof hard to do in Apex but there are ways of structuring code in Apex. And I will find it interesting thinking about how my Apex code has been formally structured (packages, functions, Apex API and of course that front end).

My torchlight2 app can be found at http://torchlight2db.apphb.com

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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

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.

Holidaying in East Java

May 17, 2012

 

I have been writing the previous two posts offline while visiting the in-laws in East Java. Even out here you could get internet via an Edge quality dongle  in fact my wife’s Uncle has it. Unfortunately I’d need to go some distance and hire a car to get a dongle for myself.

So it has been 11 days now since I have been offline, but even out here you can be contacted regarding your life back home…via SMS…some issues to sort out once I get back on top of work. So in between using my Asus Eee PC netbook for blog updates and some Grails learning (timesheet system) I have been taking part in village life

Over here the celebrate/commemorate lots of things…a wedding happens twice..once for the bride and once for the groom..there are multiple celebrations for babies…our soon had his 7 months celebration …also when someone dies there is a commemeration again 3 monthes after they died…..Still I notice more young people getting work outside the village.

Picture 001

My wife is on the right and the baby is my soon. That is my wife’s Auntie. Below is a picture of a Wedding tent here..we had one like that  a good 20 months ago

Picture 002

Just outside the inlaws house this one.

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 .

 

 

XNA Screen Manager

March 23, 2012

 

Developing a game i have found is very different from developing a business application.  In a business application you will have a menu, then a series of screens which will as a rule run independently and have similar behaviour, the user will enter data and save this to the system

A Game however will behave differently depending on what screen you are on,the main screen will contain a menu to start the game,view instructions and exit the game.  The user will press Up or Down and select the appropriate option. The Gameplay screen will be completely different, you will have a main Gameplay Loop that iterates throughout the game, updating the position of enemies, drawing on the screen and handling updates.  It will also be possible for this screen to be left immediately for example if they go to a Pause screen.

There is sample XNA code available called ScreenManager which can be used. If you google it you will soon find it

This is how you call it

screenManager = new ScreenManager(this,graphics);

Components.Add(screenManager);

 

You can then add screens using the following screens

screenManager.AddScreen(new MainMenuScreen(), null);

 

You can then use this for all the screens including the Gameplayscreen which will contains the Gameplay screen.,

To enable this function the screen will need to inherit from the Gamescreen class.

Put your own logic into the Update method in the Screen Manager class shown below to control what screen is shown or when you need your Gameplay screen to show a new level

public override void Update(GameTime gameTime)
       {
           // Read the keyboard and gamepad.
           input.Update();

           // Make a copy of the master screen list, to avoid confusion if
           // the process of updating one screen adds or removes others.
           screensToUpdate.Clear();

           foreach (GameScreen screen in screens)
               screensToUpdate.Add(screen);

           bool otherScreenHasFocus = !Game.IsActive;
           bool coveredByOtherScreen = false;

           // Loop as long as there are screens waiting to be updated.
           while (screensToUpdate.Count > 0)
           {
               // Pop the topmost screen off the waiting list.
               GameScreen screen = screensToUpdate[screensToUpdate.Count – 1];

               screensToUpdate.RemoveAt(screensToUpdate.Count – 1);

               if (screen.isLevelChange == true)
               {
                   //new leve
                   PlayerIndex e = (PlayerIndex)screen.ControllingPlayer;

                   if (icurrentLevel == 14)
                   {
                       icurrentLevel = 1;
                   }
                   else{

                       icurrentLevel++;
                   }

                       // I think isLevelchange should be false
                       LoadingScreen.Load(this, true, e, false,
                                 new GamePlayScreen(icurrentLevel));
                       // Just added this
                       //screen.isLevelChange == false;
                       RemoveScreen(screen);
                       // Just added this
                       //AddScreen(new GamePlayScreen(icurrentLevel),e);
               //    }
               }
               else
               {

                   // Update the screen.
                   screen.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

                   if (screen.ScreenState == ScreenState.TransitionOn ||
                       screen.ScreenState == ScreenState.Active)
                   {
                       // If this is the first active screen we came across,
                       // give it a chance to handle input.
                       if (!otherScreenHasFocus)
                       {
                           screen.HandleInput(input);

                           otherScreenHasFocus = true;
                       }

                       // If this is an active non-popup, inform any subsequent
                       // screens that they are covered by it.
                       if (!screen.IsPopup)
                           coveredByOtherScreen = true;
                   }
               }
           }

           // Print debug trace?
           if (traceEnabled)
               TraceScreens();
       }

      

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