Sunday, 8 January 2012

Adding the peeps

The game needs some sort of aim. In the original game, the aim was to abduct the humans standing on top of the buildings. As I'm doing a remake then I may as well keep this as the aim.

All I've done is created a new in game object called a person (extended from my Base3DObject), which is another model to load in.

However, this time around I want the little person to jump up and down and wave their arms around (like in the original). For this I'm going to need to animate my 3D object.

I'm sure there are many ways to animate the 3D objects from using bones and skeletal structures to probably having multiple frames of the object and quickly load them in succession (this seems daft though).

I could have even used the Xbox avatars as the best way to add a human to abduct. I did look into it, but for now I'll keep things simple.

What I'm going to do is animate the individual meshes of the person 3D object.

The person is made up of 6 sub meshes.

1. The head
2. The body
3. The left leg
4. The right leg
5. The left arm
6. The right arm

Up until now, any matrix transformation I've applied to my objects has been applied to all meshes. So if I rotate anything, then everything in the object rotates with it. This is all I've needed up until now as I wanted my entire UFO to rotate.

What I've done is to add another matrix multiplication to the world matrix for each mesh that I want to transform individually.

In this case, I want to rotate the arms of the person so they look as if they are waving.

I found a great link on how to do this (link)

So now I've got my person class and when I render the little fella to screen, he jumps up and down waving his arms.

All I did then was to add an imposed limit to how many could appear on the the map and in the map generation code randomly place my peeps on top of the buildings.

So when the level starts, the map is now littered with little people waiting to get abducted.

I've found the original

Just in case you wanted to have a look at the original flash game I mentioned, I've uploaded it for anyone to play (or mock as it is quite bad!)

Saturday, 7 January 2012

Making gravity work against you

Just a quick update to the game mechanic for player death.

Originally, if you touched anywhere other than the roof on a building, you would die. You could descend full speed down on to the roof and still survive.

In the original flash game (and lunar lander) you had to control your descent with your thrusters and couldn't come down full speed.

A simple addition to the player code now checks to see if the descent rate is too fast and returns an boolean true so the collision can be considered fatal even if you do collide with the roof.

I've also added Fuel in for the player, just a simple int that decreases every time you thrust. When you're out of fuel, you can no longer thrust, meaning you fall to your death!

The last addition is a Lives variable on the player, which I will use in the game to decrease every time you crash and when you reach 0 it's game over.

Thursday, 5 January 2012

Making use of particles for explosions

So far when I collide with a building. Nothing happens other than the player UFO bounces off.

I've added some quick code to make the player disapper and reset position.

But it would be nice to have a cool explosion. Well these new particles will work nicely.

Firstly I've created a wrapper class to contain the particle effects and then I can just pass this to my player object and upon collision just add the explosion particle to the game world.

Very easy to implement and now when I crash there is a satisfying explosion.

I decided to add another particle effect too for when you thrust the player UFO it now has an emission trail shoot out of the bottom.

All I did was copy the fire particle system and tweak it with a new graphic to get my desired effect.

This is kind of a distraction from getting my core game done but it was a fun experience and has added a nice polish to the game.

Wednesday, 4 January 2012

Particles are fun

Just a quick post to say I'm going to be implementing a particle system to handle things like my explosions.

Been having a play with the sample on App Hub (link) and this is what I've achieved in about an hour of tinkering

I want to see my bounding boxes

I want to try and figure out why my collision routines are all messed up now.

The logic isn't that complex, it's just a bounding box that intersects another box. How can rotation cause so many issues?

Well, first things first I want to see if I can draw my bounding boxes around my player UFO to see how things are looking.

Drawing a bounding box can't be that difficult, I know all my points of the cube, just need to add some lines. Rather than re-invent the wheel, I'll check google first to see if someone has already solved this issue.

App Hub again never fails to disappoint, this wonderful shape renderer class will do just nicely (link)

Easy enough to bolt on to my current code and get my bounding boxes rendering.

So now I have my bounding boxes drawn around the player UFO I can instantly see a random effect to the bounding box. With every rotation update, the bounding box is changing shape.


This is because the bounding box is calculated with every update to ensure it stays aligned to my player UFO.

I think there is probably a better way of doing things, but for now I'm just going to remove the rotation at the point of the bounding box calculation and re calculate when positioning the 3d object.

That works, probably not ideal but I'll revisit this later on to clean it up.

Tuesday, 3 January 2012

Giving the player a bit of character

So far the player UFO just slides around the map. It would be nice to have some sort of animation. Something like the UFO spinning around.

I think you can pre animate models and then play them in XNA, not sure though I've not really researched it.

My needs are simple, I Just want to rotate the 3D object through the Y axis and my base3Dobject already has a rotation property. All I need to do is add to this value every game iteration and my 3D object will rotate as the world matrix of the object takes scale, rotation and position into consideration.

Now the player UFO spins around when I run the game.

But now I'm getting some strange collision detection issues. I can cut right into the buildings and sometimes when I land I drop through the building.

What's going on? I've only changed the rotation!