Ejemplo n.º 1
0
        /// <summary>
        /// This method draws the Shell as a small white circle.
        /// </summary>
        public override void Step()
        {
            for (int i = 0; i < 10; i++)
            {
                x += xVelocity;
                y += yVelocity;
                x += game.WindSpeed() / 1000.0f;

                //if we go out of bounds, cancel the whole thing
                if (x > Battlefield.WIDTH || x < 0 || y > Battlefield.HEIGHT)
                {
                    game.CancelEffect(this);
                }
                // if we detect a collision hit the tank
                else if (game.CheckCollidedTank(x, y))
                {
                    player.ReportHit(x, y); //used for the computer player
                    explosion.Detonate(x, y);
                    game.AddWeaponEffect(explosion);
                    game.CancelEffect(this);
                    return;
                }
                yVelocity += gravity;
            }
        }
Ejemplo 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
 }
Ejemplo 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
        }