/// <summary>
 /// Exits the game.
 /// </summary>
 private void Exit()
 {
     MainGame.needsToExit = true;
     GameSounds.CloseSFX();
     this.Close();
     Application.Exit();
 }
 /// <summary>
 /// overridden draw method allows for the drawing of the thruster fire
 /// </summary>
 /// <param name="Initialg"></param>
 public override void DrawObj(Graphics Initialg)
 {
     base.DrawObj(Initialg);
     if (!IsDying)
     {
         if (ShieldLevel > 0 || Accelerating)
         {
             Initialg.TranslateTransform((int)Position.X, (int)Position.Y);
             Initialg.RotateTransform((float)Rotation); //degrees
             if (ShieldLevel > 0)
             {
                 Initialg.DrawImage(shieldImg, new Point(-(int)(shieldImg.Width / 2 + 8), -(int)(shieldImg.Height / 2 + 9)));
             }
             if (Accelerating)
             {
                 Initialg.DrawEllipse(new Pen(Color.PaleTurquoise, 3), -6, 15, 12, 5);
                 Initialg.FillEllipse(new SolidBrush(Color.Violet), -3, 15, 6, 20);
                 Accelerating = false;
             }
             Initialg.ResetTransform();
         }
     }
     else
     {
         IsActive = Boom.ExplosionDraw(Initialg, new Rectangle((int)(this.Position.X - (this.Dimensions.X + Settings.explodeSizeAdd) / 2), (int)(this.Position.Y - (this.Dimensions.Y + Settings.explodeSizeAdd) / 2), (int)(this.Dimensions.X + Settings.explodeSizeAdd), (int)(this.Dimensions.Y + Settings.explodeSizeAdd)));
         if (HasBoomed == false)
         {
             GameSounds.effect(GameMedia.getDir["explosion1SND"]);
             HasBoomed = true;
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// Draws the vehicle on the given grahpics
        /// </summary>
        /// <param name="Initialg">Graphics vehicle is drawn on</param>
        public override void DrawObj(Graphics Initialg)
        {
            if (!IsDying)
            {
                base.DrawObj(Initialg);

                //center world on vehicle then rotate
                Initialg.TranslateTransform((int)Position.X, (int)Position.Y);
                Initialg.RotateTransform((float)Rotation); //degrees

                if (Accelerating)
                {
                    Initialg.DrawEllipse(new Pen(Color.AliceBlue, 3), -6, 15, 12, 5);
                    Initialg.FillEllipse(new SolidBrush(Color.DeepSkyBlue), -3, 15, 6, 20);
                    Accelerating = false;
                }

                Initialg.ResetTransform();
            }
            else
            {
                IsActive = boom.ExplosionDraw(Initialg, new Rectangle((int)(this.Position.X - (this.Dimensions.X + Settings.explodeSizeAdd) / 2), (int)(this.Position.Y - (this.Dimensions.Y + Settings.explodeSizeAdd) / 2), (int)(this.Dimensions.X + Settings.explodeSizeAdd), (int)(this.Dimensions.Y + Settings.explodeSizeAdd)));
                if (hasBoomed == false)
                {
                    GameSounds.effect(GameMedia.getDir["explosion1SND"]);
                    hasBoomed = true;
                }
            }
        }
        private List <PictureBox> livesPics;        // used for displaying extra lives

        #endregion

        #region Game Initialization

        /// <summary>
        /// this method initializes the game and plays the opening sequence.
        /// </summary>
        public Form1()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, false);
            FormBorderStyle = FormBorderStyle.None;
            WindowState     = FormWindowState.Maximized;

            Utilities.populateRandPool();
            GameMedia.InitializeMedia();
            Game.IntializeGame(this);

            GameSounds.initializeMusic();
            GameSounds.backGroundLoop();

            lbl_level.Hide();
            lbl_score.Hide();

            lvlSplashCycler = -1;

            //private WriteableBitmap bmp
        }
Exemple #5
0
 /// <summary>
 /// warps the player's ship to a random location on the screen.
 /// </summary>
 public void Warp()
 {
     if (warpCoolDown <= 0)
     {
         GameSounds.effect(GameMedia.getDir["warpSND"]);
         Position.X   = (Utilities.screenBounds.Width * Utilities.getRand10() / 10);
         Position.Y   = (Utilities.screenBounds.Height * Utilities.getRand10() / 10);
         warpCoolDown = Settings.shipWarpCooldown;
     }
 }
Exemple #6
0
 /// <summary>
 /// this function shoots
 /// </summary>
 public void Shoot()
 {
     if (bulletCoolDown <= 0)
     {
         try { GameSounds.effect(GameMedia.getDir["laser0SND"]); }
         catch { }
         bullets.Add(new NormalBullet(Position.X - Settings.bulletWidth / 2, Position.Y - Settings.bulletHeight / 2, Velocity.X, Velocity.Y, Rotation, "laser0PIC"));
         bulletCoolDown = Settings.shipBulletCooldown;
     }
 }
 /// <summary>
 /// what happens when the Seeker fires
 /// </summary>
 public override void fire()
 {
     if (BulletCoolDown == 0)
     {
         Bullets.Add(new SeekingBullet(Position.X - Settings.bulletWidth / 2, Position.Y - Settings.bulletHeight / 2, Velocity.X, Velocity.Y, Rotation, "laser3PIC", target));
         BulletCoolDown = 150;
         base.fire();
         try { GameSounds.effect(GameMedia.getDir["laser2SND"]); }
         catch { }
     }
 }
 /// <summary>
 /// this happens when the form closes.
 /// </summary>
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (Settings.soundIsOn)
     {
         GameSounds.CloseSFX();
     }
     if (Settings.soundIsOn)
     {
         GameSounds.CloseMusic();
     }
     //Threads.initializeTasks();
     //Application.Exit();
 }
 /// <summary>
 /// overloaded draw allows the meteors to explode upon death
 /// </summary>
 /// <param name="Initialg"></param>
 public override void DrawObj(Graphics Initialg)
 {
     base.DrawObj(Initialg);
     if (IsDying)
     {
         deathFlag++;
         IsActive = boom.ExplosionDraw(Initialg, new Rectangle((int)(this.Position.X - (this.Dimensions.X + Settings.explodeSizeAdd) / 2), (int)(this.Position.Y - (this.Dimensions.Y + Settings.explodeSizeAdd) / 2), (int)(this.Dimensions.X + Settings.explodeSizeAdd), (int)(this.Dimensions.Y + Settings.explodeSizeAdd)));
     }
     if (deathFlag == 1)
     {
         try { GameSounds.effect(GameMedia.getDir["explosion0SND"]); }
         catch { }
     }
 }
 /// <summary>
 /// Game starts when you click the button, this is how!
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button1_Click_2(object sender, EventArgs e)
 {
     this.BackgroundImage       = global::Asteroids2._0.Properties.Resources.ag;
     this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
     Threads.Physics_Engine     = Task.Run(() => physicsEngine());
     Threads.Alien_Engine       = Task.Run(() => alienSpawningEngine());
     Threads.Collisions_Engine  = Task.Run(() => collisionEngine());
     Threads.Graphics_Engine    = Task.Run(() => graphicsEngine());
     Threads.Game_Engine        = Task.Run(() => gameStateEngine());
     if (Settings.soundIsOn)
     {
         GameSounds.InitializeSFX();
     }
     StartGame();
     populateLivesPics();
 }
 /// <summary>
 /// this is what happens when the Hunter's underlying logic decides to fire weapons
 /// </summary>
 public override void fire()
 {
     if (BulletCoolDown == 0)
     {
         GunLeft.setVector(Position);
         GunLeft.addVector(8, RadRotation);
         GunRight.setVector(Position);
         GunRight.addVector(-8, RadRotation);
         Bullets.Add(new NormalBullet(GunLeft.X - Settings.bulletWidth / 2, GunLeft.Y - Settings.bulletHeight / 2, Velocity.X, Velocity.Y, Rotation, "laser2PIC"));
         Bullets.Add(new NormalBullet(GunRight.X - Settings.bulletWidth / 2, GunRight.Y - Settings.bulletHeight / 2, Velocity.X, Velocity.Y, Rotation, "laser2PIC"));
         BulletCoolDown = 120;
         base.fire();
         try { GameSounds.effect(GameMedia.getDir["laser2SND"]); }
         catch { }
     }
 }
Exemple #12
0
 /// <summary>
 /// overridded behavior routine allows the Caller to change to a 'coward' when it's shields go down.
 /// </summary>
 /// <param name="player">the player's ship</param>
 protected override void alienLogic(PlayerShip player)
 {
     base.alienLogic(player);
     abilityCoolDown--;
     if (abilityCoolDown == 195)
     {
         GameSounds.effect(GameMedia.getDir["callSigSND"]);
     }
     if (abilityCoolDown <= 0)
     {
         if (ShieldLevel < 1)
         {
             ShieldLevel++;
             IsCoward = false;
             try { GameSounds.effect(GameMedia.getDir["shieldsUpSND"]); }
             catch { }
         }
         callAllies();
         abilityCoolDown = 3000;
     }
 }
 /// <summary>
 /// Handles the collision between a player's bullet and an alien ship
 /// </summary>
 /// <param name="alien">the alien</param>
 /// <param name="bullet">the bullet</param>
 private void bulletHitAlien(AlienBase alien, Weapon bullet)
 {
     bullet.IsDying = true;
     UsedBullets.Add(bullet);
     alien.ShieldLevel -= 1;
     if (alien.ShieldLevel < 0)
     {
         alien.IsDying = true;
         DestroyedAliens.Add(alien);
         MainGame.score             += alien.PointValue;
         MainGame.extraLivesCounter += alien.PointValue;
         if (MainGame.extraLivesCounter > Settings.scoreToNextLife)
         {
             MainGame.lives++;
             MainGame.extraLivesCounter = 0;
             MainGame.extraLifeAdded    = true;
         }
     }
     else
     {
         try { GameSounds.effect(GameMedia.getDir["shieldsDownSND"]); }
         catch { }
     }
 }
        /// <summary>
        /// does all of the operating on the form, so that there isn't more than one thread operating on the form
        /// controls at once.  Also calls all the objects' draw methods on form.refresh.
        /// </summary>
        private void graphicsEngine()
        {
            int currentTime  = 0;
            int previousTime = Environment.TickCount;
            int deltaTime    = 0;

            while (true)
            {
                currentTime = Environment.TickCount;
                deltaTime   = currentTime - previousTime;
                if (deltaTime < Settings.graphicsInverseFPS)
                {
                    Thread.Sleep(Settings.graphicsInverseFPS - deltaTime);
                }
                previousTime = currentTime;
                if (MainGame.isRunning)
                {
                    this.Refresh();
                }
                else if (MainGame.needsToExit)
                {
                    return;
                }
                else
                {
                    switch (MainGame.stateDescription)
                    {
                    case "LevelWon":
                        showLevelSplash();
                        lbl_LvlScr.Text = "LEVEL: " + MainGame.level + "\nSCORE: " + MainGame.score;
                        lbl_LvlScr.Show();
                        lbl_level.Hide();
                        lbl_score.Hide();

                        MessageBox.Show("Next Level!", "Good Job!", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000);

                        hideLevelSplash();
                        lbl_LvlScr.Hide();
                        lbl_level.Show();
                        lbl_score.Show();
                        MainGame.score += MainGame.level * 100;
                        MainGame.level++;
                        Game.InitializeNextLevel(this);
                        GameSounds.backGroundLoop();
                        break;

                    case "LevelLost":
                        MainGame.lives--;
                        this.BeginInvoke((MethodInvoker) delegate()   //() =>
                        {
                            foreach (PictureBox p in livesPics)
                            {
                                this.Controls.Remove(p);
                            }
                            populateLivesPics();
                        });
                        MessageBox.Show("Switch to next miner?", "Died!", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000);
                        Game.InitializeNextLevel(this);
                        GameSounds.backGroundLoop();
                        break;

                    case "GameLost":
                        showHighScores();
                        MainGame.needsToExit = true;
                        this.Refresh();
                        MessageBox.Show("Press ok to exit.", "Play again soon!", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000);
                        Exit();
                        return;

                    case "extraLife":
                        MainGame.extraLifeAdded = false;
                        this.BeginInvoke((MethodInvoker) delegate()
                        {
                            foreach (PictureBox p in livesPics)
                            {
                                this.Controls.Remove(p);
                            }
                            populateLivesPics();
                        });
                        break;

                    case "Paused":
                        MessageBox.Show("Game is Paused!!", "PAUSE", MessageBoxButtons.OK);
                        break;

                    case "Help":
                        MessageBox.Show("Up Arrow: Accelerate \n\nLeft Arrow: Rotate Left \n\nRight Arrow: Rotate Right \n\nSpace Bar: Shoot\n\nCTRL: Warp\n\nLeft Click: Target" +
                                        "\n\n______________\n\nFOR MOUSE:\n______________\n\nShip points at mouse.\n\nLeft click to fire\n\nRight click to accelerate" +
                                        "\n\nMiddle or Side Click to target\n\nSpace Bar: Warp\n\n______________\n\nESC: QUIT", "Help", MessageBoxButtons.OK);
                        break;
                    }
                    MainGame.isRunning = true;
                }
            }
        }
        /// <summary>
        /// checks if the level has been won or lost, writes game state to a string stored in MainGame, which
        /// string is accessed by the graphics engine.
        /// </summary>
        private void gameStateEngine()
        {
            int currentTime  = 0;
            int previousTime = Environment.TickCount;
            int deltaTime    = 0;

            while (true)
            {
                currentTime = Environment.TickCount;
                while (!MainGame.isRunning)
                {
                    ;
                }
                deltaTime = currentTime - previousTime;
                if (deltaTime < Settings.gameStateInverseFPS)
                {
                    Thread.Sleep(Settings.gameStateInverseFPS - deltaTime);
                }
                previousTime = currentTime;

                if (MainGame.isRunning)
                {
                    if (Game.isLevelWon())
                    {
                        MainGame.stateDescription = "LevelWon";
                        MainGame.isRunning        = false;
                        GameSounds.credits();
                    }
                    else if (Game.isLevelLost())
                    {
                        GameSounds.loser();
                        if (MainGame.lives <= 0)
                        {
                            MainGame.stateDescription = "GameLost";
                            MainGame.isRunning        = false;
                            return;
                        }
                        else
                        {
                            MainGame.stateDescription = "LevelLost";
                            MainGame.isRunning        = false;
                        }
                    }
                    else if (MainGame.extraLifeAdded)
                    {
                        GameSounds.effect(GameMedia.getDir["extraLifeSND"]);
                        MainGame.stateDescription = "extraLife";
                        MainGame.isRunning        = false;
                    }
                    try
                    {
                        lbl_score.Text = MainGame.score.ToString();
                        lbl_level.Text = MainGame.level.ToString();
                    }
                    catch { }
                }
                else if (MainGame.needsToExit)
                {
                    return;
                }
            }
        }