Sunday, March 22nd, 2009, 12:56 am | Computer, Download, Experiments, Gaming, Hardware, Programming, Software

MultiInput class – multiple mice in your XNA game!

I created a C# class that allows you to use more than one mouse in your XNA game. Of course this is also working with normal Windows applications, but I specially prepared it to work with XNA. This gives you new possibilities for multiplayer games on a single computer! Currently, it’s only working for mice, but I will add keyboard support soon.

Download MultiInput.dll Version 0.1

I also created a game demonstrating how to use this class and what multiple mice can be used for. I think there are many games that could make use of more than one mouse to enable a cool multiplayer mode. Currently the game is in Alpha stage and doesn’t have many features. It supports up to 6 players (if that many mice are plugged in) who have to stop zeppelins from reaching the other side of the screen by shooting them down. Although there isn’t much to do except shooting the zeppelins, it’s quite funny already.

UPDATE: NEW VERSION AVAILABLE: Download Airship Assault here!

Download MultiInput Sample Game Alpha Version 0.1

Download and install the necessary XNA Framework 3.0 here

multiinputgame_alpha_01

Each crosshair can be controlled by one mouse/player. The number in brackets on the bottom is the amout of shots you’ve left in your magazine. Leftclick to shoot, rightclick to reload. When a zeppelin reaches the other side, you will lose a life.

I tested the game only with USB mice, they’re working fine, but it should also work with PS2 mice. If you encounter any errors, please tell me!

Using MultiInput.dll

The usage of this class is really easy. Copy the DLL file to your project’s folder and set a reference to the DLL and a reference to the “System.Windows.Forms” namespace (don’t forget this!). Load the dll using

using MultiInput;

Inside your Game class, you can use the code like this:

class Game1     {         MultiInputController inputController;         Color[] mousecolors = new Color[] { Color.Red, Color.Blue, Color.Green, Color.Yellow, Color.White, Color.Pink };         public Game1()         {             inputController = new MultiInputController(this.Window.Handle);         }         public override void UnloadContent()         {             // YOU MUST!!! USE THIS LINE, otherwise your game won't exit             inputController.Dispose();             content.Unload();         }         public override void Update(GameTime gameTime)         {                 foreach(RawMouse rawmouse in inputController.Mice)                 {                         // do whatever you like here                 }             base.Update(gameTime);         }         public override void Draw(GameTime gameTime)         {                 spriteBatch.Begin();             // Draw each cursor             for (int i = 0; i < inputController.MiceCount; i++)             {                 RawMouse mouse = inputController.Mice[i];                 spriteBatch.Draw(cursor, new Vector2((float)(mouse.X - cursor.Width/2), (float)(mouse.Y - cursor.Height/2)), mousecolors[i]);             }             spriteBatch.End();         }     }
VN:F [1.0.7_345]
Rating: 9.1/10 (14 votes cast)



Comments

Click here to read or write comments