Esempio n. 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);
     }
 }
Esempio n. 2
0
        public static void createDebugConsole(XNA_InGame g, Form f)
        {
            //MessageBox.Show("Fog of war triggered.");
            ConsoleForm testDialog = new ConsoleForm();

            testDialog.g      = g;
            testDialog.Parent = null;
            testDialog.Show();



            //MessageBox.Show("Fog of war triggered.");
            //System.Windows.Forms.MessageBox.Show("Selected unit type:" + u.unitType + "TileX:" + u.unitTileWidth + "TileY:" + u.unitTileHeight);
            // Show testDialog as a modal dialog and determine if DialogResult = OK.
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        private void playGame_Click(object sender, EventArgs e)
        {
            //Need to boot game here
            // new inGame().Show();

            //Modified by AZ: we need to generate a XNA window here to display the game window with hardware boost:
            // XNA_InGame g = new XNA_InGame();
            buttonSnd();
            menuMusic.controls.stop();

            // g.Run();
            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                XNA_InGame g = new XNA_InGame();
                g.Run();
                //Console.WriteLine("Hello, world");
            }).Start();
            this.Hide();

            //new MiniMap().Show();

            //this.Hide(); //Don't hide form so can do multiple
        }
Esempio n. 5
0
        private void select_Click(object sender, EventArgs e)
        {
            MainMenu.buttonClickSnd.controls.play();
            MainMenu.menuMusic.controls.stop();//stop the menu music.

            // JD: 2/24, set the next showed window size, location, WindowState
            if (this.WindowState == FormWindowState.Normal)
            {
                Properties.Settings.Default.WindowLocation = this.Location;
                Properties.Settings.Default.WindowSize     = this.Size;
                Properties.Settings.Default.WindowMax      = false;
            }
            else
            {
                Properties.Settings.Default.WindowSize     = this.RestoreBounds.Size;
                Properties.Settings.Default.WindowLocation = this.RestoreBounds.Location;
                Properties.Settings.Default.WindowMax      = true;
            }

            //New method of starting a game:

            /*new Thread(() =>
             * {
             *  Thread.CurrentThread.IsBackground = true;
             *
             *
             *
             *  XNA_InGame g = new XNA_InGame();
             *  g.Run();
             *  //Console.WriteLine("Hello, world");
             * }).Start();*/

            Thread tempGame = new Thread(() =>
            {
                //Thread.CurrentThread.IsBackground = true;
                XNA_InGame g = new XNA_InGame();
                g.Run();
                //Console.WriteLine("Hello, world");
            });

            Thread main = Thread.CurrentThread;

            tempGame.Start();

            //this.Hide(); //hides the form

            if (Thread.CurrentThread == main)
            {
                this.Hide();
                tempGame.Join();                    //wait for game thread to end
                //Thread.CurrentThread.IsBackground = false;
                this.Show();                        //reshow form

                MainMenu.menuMusic.controls.play(); //play the menu music.

                //Not working
                tempGame = null;                  //need to free thread memory
                SplashScreen.coloredUnits = null; //need to free (as we re-init on new XNA)

                //new MainMenu();
            }
        }
Esempio n. 6
0
        bool chatShowing = false; //flag for whether chatbox is showing (aka allow input)

        public inGame_menu(XNA_InGame game)
        {
            InitializeComponent();
            this.game         = game;
            this.Load        += inGame_menu_Load;
            this.FormClosing += new FormClosingEventHandler(this.inGame_menu_FormClosing);

            this.KeyPreview = true;
            this.KeyDown   += new KeyEventHandler(inGame_menu_KeyDown);
            this.KeyUp     += new KeyEventHandler(inGame_menu_KeyUp);
            Bitmap backGround = new Bitmap(@"data\img\Texture.png");

            this.BackgroundImage = backGround;
            Bitmap color = new Bitmap(@"data\img\Colors.png");

            System.Drawing.Color color_blue = color.GetPixel(1, 1);

            mainMenuButton             = new Button();
            mainMenuButton.Location    = new Point(35, 10);
            mainMenuButton.Height      = 30;
            mainMenuButton.Width       = 60;
            mainMenuButton.BackColor   = color_blue;
            mainMenuButton.ForeColor   = Color.Gold;
            mainMenuButton.Text        = "Main Menu";
            mainMenuButton.MouseClick += new MouseEventHandler(mainMenuButton_Click);
            mainMenuButton.TabStop     = false;

            // Resource

            //gold icon
            Bitmap miniIcon = new Bitmap(@"data/img/MiniIcons.png");

            pic               = miniIcon.Clone(new Rectangle(0, 0, miniIcon.Size.Width, miniIcon.Size.Height / 4), miniIcon.PixelFormat);
            goldPic.Image     = pic;
            goldPic.BackColor = Color.Transparent;
            goldPic.Location  = new Point(this.Width / 5 * 2 - 20, 10);
            goldPic.SizeMode  = PictureBoxSizeMode.StretchImage;
            goldPic.Size      = new Size(20, 20);
            this.Controls.Add(goldPic);

            goldLabel.Location        = new Point(this.Width / 5 * 2, 10);
            goldLabel.Text            = "Gold = 300"; // how to assign value: goldLabel.Text = "Gold  = "  goldNumber;
            goldLabel.AutoSize        = true;
            goldLabel.Font            = new System.Drawing.Font("Microsoft Sans Serif", 10F);
            goldLabel.BackgroundImage = backGround;
            goldLabel.ForeColor       = Color.Gold;
            //goldLabel.Anchor = (AnchorStyles.Right); // this will change label location
            this.Controls.Add(goldLabel);

            //treePic icon
            pic               = miniIcon.Clone(new Rectangle(0, miniIcon.Size.Height / 4, miniIcon.Size.Width, miniIcon.Size.Height / 4), miniIcon.PixelFormat);
            treePic.Image     = pic;
            treePic.BackColor = Color.Transparent;
            treePic.Location  = new Point(this.Width / 5 * 3 - 20, 10);
            treePic.SizeMode  = PictureBoxSizeMode.StretchImage;
            treePic.Size      = new Size(20, 20);
            this.Controls.Add(treePic);

            treeLabel.Location        = new Point(this.Width / 5 * 3, 10);
            treeLabel.Text            = "Tree  = 300";
            treeLabel.AutoSize        = true;
            treeLabel.Font            = new System.Drawing.Font("Microsoft Sans Serif", 10F);
            treeLabel.BackgroundImage = backGround;
            treeLabel.ForeColor       = Color.Gold;
            //treeLabel.Anchor = (AnchorStyles.Right);
            this.Controls.Add(treeLabel);

            //meatPic icon
            pic               = miniIcon.Clone(new Rectangle(0, miniIcon.Size.Height / 2, miniIcon.Size.Width, miniIcon.Size.Height / 4), miniIcon.PixelFormat);
            meatPic.Image     = pic;
            meatPic.BackColor = Color.Transparent;
            meatPic.Location  = new Point(this.Width / 5 * 4 - 20, 10);
            meatPic.SizeMode  = PictureBoxSizeMode.StretchImage;
            meatPic.Size      = new Size(20, 20);
            this.Controls.Add(meatPic);

            meatLabel.Location        = new Point(this.Width / 5 * 4, 10);
            meatLabel.Text            = "Meat  = 300/300";
            meatLabel.AutoSize        = true;
            meatLabel.Font            = new System.Drawing.Font("Microsoft Sans Serif", 10F);
            meatLabel.BackgroundImage = backGround;
            meatLabel.ForeColor       = Color.Gold;
            //meatLabel.Anchor = (AnchorStyles.Right);
            this.Controls.Add(meatLabel);

            small_inGame_menu                 = new Form();
            small_inGame_menu.Location        = new Point(this.Width / 4, this.Height / 4);
            small_inGame_menu.Size            = new Size(this.Width / 2, this.Height / 2);
            small_inGame_menu.BackgroundImage = backGround;

            Button backButton = new Button();

            backButton.Location  = new Point(small_inGame_menu.Width / 2 - buttonX / 2, small_inGame_menu.Height / 4 - buttonY / 2);
            backButton.Height    = buttonY;
            backButton.Width     = buttonX;
            backButton.BackColor = color_blue;
            backButton.ForeColor = Color.Gold;
            backButton.Text      = "Back";
            backButton.Click    += new EventHandler(backButton_Click);
            small_inGame_menu.Controls.Add(backButton);

            //go back to mainMenu button
            Button goBackMainMenuButton = new Button();

            goBackMainMenuButton.Location  = new Point(small_inGame_menu.Width / 2 - buttonX / 2, small_inGame_menu.Height / 2 - buttonY / 2);
            goBackMainMenuButton.Height    = buttonY;
            goBackMainMenuButton.Width     = buttonX;
            goBackMainMenuButton.BackColor = color_blue;
            goBackMainMenuButton.ForeColor = Color.Gold;
            goBackMainMenuButton.Text      = "Main Menu";
            goBackMainMenuButton.Click    += new EventHandler(goBackMainMenuButton_Click);
            small_inGame_menu.Controls.Add(goBackMainMenuButton);

            //Exit button
            Button exitButton = new Button();

            exitButton.Location  = new Point(small_inGame_menu.Width / 2 - buttonX / 2, small_inGame_menu.Height / 4 * 3 - buttonY / 2);
            exitButton.Height    = buttonY;
            exitButton.Width     = buttonX;
            exitButton.BackColor = color_blue;
            exitButton.ForeColor = Color.Gold;
            exitButton.Text      = "Exit";
            exitButton.Click    += new EventHandler(exitButton_Click);
            small_inGame_menu.Controls.Add(exitButton);

            small_inGame_menu.TopLevel        = false;
            small_inGame_menu.FormBorderStyle = FormBorderStyle.None;
            this.Controls.Add(small_inGame_menu);
            small_inGame_menu.Show();
            small_inGame_menu.Hide();



            consoleForm = new Form();
            //consoleForm.g = this.game;
            consoleForm.TopLevel = false;
            //consoleForm.Parent = this;
            consoleForm.Location        = new Point(this.Width / 4, this.Height / 4);
            consoleForm.Size            = new Size(this.Width / 2, this.Height / 2);
            consoleForm.BackgroundImage = backGround;

            this.Controls.Add(consoleForm);

            consoleForm.Show();
            consoleForm.Hide();

            chatBox = new TextBox();
            this.Controls.Add(chatBox);
            chatBox.Location = new System.Drawing.Point(10, 390 + 125 + 10);
            chatBox.Size     = new System.Drawing.Size(125, 125);
            //inputBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F);
            chatBox.BackColor   = Color.Black;
            chatBox.ForeColor   = Color.Gold;
            chatBox.BorderStyle = BorderStyle.Fixed3D;
            chatBox.Multiline   = true;
            chatBox.ScrollBars  = ScrollBars.Both;
            chatBox.ReadOnly    = true;
            //chatBox.TextChanged += new EventHandler(chatBox_TextChanged);

            inputBox = new TextBox();
            this.Controls.Add(inputBox);
            //inputBox.Location = new System.Drawing.Point(10, 390 + 125 + 125 + 10 + 10);
            //inputBox.Location = new System.Drawing.Point(10, 10); // JD: 3/11: change inputBox location to the top

            inputBox.Size     = new System.Drawing.Size(125, 18);
            inputBox.Location = new System.Drawing.Point(this.Width + 25 - inputBox.Width, 10); // JD: 3/11: change inputBox location to the top right
            inputBox.Font     = new System.Drawing.Font("Microsoft Sans Serif", 18F);
            //inputBox.AutoSize = true;
            //inputBox.Size = new System.Drawing.Size(this.Width - (150+20), 20);
            inputBox.BackColor    = Color.Black;
            inputBox.ForeColor    = Color.Gold;
            inputBox.BorderStyle  = BorderStyle.Fixed3D;
            inputBox.TextChanged += new EventHandler(inputBox_TextChanged);
            inputBox.Hide();                   //hide by default

            this.Controls.Add(mainMenuButton); // JD: 3/11: put it here, so the button doesn't block the inputbox
        }
Esempio n. 7
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);
            }
        }
Esempio n. 8
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;
                        }
                    }
                }
            }
        }