public void handleFireballs()
        {
            //remove all thhe fireballs that aren't alive
            for (int i = 0; i < map.getFireballs().Count; i++)
            {
                if (!map.getFireballs()[i].isAlive())
                {
                    map.removeFireball(i);
                    TransparentPictureBox.removePictureBox(ui.getFireball(i));
                    ui.killFireball(i);
                    i--;
                }
            }

            //handle each arrow
            for (int i = 0; i < map.getFireballs().Count; i++)
            {
                //get the CollisionLines in the arrow's room

                CollisionLine[] collLines = map.getRooms()[map.getFireballs()[i].getRoomNumber() - 1].getRoomEdges();

                //get the list of objects that can collide with the arrows
                List <PhysicsObject> collidingObjs = new List <PhysicsObject>();
                collidingObjs.Add(map.getPlayer());


                //handle the arrow

                map.getFireballs()[i].FireballHandler(map.getPlayer(), collLines, collidingObjs.ToArray());
            }
        }
        public void newFireball(Point p, float angle)
        {
            TransparentPictureBox newFireball = new TransparentPictureBox(fireball.getZOrder());

            newFireball.Image = fireball.Image;
            newFireball.rotateTo(angle);
            newFireball.SetBounds((int)p.getX(), (int)p.getY(), fireball.Width, fireball.Height);
            fireballList.Add(newFireball);
            gamePanel.Controls.Add(newFireball);
            newFireball.BringToFront();
        }
        // Create new arrow/fireball
        public void newArrowProjectile(Point p, float angle)
        {
            TransparentPictureBox newArrow = new TransparentPictureBox(arrow.getZOrder());

            newArrow.Image = arrow.Image;
            newArrow.rotateTo(angle);
            newArrow.SetBounds((int)p.getX(), (int)p.getY(), arrow.Width, arrow.Height);
            arrowList.Add(newArrow);
            gamePanel.Controls.Add(newArrow);
            newArrow.BringToFront();
        }
Example #4
0
 //when the gamePanel is painted
 private void gamePanel_Paint(object sender, PaintEventArgs e)
 {
     //loop through all the TransparentPictureBoxes in the ordered list (based on z-order)
     foreach (TransparentPictureBox pb in TransparentPictureBox.getAllPictureBoxes())
     {
         //paint the ones that are on the panel
         if (pb.Parent != null && pb.Parent.Equals(gamePanel))
         {
             pb.Paint(e);
         }
     }
 }
        public void killProjectiles()
        {
            int numArrows = map.getArrows().Count;

            for (int i = 0; i < numArrows; i++)
            {
                map.removeArrow(0);
                TransparentPictureBox.removePictureBox(ui.getArrow(0));
                ui.killArrow(0);
            }

            int numFireballs = map.getFireballs().Count;

            for (int i = 0; i < numFireballs; i++)
            {
                map.removeFireball(0);
                TransparentPictureBox.removePictureBox(ui.getArrow(0));
                ui.killFireball(0);
            }
        }
Example #6
0
 //removes a pictureBox from the list of pictureboxes
 public static void removePictureBox(TransparentPictureBox t)
 {
     allTransparentPictureBoxControls.Remove(t);
 }
        /////////////////////////////////////////////////////// Constructor ///////////////////////////////////////////////////////

        public WumpusUI(Form gameForm, TransparentPictureBox player, TransparentPictureBox[] bats,
                        TransparentPictureBox[] pits, TransparentPictureBox[] rocks, TransparentPictureBox wumpus, TransparentPictureBox room,
                        TransparentPictureBox gold, TransparentPictureBox arrow, TransparentPictureBox fireball,
                        TransparentPictureBox secret, TransparentPictureBox win, TransparentPictureBox lose, TransparentPictureBox main, TransparentPictureBox chest,
                        TransparentPictureBox door, TextBox alertBox, Rectangle screen, DrawingPanel gamePanel)
        {
            main.Location            = new System.Drawing.Point(-10000, -10000);
            mainBackground           = main.Image;
            gameForm.BackgroundImage = main.Image;
            sound.playSound1();
            this.gameForm = gameForm;
            hs            = new HighScore();

            // Get screen dimensions - used for scaling and GC creation
            this.screen = screen;
            scX         = Screen.FromControl(gameForm).Bounds.Width;
            scY         = Screen.FromControl(gameForm).Bounds.Height;

            #region Main Menu construction
            playGameButton          = new Button(); playGameButton.Text = "Play Game"; playGameButton.Size = new Size(scX / 10, scX / 40);
            playGameButton.Location = new System.Drawing.Point((scX - playGameButton.Width) / 2, scY * 23 / 34);
            // playGameButton = makeButton("play game", (scX - scX / 10) / 2, scY * 14 / 22);
            highScoreButton          = new Button(); highScoreButton.Text = "Highscores"; highScoreButton.Size = playGameButton.Size;
            highScoreButton.Location = new System.Drawing.Point((scX - highScoreButton.Width) / 2, scY * 25 / 34);
            // highScoreButton = makeButton("highscores", (scX - scX / 10) / 2, scY * 15 / 22);
            helpButton          = new Button(); helpButton.Text = "Help and Credits"; helpButton.Size = playGameButton.Size;
            helpButton.Location = new System.Drawing.Point((scX - helpButton.Width) / 2, scY * 27 / 34);
            // helpButton = makeButton("help and credits", (scX - scX / 10) / 2, scY * 16 / 22);
            // helpButton.AutoSize = true;
            exitGameButton          = new Button(); exitGameButton.Text = "Exit Game"; exitGameButton.Size = playGameButton.Size;
            exitGameButton.Location = new System.Drawing.Point((scX - exitGameButton.Width) / 2, scY * 29 / 34);
            // exitGameButton = makeButton("exit", (scX - scX / 10) / 2, scY * 17 / 22);

            playGameButton.Click  += new System.EventHandler(playGameButton_Click);
            highScoreButton.Click += new System.EventHandler(highScoreButton_Click);
            helpButton.Click      += new System.EventHandler(helpButton_Click);
            exitGameButton.Click  += new System.EventHandler(exitGameButton_Click);

            gameForm.Controls.Add(playGameButton);
            gameForm.Controls.Add(highScoreButton);
            gameForm.Controls.Add(helpButton);
            gameForm.Controls.Add(exitGameButton);

            // Help Form
            helpForm = makeForm("Help and Credits", 640, 370);
            helpForm.StartPosition = FormStartPosition.Manual;
            helpForm.Location      = new System.Drawing.Point((scX - helpForm.Width) / 2, (scY - helpForm.Height) / 2);
            // HighScore Form
            highScoreForm = makeForm("High-scores", scX / 3, scY * 3 / 4);
            highScoreForm.StartPosition = FormStartPosition.Manual;
            highScoreForm.Location      = new System.Drawing.Point((scX - highScoreForm.Width) / 2 + 150, (scY - highScoreForm.Height) / 2);


            playerNames = new Label[10];
            highScores  = new Label[10];

            exitHighScore        = makeButton("Exit", highScoreForm.Width * 4 / 6, highScoreForm.Height * 7 / 8);
            exitHighScore.Click += ExitHighScore_Click;
            highScoreForm.Controls.Add(exitHighScore);

            // Submit Name Form
            submitNameForm = makeForm("Enter Name: ", scX / 5, scY / 6);
            submitNameForm.StartPosition = FormStartPosition.Manual;
            submitNameForm.Location      = new System.Drawing.Point((scX - submitNameForm.Width) / 2, (scY - submitNameForm.Height) / 2);
            nameBox                     = makeTextBox(submitNameForm.Width * 5 / 7, submitNameForm.Height / 4, submitNameForm.Width * 1 / 7, submitNameForm.Height / 7);
            submitNameButton            = makeButton("This is me!", submitNameForm.Width * 3 / 5, submitNameForm.Height * 3 / 7);
            submitNameButton.Click     += SubmitNameButton_Click;
            submitNameForm.AcceptButton = submitNameButton;

            submitNameForm.Controls.Add(nameBox);
            submitNameForm.Controls.Add(submitNameButton);

            // Select Cave Form
            selectCaveForm = makeForm("Choose a Cave: ", scX / 6, scY / 3);
            selectCaveForm.StartPosition = FormStartPosition.Manual;
            selectCaveForm.Location      = new System.Drawing.Point((scX - selectCaveForm.Width) / 2, (scY - selectCaveForm.Height) / 2);
            Button[] caves = new Button[5];
            for (int i = 1; i <= 5; i++)
            {
                caves[i - 1] = makeButton("Cave " + i, selectCaveForm.Width / 3, selectCaveForm.Height * i / 7);
                selectCaveForm.AcceptButton = caves[i - 1];
            }

            caves[0].Click += new System.EventHandler(this.cave1_Click);
            caves[1].Click += new System.EventHandler(this.cave2_Click);
            caves[2].Click += new System.EventHandler(this.cave3_Click);
            caves[3].Click += new System.EventHandler(this.cave4_Click);
            caves[4].Click += new System.EventHandler(this.cave5_Click);

            selectCaveForm.Controls.AddRange(caves);

            selectCaveForm.FormClosing += SelectCaveForm_FormClosing;
            #endregion

            #region Shop Form
            shopForm = makeForm("Shop", scX / 5, scY * 1 / 2);
            shopForm.StartPosition = FormStartPosition.Manual;


            shopForm.BackgroundImage = shopBackground;
            shopForm.Width           = shopBackground.Width + 20;
            shopForm.Height          = shopBackground.Height + 30;

            shopForm.Location = new System.Drawing.Point((scX - shopForm.Width) / 2, (scY - shopForm.Height) / 2);
            // buyArrow Button
            buyArrow        = makeButton("Buy", shopForm.Width * 3 / 5, shopForm.Height * 25 / 42);
            buyArrow.Click += new System.EventHandler(buyArrow_Click);
            // buySecret Button
            buySecret        = makeButton("Buy", shopForm.Width * 3 / 5, shopForm.Height * 2 / 7);
            buySecret.Click += new System.EventHandler(buySecret_Click);
            // exitShop Button
            exitShop        = makeButton("Exit", shopForm.Width * 3 / 5, shopForm.Height * 4 / 5);
            exitShop.Click += new System.EventHandler(exitShop_Click);

            shopForm.Controls.Add(buyArrow);
            shopForm.Controls.Add(buySecret);
            shopForm.Controls.Add(exitShop);
            #endregion

            #region GUI Construction

            // Image construction
            this.player   = player;
            this.wumpus   = wumpus;
            this.room     = room;
            this.chest    = chest;
            this.gold     = gold;
            this.arrow    = arrow;
            this.secret   = secret;
            this.fireball = fireball;
            this.door     = door;

            // Image array construction
            this.door  = door;
            this.bats  = bats;
            this.pits  = pits;
            this.rocks = rocks;

            // Projectile image list - images copied from the template picturebox
            arrowList    = new List <TransparentPictureBox>();
            fireballList = new List <TransparentPictureBox>();

            // Initial image locations
            player.Location        = new System.Drawing.Point(scX / 2, scY / 2);
            this.gold.Location     = new System.Drawing.Point(scX * 1 / 10, scY * 7 / 9);
            this.arrow.Location    = new System.Drawing.Point(scX * 3 / 10, scY * 7 / 9);
            this.fireball.Location = new System.Drawing.Point(scX * 4 / 3, scY * 4 / 3);

            // Set door location
            door.Location = new System.Drawing.Point(-1000, -1000);
            doors         = new TransparentPictureBox[6];
            for (int i = 0; i < doors.Length; i++)
            {
                TransparentPictureBox newDoor = new TransparentPictureBox(door.getZOrder());
                newDoor.Image = door.Image;
                gamePanel.Controls.Add(newDoor);
                doors[i]          = newDoor;
                doors[i].Location = new System.Drawing.Point(-1000, -1000);
            }

            #region Player HUD
            // Shop button
            shopButton        = makeButton("Shop", scX * 1 / 30, scY * 4 / 5);
            shopButton.Click += new System.EventHandler(shopButton_Click);
            // Items
            gold.Location  = new System.Drawing.Point(scX * 1 / 30, scY * 17 / 20);
            arrow.Location = new System.Drawing.Point(scX * 3 / 30, scY * 8 / 10);
            golds          = makeLabel("0", scX * 2 / 30, scY * 7 / 8); golds.AutoSize = true;
            arrows         = makeLabel("0", scX * 4 / 30, scY * 7 / 8); arrows.AutoSize = true;

            // Alerts
            this.alertBox     = alertBox;
            alertBox.Location = new System.Drawing.Point(scX - alertBox.Width, 1 / 80);
            #endregion

            #endregion

            #region Game Panel - Draw images here!
            // Game panel displays game images
            this.gamePanel = gamePanel;
            gamePanel.Size = new Size(0, 0);

            gamePanel.Controls.Add(shopButton);
            gamePanel.Controls.Add(golds);
            gamePanel.Controls.Add(arrows);

            shopButton.BackColor = Color.White;
            golds.BackColor      = Color.White;
            arrows.BackColor     = Color.White;
            gamePanel.BackColor  = Color.Black;
            gameForm.BackColor   = Color.White;
            #endregion

            #region Endgame
            this.win      = win;
            this.lose     = lose;
            win.Location  = new System.Drawing.Point(0, 0);
            lose.Location = new System.Drawing.Point(0, 0);

            // Keep hidden until game ends
            win.Hide();
            lose.Hide();

            // show button that takes the user to main menu
            mainMenu          = makeButton("Main Menu", scX / 2, scY * 7 / 8);
            mainMenu.AutoSize = true;
            gameForm.Controls.Add(mainMenu);
            mainMenu.Click += MainMenu_Click;
            mainMenu.Hide();
            #endregion
        }