Example #1
0
        public double Clash(IClashAble clashAble, Vector movement)
        {
            double bound = clashAble.BoundRadius;

            Vector checkFrom = FromBlockPosition(new Vector(clashAble.Position.x - bound + Math.Min(0, movement.x),
                                                            clashAble.Position.y - bound + Math.Min(0, movement.y)));

            Vector checkTo = FromBlockPosition(new Vector(clashAble.Position.x + bound + Math.Max(0, movement.x),
                                                          clashAble.Position.y + bound + Math.Max(0, movement.y)));

            double min = 1;

            for (int i = (int)Math.Max(0, checkFrom.y); i < Math.Min(blocks.GetLength(0), checkTo.y); ++i)
            {
                for (int j = (int)Math.Max(0, checkFrom.x); j < Math.Min(blocks.GetLength(1), checkTo.x); ++j)
                {
                    if (blocks[i, j].Solid)
                    {
                        min = Math.Min(min, clashAble.Clash(blocks[i, j].body, movement));
                    }
                }
            }

            return(min);
        }
Example #2
0
        public double Clash(IClashAble another, Vector movement)
        {
            if (!another.Solid)
            {
                return(1);
            }

            switch (another)
            {
            case Thing thing:
                return(Model.Models[modelID].Clash(position, angle, Model.Models[thing.modelID], thing.position, thing.angle, movement));

            case Rect rect:
                return(Model.Models[modelID].Clash(position, angle, rect, movement));

            case Circle circle:
                return(Model.Models[modelID].Clash(position, angle, circle, movement));
            }

            throw new Exception("Type error");
        }
Example #3
0
        public double Clash(IClashAble another, Vector movement)
        {
            if (!solid || !another.Solid)
            {
                return(1);
            }

            switch (another)
            {
            case Rect rect:
                return(CollisionCheck.Collision(position, radius, movement, rect.Points));

            case Thing thing:
                return(Model.Models[thing.modelID].Clash(thing.position, thing.angle, this, -movement));

            case Circle circle:
                return(CollisionCheck.PointsDistance(position, movement, circle.position, radius + circle.radius));
            }

            throw new Exception("Type error");
        }