Пример #1
0
 //AZ: convert all tile bitmaps to tex2Ds
 public void convertBitmapsToTextures(Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice)
 {
     tiles2D = new Microsoft.Xna.Framework.Graphics.Texture2D[tiles.Length];
     for (int l = 0; l < tiles.Length; l++)
     {
         tiles2D[l] = XNA_InGame.getTextureFromBitmap(tiles[l], graphicsDevice);
     }
 }
Пример #2
0
        public Texture2D[][][] allUnitTilesT2dColored;                     //to hold all shaded unit colors

        public ColorsLoader(GraphicsDevice graphicsDevice, int numPlayers) //init
        {
            allUnitTilesT2dColored = new Texture2D[numPlayers][][];        //init for 8 different colors
            for (int i = 0; i < numPlayers; i++)                           //only init enough for number of players
            {                                                              //manually create all
                allUnitTilesT2dColored[i] = new Texture2D[SplashScreen.mapUnits.allUnitTiles.Length][];
                for (int j = 0; j < SplashScreen.mapUnits.allUnitTiles.Length; j++)
                {
                    allUnitTilesT2dColored[i][j] = new Texture2D[SplashScreen.mapUnits.allUnitTiles[j].Length];
                    for (int k = 0; k < SplashScreen.mapUnits.allUnitTiles[j].Length; k++)
                    {
                        allUnitTilesT2dColored[i][j][k] = XNA_InGame.getTextureFromBitmap(SplashScreen.mapUnits.allUnitTiles[j][k], graphicsDevice);
                    }
                }
            }
            loadAllColors(graphicsDevice, numPlayers);
        }
Пример #3
0
        //Convert all unitTiles into allUnitTilesT2d
        public void convertBitmapsToTextures(GraphicsDevice graphicsDevice)
        {
            allUnitTilesT2d = new Texture2D[allUnitTiles.Length][];
            for (int k = 0; k < allUnitTiles.Length; k++)
            {
                allUnitTilesT2d[k] = new Texture2D[allUnitTiles[k].Length];
                for (int l = 0; l < allUnitTiles[k].Length; l++)
                {
                    allUnitTilesT2d[k][l] = XNA_InGame.getTextureFromBitmap(allUnitTiles[k][l], graphicsDevice);
                }
            }

            //Convert decay tiles to texture2D
            decayTiles2D = new Texture2D[decayTiles[0].Length];
            for (int k = 0; k < decayTiles[0].Length; k++)
            {
                decayTiles2D[k] = XNA_InGame.getTextureFromBitmap(decayTiles[0][k], graphicsDevice);
            }


            //Convert building death tiles to texture2D
            buildingDeathTiles2D = new Texture2D[buildingDeathTiles.Length][];
            for (int i = 0; i < buildingDeathTiles.Length; i++)
            {
                buildingDeathTiles2D[i] = new Texture2D[buildingDeathTiles[i].Length];
                for (int k = 0; k < buildingDeathTiles[i].Length; k++)
                {
                    buildingDeathTiles2D[i][k] = XNA_InGame.getTextureFromBitmap(buildingDeathTiles[i][k], graphicsDevice);
                }
            }

            //Convert cannonball tiles to texture2D
            cannonBallTiles2D = new Texture2D[2][]; //one for alive tiles, other for death tiles
            for (int i = 0; i < 2; i++)
            {
                cannonBallTiles2D[i] = new Texture2D[allProjectiles[i + 1].Length]; //+1 to skip arrow data
                for (int k = 0; k < allProjectiles[i + 1].Length; k++)
                {
                    cannonBallTiles2D[i][k] = XNA_InGame.getTextureFromBitmap(allProjectiles[i + 1][k], graphicsDevice);
                }
            }

            //Convert arrow tiles to texture2D
            arrowTiles2D = new Texture2D[allProjectiles[0].Length];
            for (int i = 0; i < allProjectiles[0].Length; i++)
            {
                arrowTiles2D[i] = XNA_InGame.getTextureFromBitmap(allProjectiles[0][i], graphicsDevice);
            }

            miniBevel2D = new Texture2D[miniBevel.Length];
            for (int i = 0; i < miniBevel.Length; i++)
            {
                miniBevel2D[i] = XNA_InGame.getTextureFromBitmap(miniBevel[i], graphicsDevice);
            }

            droppedResource2D = new Texture2D[droppedResource.Length];
            for (int i = 0; i < droppedResource.Length; i++)
            {
                droppedResource2D[i] = XNA_InGame.getTextureFromBitmap(droppedResource[i], graphicsDevice);
            }
        }
Пример #4
0
        public void loadAllColors(GraphicsDevice graphicsDevice, int numPlayers)
        {                                                                                          //Function to load and store selected player color for game //doesn't work because we can't deep copy array
            Texture2D color = XNA_InGame.getTextureFromBitmap(SplashScreen.color, graphicsDevice); //convert color bitmap to tex2D

            //Reference for coloring: https://stackoverflow.com/questions/3255311/color-replacement-in-xna-c-sharp
            Color[] tempColors = new Color[color.Width * color.Height];
            color.GetData(tempColors);            //get color data
            this.defaultColor = new Color[color.Width];
            for (int c = 0; c < color.Width; c++) //load default color and save
            {
                this.defaultColor[c] = tempColors[c];
            }

            for (int i = 0; i < numPlayers; i++) //iterate through all colors (except 0 which is default red)
            {
                Color[] chosenColor       = new Color[color.Width];
                int     playerColorChoice = SplashScreen.playerColor[i];
                if (playerColorChoice != 0)               //not default red (as if it is, we don't have to edit texture)
                {
                    for (int c = 0; c < color.Width; c++) //load current color
                    {
                        chosenColor[c] = tempColors[playerColorChoice * color.Width + c];
                    }

                    for (int k = 0; k < this.allUnitTilesT2dColored[i].Length; k++) //iterate through texture2D array
                    {
                        //allUnitTilesT2d[k] = new Texture2D[this.allUnitTilesT2dColored[k].Length];
                        for (int l = 0; l < this.allUnitTilesT2dColored[i][k].Length; l++)
                        {
                            //Color the unit texture Reference: https://stackoverflow.com/questions/3255311/color-replacement-in-xna-c-sharp
                            Texture2D tempImg = this.allUnitTilesT2dColored[i][k][l];
                            Color[]   data    = new Color[tempImg.Width * tempImg.Height];
                            tempImg.GetData(data);                //store sprite data for editing
                            for (int c = 0; c < data.Length; c++) //iterate through and swap all pixels of default color to chosen color
                            {
                                if (data[c] == defaultColor[0])
                                {
                                    data[c] = chosenColor[0];
                                }
                                else if (data[c] == defaultColor[1])
                                {
                                    data[c] = chosenColor[1];
                                }
                                else if (data[c] == defaultColor[2])
                                {
                                    data[c] = chosenColor[2];
                                }
                                else if (data[c] == defaultColor[3])
                                {
                                    data[c] = chosenColor[3];
                                }
                            }
                            //tempImg.SetData(data); //set the image to edited sprite
                            tempImg.SetData(data);
                            //this.allUnitTilesT2dColored[i][k][l].SetData(data);
                            this.allUnitTilesT2dColored[i][k][l] = tempImg;
                        }
                    }
                }
            }
        }