Archive for May, 2007
Crimson Update: Vasculitis (v0.0.2.24380)
cubed2D
May 10th, 2007.
 So heres the layout of my engine at the momentÂ
Without any diagrams, things get messy quickly. I had the thing planned out in my head, i had no paper in my room, my windows were too small to write on (at home i design programs on my windows with dry wipe markers) so i decided to go ahead anyway, and not so surprisingly it got messy. I then decided to use blue J (a java ide we use in university) to draw down what id written so far. Now i know how things connect and i can visualize it better. Id say a visual program designer is a good tool, you can pull things and its cool, but not as cool as using a window!
 Animated sprites have been a fun feature to add, my implementation hangs around the concept of an animation sheet. my orc test sprite has some animations in separate.png files and some bunched together on the same .png. So how do i handle them? every animation gets a animation sheet, which contains its start frame, end frame and a reference to its texture. these are held in a dictionary as a value, the key to that dictionary is a CompassDirection (north, NorthEast ect). I have a load of these in a list, and i keep there indexes in another dictionary with a AnimationState(move, idle, jump etc). To get the correct animation sheet you just need to know what direction and animation you currently in and pull em out. More difficult problems were finding out the current direction and grabbing the current frame from a texture. At the moment i only support the xbox controller, so i needed a way to turn the vector2 returned from the thumb stick in to a cardinal direction. I did this using the magic of dot product. The dot product between two vectors will give you the angle between them. All i needed to do was to have a list of all the directions i wanted to test, try the dot product between them all and then use the animation with the smallest dot product (which would be the closet to the angle of the stick) Heres some code for you!
public class DirectionSet // the 8 compass directions represented in vectors
 {
 public Dictionary
 public DirectionSet()
 {
 directions.Add(0, new Vector2(0f, 1f));
 directions.Add(1, new Vector2(0.5f, 0.5f));
 directions.Add(2, new Vector2(1f, 0f));
 directions.Add(3, new Vector2(0.5f, -0.5f));
 directions.Add(4, new Vector2(0f, -1f));
 directions.Add(5, new Vector2(-0.5f, -1f));
 directions.Add(6, new Vector2(-1f, 0f));
 directions.Add(7, new Vector2(-1f, 1f));
 }
 }
Use this function to get the sticks direction:
public int GrabAnimationDirection(Vector2 stick)
 {
 float bestDot = -100;
 int bestAnim = 0;
 for (int i = 0; i < 8; i++)
 {
 Vector2 normal = Vector2.Normalize(directionSet.directions[i]);//normalise the directions
 float dot = Vector2.Dot(velocity, normal); //find the angle
 if (dot >= bestDot) //if its smaller, save it
 {
 bestDot = dot;
 bestAnim = i;
 }
 }
 return besttAnim;
 }
Then i just cast the returned int to my CompassDirection enum for use!
The other problem is alot easier, how do we choose the tile? First, we need a frame counter to increment. I increment it every 33ms (30fps). we also need to know the number of columns in the sprite sheet and the height and width of each sprite. with this info we can find the top left corner of each frame
int x = (frame % column) * width;
int y = (frame / column) * height;
Its really simple when you think about it, just grab a sprite sheet, and try these for a frame in the middle, I’m sure your understand how it works straight away!
The other useful thing i learned is how to cast a string in to a enum. Which is really useful when reading info out of an xml file.
(CompassDirection)Enum.Parse(typeof(CompassDirection), “North”);
remember to test its going to work first!
Enum.IsDefined(typeof(CompassDirection),”apples”);
would return false, because apples just arn’t directions no matter how hard they try.
anyways, Crimson 0.0.2.24380 new features!
Features:
- Better, more flexible animation system, which supports:
- Idle animations
- Movement
- Shooting
- Death
- and flexible to add others!
- Loading XML files which describe an animation, and serializing them in to actual animation sprites.
- early prototype of the input manager.
- updates to my content manager
also, for anyone who is interested, heres a short demo. It only works with an xbox controller at the moment. left stick moves you around, B jumps and A kills you. If anyone can run it and tell me how it runs on there pc id be grateful!
Crimson Update: Vasculitis (v0.0.1.423)
cubed2D
May 08th, 2007.
And now for an update on my Crimson engine! I’ve been working on the fist minor milestone, codenamed Vasculitis over the passed few days. The plan is for Vasculitis path to take Crimson all the way up to v0.2, and by the end its lifespan to have all the basic features (apart from scripting) implemented.
So far, ive completely rebuilt the screen system. Ive looked through Microsoft’s game state management sample and i loved the way they implemented some things (especially the transitions!). After playing with it a bit, it was clear id have to do a bit of retooling on my screen system, which ended up with me ripping out the whole screen system and starting from scratch.
 After that, i added in basic support for menu screens, worlds and UI popups. Then built a basic entity system, that currently supports static and animated sprites! been a busy few days! still needs allot of work and clean up, but its cool so far!
My animated sprites support single or multiple animation sprite sheets, and multiple animations. Heres a short video of an orc running around my test level. He’ only using the running animation (small bug at the moment with switching through different animations) but does show that sprite sheet switching does work, as each direction is on its own sheet.
Crimson build name Vasculitis (v0.0.1.423)
Fun with Bézier Curves!
cubed2D
May 02nd, 2007.
Ive written a short tutorial for Ziggyware’s upcoming tutorial contest! Its about moving a sprite over a curve. Not the most exciting thing in the world, but then FPS monitoring and screen resolutions arnt really a bag of fun either.
 But someone has to write articles on the things nobody else even considers, so part 3 of the neckocake code dump is out! Check the code page for the code as always (this time you can grab yourself a lovely test exe too!) and the customary video is up as well.
Ohh, and these lovely looking equations!
 /Sarcasm off
Hope Someone finds it useful! Read it on Ziggyware
