コード例 #1
0
ファイル: Ball.cs プロジェクト: alexdbaldwin/ab4645-Breakout
        public Ball(Player player, Vector2 position, float radius, float maxY, World world) : base(world) {
            this.player = player;
            this.radius = ConvertUnits.ToSimUnits(player.BallRadius);
            this.maxY = maxY;

            switch (player.Index)
            {
                case PlayerIndex.One:
                    trail = ParticleEmitter.SpawnGenericProjectileEmitterRed(ConvertUnits.ToDisplayUnits(position));
                    break;
                case PlayerIndex.Two:
                    trail = ParticleEmitter.SpawnGenericProjectileEmitterBlue(ConvertUnits.ToDisplayUnits(position));
                    break;
                default:
                    trail = ParticleEmitter.SpawnGenericProjectileEmitterRed(ConvertUnits.ToDisplayUnits(position));
                    break;
            }

            trail.startScale = 0.5f * ConvertUnits.ToDisplayUnits(this.radius) / 10.0f;
            trail.endScale = 0.05f * ConvertUnits.ToDisplayUnits(this.radius) / 10.0f;


            body = BodyFactory.CreateCircle(world, this.radius, 1, position);
            body.BodyType = BodyType.Dynamic;
            body.CollidesWith = Category.Cat2 | Category.Cat4;
            body.CollisionCategories = Category.Cat1;
            body.Restitution = 1.0f;
            body.Friction = 0.0f;
            body.OnCollision += OnCollision;

            //body.ApplyLinearImpulse(new Vector2(-0.2f, -1f)*0.8f);
            body.UserData = this;

            speed = Owner.BallSpeed;
            //body.LinearVelocity = Vector2.Normalize(new Vector2(-1f, -1f))*10f;
        }
コード例 #2
0
 public void ArmPlayer(Player p){
     p.Paddle.ActivateGun(15);
 }
コード例 #3
0
 public void ShrinkBalls(Player player)
 {
     player.BallRadius = MathHelper.Clamp(player.BallRadius * 0.75f, 3.0f, 30.0f);
     for (int i = gameObjects.Count - 1; i >= 0; i--)
     {
         if (gameObjects[i] is Ball && (gameObjects[i] as Ball).Owner == player)
         {
             (gameObjects[i] as Ball).UpdateRadius(player.BallRadius);
         }
     }
 }
コード例 #4
0
 public void EnlargeBalls(Player player)
 {
     player.BallRadius = MathHelper.Clamp(player.BallRadius * 1.5f, 10f, 50.0f);
     for (int i = gameObjects.Count - 1; i >= 0; i--)
     {
         if (gameObjects[i] is Ball && (gameObjects[i] as Ball).Owner == player)
         {
             (gameObjects[i] as Ball).UpdateRadius(player.BallRadius);
         }
     }
 }
コード例 #5
0
 public void SlowDownBalls(Player player)
 {
     player.BallSpeed = MathHelper.Clamp(player.BallSpeed * 0.75f, 5.0f, 30.0f);
     for (int i = gameObjects.Count - 1; i >= 0; i--)
     {
         if (gameObjects[i] is Ball && (gameObjects[i] as Ball).Owner == player)
         {
             (gameObjects[i] as Ball).UpdateSpeed(player.BallSpeed);
         }
     }
 }
コード例 #6
0
        public void SplitBalls(Player player)
        {
            for(int i = gameObjects.Count - 1; i >= 0; i--)
            {
                if (gameObjects[i] is Ball && (gameObjects[i] as Ball).Owner == player) {
                    

                    float angle = (float)Game1.rand.NextDouble() * MathHelper.TwoPi;
                    Vector2 heading = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
                    (gameObjects[i] as Ball).Launch(heading);

                    for(int j = 0; j < Game1.rand.Next(2,5); j++)
                    {
                        if (player.Balls >= 15)
                            continue;
                        angle = (float)Game1.rand.NextDouble() * MathHelper.TwoPi;
                        heading = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));



                        player.AddBall();
                        Ball b = new Ball(player, gameObjects[i].Position + new Vector2(0, 0.001f), ConvertUnits.ToSimUnits(10.0f), ConvertUnits.ToSimUnits(screenHeight), world);
                        gameObjects.Add(b);
                        b.Launch(heading);
                    }
                }
            }
        }
コード例 #7
0
 /// <summary>
 /// Spawns a ball and attaches it to player's paddle
 /// </summary>
 /// <param name="player"></param>
 public void SpawnBall(Player player) {
     player.AddBall();
     Ball b = new Ball(player, ConvertUnits.ToSimUnits(new Vector2(screenWidth / 2.0f, screenHeight - 400.0f)), ConvertUnits.ToSimUnits(10.0f), ConvertUnits.ToSimUnits(screenHeight), world);
     gameObjects.Add(b);
     player.Paddle.Attach(b);
 }
コード例 #8
0
 private void RestartGame(PlayerIndex player) {
     twoPlayers = false;
     levelIndex = 0;
     player1 = null;
     player2 = null;
     ClearGameObjects();
     LoadLevel(levels[levelIndex]);
     JoinGame(player);
     currentGameState = GameState.Playing;
 }
コード例 #9
0
        private void UpdatePlaying(GameTime gameTime)
        {
            for (int i = 0; i < gameObjects.Count; i++)
            {
                gameObjects[i].Update(gameTime);
                if (gameObjects[i].Dead)
                {
                    if (gameObjects[i] is Ball)
                    {
                        (gameObjects[i] as Ball).Owner.RemoveBall();
                    }
                    if (gameObjects[i] is Block) {
                        blocksRemaining--;
                        if (Game1.rand.NextDouble() < powerUpSpawnChance)
                            SpawnRandomPowerUp(gameObjects[i].Position);
                    }
                    gameObjects[i].CleanUp();
                    gameObjects.RemoveAt(i--);
                }
            }

            if (blocksRemaining <= 0 && levelIndex < levels.Length - 1) {
                NextLevel();
            }

            if (player1 != null && !player1.Alive)
            {
                player1.Paddle.CleanUp();
                gameObjects.Remove(player1.Paddle);
                player1 = null;
                player2WaitTime = 20.0f;
            }
            if (player2 != null && !player2.Alive)
            {
                player2.Paddle.CleanUp();
                gameObjects.Remove(player2.Paddle);
                player2 = null;
                player2WaitTime = 20.0f;
            }

            if (!APlayerIsAlive())
            {
                GameOver();
            }

            DropInPlayer2(gameTime);

        }
コード例 #10
0
        private void JoinGame(PlayerIndex playerIndex) {
            switch (playerIndex)
            {
                case PlayerIndex.One:
                    if (player1 == null)
                    {
                        Paddle paddle1 = new Paddle(PlayerIndex.One, this, ConvertUnits.ToSimUnits(screenWidth / 2.0f, screenHeight - 100.0f), ConvertUnits.ToSimUnits(150.0f), ConvertUnits.ToSimUnits(21.0f), ConvertUnits.ToSimUnits(screenWidth / 2.0f - sideMargin), world);
                        gameObjects.Add(paddle1);
                        player1 = new Player(this, paddle1, PlayerIndex.One);
                        SpawnBall(player1);

                        //gameObjects.Add(new Ball(player1, ConvertUnits.ToSimUnits(new Vector2(screenWidth / 2.0f, screenHeight - 400.0f)), ConvertUnits.ToSimUnits(10.0f), world));
                    }
                    else {
                        throw new InvalidOperationException("Player One is already in the game.");
                    }
                    break;
                case PlayerIndex.Two:
                    if (player2 == null)
                    {
                        Paddle paddle2 = new Paddle(PlayerIndex.Two, this, ConvertUnits.ToSimUnits(screenWidth / 2.0f, screenHeight - 100.0f), ConvertUnits.ToSimUnits(150.0f), ConvertUnits.ToSimUnits(21.0f), ConvertUnits.ToSimUnits(screenWidth / 2.0f - sideMargin), world);
                        gameObjects.Add(paddle2);
                        player2 = new Player(this, paddle2, PlayerIndex.Two);
                        SpawnBall(player2);

                        //gameObjects.Add(new Ball(player2, ConvertUnits.ToSimUnits(new Vector2(screenWidth / 2.0f, screenHeight - 400.0f)), ConvertUnits.ToSimUnits(10.0f), world));
                    }
                    else {
                        throw new InvalidOperationException("Player Two is already in the game.");
                    }
                    break;
                default:
                    break;
            }
        }