Esempio n. 1
0
        public override void ProcessTimeEvent()
        {
            /// <summary>
            ///
            /// This method moves the given projectile according to its angle, power, gravity and the wind
            ///
            /// </summary>

            for (int i = 0; i <= 10; i++)
            {
                _x += _xVelocity + (_game.Wind() / 1000.0f);
                _y += _yVelocity;

                if (_x < 0 || _x > Battlefield.WIDTH || _y > Battlefield.HEIGHT)
                {
                    _game.RemoveWeaponEffect(this);
                    return;
                }
                else if (_game.CheckHitTank(_x, _y))
                {
                    _player.HitPos(_x, _y);
                    _explosion.Explode(_x, _y);
                    _game.AddEffect(_explosion);
                    _game.RemoveWeaponEffect(this);
                    return;
                }
                _yVelocity += _gravity;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// moves the given projectile across the battelfeild
 /// </summary>
 public override void Tick()
 {
     // each tick occures ten times in a frame
     //loop procedure 10 times
     for (int Loop = 0; Loop < 10; Loop++)
     {
         // increase the location of bullet by velocity
         bulletX = bulletX + velocityX;
         bulletY = bulletY + velocityY;
         // move the bullet according to the current wind
         // get windspeed
         float wind = this.currrentGame.GetWind() / 1000.0f;
         // move bullet's horizontal postion by adding the wind
         bulletX = bulletX + (wind);
         //check to see if bullet has moved outside game bounds
         if (bulletX > Battlefield.WIDTH | bulletY > Battlefield.HEIGHT | bulletX < 0)
         {
             //destroy bullet as its gone too far
             this.currrentGame.RemoveWeaponEffect(this);
             return; //exit function as bullet doesnt exist anymore
         }
         else // bullet inside bounds
         {
             // check to see if a bullet has hit a tank or collision
             if (this.currrentGame.CheckCollidedTank(bulletX, bulletY))
             {
                 //record the hit if the owner's tank isnt at location
                 if (!CheckPlayerOwner(bulletOwner, (int)bulletX))
                 {
                     bulletOwner.ReportHit(bulletX, bulletY);
                 }
                 //cause explosion
                 bulletExplosion.Explode(bulletX, bulletY);
                 //add the explosion to effects
                 this.currrentGame.AddEffect(bulletExplosion);
                 //destroy this bullet
                 this.currrentGame.RemoveWeaponEffect(this);
                 return; // exit function as bullet doesnt exist anymore
             }
         }
         // calucalte fall due to gravity on next frame
         velocityY = velocityY + bulletGravity;
     }//end loop
     // function end
 }
Esempio n. 3
0
        /// <summary>
        /// moves the given projectile according to its angle, power, gravity and the wind.
        /// </summary>
        public override void Tick()
        {
            // each tick occures ten times in a frame
            //loop procedure 10 times
            for (int Loop = 0; Loop < 10; Loop++)
            {
                // increase the location of bullet by velocity
                bulletX = bulletX + velocityX;
                bulletY = bulletY + velocityY;
                // move the bullet according to the current wind
                // get windspeed
                float wind = this.currrentGame.GetWind() / 1000.0f;
                // move bullet's horizontal postion by adding the wind
                bulletX = bulletX + (wind);
                //check to see if bullet has moved outside game bounds
                if (bulletX > Battlefield.WIDTH | bulletY > Battlefield.HEIGHT | bulletX < 0)
                {
                    //destroy bullet as its gone too far
                    this.currrentGame.RemoveWeaponEffect(this);
                    return; //exit function as bullet doesnt exist anymore
                }
                else // bullet inside bounds
                {
                    // check to see if a bullet has hit a tank or collision
                    if (this.currrentGame.CheckCollidedTank(bulletX, bulletY))
                    {
                        //record the hit if the owner's tank isnt at location
                        if (!CheckPlayerOwner(bulletOwner, (int)bulletX))
                        {
                            bulletOwner.ReportHit(bulletX, bulletY);
                        }

                        //cause explosion
                        bulletExplosion.Explode(bulletX, bulletY);
                        //add the explosion to effects
                        this.currrentGame.AddEffect(bulletExplosion);
                        //destroy this bullet
                        this.currrentGame.RemoveWeaponEffect(this);
                        //create a new bullet and explosion for the inner shell
                        //add it to the environment
                        InnerShell();

                        return; // exit function as bullet doesnt exist anymore
                    }
                }
                // calucalte fall due to gravity on next frame
                velocityY = velocityY + bulletGravity;
                ////work out the new bullet angle
                //// in the constructor we have a formula to work out the velocity from the angle
                //// to find the angle we just reverse the formula

                //// velocityY = Math.Sin(angleRadians) * -bulletPower
                //// velocityY/-bulletPower = Math.Sin(angleRadians)
                //// Math.Asin(velocityY/-bulletPower) = angleRadians
                ////now we can get the radians on the angle for the bullet

                //bulletAngle =-1f*(float)Math.Asin(  (Math.Abs(velocityY) / bulletPower))  ;
                //// use the radians to get the using the formula in the constructor
                //// radians = (90 - angle) * (float)Math.PI / 180
                //// radians/(Math.PI/180) = 90-angle
                //// (radians/(Math.PI/180))-90 = -angle
                ////-1 * ( (radians/ (Math.PI/180) ) -90 ) =  angle
                //bulletAngle = -1f * ((bulletAngle / (float)(Math.PI / 180f)) - 90f);

                //end loop
            }
            // function end
        }