Ejemplo n.º 1
0
        public Terrain(int width, int height)
        {
            bool test = false;

            this.width  = width;
            this.height = height;

            tiles        = new Tile[this.width, this.height];
            collisionMap = new ByteMap(this.width, this.height);

            if (test)
            {
                int n = 0;

                for (int i = 0; i < tiles.GetLength(0); i++)
                {
                    for (int j = 0; j < tiles.GetLength(1); j++)
                    {
                        switch (n % 4)
                        {
                        case 0:
                            tiles[i, j] = new FloorTile();
                            break;

                        case 1:
                            tiles[i, j] = new LightRubblePile();
                            break;

                        case 2:
                            tiles[i, j] = new MediumRubblePile();
                            break;

                        case 3:
                            tiles[i, j] = new HeavyRubblePile();
                            break;
                        }

                        n++;
                    }
                }
            }
            else
            {
                for (int i = 0; i < tiles.GetLength(0); i++)
                {
                    for (int j = 0; j < tiles.GetLength(1); j++)
                    {
                        tiles[i, j] = new FloorTile();
                    }
                }
            }

            GenerateCollisionMap();
        }
Ejemplo n.º 2
0
        public Terrain(int width, int height)
        {
            bool test = false;
            this.width = width;
            this.height = height;

            tiles = new Tile[this.width, this.height];
            collisionMap = new ByteMap(this.width, this.height);

            if (test)
            {
                int n = 0;

                for (int i = 0; i < tiles.GetLength(0); i++)
                {
                    for (int j = 0; j < tiles.GetLength(1); j++)
                    {
                        switch (n % 4)
                        {
                            case 0:
                                tiles[i, j] = new FloorTile();
                                break;

                            case 1:
                                tiles[i, j] = new LightRubblePile();
                                break;

                            case 2:
                                tiles[i, j] = new MediumRubblePile();
                                break;

                            case 3:
                                tiles[i, j] = new HeavyRubblePile();
                                break;
                        }

                        n++;
                    }
                }
            }
            else
            {
                for (int i = 0; i < tiles.GetLength(0); i++)
                {
                    for (int j = 0; j < tiles.GetLength(1); j++)
                    {
                        tiles[i, j] = new FloorTile();
                    }
                }
            }

            GenerateCollisionMap();
        }
Ejemplo n.º 3
0
        public void AddRobot(Robot robot)
        {
            robots.Add(robot);
            //if (robot.IsFriendly())
            //    friendlyCount++;
            //else
            //    enemyCount++;

            FloorTile ft = (FloorTile)terrain.tiles[robot.MapPosX, robot.MapPosY];

            ft.MarkOccupied();
        }
Ejemplo n.º 4
0
        public void Render()
        {
            //Track all unoccupied tiles and clean up
            for (int i = 0; i < terrain.tiles.GetLength(0); i++)
            {
                for (int j = 0; j < terrain.tiles.GetLength(1); j++)
                {
                    Tile      t  = terrain.tiles[i, j];
                    FloorTile ft = null;
                    if (t is FloorTile)
                    {
                        ft = (FloorTile)t;
                        ft.MarkUnOccupied();                         //initially, its unoccupied
                    }

                    if (!t.IsCollideable() && t is FloorTile)
                    {
                        for (int k = 0; k < robots.Count; k++)                         //till the robot says otherwise!
                        {
                            int robPosX = robots[k].MapPosX;
                            int robPosY = robots[k].MapPosY;

                            if (robPosX == i && robPosY == j)                      //check if its occupied
                            {
                                ft.MarkOccupied();                                 //if it is, then mark it occupied
                            }
                        }
                    }
                }
            }

            //Track all travelling projectiles fired by the robots
            for (int i = 0; i < projectiles.Count; i++)
            {
                if (projectiles[i].IsDead())
                {
                    projectiles.Remove(projectiles[i]);
                    i = 0;                     //Reset count back to 0
                }
            }

            GL.PushMatrix();

            /* Render Map */

            GL.PushMatrix();

            GL.Translate(0.0f, 0.0f, 0.0f);

            /* Render terrain */

            GL.PushMatrix();

            terrain.Render();

            GL.PopMatrix();

            /* Render robots */

            GL.PushMatrix();

            for (int j = 0; j < robots.Count; j++)
            {
                Robot robot = robots[j];

                for (int i = 0; i < projectiles.Count; i++)
                {
                    if (robot.ProjectileTest(projectiles[i]))
                    {
                        projectiles.Remove(projectiles[i]);
                        i = 0;
                    }
                }

                if (robot.IsDead())
                {
                    robots.Remove(robot);
                    SetTile(new LightRubblePile(), robot.MapPosX, robot.MapPosY);
                    j = 0;
                }
                else
                {
                    //GL.Translate(robot.PosX * 1.0f, 0.0f, robot.PosY * 1.0f);
                    robot.RenderAll();
                    //GL.Translate(-robot.PosX * 1.0f, 0.0f, robot.PosY * -1.0f);
                }
            }

            GL.PopMatrix();

            /* Render projectiles */

            GL.PushMatrix();

            foreach (Projectile projectile in projectiles)
            {
                projectile.RenderAll();
            }

            GL.PopMatrix();

            /* Render factories */

            GL.PushMatrix();

            foreach (Factory factory in factories)
            {
                GL.Translate(factory.PosX * 1.0f, 0.0f, factory.PosY * -1.0f);
                factory.Render();
                GL.Translate(-factory.PosX * 1.0f, 0.0f, factory.PosY * 1.0f);
            }

            GL.PopMatrix();

            /* Render buildings (or blocks) */

            GL.PushMatrix();

            foreach (Block block in blocks)
            {
                GL.Translate(block.PosX * 1.0f, 0.0f, block.PosY * -1.0f);
                block.Render();
                GL.Translate(-block.PosX * 1.0f, 0.0f, block.PosY * 1.0f);
            }

            GL.PopMatrix();

            /* Render the bases */

            GL.PushMatrix();

            foreach (Base cBase in bases)
            {
                cBase.Render();
            }

            GL.PopMatrix();

            /* Render Remote Control Unit */

            GL.PushMatrix();

            remoteControlUnit.Render();

            GL.PopMatrix();

            GL.PopMatrix();

            //foreach (Light light in lights)
            //    light.unapply();

            GL.PopMatrix();
        }