コード例 #1
0
        public override void Step()
        {
            // Moving the projectile
            for (int i = 0; i < 10; i++)
            {
                xPos += xVel;
                yPos += yVel;

                xPos += gcGame.WindSpeed() / 1000.0f;

                if (xPos < 0 || xPos > Battlefield.WIDTH || yPos > Battlefield.HEIGHT /* || yPos <= 0*/)
                {
                    gcGame.EndEffect(this);
                    return;
                }
                else if (yPos <= 0)
                {
                    yVel += graV;
                }
                else if (gcGame.CheckHitTank(xPos, yPos) && !(yPos <= 0))
                {
                    tankPlayer.ProjectileHit(xPos, yPos);
                    exP.Explode(xPos, yPos);
                    gcGame.AddEffect(exP);
                    gcGame.EndEffect(this);
                    return;
                }

                yVel += graV;
            }
        }
コード例 #2
0
ファイル: Projectile.cs プロジェクト: tdiego95/TankBattle
        //calculate the path of the projectile and eventually the hit and explosion
        public override void ProcessTimeEvent()
        {
            for (int i = 0; i < 10; i++)
            {
                x += xVelocity;
                y += yVelocity;
                x += game.Wind() / 1000.0f;

                if (x > Map.HEIGHT || y > Map.WIDTH)
                {
                    game.EndEffect(this);
                }
                else if (game.DetectCollision(x, y))
                {
                    player.ProjectileHit(x, y);
                    explosion.Detonate(x, y);
                    game.AddWeaponEffect(explosion);
                    game.EndEffect(this);
                    return;
                }

                yVelocity += gravity;
            }
        }