コード例 #1
0
        public static bool TestCollide(ISolid obj1, ISolid obj2, PointF p1 = new PointF(), PointF p2 = new PointF())
        {
            CollideZone c1 = obj1.Shape.GetCollideZone();
            CollideZone c2 = obj1.Shape.GetCollideZone();

            PointF pos1 = p1 == new PointF(0, 0) ?
                          (obj1 as AbstrUnit).Pos : p1;

            PointF pos2 = p2 == new PointF(0, 0) ?
                          (obj2 as AbstrUnit).Pos : p2;



            if (!(obj1.Shape.IsActive & obj2.Shape.IsActive) ||
                (PointOp.lenght(PointOp.Sub(pos1, pos2)) > c1.R + c2.R))
            {
                return(false);
            }



            if ((obj1.Shape is SquareShape) && (obj1.Shape is SquareShape))
            {
                float edge1 = (obj1.Shape as SquareShape).Edge;
                float edge2 = (obj2.Shape as SquareShape).Edge;

                if (Math.Abs(pos1.X - pos2.X) <= (edge1 / 2 + edge2 / 2) &&
                    Math.Abs(pos1.Y - pos2.Y) <= (edge1 / 2 + edge2 / 2))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        public static bool TestMoveCollide(IMovable obj1, ISolid obj2)
        {
            if (!(obj1 is ISolid))
            {
                return(false);
            }

            PointF test_pos = PointOp.Sum(
                (obj1 as AbstrUnit).Pos,
                PointOp.Mul(obj1.Direction, obj1.Speed));

            return(TestCollide(obj1 as ISolid, obj2, test_pos));
        }
コード例 #3
0
ファイル: Render.cs プロジェクト: alekseyIsakin/LabGame
        public static void Draw(Graphics gr, IDrawable obj, bool always = false)
        {
            PointF pointDraw = PointOp.Sub(
                (obj as AbstrUnit).Pos, Offset - Screen);

            if (!always && (
                    pointDraw.X < -1 || pointDraw.X > Screen.Width * 2 + 1 ||
                    pointDraw.Y < -1 || pointDraw.Y > Screen.Height * 2 + 1))
            {
                return;
            }

            if (obj is AbstrUnit)
            {
                obj.Draw(gr,
                         PointOp.Mul(pointDraw, MainGame.CellEdge), MainGame.CellSize);
            }
            else
            {
                obj.Draw(gr);
            }
        }