Beispiel #1
0
 public Robot Detach()
 {
     Robot previousRobot = robot;
     attached = false;
     robot = null;
     return previousRobot;
 }
Beispiel #2
0
        int lifeTime = LIFE_TIME; //The time of life the projectile is in function till it dies or gets hit

        #endregion Fields

        #region Constructors

        public Projectile(Robot robot, float x, float y, float xdir, float yDir)
        {
            self = robot; //to make sure it doesn't get damaged by its own fire.
            PosX = x; PosY = y;
            DirX = xdir; DirY = yDir;
            flare.SetColor(0.75f, 0.0f, 0.0f);
            flare.SetRenderMode(RenderMode.SOLID);
        }
Beispiel #3
0
 public RobotCamera(float x, float y, float z)
     : base(x, y, z)
 {
     robot = null;
     tiltLeft = false;
     tiltRight = false;
     tiltUp = false;
     tiltDown = false;
 }
Beispiel #4
0
 public Robot Attach(Robot robot)
 {
     Robot previousRobot = robot;
     this.robot = robot;
     attached = true;
     float rotation = robot.Angle;
     Reset(robot.PosX, 1.0f, robot.PosY);
     RotateLocal(-rotation, 0.0f, 1.0f, 0.0f);
     return previousRobot;
 }
Beispiel #5
0
        public void LoadMap(string filename)
        {
            int x = 0;
            int y = 0;
            Light light;

            map = MapFile.Load(resourcePath + "/Maps/" + filename);

            mapWidth = map.GetWidth();
            mapHeight = map.GetHeight();

            activeRobot = map.GetActiveRobot();
            robotCamera.Attach(activeRobot);
            map.AddRobotToRemoteControlUnitList(activeRobot);

            light = new Light(LightName.Light7);
            activeRobot.AddLight(light);

            someRobot = activeRobot;

            LightPost lightpost = new LightPost(4);
            map.SetTile(lightpost, x, y);

            light = new Light(LightName.Light0);
            light.setCutOff(45.0f);
            light.lookAt(0.0f, 6.0f, 0.0f,
                         2.0f * (float) Math.Sqrt(2.0f), 0.0f, -2.0f * (float) Math.Sqrt(2.0f),
                         1.0f, 1.0f, 1.0f);

            lightpost.AddLight(light);

            l = light;

            lightCamera1 = new Camera(0.0f, 6.0f, 0.0f,
                         2.0f * (float) Math.Sqrt(2.0f), 0.0f, -2.0f * (float) Math.Sqrt(2.0f),
                         0.0f, 1.0f, 0.0f);

            lightpost = new LightPost(3);
            map.SetTile(lightpost, x + mapWidth - 1, y);

            light = new Light(LightName.Light1);
            light.setCutOff(45.0f);
            light.lookAt(0.0f, 6.0f, 0.0f,
                -2.0f * (float) Math.Sqrt(2.0f), 0.0f, -2.0f * (float) Math.Sqrt(2.0f),
                0.0f, 0.0f, 1.0f);
            lightpost.AddLight(light);

            lightCamera2 = new Camera(mapWidth - 1, 6.0f, 0.0f,
                (mapWidth - 1) - 2.0f * (float) Math.Sqrt(2.0f), 0.0f, -2.0f * (float) Math.Sqrt(2.0f),
                0.0f, 1.0f, 0.0f);

            lightpost = new LightPost(2);
            map.SetTile(lightpost, x + mapWidth - 1, y + mapHeight -1);

            light = new Light(LightName.Light2);
            light.setCutOff(45.0f);
            light.lookAt(0.0f, 6.0f, 0.0f,
                -2.0f * (float) Math.Sqrt(2.0f), 0.0f, 2.0f * (float) Math.Sqrt(2.0f),
                1.0f, 1.0f, 1.0f);
            lightpost.AddLight(light);

            lightCamera3 = new Camera(mapWidth, 6.0f, -(mapHeight - 1),
                (mapWidth - 1) - 2.0f * (float) Math.Sqrt(2.0f), 0.0f, -(mapHeight - 1) + 2.0f * (float) Math.Sqrt(2.0f),
                0.0f, 1.0f, 0.0f);

            lightpost = new LightPost(1);
            map.SetTile(lightpost, x, y + (mapHeight - 1));

            light = new Light(LightName.Light3);
            light.setCutOff(45.0f);
            light.lookAt(0.0f, 6.0f, 0.0f,
                2.0f * (float) Math.Sqrt(2.0f), 0.0f, 2.0f * (float) Math.Sqrt(2.0f),
                1.0f, 1.0f, 1.0f);
            lightpost.AddLight(light);

            lightCamera4 = new Camera(0.0f, 6.0f, -(mapHeight - 1),
                2.0f * (float) Math.Sqrt(2.0f), 0.0f, -(mapHeight - 1) + 2.0f * (float) Math.Sqrt(2.0f),
                0.0f, 1.0f, 0.0f);

            this.Title = this.baseTitle;

            PrintHelp();

            prevMousePosition = this.WindowCenter;
            prevMouseDelta = new Point(0, 0);
            nullDelta = new Point(0, 0);

            globalCamera.SetMap(map);
            robotCamera.SetMap(map);

            camera = globalCamera;

            System.Windows.Forms.Cursor.Hide();

            GL.Enable(EnableCap.Lighting);
            GL.Enable(EnableCap.ColorMaterial);
            GL.Enable(EnableCap.Texture2D);

            /* To Avoid Having Z-Fighting for projecting surfaces onto another surface (Shadows) */
            GL.PolygonOffset(-10.0f, -25.0f);
        }
Beispiel #6
0
 public void AddRobot(Robot robot)
 {
     robotList.Add(robot);
 }
Beispiel #7
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;
        }
Beispiel #8
0
        private static Robot LoadRobot(XmlTextReader xml)
        {
            int x, y;
            Robot robot = null;

            x = Int32.Parse(xml.GetAttribute("x"));
            y = Int32.Parse(xml.GetAttribute("y"));

            robot = new Robot(x, y);

            string friendly = xml.GetAttribute("f");
            if (friendly != null)
                robot.MarkFriendly();

            while (xml.Read())
            {
                switch (xml.NodeType)
                {
                    case XmlNodeType.Element:

                        if (xml.Name.Equals("AntiGravChassis"))
                            robot.AddChassis(new AntiGravChassis());
                        else if (xml.Name.Equals("BipodChassis"))
                            robot.AddChassis(new BipodChassis());
                        else if (xml.Name.Equals("TrackedChassis"))
                            robot.AddChassis(new TrackedChassis());
                        else if (xml.Name.Equals("CannonWeapon"))
                            robot.AddWeapon(new CannonWeapon());
                        else if (xml.Name.Equals("MissilesWeapon"))
                            robot.AddWeapon(new MissilesWeapon());
                        else if (xml.Name.Equals("NuclearWeapon"))
                            robot.AddWeapon(new NuclearWeapon());
                        else if (xml.Name.Equals("PhasersWeapon"))
                            robot.AddWeapon(new PhasersWeapon());
                        else if (xml.Name.Equals("Electronics"))
                            robot.AddElectronics(new Electronics());

                        break;

                    case XmlNodeType.EndElement:

                        if (xml.Name.Equals("Robot"))
                            return robot;

                        break;
                }
            }

            return robot;
        }