• entries
707
1173
• views
435681

# Untitled

241 views

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])            continue;        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.

There are no comments to display.

## Create an account

Register a new account