public static int VerticalCollisionIndex(MovingObject moving, List<GameObject> objects) { List<MatrixCoords> profile = moving.GetCollisionProfile(); List<MatrixCoords> verticalProfile = new List<MatrixCoords>(); foreach (var coord in profile) { verticalProfile.Add(new MatrixCoords(coord.Row + moving.Speed.Row, coord.Col)); } int collisionIndex = GetCollisionIndex(moving, objects, verticalProfile); return collisionIndex; }
private static int GetCollisionIndex(MovingObject moving, ICollection<GameObject> objects, List<MatrixCoords> movingProfile) { int collisionIndex = 0; foreach (var obj in objects) { if (moving.CanCollideWith(obj.GetCollisionGroupString()) || obj.CanCollideWith(moving.GetCollisionGroupString())) { List<MatrixCoords> objProfile = obj.GetCollisionProfile(); if (ProfilesIntersect(movingProfile, objProfile)) { return collisionIndex; } } collisionIndex++; } return -1; }
private void AddMovingObject(MovingObject obj) { this.movingObjects.Add(obj); this.allObjects.Add(obj); }