Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Tuesday, 17 August 2010

Modifying the C# CollectionEditor for real-time updates

In one of my projects I'm using a PropertyGrid element in the main form as an easy way for users to change settings. One item in the class used by the PropertyGrid is a collection and C# automatically opens a CollectionEditor form for the user to add, remove and modify elements of the collection.

The issue however is that changes to the collection should be represented in the main area of the form immediately, but the CollectionEditor control seems to leave the collection in an undefined state until the form is closed.

I can understand what the CollectionEditor form is trying to do, it is waiting until the user clicks on OK or Cancel before writing the changes to the actual collection. However it doesn't do this, it partly mucks up the collection when the user changes items or adds them, but doesn't touch the actual collection when the user removes or rearranges items.

Tuesday, 18 May 2010

Input management in XNA

Managing input in even the simplest game can result in a mess of confused lines of code scattered across the entire project. I have started to write an InputManager class that can be used to easily set up and use during the game.

There will be two main parts to the class. The first part is how to set it up during game loading, and the second is how to use it during the game to check what the player is doing. I use the concept of "Actions", which can describe a particular action the user wants to do, for example selecting a menu item, asking a character to jump, or steering a car to the left.

Wednesday, 21 April 2010

Games for 3D glasses with XNA

Following on from my post about creating images for 3D glasses, here is how I modified my XNA game engine to render stereo images.

Previously my camera class simply set up the view and projection matrices based on various input. These matrices are then used by the other components in the game to draw themselves. I have now added an extra property to the class, AnaglyphType, to determine whether the scene is rendered as a left/right stereo pair. Also extra code is added to the game loop to draw the scene into two textures, then combine them with a pixel shader.

Monday, 12 April 2010

Simple 2D car steering physics in games

How to do a realistic moving car in only 6 lines of code!

I find nothing more frustrating in car games than when the developer has implemented some ridiculously unrealistic model for how the car moves. For most games, especially flash-based mini-games, simulation grade 3D physics are not required, but still the car should move and turn roughly like you'd expect a real car to.

Have a quick go at this car parking game, or this one, try to turn into a parking space, something doesn't feel right. More specifically the rear wheels are sliding sideways whenever you turn - this does not (normally) happen in a real car, and it makes this game very hard for all of us used to controlling a real car. I'll show you here how to get better physics than this in just half a dozen lines of code.