Example #1
0
        public void Render()
        {
            robotToGrab = null;

            for (int i = 0; i < robotList.Count; i++)
            {
                Robot r = robotList[i];

                float invY = -(r.PosY);

                float[] UpperLeft  = new float[] { PosX, PosY };
                float[] UpperRight = new float[] { PosX + 1.0f, PosY };
                float[] LowerLeft  = new float[] { PosX, PosY + 1.0f };
                float[] LowerRight = new float[] { PosX + 1.0f, PosY + 1.0f };

                //if (UpperLeft[0] >= r.PosX && UpperLeft[0] <= r.PosX + 1.0f)
                //    if (UpperLeft[1] >= invY && UpperLeft[1] <= invY + 1.0f)
                //        Console.WriteLine("Robot Hit Upper Left");

                //if (UpperRight[0] >= r.PosX && UpperRight[0] <= r.PosX + 1.0f)
                //    if (UpperRight[1] >= invY && UpperRight[1] <= invY + 1.0f)
                //        Console.WriteLine("Robot Hit Upper Right");

                //if (LowerRight[0] >= r.PosX && LowerRight[0] <= r.PosX + 1.0f)
                //    if (LowerRight[1] >= invY && LowerRight[1] <= invY + 1.0f)
                //        Console.WriteLine("Robot Hit Lower Right");

                //if (LowerLeft[0] >= r.PosX && LowerLeft[0] <= r.PosX + 1.0f)
                //    if (LowerLeft[1] >= invY && LowerLeft[1] <= invY + 1.0f)
                //        Console.WriteLine("Robot Hit Lower Left");

                if (Utility.Collision.IntersectionTest2D(PosX, PosY, 1.0f, 1.0f,
                                                         r.PosX, invY, 1.0f, 1.0f))
                {
                    //Console.WriteLine("Robot " + i + " hit");
                    robotToGrab = robotList[i];
                }
            }

            float minHeight = MIN_HOVER_HEIGHT;

            if (Hovering)
            {
                if (HoverHeight <= MAX_HOVER_HEIGHT)
                {
                    HoverHeight += 0.1f;
                }
            }
            else
            {
                if (robotToGrab != null)
                {
                    minHeight += robotToGrab.GetHeight();
                }

                if (HoverHeight > minHeight)
                {
                    HoverHeight -= 0.1f;
                }
            }

            float rotation = 0.0f;

            if (MovingLeft)
            {
                PosX -= 0.1f;
                light.setDirection(-0.45f, -0.45f, -0.45f);
                //Console.WriteLine("RMC (" + PosX + "," + PosY + ")");
                rotation = 90.0f;
            }

            if (MovingRight)
            {
                PosX += 0.1f;
                light.setDirection(0.45f, -0.45f, -0.45f);
                //Console.WriteLine("RMC (" + PosX + "," + PosY + ")");
                rotation = -90.0f;
            }

            if (MovingUp)
            {
                PosY += 0.1f;
                light.setDirection(0.0f, -0.45f, -0.45f);
                //Console.WriteLine("RMC (" + PosX + "," + PosY + ")");
            }

            if (MovingDown)
            {
                PosY -= 0.1f;
                light.setDirection(0.0f, -0.45f, 0.45f);
                //Console.WriteLine("RMC (" + PosX + "," + PosY + ")");
                rotation = 180.0f;
            }

            if (light != null)
            {
                light.setPosition(PosX, HoverHeight, -PosY, 1.0f);
                light.apply();
            }

            if (robotToGrab != null && GrabRobot && robotToGrab.IsFriendly())
            {
                //Console.WriteLine("Grabbing Robot");
                robotToGrab.PosX  = PosX; robotToGrab.PosY = -PosY;
                robotToGrab.Angle = rotation;
            }

            GL.Translate(PosX, HoverHeight, -PosY);

            GL.PushMatrix();
            GL.Scale(0.07f, 0.07f, 0.07f);
            model.Render();
            GL.PopMatrix();

            GrabRobot   = false;
            Hovering    = false;
            MovingLeft  = false;
            MovingRight = false;
            MovingUp    = false;
            MovingDown  = false;
        }
Example #2
0
        public override void Render()
        {
            GL.PushMatrix();

            Light light = GetLight();

            if (light != null)
            {
                light.apply();
            }

            base.Render();

            switch (position)
            {
            /* top-left corner of tile */
            case 1:
                GL.PushMatrix();
                GL.Translate(-0.35f, 0.0f, -0.35f);
                DrawLightPost();
                GL.PopMatrix();
                break;

            /* top-right corner of tile */
            case 2:
                GL.PushMatrix();
                GL.Translate(0.35f, 0.0f, -0.35f);
                DrawLightPost();
                GL.PopMatrix();
                break;

            /* bottom-right corner of tile */
            case 3:
                GL.PushMatrix();
                GL.Translate(0.35f, 0.0f, 0.35f);
                DrawLightPost();
                GL.PopMatrix();
                break;

            /* top-right corner of tile */
            case 4:
                GL.PushMatrix();
                GL.Translate(-0.35f, 0.0f, 0.35f);
                DrawLightPost();
                GL.PopMatrix();
                break;

            default:
                Console.WriteLine("Invalid selection. Please select 1 to draw a lightpost in the top-left corner of the tile" +
                                  '\n' + "2 to draw a lightpost in the top-right of the tile" +
                                  '\n' + "3 to draw a lightpost in the bottom-right of the tile" +
                                  '\n' + "and 4 to draw a lightpost in the bottom-left of the tile");
                break;
            }

            if (light != null)
            {
                light.unapply();
            }

            GL.PopMatrix();
        }