• Advertisement
  • entries
  • comments
  • views


Sign in to follow this  


Things are going pretty smoothly. The terrain system is working well and I'm finishing up implementing the collision detection system.

At the moment I have a single class, named CollisionManager. It has two methods: ObjectTerrainTest() and ObjectObjectTest(). I use them like so:

for(int Index = 0; Index < mapObjects.Count; ++Index)
collisionManager.ObjectTerrainTest(tileTerrain, mapObjects[Index], FrameRate);

for(int IndexB = Index; IndexB < mapObjects.Count; ++IndexB)
if(mapObjects[Index] == mapObjects[IndexB])

collisionManager.ObjectObjectTest(mapObjects[Index], mapObjects[IndexB], FrameRate);

I simply iterate through and do a terrain test and then do an object-object test. The methods adjust the object's position and velocity if needed.

The class also has 2 events: ObjectTerrainCollision and ObjectObjectCollision. These are the heart of the system, as its how I implement things like platforms, damaging spikes, etc (pretty much, anything that is game specific responses.)

For example, as a test I just added the ability to add spring tiles. First, I added a property, IsSpring, to my implementation of CellData:

public sealed class CellData : ICellData
public int BrushIndex { /* ... */ }
public Drawing.Color Tint { /* ... */ }
public bool IsSolid { /* ... */ }
public bool IsSpring { /* ... */ }

// Constructors, ICellData implementations, etc.

Then I update my ObjectTerrainCollision event handler:

void collisionManager_ObjectTerrainCollision(object sender, ObjectTerrainCollisionEventArgs e)
CellData Data = e.CollisionCell as CellData;
if(Data != null && e.MovementDirection.HasFlag(Direction.South) && Data.IsSpring)
e.Object.Velocity = new Vector2(e.Object.Velocity.X, -700.0f);

And I'm done. I convert the cell from ICellData to my CellData class, make sure it's not null, is a spring, and that the object in question is moving south (falling in the case of a platformer.) If all conditions are met, I set the object's velocity to -700, launching it into the air.

Next step: getting platforms working.
Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement