Ejemplo n.º 1
0
        private void shieldLogic(Tank tank, Tank otherTank, PowerUp powerUp)
        {
            shieldHealthRect.X          = (int)tank.getTankPos().X - 20;
            shieldHealthRect.Y          = (int)tank.getTankPos().Y - 40;
            ShieldLayer.powerUpPosition = tank.getTankPos() - new Vector2(8, 20);
            if (powerUp.collisionRect.Intersects(otherTank.bullet.collisionRect))
            {
                otherTank.bullet.outOfBounds = true;
                if (otherTank.bullet.type == BulletType.TeleportShot)
                {
                    otherTank.bullet.speed.X = -(otherTank.bullet.speed.X);
                }

                shieldHealth          -= otherTank.bullet.damage / 10;
                shieldHealthRect.Width = shieldHealth;
                game.soundManager.shieldHit.Play();

                if (shieldHealth <= 100)
                {
                    ShieldLayer.powerUpPic = Game.Content.Load <Texture2D>(@"Images/BrokenShield");
                }

                if (shieldHealth <= 0)
                {
                    game.soundManager.shieldBreaking.Play();
                    powerList.Remove(powerUp);
                    shieldActive   = false;
                    play1HasShield = false;
                    play2HasShield = false;
                }
            }
        }
Ejemplo n.º 2
0
 public void PowerUpEffect(PowerUp powerUp, Tank tank)
 {
     if (powerUp == Health)
     {
         game.uiManager.floatingPowerUpText("+100 Health", tank.getTankPos());
         tank.healTank(100);
     }
     if (powerUp == HeavyShot)
     {
         game.uiManager.floatingPowerUpText("Heavy Shot +1", tank.getTankPos());
         tank.inventory.incrementShot(BulletType.HeavyShot);
     }
     if (powerUp == ScatterShot)
     {
         game.uiManager.floatingPowerUpText("ScatterShot +1", tank.getTankPos());
         tank.inventory.incrementShot(BulletType.ScatterShot);
     }
     if (powerUp == ExtraMovement)
     {
         game.uiManager.floatingPowerUpText("Move Limit +3", tank.getTankPos());
         tank.moveLimit += 3;
     }
     if (powerUp == ShieldPower)
     {
         game.uiManager.floatingPowerUpText("Shield", tank.getTankPos());
         updateShield(tank.getTankPos());
     }
 }
Ejemplo n.º 3
0
        private void takeTurn(GameTime time)
        {
            if (currentTank.turnTime > 0 & !shotFired)
            {
                if (currentTank.inventory.getShotCount(currentTank.type) < 1)
                {
                    currentTank.type = currentTank.inventory.findNextShotType();
                }

                if (currentTank.moveLimit > 0)
                {
                    currentTank.move(time);
                }

                if ((currentTank.tankPosition.X > 180 && currentTank.tankPosition.X < 468) || (currentTank.tankPosition.X > 1160 && currentTank.tankPosition.X < 1260))
                {
                    currentTank.rotateTurret(2, -1);
                }
                else if ((currentTank.tankPosition.X > 705 && currentTank.tankPosition.X < 950) || (currentTank.tankPosition.X > 1540 && currentTank.tankPosition.X < 1795))
                {
                    currentTank.rotateTurret(1, -2);
                }
                else
                {
                    currentTank.rotateTurret(Math.PI / 2, -Math.PI / 2);
                }

                if (screenManager.currentState == ScreenManager.GameState.PLAYER1)
                {
                    cameraFollow(player1Tank.getTankPos());
                }
                else if (screenManager.currentState == ScreenManager.GameState.PLAYER2)
                {
                    cameraFollow(player2Tank.getTankPos());
                }

                playerControls();

                currentTank.turnTime -= (float)time.ElapsedGameTime.TotalSeconds;
                screenManager.updateTime((int)currentTank.turnTime, (int)currentTank.moveLimit);

                if (currentTank.turnTime < 0 & !(chargingShot || chargingShot2))
                {
                    turnOver = true;
                }
            }

            else if (chargingShot || chargingShot2)
            {
                currentTank.shoot(power);
                chargingShot  = false;
                chargingShot2 = false;
                shotFired     = true;
                setPreviousShotLine();
            }

            if (shotFired & !shotCollided)
            {
                if (currentTank.firstShot)
                {
                    currentTank.firstShot = false;
                }

                cameraFollow(currentTank.bullet.getBulletPosition());

                if (currentTank.bullet.type == BulletType.ScatterShot)
                {
                    if ((Keyboard.GetState().IsKeyDown(Keys.Space) || controller.IsButtonDown(Buttons.RightTrigger)) & !
                        ((ScatterShot)currentTank.bullet).scattered)
                    {
                        ((ScatterShot)currentTank.bullet).scatter();
                    }
                }

                #region MissileDropCollision

                if (currentTank.bullet.type == BulletType.MissileDrop && ((MissileDrop)currentTank.bullet).targetLockedOn)
                {
                    Missile currentMissile = ((MissileDrop)currentTank.bullet).missile;

                    if (currentMissile.intersectPixels(player1Tank.getTankRect(), player1Tank.tankTextureData) && currentTank != player1Tank ||
                        currentMissile.intersectPixels(player2Tank.getTankRect(), player2Tank.tankTextureData) && currentTank != player2Tank ||
                        currentMissile.intersectPixels(background.layers[1].Sprites[0].Position, background.terrainTextureData) ||
                        currentMissile.outOfBounds)
                    {
                        currentMissile.bulletCollided();

                        shotCollided = true;
                        shotPause    = 2.0f;
                    }

                    if (currentMissile.explosion != null)
                    {
                        if (currentTank != player1Tank)
                        {
                            if (currentMissile.explosion.collisionRectangle.Intersects(player1Tank.collisionRect) & !currentMissile.damageDealt)
                            {
                                player1Tank.takeDamage(currentMissile.damage);
                                GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f);
                                uiManager.floatingDamageText(currentMissile.damage.ToString(), currentMissile.getBulletPosition());
                                currentMissile.damageDealt = true;
                            }
                        }

                        if (currentTank != player2Tank)
                        {
                            if (currentMissile.explosion.collisionRectangle.Intersects(player2Tank.collisionRect) & !currentMissile.damageDealt)
                            {
                                player2Tank.takeDamage(currentMissile.damage);
                                GamePad.SetVibration(PlayerIndex.Two, 1.0f, 1.0f);
                                uiManager.floatingDamageText(currentMissile.damage.ToString(), currentMissile.getBulletPosition());
                                currentMissile.damageDealt = true;
                            }
                        }
                    }
                }

                #endregion MissileDropCollision

                #region ScatterShotCollision

                else if (currentTank.bullet.type == BulletType.ScatterShot && ((ScatterShot)currentTank.bullet).scattered)
                {
                    foreach (Shots s in ((ScatterShot)currentTank.bullet).scatterShots)
                    {
                        if (s.intersectPixels(player1Tank.getTankRect(), player1Tank.tankTextureData) && currentTank != player1Tank ||
                            s.intersectPixels(player2Tank.getTankRect(), player2Tank.tankTextureData) && currentTank != player2Tank ||
                            s.intersectPixels(background.layers[1].Sprites[0].Position, background.terrainTextureData) ||
                            s.outOfBounds)
                        {
                            s.bulletCollided();
                        }

                        if (s.explosion != null)
                        {
                            if (currentTank != player1Tank)
                            {
                                if (s.explosion.collisionRectangle.Intersects(player1Tank.collisionRect) & !s.damageDealt)
                                {
                                    player1Tank.takeDamage(s.damage);
                                    GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f);
                                    uiManager.floatingDamageText(s.damage.ToString(), s.getBulletPosition());
                                    s.damageDealt = true;
                                }
                            }

                            if (currentTank != player2Tank)
                            {
                                if (s.explosion.collisionRectangle.Intersects(player2Tank.collisionRect) & !s.damageDealt)
                                {
                                    player2Tank.takeDamage(s.damage);
                                    GamePad.SetVibration(PlayerIndex.Two, 1.0f, 1.0f);
                                    uiManager.floatingDamageText(s.damage.ToString(), s.getBulletPosition());
                                    s.damageDealt = true;
                                }
                            }
                        }
                    }

                    bool scatterCollided = false;
                    bool scatterChecked  = false;

                    for (int i = 0; i < ((ScatterShot)currentTank.bullet).scatterShots.Count; i++)
                    {
                        if (((ScatterShot)currentTank.bullet).scatterShots[i].exploded & !scatterChecked)
                        {
                            scatterCollided = true;
                        }
                        else
                        {
                            scatterCollided = false;
                            scatterChecked  = true;
                        }
                    }

                    if (scatterCollided)
                    {
                        shotCollided = true;
                        shotPause    = 2.0f;
                    }
                }

                #endregion ScatterShotCollision

                #region BasicCollision

                else if (currentTank.bullet.intersectPixels(player1Tank.getTankRect(), player1Tank.tankTextureData) && currentTank != player1Tank ||
                         currentTank.bullet.intersectPixels(player2Tank.getTankRect(), player2Tank.tankTextureData) && currentTank != player2Tank)
                {
                    shotCollided = true;
                    shotPause    = 2.0f;
                }
                else if (currentTank.bullet.intersectPixels(background.layers[1].Sprites[0].Position, background.terrainTextureData))
                {
                    if (currentTank.bullet.type == BulletType.TeleportShot)
                    {
                        currentTank.teleportTank(currentTank.bullet.getBulletPosition());
                        currentTank.terrainMovement();
                        currentTank.bullet.damageDealt = true;
                    }

                    shotCollided = true;
                    shotPause    = 1.0f;
                }
                else if (currentTank.bullet.outOfBounds)
                {
                    shotCollided = true;
                    shotPause    = 1.0f;
                }

                #endregion BasicCollision

                if (shotCollided && currentTank.bullet.type == BulletType.MissileDrop & !currentTank.bullet.outOfBounds)
                {
                    MissileDrop drop = ((MissileDrop)currentTank.bullet);

                    if (!drop.targetLockedOn)
                    {
                        if (currentTank != player1Tank)
                        {
                            drop.sendTankData(player1Tank.getTankPos(), player1Tank.getTankRect().Width / 2,
                                              player1Tank.tankPic.Width, player1Tank.tankPic.Height, player1Tank.collisionRect);
                        }
                        else if (currentTank != player2Tank)
                        {
                            drop.sendTankData(player2Tank.getTankPos(), player2Tank.getTankRect().Width / 2,
                                              player2Tank.tankPic.Width, player2Tank.tankPic.Height, player2Tank.collisionRect);
                        }

                        if (drop.scanTarget())
                        {
                            shotCollided = false;
                            shotPause    = 0;
                        }
                    }
                }
                else if (shotCollided)
                {
                    currentTank.bullet.bulletCollided();
                }

                if (currentTank.bullet.explosion != null)
                {
                    if (currentTank != player2Tank)
                    {
                        if (currentTank.bullet.explosion.collisionRectangle.Intersects(player2Tank.collisionRect) & !currentTank.bullet.damageDealt)
                        {
                            player2Tank.takeDamage(currentTank.bullet.damage);
                            GamePad.SetVibration(PlayerIndex.Two, 1.0f, 1.0f);
                            uiManager.floatingDamageText(currentTank.bullet.damage.ToString(), currentTank.bullet.getBulletPosition());
                            currentTank.bullet.damageDealt = true;
                        }
                    }

                    if (currentTank != player1Tank)
                    {
                        if (currentTank.bullet.explosion.collisionRectangle.Intersects(player1Tank.collisionRect) & !currentTank.bullet.damageDealt)
                        {
                            player1Tank.takeDamage(currentTank.bullet.damage);
                            GamePad.SetVibration(PlayerIndex.One, 1.0f, 1.0f);
                            uiManager.floatingDamageText(currentTank.bullet.damage.ToString(), currentTank.bullet.getBulletPosition());
                            currentTank.bullet.damageDealt = true;
                        }
                    }
                }
            }
            else if (shotPause > 0)
            {
                shotPause -= (float)time.ElapsedGameTime.TotalSeconds;
                screenManager.updateTime((int)shotPause, (int)currentTank.moveLimit);

                if (shotPause < 0)
                {
                    turnOver = true;
                }
            }
            else if (turnOver)
            {
                gameRunning = false;
                turnsTaken++;
                GamePad.SetVibration(PlayerIndex.One, 0.0f, 0.0f);
                GamePad.SetVibration(PlayerIndex.Two, 0.0f, 0.0f);
                uiManager.removeText();
                swapPlayers();
            }
        }
Ejemplo n.º 4
0
        protected override void Update(GameTime gameTime)
        {
            //if (!gameRunning)
            //{
            //    if (!soundManager.introPlaying)
            //        soundManager.playIntro();
            //}
            //else
            //{
            //    if (!soundManager.backgroundPlaying)
            //        soundManager.playBackground();
            //}

            if (turnsTaken == 0 & !shotFired)
            {
                cameraFollow(currentTank.getTankPos());
            }

            player1Tank.checkAngle();
            player2Tank.checkAngle2();

            if (currentTank == player1Tank)
            {
                currentTank.turretPosition = new Vector2(currentTank.tankPosition.X + 45, currentTank.tankPosition.Y + 10);
                controller = GamePad.GetState(PlayerIndex.One);
                currentTank.recieveController(GamePad.GetState(PlayerIndex.One));
            }

            if (currentTank == player2Tank)
            {
                currentTank.turretPosition = new Vector2(currentTank.tankPosition.X + 30, currentTank.tankPosition.Y + 10);
                controller = GamePad.GetState(PlayerIndex.Two);
                currentTank.recieveController(GamePad.GetState(PlayerIndex.Two));
            }

            if ((currentTank.tankPosition.X > 180 && currentTank.tankPosition.X < 468) || (currentTank.tankPosition.X > 1160 && currentTank.tankPosition.X < 1260))
            {
                currentTank.turretPosition.X = currentTank.tankPosition.X + 50;
                currentTank.turretPosition.Y = currentTank.tankPosition.Y + 15;
            }
            else if ((currentTank.tankPosition.X > 705 && currentTank.tankPosition.X < 950) || (currentTank.tankPosition.X > 1540 && currentTank.tankPosition.X < 1795))
            {
                currentTank.turretPosition.X = currentTank.tankPosition.X + 30;
                currentTank.turretPosition.Y = currentTank.tankPosition.Y + 15;
            }
            else
            {
                currentTank.turretPosition.X = currentTank.tankPosition.X + 40;
                currentTank.turretPosition.Y = currentTank.tankPosition.Y + 10;
            }

            if (controller.Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            screenManager.Update(gameTime);

            player1Tank.tempSpeed = 1f;
            player2Tank.tempSpeed = 1f;

            if (player1Tank.intersectPixels(background.layers[1].Sprites[0].Position, background.terrainTextureData))
            {
                player1Tank.tempSpeed = 0;
            }

            if (player2Tank.intersectPixels(background.layers[1].Sprites[0].Position, background.terrainTextureData))
            {
                player2Tank.tempSpeed = 0;
            }

            if (gameRunning)
            {
                //if (soundManager.introPlaying)
                //    soundManager.stopIntro();

                uiManager.Update(gameTime);
                background.Update(gameTime);

                takeTurn(gameTime);

                tankCollision(player1Tank, player2Tank);
                powerUpManager.PowerUpCollision(player1Tank, player2Tank);

                if (isGameOver() || Keyboard.GetState().IsKeyDown(Keys.P))
                {
                    gameRunning = false;
                    GamePad.SetVibration(PlayerIndex.One, 0.0f, 0.0f);
                    GamePad.SetVibration(PlayerIndex.Two, 0.0f, 0.0f);
                    screenManager.ChangeGameState(ScreenManager.GameState.END);
                }

                if (currentTank.turnTime <= 5 && currentTank.turnTime > 0)
                {
                    if (countdownTimer >= 1)
                    {
                        soundManager.timeBeep.Play();
                        countdownTimer = 0;
                    }
                    else
                    {
                        countdownTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                }
            }

            if (screenManager.currentState == ScreenManager.GameState.END)
            {
                resetSetting();
            }

            uiManager.moveFloatingText();

            base.Update(gameTime);
        }
Ejemplo n.º 5
0
        private void shieldLogic(Tank tank, Tank otherTank, PowerUp powerUp)
        {
            shieldHealthRect.X = (int)tank.getTankPos().X - 20;
            shieldHealthRect.Y = (int)tank.getTankPos().Y - 40;
            ShieldLayer.powerUpPosition = tank.getTankPos() - new Vector2(8, 20);
            if (powerUp.collisionRect.Intersects(otherTank.bullet.collisionRect))
            {
                otherTank.bullet.outOfBounds = true;
                if (otherTank.bullet.type == BulletType.TeleportShot)
                    otherTank.bullet.speed.X = -(otherTank.bullet.speed.X);

                shieldHealth -= otherTank.bullet.damage / 10;
                shieldHealthRect.Width = shieldHealth;
                game.soundManager.shieldHit.Play();

                if (shieldHealth <= 100)
                    ShieldLayer.powerUpPic = Game.Content.Load<Texture2D>(@"Images/BrokenShield");

                if (shieldHealth <= 0)
                {
                    game.soundManager.shieldBreaking.Play();
                    powerList.Remove(powerUp);
                    shieldActive = false;
                    play1HasShield = false;
                    play2HasShield = false;
                }
            }
        }
Ejemplo n.º 6
0
 public void PowerUpEffect(PowerUp powerUp, Tank tank)
 {
     if (powerUp == Health)
     {
         game.uiManager.floatingPowerUpText("+100 Health", tank.getTankPos());
         tank.healTank(100);
     }
     if (powerUp == HeavyShot)
     {
         game.uiManager.floatingPowerUpText("Heavy Shot +1", tank.getTankPos());
         tank.inventory.incrementShot(BulletType.HeavyShot);
     }
     if (powerUp == ScatterShot)
     {
         game.uiManager.floatingPowerUpText("ScatterShot +1", tank.getTankPos());
         tank.inventory.incrementShot(BulletType.ScatterShot);
     }
     if (powerUp == ExtraMovement)
     {
         game.uiManager.floatingPowerUpText("Move Limit +3", tank.getTankPos());
         tank.moveLimit += 3;
     }
     if (powerUp == ShieldPower)
     {
         game.uiManager.floatingPowerUpText("Shield", tank.getTankPos());
         updateShield(tank.getTankPos());
     }
 }