Esempio n. 1
0
 //think, we can load textures in Renderer instead of passing them as parameter
 public GameRenderer(float windowWidth, float windowHeight, Texture[] textureList)
 {
     this.windowWidth = windowWidth;
     this.windowHeight = windowHeight;
     this.textureList = textureList;
     elementWidth = windowWidth / 19;
     elementHeight = windowHeight / 20;
 }
 public AbstractTank(Player managingPlayer, int x, int y, Texture.Rotation rotation)
 {
     managingPlayer.tank = this;
     this.managingPlayer = managingPlayer;
     X = x;
     Y = y;
     this.rotation = rotation;
     Init();
 }
Esempio n. 3
0
 public void AddTank(Player player, AbstractTank.Type tankType, int x, int y, Texture.Rotation rotation)
 {
     switch (tankType)
     {
         case AbstractTank.Type.PlayerNormal:
             tanks.Add(new NormalTank(player, x, y, rotation));
             break;
         case AbstractTank.Type.PlayerFast:
             tanks.Add(new FastTank(player, x, y, rotation));
             break;
     }
 }
 public void Render(Texture texture, float x1, float y1, float x2, float y2)
 {
     texture.Bind();
     GL.Begin(BeginMode.Quads);
     {
         GL.TexCoord2(0, 0);
         GL.Vertex2(x1, y2);
         GL.TexCoord2(texture.TextureXCoord, 0);
         GL.Vertex2(x2, y2);
         GL.TexCoord2(texture.TextureXCoord, texture.TextureYCoord);
         GL.Vertex2(x2, y1);
         GL.TexCoord2(0, texture.TextureYCoord);
         GL.Vertex2(x1, y1);
     }
     GL.End();
 }
 public void Render(Texture texture, float x, float y)
 {
     texture.Bind();
     // TODO: test this class
     GL.Begin(BeginMode.Quads);
     {
         GL.TexCoord2(0, 0);
         GL.Vertex2(x, y + texture.Height);
         GL.TexCoord2(texture.TextureXCoord, 0);
         GL.Vertex2(x + texture.Width, y + texture.Height);
         GL.TexCoord2(texture.TextureXCoord, texture.TextureYCoord);
         GL.Vertex2(x + texture.Width, y);
         GL.TexCoord2(0, texture.TextureYCoord);
         GL.Vertex2(x, y);
     }
     GL.End();
 }
        public void Render(Texture texture, float[] coords)
        {
            if (coords.Length < 8)
                throw new ArgumentOutOfRangeException("coord", "Incorrect coordinate massive");
            // TODO: thinks, it's not effective, should remake it in the future
            texture.Bind();
            Vector2 v1 = new Vector2(coords[0], coords[1]);
            Vector2 v2 = new Vector2(coords[2], coords[3]);
            Vector2 v3 = new Vector2(coords[4], coords[5]);
            Vector2 v4 = new Vector2(coords[6], coords[7]);

            GL.Begin(BeginMode.Quads);
            {
                GL.TexCoord2(0, 0);
                GL.Vertex2(v1);
                GL.TexCoord2(texture.TextureXCoord, 0);
                GL.Vertex2(v2);
                GL.TexCoord2(texture.TextureXCoord, texture.TextureYCoord);
                GL.Vertex2(v3);
                GL.TexCoord2(0, texture.TextureYCoord);
                GL.Vertex2(v4);
            }
            GL.End();
        }
 public void Rotate(Texture.Rotation rotation)
 {
     if (!this.rotation.Equals(rotation))
     {
         this.rotation = rotation;
     }
 }
Esempio n. 8
0
 public NormalTank(Player managingPlayer, int x, int y, Texture.Rotation rotation)
     : base(managingPlayer, x, y, rotation)
 {
     type = Type.PlayerNormal;
     Speed = 1;
 }
 public void DrawTank(int x, int y, AbstractTank.Type type, Texture.Rotation rotation)
 {
     switch (type)
     {
         case AbstractTank.Type.PlayerNormal:
             DrawTexture(x, y, tankTextureList[0], rotation);
             //DrawTank(x, y, 0);
             break;
         case AbstractTank.Type.PlayerFast:
             break;
     }
 }
Esempio n. 10
0
        private List<MapObject.Types> NextMapObjects(Level level, AbstractTank tank, Texture.Rotation rotation)
        {
            PointF tankPositionOnMap = TankPositionOnMap(tank);
            List<MapObject.Types> objects = new List<MapObject.Types>();

            switch (rotation)
            {
                case Texture.Rotation.Top:
                    if (((int)(tankPositionOnMap.Y)).Equals(0))
                    {
                        return new List<MapObject.Types> { MapObject.Types.TEMPORARY };
                    }
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y - 1][(int)tankPositionOnMap.X].Type);//get current tank pos MapObject
                    if (tankPositionOnMap.X - ((int)tankPositionOnMap.X) > 0)//if tank is on two MapObjects
                    {
                        objects.Add(level.MapInstance[(int)tankPositionOnMap.Y - 1][(int)tankPositionOnMap.X + 1].Type);
                    }
                    break;
                case Texture.Rotation.Bottom:
                    if (((int)(tankPositionOnMap.Y)).Equals(19))
                    {
                        return new List<MapObject.Types> { MapObject.Types.TEMPORARY };
                    }
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y + 1][(int)tankPositionOnMap.X].Type);
                    if (tankPositionOnMap.X - ((int)tankPositionOnMap.X) > 0)
                    {
                        objects.Add(level.MapInstance[(int)tankPositionOnMap.Y + 1][(int)tankPositionOnMap.X + 1].Type);
                    }
                    break;
                case Texture.Rotation.Right:
                    if (((int)(tankPositionOnMap.X)).Equals(18))
                    {
                        return new List<MapObject.Types> { MapObject.Types.TEMPORARY };
                    }
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y][(int)tankPositionOnMap.X + 1].Type);
                    if (tankPositionOnMap.Y - ((int)tankPositionOnMap.Y) > 0)
                    {
                        objects.Add(level.MapInstance[(int)tankPositionOnMap.Y + 1][(int)tankPositionOnMap.X + 1].Type);
                    }
                    break;
                case Texture.Rotation.Left:
                    if (((int)(tankPositionOnMap.X)).Equals(0))
                    {
                        return new List<MapObject.Types> { MapObject.Types.TEMPORARY };
                    }
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y][(int)tankPositionOnMap.X - 1].Type);
                    if (tankPositionOnMap.Y - ((int)tankPositionOnMap.Y) > 0)
                    {
                        objects.Add(level.MapInstance[(int)tankPositionOnMap.Y + 1][(int)tankPositionOnMap.X - 1].Type);
                    }
                    break;
            }
            return objects;
        }
Esempio n. 11
0
        private void DrawTexture(int x, int y, Texture texture, Texture.Rotation rotation)
        {
            Vector2 v1 = new Vector2(), v2 = new Vector2(), v3 = new Vector2(), v4 = new Vector2();
            switch (rotation)
            {
                case Texture.Rotation.Top:
                    v1 = new Vector2(x, y);
                    v2 = new Vector2(x + elementWidth, y);
                    v3 = new Vector2(x + elementWidth, y - elementHeight);
                    v4 = new Vector2(x, y - elementHeight);
                    break;
                case Texture.Rotation.Right:
                    v1 = new Vector2(x + elementWidth, y);
                    v2 = new Vector2(x + elementWidth, y - elementHeight);
                    v3 = new Vector2(x, y - elementHeight);
                    v4 = new Vector2(x, y);
                    break;
                case Texture.Rotation.Bottom:
                    v1 = new Vector2(x + elementWidth, y - elementHeight);
                    v2 = new Vector2(x, y - elementHeight);
                    v3 = new Vector2(x, y);
                    v4 = new Vector2(x + elementWidth, y);
                    break;
                case Texture.Rotation.Left:
                    v1 = new Vector2(x, y - elementHeight);
                    v2 = new Vector2(x, y);
                    v3 = new Vector2(x + elementWidth, y);
                    v4 = new Vector2(x + elementWidth, y - elementHeight);
                    break;
            }
            //Clear zone
            //GL.Begin(BeginMode.Quads);
            //{
            //    GL.Color3(Color.Black);
            //    GL.Vertex2(v1);
            //    GL.Vertex2(v2);
            //    GL.Vertex2(v3);
            //    GL.Vertex2(v4);
            //}
            //GL.End();

            //mapping texture
            texture.Bind();
            GL.Begin(BeginMode.Quads);
            {
                GL.Color4(Color4.Transparent);
                GL.TexCoord2(0, 0);
                GL.Vertex2(v1);
                GL.TexCoord2(1, 0);
                GL.Vertex2(v2);
                GL.TexCoord2(1, 1);
                GL.Vertex2(v3);
                GL.TexCoord2(0, 1);
                GL.Vertex2(v4);
            }
            GL.End();
        }
Esempio n. 12
0
        private List<MapObject.Types> CurrentMapObjects(Level level, AbstractTank tank, Texture.Rotation rotation)
        {
            PointF tankPositionOnMap = TankPositionOnMap(tank);
            float fX = (float)Math.Round(tankPositionOnMap.X, 0), fY = (float)Math.Round(tankPositionOnMap.Y, 0);
            List<MapObject.Types> objects = new List<MapObject.Types>();

            switch (rotation)
            {
                case Texture.Rotation.Top:
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y][(int)tankPositionOnMap.X].Type);
                    if (!tank.Y.Equals((int) (windowHeight/2 - fY*elementHeight)) &&
                        tankPositionOnMap.X - ((int)tankPositionOnMap.X) > 0)
                    {
                        objects.Add(level.MapInstance[(int) tankPositionOnMap.Y][(int) tankPositionOnMap.X + 1].Type);
                    }
                    break;
                case Texture.Rotation.Bottom:
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y][(int)tankPositionOnMap.X].Type);
                    if (!(tank.Y - ElementHeight).Equals((int) (windowHeight/2 - (fY + 1)*elementHeight)) &&
                        tankPositionOnMap.X - ((int) tankPositionOnMap.X) > 0)
                    {
                        objects.Add(level.MapInstance[(int) tankPositionOnMap.Y][(int) tankPositionOnMap.X + 1].Type);
                    }
                    break;
                case Texture.Rotation.Right:
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y][(int)tankPositionOnMap.X].Type);
                    if (!(tank.X + elementWidth).Equals((int) (-windowWidth/2 + (fX + 1)*ElementHeight)) &&
                        tankPositionOnMap.Y - ((int) tankPositionOnMap.Y) > 0)
                    {
                        objects.Add(level.MapInstance[(int) tankPositionOnMap.Y + 1][(int) tankPositionOnMap.X].Type);
                    }
                    break;
                case Texture.Rotation.Left:
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y][(int)tankPositionOnMap.X].Type);
                    if (!tank.X.Equals((int) (-windowWidth/2 + fX*elementWidth)) &&
                        tankPositionOnMap.Y - ((int) tankPositionOnMap.Y) > 0)
                    {
                        objects.Add(level.MapInstance[(int) tankPositionOnMap.Y + 1][(int) tankPositionOnMap.X].Type);
                    }
                    break;
            }
            return objects;
        }
Esempio n. 13
0
        public bool TankCanMove(Level level, AbstractTank tank, Texture.Rotation rotation)
        {
            PointF pos = TankPositionOnMap(tank);
            List<MapObject.Types> nextMapObjectType = NextMapObjects(level, tank, rotation);
            List<MapObject.Types> currentMapObjectType = CurrentMapObjects(level, tank, rotation);
            nextMapObjectType.RemoveAll(x => x.Equals(MapObject.Types.FOREST) || x.Equals(MapObject.Types.EMPTY));
            currentMapObjectType.RemoveAll(x => x.Equals(MapObject.Types.FOREST) || x.Equals(MapObject.Types.EMPTY));

            switch (rotation)
            {
                case Texture.Rotation.Top:
                    return windowHeight/2 - ((int) pos.Y)*elementHeight - tank.Y == 0
                               ? nextMapObjectType.Count.Equals(0)
                               : currentMapObjectType.Count.Equals(0);
                case Texture.Rotation.Bottom:
                    return windowHeight/2 - ((int) pos.Y)*elementHeight - elementHeight - tank.Y == -elementHeight
                               ? nextMapObjectType.Count.Equals(0)
                               : currentMapObjectType.Count.Equals(0);
                case Texture.Rotation.Right:
                    return -windowWidth/2 + ((int) pos.X)*elementWidth + elementWidth - tank.X == elementWidth
                               ? nextMapObjectType.Count.Equals(0)
                               : currentMapObjectType.Count.Equals(0);
                case Texture.Rotation.Left:
                    return -windowWidth/2 + ((int) pos.X)*elementWidth - tank.X == 0
                               ? nextMapObjectType.Count.Equals(0)
                               : currentMapObjectType.Count.Equals(0);
            }
            return false;
        }
Esempio n. 14
0
 public FastTank(Player managingPlayer, int x, int y, Texture.Rotation rotation)
     : base(managingPlayer, x, y, rotation)
 {
     type = Type.PlayerFast;
     Speed = 2;
 }