コード例 #1
0
        public SpaceInvasion(int w, int h)
        {
            try
            {
                this.state_e  = GameState.LOADING;
                this.level_e  = GameLevel.LEVEL_01;
                this.fire_bl  = false;
                this.width_i  = w;
                this.height_i = h;

                this.dataAccess  = new DataAccess();
                this.highScore_l = this.dataAccess.GetHighScore();

                ///////////////////////////////////////////////////////

                this.backdrop = new Backdrop(
                    this.width_i,
                    this.height_i,
                    2, 2); // backdropCount, scrollSpeed

                this.aliens = new Aliens(
                    this.width_i,
                    this.height_i,
                    3, 10, // bulletCount, bulletSpeed
                    5, 8); // rowCount, colCount

                this.player = new Player(
                    this.width_i,
                    this.height_i,
                    4, 10, 5); // bulletCount, bulletSpeed, lives

                this.sound = new GameSound();
            }
            catch (Exception ex)
            {
                this.exception_ex = ex;
            }
        }
コード例 #2
0
 private void AliensShoot(
     ref Player player,
     ref GameSound sound)
 {
     try
     {
         for (int i = 0; i < (this.rowCount_i * this.colCount_i); i++)
         {
             if ((this.aliens_s[i].X - (this.alienImage.Width / 2)) > (player.sprite.X) &&
                 (this.aliens_s[i].X - (this.alienImage.Width / 2)) < (player.sprite.X + player.sprite.Width))
             {
                 if (!this.shooting_s.ContainsValue(this.aliens_s[i]) &&
                     this.shooting_s.Count < this.count_i)
                 {
                     for (int a = 0; a < this.count_i; a++)
                     {
                         if (!this.bullets_s[a].Visible)
                         {
                             this.bullets_s[a].Visible = true;
                             this.bullets_s[a].Position(
                                 (this.aliens_s[i].X + (this.aliens_s[i].Width / 2)),
                                 (this.aliens_s[i].Y + (this.aliens_s[i].Height / 2)));
                             sound.PlayFire();
                             this.shooting_s.Add(this.bullets_s[a], this.aliens_s[i]);
                             break;
                         }
                     }
                     break;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         this.exception_ex = ex;
     }
 }
コード例 #3
0
ファイル: Player.cs プロジェクト: hippy-runner/SpaceInvasion
        private void BulletUpdates(
            ref Backdrop backdrop,
            ref GameSound sound)
        {
            Sprite tempCollision_s = null;

            try
            {
                if (this.fire_bl)
                {
                    for (int i = 0; i < this.count_i; i++)
                    {
                        if (!this.bullets_s[i].Visible)
                        {
                            this.bullets_s[i].Visible = true;
                            sound.PlayFire();
                            break;
                        }
                    }

                    this.fire_bl = false;
                }

                for (int i = 0; i < this.count_i; i++)
                {
                    if (this.bullets_s[i].Visible)
                    {
                        if (this.bullets_s[i].Y > -(this.bullets_s[i].Height))
                        {
                            this.bullets_s[i].Position(
                                this.bullets_s[i].X,
                                (this.bullets_s[i].Y - this.speed_i));
                        }
                        else
                        {
                            this.misses_f++;
                            this.bullets_s[i].Visible = false;
                        }

                        tempCollision_s = this.bullets_s[i].Collision();

                        if (tempCollision_s != null
                            //&& tempCollision_s != this.player_s
                            && !backdrop.sprites.Contains(tempCollision_s))
                        {
                            this.hits_f++;
                            this.score_i += 100;
                            this.bullets_s[i].Visible = false;

                            sound.PlayExplosion();
                            tempCollision_s.Visible = false;
                            tempCollision_s         = null;
                        }
                    }
                    else
                    {
                        this.bullets_s[i].Position(
                            (this.player_s.X + (this.player_s.Width / 2)),
                            (this.player_s.Y + (this.player_s.Height / 2)));
                    }
                }
            }
            catch (Exception ex)
            {
                this.exception_ex = ex;
            }
        }