Showing posts with label XNA. Show all posts
Showing posts with label XNA. Show all posts

Thursday, October 18, 2007

Couple of things I miss from Visual C# Express

I know this great little application is free and so can't really complain, when you work with Visual Studio 2005 Professional five days a week the bits that are missing start to get to you:

  1. No "delete all breakpoints" option.
  2. Can't attach the debugger to another process, or set the project to load a different application
Doesn't sound like much, and I didn't think that was much, until you step through an XNA project, and then have to manually remove all your breakpoints. Or if you want to unit test something and you can't attach to the NUnit process, which means you can't step through your tests.

Glad it's got Intellisense though :)

Monday, October 15, 2007

Log Visualiser using a particle system

I carried on my attempts to make logging output look a bit interesting, and what I think I wanted was a stream of pixels flowing down from a server name to give a waterfall effect. Each pixel streaming down would represent one log event, and the colour of the pixel would be determined by the log level of that event.

I set out to implement this, but then thought that someone else must have come up with a particle system for XNA already. And they have, check out this particle sample on the XNA Creators Club.

This sample shows how you can make explosions and smoke effects in XNA, and the end result is surprisingly realistic. I took this example and derived my own class from the abstract ParticleSystem class. It took some experimentation with the parameters I used, but now I've got a stream of pixels flowing in the way that I planned.

I've also got a mock application that just generates log entries for the XNA application, and I've generated 10,000 logging events in a very quick sequence. As the XNA application doesn't store the events for very long there doesn't appear to be much slow down, but it would be interesting to load test it against a number of servers generating a high volume of logs. At the moment I think there would be a slow down but I'm pretty sure I can refactor the event handling so that it will be more scalable.

There's some cleaning up to do, mainly with the positioning of new server entries and externalising a number of parameters to a config file, but I think I'm mostly there.

Thursday, October 11, 2007

Visualising Logs - Progress Report

Just a short one as it's getting late now. I've continued a little with my XNA log viewer mentioned previously.

I've set up a mock application that generates logs on command, and I've set up log4net in the same way you would if you wanted to look at the logs in Chainsaw. So this fires off UDP packets containing the entry in XML. I've then got a class that listens asynchronously to a socket. When it receives data it deserialises it to an object, and then raises an event.

My XNA "game" has one of these socket listening classes, and provides an event handler to receive the logs.

On screen right now I'm just scrolling the messages. To do this I have a GameComponent that contains a rough implementation of a generic circular queue. The contents of this queue are drawn to the screen, and as it's always wrapping around, it gives the effect of scrolling without having to move the position of the string.

Next I need to figure out how I want the logs to be visualised.

Tuesday, October 09, 2007

Making logging output "interesting"

This slashdot article caught my interest last night: Logfiles Made Interesting with glTail. Basically a guy has written a Ruby on Rails program that parses Apache access logs and gives you a visual representation of them using OpenGL graphics.

The outcome of it looks pretty interesting, and it got me thinking about what else you can do. I'm wondering how we could visualise some log4net logging, maybe using the XNA framework to output the graphics.

So last night I coded up a simple UDP Socket listener, and made a mock application that logs out an XML event to a UDPAppender. I found it should be pretty simple to get the log events to an XNA application, and now I'm thinking how the logs that the Esendex system generates can be displayed in an interesting yet useful way.

I'll keep you posted if I do anything else.

Monday, September 17, 2007

Using UDP in XNA

I've had an anonymous comment left on a UdpClient post asking if I have used the UdpClient in an XNA game. Well, no I haven't--and to be honest I've not used the class much in anything else either. In fact that previous blog entry was posted after pairing with Nick on a bespoke application for a customer of ours.

But, the question got me thinking about it anyway. The comment says that they have a piece of code using the UdpClient that works in a normal .Net application, but when included in an XNA game, it no longer receives anything.

Now, I can't see why this would be the case if you are compiling to a Windows game. A Windows game is just running on the standard .Net framework, so everything should be OK. However, XBOX 360 games will run on a variation of the .Net Compact Framework, so there is a difference there to be aware of.

So assuming you're making a Windows game, why should the UdpClient now not work? Well to start I made a normal console application with the code snippet posted in the comment, and tried to get that to work. I made a separate console application to use as the sender.

And that's when the problem struck--one which I should have seen at first glance anyway. If you try to have multiple applications on the same computer accessing the same port using UdpClient you will get an exception that says "Only one usage of each socket address (protocol/network address/port) is normally permitted". (Read this article for a bit more information).

The only way we've found to stop this happening is to not use UdpClient at all, but to create Sockets yourself and use those instead.

However, I thought there must be an easier way--someone must have solved this problem before. And it looks like someone has.

I've not had a look at it in much depth, but if you want to send and receive UDP packets in XNA then take a look at the lidgren-library-network, which is on Google Code.

I don't know whether this uses UdpClient under the hood or not, but it has an XNA extension for sending Vectors and Matrices so it must have been used in some XNA games somewhere along the line.

Check it out and see if it helps.

Thursday, August 09, 2007

Problems Rotating Models in XNA

After finding Blender I've created some simple cubes and exported them into an XNA project. I want to rotate these after receiving input from the GamePad (although currently I'm testing with the Keyboard).

The idea that I have calls for the cubes to be rotated 90 degrees after a button press. The camera isn't moving, so having a cube rotate in this way means that the cube will always be displaying a full face.

I've figured out how to rotate, but as soon as I rotate around more than 1 axis I have to consider which direction the cube is facing to determine which direction I should rotate based on the next button press.

The cube needs to rotate up and down, and left and right, and the buttons to do this should be the same regardless of the cube's current orientation. My initial simple hamfisted attempt at rotating didn't take this into account. So if I rotated left and then pressed the button to rotate up, the model twists clockwise.

I rather stupidly failed to realise that the rotations are being done in relation to the model. Hindsight tells me how stupid I am for not realising this--how difficult would model movement and rotation be if everything was done in relation to the camera or an absolute point?

But now I know this it's got me wondering how I can achieve what I need. I suspect I need to store the current orientation of the cube, and then based on this determine which way is up so I can rotate accordingly.

Anyone have any experience of rotating models in this way?

XNA Arcade

Over at Ziggyware XNA News there's a post about XNA Arcade.

Kyle Schouviller's created the application to allow people to easily distribute their XNA games.

Haven't checked it out yet, and it is still in it's alpha stage, but the concept certainly sounds interesting.

Check out the application here.

Tuesday, July 31, 2007

Getting Started with Blender 3D and XNA

Glenn's posted a comment on one of my Blender posts to an article he's written about exporting Blender's 3D models into Game Studio Express.

Check out Getting Started with Blender 3D and XNA for more information.

I'll need to make some models first, but when I've done that this article should provide some much needed assistance.

Thanks Glenn

Monday, July 30, 2007

Blender - Free 3D Modelling Software

I've had an anonymous comment left on a post in which I asked if anyone knew of anything free I could download to create some 3D models for an XNA game I want to start.

The comment suggested Blender, so I've downloaded it and given it a go. Seeing as I've done zero 3D modelling before it's going to be a steep learning curve, but there seems to be tutorials to walk you through most of it. There's DirectX's .X format in the Export list as well, so hopefully this should be all I need.

Thanks for the heads up who ever you are.

Thursday, July 26, 2007

Download XNA Card Game Code

Please feel free to download the code for the card game I wrote in XNA. It's not the best card game to play, and I have no idea whether the code is correct from a gaming point of view, but if you want to take a look at a possible way of developing a card game, then you're welcome to take a look.

If you're looking to write a card game and you need card graphics, then some are included in the download for you to use.

If anyone finds it useful then please let me know. The 3D game idea I had has fallen through a little as I can't find any free software that will allow me to create my own simple 3D models. If anyone knows of one I can use, then let me know about that as well.

Wednesday, July 25, 2007

My XNA Card Game - please wait a moment

Ken's posted comments on a couple of posts asking for the code for the card game that I wrote in XNA. I'm glad someone asked as I'd totally forgotten I'd said I would make it available.

It's woken me up from my XNA slumber, I've just had lots of things happening recently that I haven't had chance to look at it as much.

I've packaged up the code as a download, but I can't find the login credentials for my FTP site right now, and it's getting late and I need to go to bed.

I swear I'll upload the code tomorrow evening (UK time) and post a link here. So just watch this space.

Thanks

Monday, May 28, 2007

Introduction to 3D in XNA

For my next XNA project I think I should move into 3D. The Spacewars starter kit still looks complicated but I think I've come up with a game idea that can make use of 3D while still being relatively simple to visualise.

I'm not certain of this idea so won't go into detail yet, but I will need to figure out how to place models in the world and move the camera for any 3D game to work.

I've found an introduction to 3D models in XNA, and an introduction to matrices that should help somewhat. I've managed to render one of the Spacewars models into the game and can move the camera around in the way that I want.

Now I need to get the model moving based on mouse input. Oh, and get some 3D models to display in the actual game. I've found Turbo Squid, but what I've found on there can't be imported into XNA and need to be opened in 3D modelling software, which I don't have.

Does anyone have any recommendations as to some free software I can use that will let me create my own 3D models?

Thursday, May 24, 2007

First Stab at Pong in XNA

Pong was probably not a great choice as an ongoing XNA project after all. I know what I said about the possibility of adding different features, but Pong doesn't really offer itself up as an interesting game that is going to be able to grab my attention for long enough to make something more of it.

So for now I'm done with it I think. It's playable, and relatively challenging. It keeps score and certainly looks quite retro in its black and white styling, but doesn't really do much else right now.

UPDATE: Changed the download location to something I have control over :)

For the time being you can download the code for the game if you want. Please read the readme.txt file as it explains a few things.

And please excuse my lack of knowledge when it comes to free file hosting, I just wanted something quick so I could upload the zip file. I might put the file somewhere else in the future.

I know that Ziggy wanted to download my first card game too, and I'll try to get that uploaded over the weekend.

But for my next project I think I'll try something new, no more copying existing games.

Tuesday, May 22, 2007

A Packed Tech Ed Schedule

After reading a few tips for Tech Ed first timers I went back to the schedule builder and started to select every session that looked interesting, both for myself and for Esendex. Adam's given me a few pointers for some potentially interesting sessions too.

I've now got a schedule where pretty much every time slot is filled, and most are filled with more than one. I've got a choice of about 4 at one time in places. Tuesday is looking particularly busy.

I was going to post the schedule I had, but I don't really have time right now to copy the sessions I've got planned. If anyone knows of an easy way to publish or save these sessions then let me know.

Thursday's 4.30pm session should be interesting too: "DEV344 Microsoft XNA Game Studio Express: Creating Your First Microsoft Windows and Xbox 360 Game".

I've already created my first XNA game, and am well on the way to my second, so maybe I won't learn much. But the session is rated as a 300 difficulty, which should mean that it's more advanced than just an introduction.

Wednesday, May 16, 2007

Time For a New XNA Project

Well I've finished what I'm doing on my first card game in XNA. I'm not claiming it's a fun game, or that playable, but it has rules, 2D sprites, mouse control, scoring, and a win condition.

Now I want to move on to something with a little more action. I still think that the Spacewars 3D project is a little beyond me right now though. I've gone through the video tutorials and followed them so I can move a 3D model on the screen, but I've yet to get the 3D co-ordinate system straight in my head and can't quite visualise it enough. I'm sure that will come in time though.

I'm not going to be terribly original in my next game idea. It seems everyone needs to write a version in XNA: like a rite of passage or something. I am, of course, talking about Pong--that age old game from the 70s that started it all.

It's an advance on my card game because (among other things) it's 2 player, it has moving sprites on screen, I'll need to detect collisions between bats and ball, and it contains some rudimentary physics to calculate how the ball should bounce from the bat and walls.

It also has plenty of opportunities for additions later. I could:

  1. add AI to make it a single player game
  2. add network play (I have no idea if XNA helps with this at all)
  3. have a 4 player version with 2 bats on either side for a doubles game
  4. allow the bats to be moved left and right instead of just up and down
  5. allow players to set colours and control preferences

So it should be more of a real game. Certainly seems more substantial than a card game which I could really have written as a standard Winforms application.

Maybe after this I could create a 3D Pong. I know its been done before as well (I think the version on kontraband.com is highly addictive), but it might be an easier starting point than the full Spacewars project.

Tuesday, May 08, 2007

XNA Mouse "Clicks" Update

Zygote's made an interesting point in my previous post about changing the way I detect a click. It certainly would make more sense to detect a "click" as when the state goes from Released to Pressed, rather than Pressed to Released which I have now.

This more accurately detects a "MouseDown" event that will make the interface more responsive.

Thank you!

XNA Mouse "Clicks"

So I've been carrying on with my card game in XNA. I've created some crude textures for the empty card "slot" and managed to find some pictures of playing cards online that I can use for the card faces.

One of the first things I did was sort out all the back end stuff (like shuffling the deck, dealing a card, etc.), I just needed to capture a mouse click on an empty card stack and deal a card.

But when it came to detecting the mouse click I was surprised that not 1 card was dealt when I clicked a card stack, but pretty much half of the deck.

I was using the Mouse.GetState method to check if the LeftButton was Pressed. As this was happening in the Update loop the game was looping around multiple times for as long as I kept the mouse button down.

Pressed really does mean Pressed.

So now I'm storing the previous state of the mouse, and only when the LeftButton state goes from Pressed to Released do I count a click.

EDIT: Detecting Pressed to Released models a "MouseUp" event, and while this may be useful in some situations, in this game a "MouseDown" would make more sense. To detect a MouseDown you count a click as the state going from Released to Pressed.

Now I just need to implement the rules of the game, and some scoring mechanism so scores can be compared.

Friday, May 04, 2007

XNA Resources

Mykre's been kind enough to send over a couple of links to easily show the mouse pointer in an XNA game. I knew I had seen the IsMouseVisible property somewhere but couldn't find it again when I needed it. Seems so obvious that it would be there now...

The links are in the comments for my XNA Mouse and Sprite Tests posts, but for ease of use here they are again:

Thanks Mykre

XNA Mouse and Sprite Tests

Played around with XNA last night again. For the card game I need to be able to display cards on the screen and click a stack of them to deal another card onto it.

So there's two basic things there that I need: display cards, and control the mouse.

I just followed the example for How To Draw a Sprite and I think that this will be all I need to draw cards to the screen. I'm pretty sure I know how to use the SpriteBatch and Texture2D classes now, but whether or not I'm using them correctly is another thing. All I can say is, I followed the examples and it works.

So I looked into showing the mouse pointer. I found a good article about encapsulating the mouse functionality into a class, and I'll probably follow this to tidy up my code, but for now I've just put that in my main Game class.

So I drew a pointer in MSPaint and used that as my cursor. I don't have the DirectX SDK yet (couldn't be bothered to download it last night), so the pointer isn't masked in the way that is described. It looks a little odd having a block of white surrounding the pointer, but for a proof of concept it's fine.

It struck me as odd that there wasn't a simpler way to show the mouse. Maybe there is and I just haven't found it, but then I though that the way I'm using is very flexible. It gives me full control of when I show the mouse, and I can update it only when I need to. Why have needless processing of the mouse when you're in a section of game that doesn't require it?

So for now I've got a random card showing on my screen (which I can show in full screen mode and at a really nice resolution, but that's another story), a pointer on the screen, and a continuously updating line of text which tells me where the pointer actually is.

I'm still a long way from a playable game, but I think I'm beginning to get the basics.

Wednesday, May 02, 2007

XNA Game Studio Express

I tried XNA Game Studio Express when it was still in Beta, but at the weekend I thought I'd try the one that has actually been released. If you don't know what I'm talking about then I guess a quick introduction would be that XNA is a framework for creating games in .Net, and Game Studio Express is an addon to Visual C# Express that lets you create games.

It's all free, so go and download it if you want to try it.

So I went through the 2D tutorial, which teaches you how to display a sprite on the screen and get it moving. That was pretty easy to do, but you're not left with much of a game--more a screen saver of a picture bouncing around your screen.

I tried some of the additions described at the end of the article, and although it was pretty cool adding mouse support to throw the picture around, it still wasn't much of a game.

So I went onto the next tutorial, which was creating a 3D game. And talk about being thrown in at the deep end! The learning curve between the two examples is pretty steep, and I don't have the time to go through it to figure it all out.

So I've settled for a middle ground. I'm going to try and create a 1 player card game based on a game my parents taught me years ago. It's got quite simple rules, and will have simple graphics too, but at the end I hope to have an actual playable game.