public void CheckForShoot(GameTime gameTime, Vector2 crossHairPoint) { timeSinceLastShot += (int)gameTime.ElapsedGameTime.TotalMilliseconds; if (timeSinceLastShot >= shootDelay) { if (Mouse.GetState().LeftButton == ButtonState.Pressed) { if (Vector2.Distance(Position, crossHairPoint) < Width) { return; } timeSinceLastShot = 0; Vector2 shootPoint = Position + new Vector2(Width * (float)Math.Cos(Rotation), Width * (float)Math.Sin(Rotation)); //float distance = Vector2.Distance(shootPoint, crossHair.CenterPoint); float distance = Vector2.Distance(Position, crossHairPoint) - Width; Vector2 target = shootPoint + new Vector2(distance * (float)Math.Cos(Rotation), distance * (float)Math.Sin(Rotation)); Bullet b = new ExplodingBullet(BulletType.Peanut, bulletSpeed, target); b.Width = bulletSize; b.Height = bulletSize; b.CenterPoint = shootPoint; } } }
public void CheckForShoot(GameTime gameTime, Vector2 crossHairPoint) { timeSinceLastShot += (int)gameTime.ElapsedGameTime.TotalMilliseconds; if (timeSinceLastShot >= shootDelay) { if (Mouse.GetState().LeftButton == ButtonState.Pressed) { if (Vector2.Distance(Position, crossHairPoint) < Width) return; timeSinceLastShot = 0; Vector2 shootPoint = Position + new Vector2(Width * (float)Math.Cos(Rotation), Width * (float)Math.Sin(Rotation)); //float distance = Vector2.Distance(shootPoint, crossHair.CenterPoint); float distance = Vector2.Distance(Position, crossHairPoint) - Width; Vector2 target = shootPoint + new Vector2(distance * (float)Math.Cos(Rotation), distance * (float)Math.Sin(Rotation)); Bullet b = new ExplodingBullet(BulletType.Peanut, bulletSpeed, target); b.Width = bulletSize; b.Height = bulletSize; b.CenterPoint = shootPoint; } } }