XNA UK User Group

A helping hand for bedroom coders throughout the land.
in

RandomChaos

January 2008 - Posts

  • RandomChaos GSM Library

     

    Well, here is the first "Alpha" of my GSM. I have not supplied an example project with this release but there is a word doc and a help file in the help folder to get you started.

    Basically you have a screen manager object that you add screens to, these screens have screen items that you add to the screens and once you have got all that in place you just add the screen manager to the Game.Components and away you go.

    Here is a quick and very simple example:

               // Create a screen manager.
               RandomChaos.GameStateMenuSystem.ScreenManager screenManager = new RandomChaos.GameStateMenuSystem.ScreenManager(this);

               // Create a menu instance
               RandomChaos.GameStateMenuSystem.BaseMenuScreen menu = new RandomChaos.GameStateMenuSystem.BaseMenuScreen(this);

               // Give it a name and a background image and switch on the bloom effect.
               menu.ScreenName = "MenuScreen";
               menu.AddBackgroundImage("Textures/steel2");
               menu.Bloom = true;

               // Set up a menu item.
               menuItem.ForeColor = Color.White;
               menuItem.FontAsset = "Fonts/test";
               menuItem.TextureAsset = "Textures/perlin";
               menuItem.Text = "Exit";
               menuItem.SetAction(RandomChaos.GameStateMenuSystem.SelectAction.Exit, null);
               menuItem.ImageTileSize = 2;

               // Give the menu item a shadow.
               menuItem.ShadowDepth = 2;
               menuItem.ShadowColor = Color.Black;

               // Add key/buttons to handle menu navigation.
               menu.AddScreenExitInput(Keys.Escape);
               menu.AddMenuSelectInput(Keys.Space, Keys.Enter);
               menu.AddMenuSelectInput(Buttons.A, Buttons.Start);
               menu.AddMenuDownInput(Keys.Down);
               menu.AddMenuDownInput(Buttons.DPadDown, Buttons.LeftThumbstickDown);
               menu.AddMenuUpInput(Keys.Up);
               menu.AddMenuUpInput(Buttons.DPadUp, Buttons.LeftThumbstickUp);

               // Add the menu item
               menu.AddMenuItem(menuItem);

               // Add the menu to the screen manager.
               screenManager.AddScreen(menu);            

               // Add the manager to the game.Components.
               Components.Add(screenManager);

    As you can see it is pretty simple to get a GSM up ans running with this (don't forget to add the library as a reference to your project!), have a go and see what you can come up with. Naturally for your game you will want a menu option to take you to your game class. To do this simply create your game class and derive from BaseScreen, you can then add your game class to the screen manager and then have it called from the menu item by setting the menu items Action to GoTo and the action screen to an instance of your game class by using the menu items SetAction method. Take a look at the help file for more info on this function.

    I still have a few optimizations to make. As ever C&C are welcome, also if you have any effects or transitions you would like to see in the GSM, post them up here and I will do my best to get them in.

    This is a full content version too so you wont have to set up a default font or have your own perlin and displacement map textures, but if you want to swap these items for your own then by all means do. It is also only for the PC, I have created and tested it on the 360 and all went well,but I probably wont do a full 360 version until I have this at first release, I guess if you ask me for it though, I could build it and put it up.

    The download for this is here.

  • XNA Socket/UDP Server

     

    The other day I was discussing with a friend (Jeremy) MMOG's and how we might go about writing one, we then went on to chat about MUD's we had written in the past and so lead me to the idea of creating a socket server; as I had had some experience of writing sockets in C++ and VB I thought I would give it a go in C#. Turns out there are a tone of articles on line that you can reference for this sort of stuff. Having written most of the socket side another friend of mine (Chr0n1x) suggested looking at writing a UDP server as that's what is mostly used in games development these days.

    If you are not up on Sockets and UDP, take a look here for a pros and cons.

    I guess your first question will be, what is wrong with using the Live networking that comes with XNA 2.0, my answer is, nothing, by all means use it, but if you don't want to go through the Live network, then you will have to write your own server and client system. This is a way to start doing that. This post only has the basic connection management, you will naturally have to add the messaging system that your game will need but you can also see a rudimentary example of this in the way the server accepts clients and adds them to the client list.

    Your next question will by, why put it in an XNA project, why not, means I don't have to write the message pump and just create it as a Game Component and write the rest around it. Also, you could then have the server in the game code as well and then have one game serving with the others as clients on a LAN or even if you have a static IP, serve it on line (may be some security issues there :P)

    Well here is how I have laied it out in this example.

    As you can see in the class diagram above, there four classes, two enumerated types and six delegates.

    Classes:

    BaseServer has all the basic items both server types will need; events to inform the user that connections are being attempted, dropped and that data has been received etc.. also basic fields and related properties that both servers will use like MachineName and Port.

    SocketServer is the class used to create a socket server (well named or what eh?). It has a few extra fields and properties for the serving IP and a TcpListener to obtain connections to it. It also overrides some of BaseServer methods to get extra things done in those methods.

    UDPServer is the class (you guessed it) used to create a UDP server. As with the SocketServer it has extra fields and properties with overrides to BaseServer to do the jobs it needs to to as a UDP server.

    ClientData is used to store your client/player data, it has basic authentication for adding a server generated Guid to uniquely identify each user. In this example I have not added any other data objects than are needed to bind clients to the server.

    Enumerators:

    The enumerators are my stab at a very basic messaging protocol, you can use this, extend it or even throw it out and create your own.

    MessageType is the main message type so I can split out messages that are to passed strait on to another user like an in game message or if it is data that is going to change an item or items in the world it's self etc..

    MessageSubType, so you have a min message type and these can then be split down further, so staying with a player to player message, one message could be to all on players like an OOC (Out Of Character) message or could be a personal message sent to a single player in game.

    Delegates:

    The delegates define the event signatures that a user of the classes can use to wire up events from the server.

    ConnectionAttemptEvent is fired each time a client/player tries to connect to the server.

    ConnectionDroppedEvent is fired when a clients connection is dropped or lost.

    DataReceivedEvent is fired when data comes into the server from a client.

    ErrorEvent is fired when an error occurs on the server.

    ServerStartEvent is fired when the server starts listening for clients.

    ServerStopEvent is fired when the server is stopped.

    In the example project you can download there is also a test client, all that this client does is connect to the service and can send text messages to it, nothing else, it's pretty rough realy. The server example using the objects described above just allows and acknowledges connections to it and drops them if they are inactive for the default ClientTimeOut, which I set at an arbitrary 30 seconds.

    You can get the example code here.

  • Game State/Menu Manager II

     

    Well, I have done another vid to show what it can do at the moment, you can take a look here. The vid shows the same effects as before but also menu and menu item transitions and the menu cursor that (if implemented) can be moved by the game pad or the keyboard. Also instead of just having hard coded keys/ game pad buttons to navigate the system you can specify your own so you have full control over the flow and navigation control of the system.

    It's a little it better quality to so you can see the effects a little more clearly.

    Here is a list of some of the things you can do at present:-

    Font (menu Item) Effects:

    • Textured
    • Refracted Texture
    • Bumped Texture
    • Bloom

    Menu Item Transitions:

    • Opacity Blend
    • Instant (no transition effect)
    • Drag Up
    • Drag Down
    • Drag Left
    • Drag Up with Opacity Blend
    • Drag Down with Opacity Blend
    • Drag Left with Opacity Blend
    • Drag Right with Opacity Blend
    • Slide Up
    • Slide Down
    • Slide Left
    • Slide Right

    Menu Effects:

    • Colored Edge Glow
    • Refraction
    • Bumped
    • Ripple
    • Colored Smoke
    • Bloom

    Menu Transition Effects:

    • Same as Menu Item Effects.

    With any luck you will be able to see these effects in action in the new movie.

  • Game State/Menu Manager

     

    Inspired by the Example on the Creators Club I decided to write my own so it would do the stuff I needed it to. As always the one on the Creators is great and a nice starting point.

    This is written from scratch and instead of releasing the code I might just put it up as a binary for you to bolt into your projects, naturally you will be able to inherit from it and create the menus you want from it.

    As the image I put up does not really show what is going on I have put up a short vid (here) to demonstrate some of the things it can do.

    Features:

    • Based on GameComponent so you can just add it to your game via Component.Add
    • Ability to texture your fonts
    • 2D shader effects on both the menu, fonts and cursor
    • Menu cursor driven by the keyboard or 360 Controller

    There are only a few effects at the moment but I plan to add more, still much to do, but once done I think it will be useful.

  • Rolling Shader Fog

    http://www.youtube.com/v/1ajrL-iORZk <p><a href="http://www.youtube.com/v/1ajrL-iORZk">http://www.youtube.com/v/1ajrL-iORZk</a></p>  

    Well here is my rolling fog. The sample download has two projects, one for XNA 1.0 Refresh and the other for XNA 2.0. I got it up and running on my 360, but for some reason on there the textures got mashed, the fog was fine though. I will have to look into coding shaders for the 360 more, must be me doing something silly...

     

    Also forgot to mention on both the other shader fog posts and this, that the models for the building were from 3DRT in the free download section.

    Anyway, the download can be found here.