예제 #1
0
        /// <summary>
        /// Update Function for key handling.
        /// </summary>
        public override void Update()
        {
            base.Update();
            #region Movement Controls
            // Move to the left
            if (this.PlayerSession.Controller.Left.Down)
            {
                if (this.X > this.Speed + MainModel.HalfWidth)
                {
                    this.X -= this.Speed;
                }
            }
            // Move to the right
            else if (this.PlayerSession.Controller.Right.Down)
            {
                if (this.X < Game.Instance.Width - MainModel.HalfWidth - this.Speed)
                {
                    this.X += this.Speed;
                }
            }
            else if (this.PlayerSession.Controller.B.Down)
            {
                this.Destroy();
            }
            #endregion
            #region Ship Based Displays
            RocketText.String = WeaponSecondary.GetAmmo().ToString("00");
            RocketText.X      = this.X + this.MainModel.HalfWidth;
            RocketText.Y      = this.Y - this.MainModel.HalfHeight;

            // Healthbar
            if (this.Upgrade_Invincible_Time == 0)
            {
                HealthBar = Image.CreateRectangle((int)(BAR_WIDTH * this.GetHealthPercent() / 100), 10, Color.Red);
            }
            else
            {
                HealthBar = Image.CreateRectangle((int)(BAR_WIDTH), 10, Color.Blue);
            }
            HealthBar.X = this.X - this.MainModel.HalfWidth - BAR_WIDTH;
            HealthBar.Y = this.Y - this.MainModel.HalfHeight;

            WeaponPrimaryBar   = Image.CreateRectangle((int)(BAR_WIDTH * this.WeaponPrimary.GetLevelPercent() / 100), 10, Color.Green);
            WeaponPrimaryBar.X = this.X - this.MainModel.HalfWidth - BAR_WIDTH;
            WeaponPrimaryBar.Y = this.Y - this.MainModel.HalfHeight + 15;
            #endregion
            #region Weapon Controls
            // Shoot the Primary Weapon
            if (this.PlayerSession.Controller.A.Down)
            {
                this.WeaponPrimary.Shoot(this.X, this.Y);
            }
            // Shoot the Secondary Weapon
            if (this.PlayerSession.Controller.X.Down)
            {
                this.WeaponSecondary.Shoot(this.X, this.Y);
                //this.WeaponPrimary.Upgrade();
            }
            #endregion
            #region Collisions
            PickupManager.Instance.CheckCollide(this);

            if (this.Upgrade_Invincible_Time != 0)
            {
                var collb = Collider.Collide(X, Y, (int)Global.HIT_TYPES.PRIMARY_SHOT);
                if (collb != null)
                {
                    Weapon_Primary_Shot weapon = (Weapon_Primary_Shot)collb.Entity;
                    if (weapon.IsBotWeapon())
                    {
                        weapon.Destroy();
                        this.CurrentHealth -= weapon.GetDamage();
                        if (this.CurrentHealth <= 0)
                        {
                            this.Destroy();
                            return;
                        }
                    }
                }
            }

            /*
             * var collb = Collider.Collide(X, Y, (int)Global.HIT_TYPES.PRIMARY_SHOT);
             * if (collb != null)
             * {
             *  Weapon_Primary_Shot b = (Weapon_Primary_Shot)collb.Entity;
             *  if (!b.IsBotWeapon())
             *  {
             *      b.Destroy();
             *      this.CurrentHealth -= b.GetDamage();
             *      if (this.CurrentHealth <= 0)
             *      {
             *          this.Destroy();
             *          EnemyManager.GetInstance().Remove(this);
             *          Scene.Add(new Pickup(this.X, this.Y, (Int16)Global.PICKUPTYPES.UPGRADE_WEAPON_PRIMARY));
             *          return;
             *      }
             *  }
             * }*/
            #endregion
            #region Times
            if (this.Upgrade_Invincible_Time > 0)
            {
                this.Upgrade_Invincible_Time--;
            }
            #endregion
        }
예제 #2
0
        public override void Update()
        {
            base.Update();

            // Moving
            if (this.Y >= SpawnY)
            {
                if (this.MovingDirection == (int)MovingDirectons.DIR_LEFT)
                {
                    this.X -= speed.X;
                    if (this.X < this.MinX)
                    {
                        this.MovingDirection = (int)MovingDirectons.DIR_RIGHT;
                    }
                }
                else
                {
                    this.X += speed.X;
                    if (this.X > this.MaxX)
                    {
                        this.MovingDirection = (int)MovingDirectons.DIR_LEFT;
                    }
                }
                if (rand.Next(1, 30) == 10)
                {
                    this.Y += speed.Y;
                }
            }
            else
            {
                // Reinfliegen
                this.Y += 3.0f;
            }

            // Primary Weapon Collision
            var collb = Collider.Collide(X, Y, (int)Global.HIT_TYPES.PRIMARY_SHOT);

            if (collb != null)
            {
                Weapon_Primary_Shot b = (Weapon_Primary_Shot)collb.Entity;
                if (!b.IsBotWeapon())
                {
                    b.Destroy();
                    this.CurrentHealth -= b.GetDamage();
                    if (this.CurrentHealth <= 0)
                    {
                        this.Destroy();
                        EnemyManager.GetInstance().Remove(this);

                        PickupManager.Instance.SpawnRandomUpgrade(this.X, this.Y);
                        Global.KilledEnemies++;
                        return;
                    }
                }
            }

            // Chance ist 1 zu 2500, dass der Bot schießt
            if (Rand.Int(1, 2500) == 1)
            {
                weapon.Shoot(this.X, this.Y);
            }

            #region Enemy Based display
            Int32 percent = Convert.ToInt32(CurrentHealth * 100 / MaximalHealth);

            //HealthText.String = percent.ToString("00") + " %";
            HealthBarBackground   = Image.CreateRectangle(this.Width * percent / 100, 5, Color.Red);
            HealthBarBackground.X = this.X - this.Width / 2;
            HealthBarBackground.Y = this.Y + this.Height / 2;

            /*
             * HealthBarValue = Image.CreateRectangle(this.Width / 100 * percent, 5, Color.Red);
             * HealthBarValue.X = this.X - this.Width / 2 + (this.Width / 100 * (100 - percent));
             * HealthBarValue.Y = this.Y + this.Height / 2;*/

            //HealthBarValue.Width = this.Width - this.X;

            //HealthBarBackground
            #endregion
        }