Exemple #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            new Camera(this, Vector2.Zero,
                       new Vector2(tileMap.GetLength(1) * tileWidth, tileMap.GetLength(0) * tileHeight));
            new InputEngine(this);

            //Player Service
            Services.AddService(new TilePlayer(this, new Vector2(64, 128), new List <TileRef>()
            {
                new TileRef(15, 2, 0),
                new TileRef(15, 3, 0),
                new TileRef(15, 4, 0),
                new TileRef(15, 5, 0),
                new TileRef(15, 6, 0),
                new TileRef(15, 7, 0),
                new TileRef(15, 8, 0),
            }, 64, 64, 0f));

            TilePlayer tilePlayer = Services.GetService <TilePlayer>();

            tilePlayer.AddHealthBar(new HealthBar(tilePlayer.Game, tilePlayer.PixelPosition));
            SetColliders(TileType.BLUEBOX);

            player = (TilePlayer)Services.GetService(typeof(TilePlayer));

            base.Initialize();
        }
Exemple #2
0
        public override void Update(GameTime gameTime)
        {
            if (InputEngine.IsKeyHeld(Keys.Left))
            {
                move(new Vector2(-1, 0) * CameraSpeed, Game.GraphicsDevice.Viewport);
            }
            if (InputEngine.IsKeyHeld(Keys.Right))
            {
                move(new Vector2(1, 0) * CameraSpeed, Game.GraphicsDevice.Viewport);
            }
            if (InputEngine.IsKeyHeld(Keys.Down))
            {
                move(new Vector2(0, 1) * CameraSpeed, Game.GraphicsDevice.Viewport);
            }
            if (InputEngine.IsKeyHeld(Keys.Up))
            {
                move(new Vector2(0, -1) * CameraSpeed, Game.GraphicsDevice.Viewport);
            }

            TilePlayer p = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

            if (p != null)
            {
                follow(p.PixelPosition, Game.GraphicsDevice.Viewport);

                //Make sure the player stays in the bounds
                p.PixelPosition = Vector2.Clamp(p.PixelPosition, Vector2.Zero,
                                                new Vector2(_worldBound.X - p.BoundingRectangle.Width,
                                                            _worldBound.Y - p.BoundingRectangle.Height));
            }
            base.Update(gameTime);
        }
Exemple #3
0
        public override void Update(GameTime gametime)
        {
            if (Helper.CurrentGameStatus == GameStatus.PLAYING)
            {
                TilePlayer          player        = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));
                TilePlayerTurret    playerTurret  = (TilePlayerTurret)Game.Services.GetService(typeof(TilePlayerTurret));
                List <SentryTurret> sentryTurrets = (List <SentryTurret>)Game.Services.GetService(typeof(List <SentryTurret>));

                if (player != null && playerTurret != null)
                {
                    if (State == PowerUpStatus.Deactivated && CollisionDetect(player))
                    {
                        Activate();
                    }

                    if (State == PowerUpStatus.Activated || State == PowerUpStatus.ExecuteOnce)
                    {
                        Duration += (float)gametime.ElapsedGameTime.TotalSeconds;

                        if (State != PowerUpStatus.ExecuteOnce)
                        {
                            Affect(player, playerTurret, sentryTurrets);
                        }

                        if (Duration >= MaxLifeTime)
                        {
                            State = PowerUpStatus.Depleted;
                            Deactivate(player, playerTurret, sentryTurrets);
                        }
                    }
                }

                base.Update(gametime);
            }
        }
Exemple #4
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            explosion = Content.Load <SoundEffect>("SoundFiles/Explosion");
            shoot     = Content.Load <SoundEffect>("SoundFiles/TankShot");

            backgroundAudio = Content.Load <Song>("SoundFiles/Battle_in_the_winter");
            gameOver        = Content.Load <Song>("SoundFiles/Game_Over");
            winner          = Content.Load <Song>("SoundFiles/Winner");

            gameOverScreen = Content.Load <Texture2D>(@"Game-Over");
            youWinScreen   = Content.Load <Texture2D>(@"YouWin");
            // TODO: Add your initialization logic here
            new Camera(this, Vector2.Zero,
                       new Vector2(tileMap.GetLength(1) * tileWidth, tileMap.GetLength(0) * tileHeight));
            new InputEngine(this);
            Services.AddService(new TilePlayer(this, new Vector2(64, 128), new List <TileRef>()
            {
                new TileRef(15, 2, 0),
                new TileRef(15, 3, 0),
                new TileRef(15, 4, 0),
                new TileRef(15, 5, 0),
                new TileRef(15, 6, 0),
                new TileRef(15, 7, 0),
                new TileRef(15, 8, 0),
            }, 64, 64, 0f));
            TilePlayer tilePlayer = Services.GetService <TilePlayer>();

            tilePlayer.AddHealthBar(new HealthBar(tilePlayer.Game, tilePlayer.PixelPosition));
            SetColliders(TileType.GROUND);
            SetColliders(TileType.BLUEBOX);
            SetColliders(TileType.GREEN);
            base.Initialize();
        }
Exemple #5
0
        private void DeathCam(TilePlayer player)
        {
            PenumbraComponent Penumbra = Game.Services.GetService <PenumbraComponent>();

            Zoom   += ZOOM_SPEED * (ZOOM_SPEED * 2);
            CamPos += new Vector2(Zoom * 2, Zoom * 2);
            Penumbra.Lights.Clear();
            Penumbra.Hulls.Clear();
        }
Exemple #6
0
 private void Awake()
 {
     Instance                = this;
     speed                   = Parameters.Parameters.Instance.playerSpeed;
     inputQueueSize          = Parameters.Parameters.Instance.inputQueueSize < 0 ? int.MaxValue : Parameters.Parameters.Instance.inputQueueSize;
     maxDistance             = 0;
     difficulty              = 0;
     autoMoveTimer           = GetAutomoveDelay();
     cameraMove.followPlayer = true;
 }
Exemple #7
0
        public override void Update(GameTime gameTime)
        {
            TilePlayer player = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

            #region Camera Shake Logic
            if (shaking)
            {
                // Move our timer ahead based on the elapsed time
                shakeTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;

                // If we're at the max duration, we're not going to be shaking anymore
                if (shakeTimer >= shakeDuration)
                {
                    shaking    = false;
                    shakeTimer = shakeDuration;
                }

                // Compute our progress in a [0, 1] range
                float progress = shakeTimer / shakeDuration;

                // Compute our magnitude based on our maximum value and our progress. This causes
                // the shake to reduce in magnitude as time moves on, giving us a smooth transition
                // back to being stationary. We use progress * progress to have a non-linear fall
                // off of our magnitude. We could switch that with just progress if we want a linear
                // fall off.

                float magnitude = shakeMagnitude * (1f - (progress * progress));

                // Generate a new offset vector with three random values and our magnitude

                shakeOffset = new Vector2(NextFloat(), NextFloat()) * magnitude;

                // If we're shaking, add our offset to our position and target

                _camPos    += shakeOffset;
                _followPos += shakeOffset;
            }
            #endregion

            if (player != null)
            {
                Follow((player.CentrePos + (player.Direction * CameraSpread)), Game.GraphicsDevice.Viewport, CameraSpeed);

                #region Clamp player within bounds
                player.PixelPosition = Vector2.Clamp(player.PixelPosition, Vector2.Zero,
                                                     new Vector2(_worldBound.X - player.BoundingRectangle.Width,
                                                                 _worldBound.Y - player.BoundingRectangle.Height));
                #endregion
            }

            // TILE GRID FIX
            //CamPos = new Vector2((int)CamPos.X, (int)CamPos.Y);

            base.Update(gameTime);
        }
Exemple #8
0
        public void Deactivate(TilePlayer other, TilePlayerTurret otherTurret, List <SentryTurret> sentryTurrets)
        {
            switch (Type)
            {
            case PowerUpType.Heal:
                // Do nothing on deactivation
                break;

            case PowerUpType.DefenseBoost:
                foreach (SentryTurret turret in sentryTurrets)
                {
                    if (turret != null)
                    {
                        turret.Bullet.playerDamageRate = defaultPlayerDamageRate;
                    }
                }
                break;

            case PowerUpType.SpeedBoost:
                other.MaxVelocity  = defaultMaxVelocity;
                other.Acceleration = defaultPlayerAcceleration;
                other.Deceleration = defaultPlayerDeceleration;
                other.turnSpeed    = defaultTurnSpeed;
                break;

            case PowerUpType.ExtraDamage:
                otherTurret.Bullet = defaultBullet;
                otherTurret.Bullet.sentryDamageRate = defaultSentryDamageRate;
                otherTurret.ShellSound = defaultShellSnd;
                break;

            case PowerUpType.Camouflage:
                other.Alpha       = 1;
                otherTurret.Alpha = 1;

                List <Sentry> otherTanks = (List <Sentry>)Game.Services.GetService(typeof(List <Sentry>));

                foreach (Sentry tank in otherTanks)
                {
                    if (tank != null)
                    {
                        tank.StayVisible = false;
                    }
                }

                foreach (SentryTurret turret in sentryTurrets)
                {
                    if (turret != null)
                    {
                        turret.DetectRadius = defaultRadius;
                    }
                }
                break;
            }
        }
        public void FireArrow(TilePlayer p)
        {
            Bullet.PixelPosition = this.PixelPosition;

            Bullet.fire(p.PixelPosition);
            PlayGunFire();



            UpdateFireState(false);
        }
 public bool IsPlayerHit(TilePlayer p)
 {
     if (Bullet.SourceRectangle.Contains(p.PixelPosition.ToPoint()))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #11
0
        private void RunToPlayer(TilePlayer player)
        {
            distance = Math.Abs(Vector2.Distance(this.CentrePos, player.CentrePos));

            if (distance <= RUN_RADIUS)
            {
                PixelPosition = Vector2.Lerp(
                    this.PixelPosition,
                    player.PixelPosition,
                    RUN_SPEED);
            }
        }
Exemple #12
0
    private void EnablePlayerTiles()
    {
        TilePlayer turnPlayer = (TilePlayer)Enum.Parse(typeof(TilePlayer), GameController.turnPlayer.ToString());

        foreach (Tile t in board)
        {
            if (t.Player == turnPlayer && !t.moved)
            {
                t.button.interactable = true;
            }
        }
    }
Exemple #13
0
        public override void Draw(GameTime gameTime)
        {
            TilePlayer player = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

            if (attachToHUD && Helper.CurrentGameStatus == GameStatus.PAUSED || player.Health <= 0)
            {
                // Don't draw over pause screen.
            }
            else
            {
                base.Draw(gameTime);
            }
        }
Exemple #14
0
        private bool Winning()
        {
            TilePlayer player = Services.GetService <TilePlayer>();

            if (player.PixelPosition.X > 37 * 64 && player.PixelPosition.X < 38 * 64)
            {
                if (player.PixelPosition.Y > 15 * 64 && player.PixelPosition.Y < 16 * 64)
                {
                    return(true);
                }
            }
            return(false);
        }
        public bool IsPlayerInShootingArea(TilePlayer p)
        {
            float distance = Math.Abs(Vector2.Distance(this.PixelPosition, p.PixelPosition));

            if (distance < shootingArea)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #16
0
        public override void Update(GameTime gametime)
        {
            if (Helper.CurrentGameStatus == GameStatus.PLAYING)
            {
                OrbLight.Position = (CentrePos - Camera.CamPos);

                TilePlayer          player        = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));
                TilePlayerTurret    playerTurret  = (TilePlayerTurret)Game.Services.GetService(typeof(TilePlayerTurret));
                List <SentryTurret> sentryTurrets = (List <SentryTurret>)Game.Services.GetService(typeof(List <SentryTurret>));

                if (player != null && playerTurret != null)
                {
                    if (State == PowerUpStatus.Deactivated && CollisionDetect(player))
                    {
                        Activate();
                    }

                    if (State == PowerUpStatus.Activated || State == PowerUpStatus.ExecuteOnce)
                    {
                        // Comment out to make effects last infinitely.
                        //Duration += (float)gametime.ElapsedGameTime.TotalSeconds;

                        attachToHUD = true;

                        if (State != PowerUpStatus.ExecuteOnce)
                        {
                            Affect(gametime, player, playerTurret, sentryTurrets);
                        }

                        if (Duration >= MaxLifeTime)
                        {
                            State = PowerUpStatus.Depleted;
                            Deactivate(player, playerTurret, sentryTurrets);
                        }
                    }

                    RunToPlayer(player);

                    // Cool Down Timer
                    if (State == PowerUpStatus.Depleted && coolDownTime <= MAX_COOLDOWN)
                    {
                        coolDownTime += (float)gametime.ElapsedGameTime.TotalSeconds;
                    }

                    UpdateHUD(gametime);
                }

                base.Update(gametime);
            }
        }
        public override void Update(GameTime gameTime)
        {
            TilePlayer p = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

            if (p != null)
            {
                follow(p.Position, Game.GraphicsDevice.Viewport);
                // Make sure the player stays in the bounds
                p.Position = Vector2.Clamp(p.Position, Vector2.Zero,
                                           new Vector2(_worldBound.X - p.CollisionField.Width,
                                                       _worldBound.Y - p.CollisionField.Height));
            }
            base.Update(gameTime);
        }
Exemple #18
0
        private int defaultRadius;           // Player spotted radius.
        #endregion

        #region Constructors
        public PowerUp(Game game, Vector2 position, List <TileRef> sheetRefs,
                       int frameWidth, int frameHeight, float layerDepth,
                       float maxLifeTime, PowerUpType type, int amount, float multiplier,
                       SoundEffect pickupSnd)
            : base(game, position, sheetRefs, frameWidth, frameHeight, layerDepth)
        {
            Visible          = true;
            DrawOrder        = 100;
            this.Type        = type;
            this.MaxLifeTime = maxLifeTime;
            this.Factor      = multiplier;
            this.Amount      = amount;
            this.State       = PowerUpStatus.Deactivated;

            #region Get Default Values
            TilePlayer          player        = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));
            TilePlayerTurret    playerTurret  = (TilePlayerTurret)Game.Services.GetService(typeof(TilePlayerTurret));
            List <SentryTurret> sentryTurrets = (List <SentryTurret>)Game.Services.GetService(typeof(List <SentryTurret>));

            if (player != null)
            {
                defaultMaxVelocity        = player.MaxVelocity;
                defaultPlayerAcceleration = player.Acceleration;
                defaultPlayerDeceleration = player.Deceleration;
            }

            foreach (SentryTurret turret in sentryTurrets)
            {
                if (turret != null)
                {
                    // Finds first enemy tank in list that's not NULL and takes those as default values.
                    defaultPlayerDamageRate = turret.Bullet.playerDamageRate;
                    defaultRadius           = turret.DetectRadius;
                    break;
                }
            }

            if (playerTurret != null)
            {
                defaultSentryDamageRate = playerTurret.Bullet.sentryDamageRate;
            }
            #endregion

            #region Handle Audio
            this.pickupSnd = pickupSnd;
            pickupSndInst  = this.pickupSnd.CreateInstance();
            #endregion
        }
Exemple #19
0
        private void Affect(TilePlayer other, TilePlayerTurret otherTurret, List <SentryTurret> sentryTurrets)
        {
            switch (Type)
            {
            case PowerUpType.Heal:
                other.Health += Amount * (int)Factor;
                State         = PowerUpStatus.Depleted;
                break;

            case PowerUpType.DefenseBoost:
                foreach (SentryTurret turret in sentryTurrets)
                {
                    if (turret != null)
                    {
                        turret.Bullet.playerDamageRate /= (int)Factor;
                    }
                }
                State = PowerUpStatus.ExecuteOnce;
                break;

            case PowerUpType.SpeedBoost:
                // Accelerate slowly, gain more speed and stop your tracks faster!
                other.MaxVelocity *= Factor;
                //other.Acceleration = other.Acceleration * Factor;
                other.Deceleration *= Factor;
                State = PowerUpStatus.ExecuteOnce;
                break;

            case PowerUpType.ExtraDamage:
                otherTurret.Bullet.sentryDamageRate *= (int)Factor;
                State = PowerUpStatus.ExecuteOnce;
                break;

            case PowerUpType.Camouflage:
                foreach (SentryTurret turret in sentryTurrets)
                {
                    if (turret != null)
                    {
                        turret.DetectRadius = Amount * (int)Factor;
                    }
                }
                State = PowerUpStatus.ExecuteOnce;
                break;
            }
        }
Exemple #20
0
    private bool TestTile(int tile, TilePlayer tilePlayer)
    {
        PlayerInfo player = (PlayerInfo)Enum.Parse(typeof(PlayerInfo), tilePlayer.ToString());

        if (board[tile].card == null) //if there is no card at destination
        {
            return(true);
        }

        if (board[tile].card.player.player == player) //if the card is an ally
        {
            return(false);
        }
        else if (combat) //prevents a second combat from happening
        {
            return(false);
        }
        return(true);
    }
	IEnumerator addRoom(int xPos, int yPos, Room sourceRoom, Tile.Direction dir){
		if (sourceRoom != null) {
			//audioSource.clip = runeSound;
			runeSoundSource.Play ();
			sourceRoom.doRuneAnimations ();
		}
		yield return null;
		while (areAnyAnimationsOccurring ()) {
			yield return null;
		}

		GameObject roomObj = Instantiate (sourceRoom==null ? firstRoomPrefab : roomPrefab, transform.position, Quaternion.identity) as GameObject;
		Room thisRoom = roomObj.GetComponent<Room> ();
		thisRoom.setup (xPos, yPos, this);

		//audioSource.clip = revealSound;
		revealSoundSource.Play ();

		if (sourceRoom != null) {
			int runeSeedFromCurRoom = sourceRoom.getSeedFromRunes ();
			thisRoom.seedRoom (runeSeedFromCurRoom);
		} else {
			thisRoom.seedFirstRoom ();

			//add the player
			thisRoom.addTileToGrid (playerTilePrefab, 1, 1);
			playerTile = (TilePlayer) thisRoom.Grid [1, 1];
			playerTile.manager = this;
		}

		yield return null;
		while (areAnyAnimationsOccurring ()) {
			yield return null;
		}

		rooms.Add (thisRoom);

		//if there was a source room, we shoudl move the player if possible
		if (sourceRoom != null) {
			rooms [rooms.Count - 1].tryToMovePlayerToRoom (playerTile, dir);
		}
	}
Exemple #22
0
    public void AddCard(UnitCard card)
    {
        if (card == null)
        {
            RemoveCard();
            return;
        }

        this.card = card;
        card.SetParent(rect);

        if (card.player.player == PlayerInfo.PLAYER1)
        {
            player = TilePlayer.PLAYER1;
        }
        else
        {
            player = TilePlayer.PLAYER2;
        }
    }
Exemple #23
0
        public void Deactivate(TilePlayer other, TilePlayerTurret otherTurret, List <SentryTurret> sentryTurrets)
        {
            switch (Type)
            {
            case PowerUpType.Heal:
                // Do nothing on deactivation
                break;

            case PowerUpType.DefenseBoost:
                foreach (SentryTurret turret in sentryTurrets)
                {
                    if (turret != null)
                    {
                        turret.Bullet.playerDamageRate = defaultPlayerDamageRate;
                    }
                }
                break;

            case PowerUpType.SpeedBoost:
                other.MaxVelocity  = defaultMaxVelocity;
                other.Acceleration = defaultPlayerAcceleration;
                other.Deceleration = defaultPlayerDeceleration;
                break;

            case PowerUpType.ExtraDamage:
                otherTurret.Bullet.sentryDamageRate = defaultSentryDamageRate;
                break;

            case PowerUpType.Camouflage:
                foreach (SentryTurret turret in sentryTurrets)
                {
                    if (turret != null)
                    {
                        turret.DetectRadius = defaultRadius;
                    }
                }
                break;
            }
        }
Exemple #24
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Gray);

            TilePlayer player = Services.GetService <TilePlayer>();
            SpriteFont font   = Services.GetService <SpriteFont>();

            if (player.Health <= 0)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(txGameOver, GraphicsDevice.Viewport.Bounds, Color.White);
                spriteBatch.End();
            }
            else if (win)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(txwinner, GraphicsDevice.Viewport.Bounds, Color.White);
                spriteBatch.End();
            }
            ///When all enemies are dead draws the you win Screen.
            ///Needs to be edited to allow the player to stand on the flag tile to Win.

            else
            {
                base.Draw(gameTime);
                spriteBatch.Begin();
                spriteBatch.DrawString(font, timeSpan.TotalSeconds.ToString(), new Vector2(10, 10), Color.White);
                spriteBatch.End();

                if (timeSpan.TotalSeconds <= 0)
                {
                    spriteBatch.Begin();
                    spriteBatch.Draw(txGameOver, GraphicsDevice.Viewport.Bounds, Color.White);
                    spriteBatch.End();
                }
            }
        }
Exemple #25
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            TilePlayer player = Services.GetService <TilePlayer>();

            if (player.Health > 0)
            {
                if (!sound && player.Health > 0 && timeSpan.TotalSeconds > 0 && !win)
                {
                    MediaPlayer.Play(bkMusic);
                    sound = true;
                }

                if (player.Health <= 0 || timeSpan.TotalSeconds <= 0)
                {
                    if (sound)
                    {
                        death.Play();
                        sound = false;
                    }
                }

                if (win)
                {
                    if (sound)
                    {
                        winner.Play();
                        sound    = false;
                        timeSpan = new TimeSpan(0, 0, 1);
                    }
                }
            }

            for (int i = 0; i < sentryList.Count; i++)
            {
                sentryList[i].follow(player);

                if (sentryList[i].sentryProjectile.ProjectileState == Projectile.PROJECTILE_STATE.EXPOLODING && sentryList[i].sentryProjectile.collisionDetect(player))
                {
                    if (!sentryList[i].sentryProjectile.hit)
                    {
                        player.Health -= 20;
                    }
                    sentryList[i].sentryProjectile.hit = true;
                }

                if (player.myProjectile.ProjectileState == Projectile.PROJECTILE_STATE.EXPOLODING && player.myProjectile.collisionDetect(sentryList[i]))
                {
                    if (!player.myProjectile.hit)
                    {
                        sentryList[i].KillTurret();
                        player.myProjectile.hit = true;
                    }
                }
            }

            if (SentryTurret.aliveSentries <= 0 && Winning())
            {
                win = true;
            }

            if (SentryTurret.aliveSentries <= 0)
            {
                SimpleTileLayer.Tiles[15, 37].TileRef = TileRefs[5];
            }

            timeSpan = new TimeSpan(0, 0, 200 - gameTime.TotalGameTime.Seconds);

            //for if there are no sentries left, show the exit tile as tile enum 5
            if (SentryTurret.aliveSentries <= 0)
            {
                SimpleTileLayer.Tiles[15, 37].TileRef = TileRefs[5];
            }

            //sentries set to follow the player
            for (int i = 0; i < sentryList.Count; i++)
            {
                sentryList[i].follow(player);
            }

            // TODO: Add your update logic here

            base.Update(gameTime);
        }
Exemple #26
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            //Audio Load
            bkMusic   = Content.Load <Song>("bkMusic");
            death     = Content.Load <SoundEffect>("Wasted");
            shot      = Content.Load <SoundEffect>("Grenade");
            explosion = Content.Load <SoundEffect>("Explosion");
            winner    = Content.Load <SoundEffect>("Winner");

            //Tiles for EndGame Screen
            txGameOver = Content.Load <Texture2D>(@"Tiles/Wasted");
            txwinner   = Content.Load <Texture2D>(@"Tiles/Winner");
            gameOver   = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(spriteBatch);
            Services.AddService(Content.Load <Texture2D>(@"Tiles/tank tiles 64 x 64"));
            Services.AddService(Content.Load <SpriteFont>(@"font"));

            // Tile References to be drawn on the Map corresponding to the entries in the defined
            // Tile Map
            // "free", "pavement", "ground", "blue", "home", "exit"
            TileRefs.Add(new TileRef(4, 2, 0));
            TileRefs.Add(new TileRef(3, 3, 1));
            TileRefs.Add(new TileRef(6, 3, 2));
            TileRefs.Add(new TileRef(6, 2, 3));
            TileRefs.Add(new TileRef(0, 2, 4));
            TileRefs.Add(new TileRef(3, 3, 5));
            // Names of the Tiles
            new SimpleTileLayer(this, backTileNames, tileMap, TileRefs, tileWidth, tileHeight);

            TilePlayer player = Services.GetService <TilePlayer>();

            //Projectile Service
            Projectile playerProjectile = new Projectile(this, new List <TileRef>()
            {
                new TileRef(7, 0, 0)
            },
                                                         new AnimateSheetSprite(this, player.PixelPosition, new List <TileRef>()
            {
                new TileRef(0, 0, 0),
                new TileRef(1, 0, 1),
                new TileRef(2, 0, 2),
            }, 64, 64, 0), player.PixelPosition, 1);

            SetColliders(TileType.BLUEBOX);
            SetColliders(TileType.EXIT);

            playerProjectile.AddShot(shot);
            playerProjectile.AddExplosionSound(explosion);

            player.LoadProjectile(playerProjectile);

            //This is the only bit of code done by either of my teammates, this part was done by Conor Flannery
            //Sentry Turret
            List <Tile> found = SimpleTileLayer.getNamedTiles(backTileNames[(int)TileType.GREENBOX]);

            // TODO: use this.Content to load your game content here

            for (int i = 0; i < found.Count; i++)
            {
                sentryTurret = new SentryTurret(this, new Vector2(found[i].X * tileWidth, found[i].Y * tileHeight), new List <TileRef>()
                {
                    new TileRef(21, 2, 0),
                    new TileRef(21, 3, 0),
                    new TileRef(21, 4, 0),
                    new TileRef(21, 5, 0),
                    new TileRef(21, 6, 0),
                    new TileRef(21, 7, 0),
                    new TileRef(21, 8, 0),
                }, 64, 64, 0f);
                sentryList.Add(sentryTurret);
            }
            //This is the end of the code done by Conor Flannery

            for (int i = 0; i < sentryList.Count; i++)
            {
                Projectile projectile = new Projectile(this, new List <TileRef>()
                {
                    new TileRef(8, 0, 0)
                },
                                                       new AnimateSheetSprite(this, sentryList[i].PixelPosition, new List <TileRef>()
                {
                    new TileRef(0, 0, 0),
                    new TileRef(1, 0, 1),
                    new TileRef(2, 0, 2)
                }, 64, 64, 0), sentryList[i].PixelPosition, 1);

                projectile.AddShot(shot);
                projectile.AddExplosionSound(explosion);

                sentryList[i].LoadProjectile(projectile);
                sentryList[i].Health = 20;
            }
        }
Exemple #27
0
 public void RemoveCard()
 {
     this.card = null;
     player    = TilePlayer.NEUTRAL;
 }
Exemple #28
0
        public override void Update(GameTime gameTime)
        {
            float deltaTime = gameTime.ElapsedGameTime.Milliseconds;

            switch (CurrentScreen)
            {
            case ActiveScreen.MAIN:
                if (Active)
                {
                    if (MediaPlayer.State == MediaState.Stopped)
                    {
                        MediaPlayer.Play(MenuTrack);
                    }
                }
                else
                {
                    MediaPlayer.Stop();
                    MediaPlayer.Play(BackingTrack);
                    CurrentScreen = ActiveScreen.PLAY;
                }

                if (fadeIn && OverlayAlpha <= 1)
                {
                    OverlayAlpha -= FADE_AMOUNT;
                }

                // Check Input
                if (InputEngine.IsKeyPressed(ActivationKey) ||
                    InputEngine.IsButtonPressed(ActivationButton))
                {
                    OverlayAlpha = 1;
                    BlinkPlay.Play();
                    Active = !Active;
                    Helper.CurrentGameStatus = GameStatus.PLAYING;
                }

                break;

            case ActiveScreen.PLAY:
                TilePlayer player = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

                if (Active)
                {
                    MediaPlayer.Stop();
                    PauseTime     = gameTime.TotalGameTime;
                    CurrentScreen = ActiveScreen.PAUSE;
                }

                if (player.Health > 0 && TimeRemaining > 0)
                {
                    TimeRemaining -= deltaTime;

                    // Check Input
                    if (InputEngine.IsKeyPressed(PauseKey) ||
                        InputEngine.IsButtonPressed(PauseButton))
                    {
                        Active = !Active;
                        BlinkPause.Play();
                        Helper.CurrentGameStatus = GameStatus.PAUSED;
                    }

                    if (OverlayAlpha <= 0)
                    {
                        fadeIn = false;
                    }
                    if (fadeIn && OverlayAlpha > 0)
                    {
                        OverlayAlpha -= FADE_AMOUNT;
                    }
                }
                else
                {
                    MediaPlayer.Stop();

                    // Wait for Input
                    if (InputEngine.IsPadInputChanged(true) ||
                        InputEngine.IsKeyInputChanged())
                    {
                        fadeOut = true;
                    }

                    if (fadeOut)
                    {
                        OverlayAlpha += FADE_AMOUNT;
                        if (OverlayAlpha >= 1)
                        {
                            Active = !Active;
                            CurrentGameCondition = GameCondition.LOSE;
                            CurrentScreen        = ActiveScreen.LOSE;
                            fadeIn = true;
                        }
                    }
                }

                if (CurrentGameCondition == GameCondition.WIN)
                {
                    OverlayAlpha += FADE_AMOUNT;
                    if (OverlayAlpha >= 1)
                    {
                        MediaPlayer.Stop();
                        Active        = !Active;
                        CurrentScreen = ActiveScreen.WIN;
                    }
                }
                break;

            case ActiveScreen.PAUSE:
                if (MediaPlayer.State == MediaState.Stopped)
                {
                    OverlayAlpha = 0.5f;
                    MediaPlayer.Play(PauseTrack);
                }

                if (!Active)
                {
                    MediaPlayer.Stop();
                    MediaPlayer.Play(BackingTrack);
                    CurrentScreen          = ActiveScreen.PLAY;
                    gameTime.TotalGameTime = PauseTime;
                }

                // Check Input
                if (InputEngine.IsKeyPressed(PauseKey) ||
                    InputEngine.IsButtonPressed(PauseButton))
                {
                    OverlayAlpha = 0;
                    Active       = !Active;
                    BlinkPause.Play();
                    Helper.CurrentGameStatus = GameStatus.PLAYING;
                }
                break;

            case ActiveScreen.LOSE:
                if (OverlayAlpha <= 1 || OverlayAlpha > 0)
                {
                    OverlayAlpha -= FADE_AMOUNT;
                }

                if (MediaPlayer.State == MediaState.Stopped && TrackPlayCount < 1)
                {
                    MediaPlayer.Play(GameOverTrack);
                    TrackPlayCount++;
                    MediaPlayer.IsRepeating = false;
                }
                Helper.CurrentGameStatus = GameStatus.PAUSED;
                break;

            case ActiveScreen.WIN:
                if (OverlayAlpha <= 1 || OverlayAlpha > 0)
                {
                    OverlayAlpha -= FADE_AMOUNT;
                }

                if (MediaPlayer.State == MediaState.Stopped && TrackPlayCount < 1)
                {
                    MediaPlayer.Play(WinTrack);
                    TrackPlayCount++;
                }

                frameTime += gameTime.ElapsedGameTime;

                if (frameTime.Milliseconds > FRAME_SPEED)
                {
                    txWin = txWinQueue.Dequeue();
                    txWinQueue.Enqueue(txWin);
                    frameTime = TimeSpan.Zero;
                }

                Helper.CurrentGameStatus = GameStatus.PAUSED;
                break;

            default:
                break;
            }

            base.Update(gameTime);
        }
	public void setPlayer(TilePlayer _player){
		player = _player;
	}
Exemple #30
0
        private int defaultRadius;           // Player spotted radius.
        #endregion
        #endregion

        #region Constructors
        public PowerUp(Game game, Vector2 position, List <TileRef> sheetRefs,
                       int frameWidth, int frameHeight, float layerDepth,
                       float maxLifeTime, PowerUpType type, int amount, float multiplier,
                       SoundEffect pickupSnd, SoundEffect camoSnd, Ricochet newRound)
            : base(game, position, sheetRefs, frameWidth, frameHeight, layerDepth)
        {
            Visible           = true;
            DrawOrder         = 100;
            this.Type         = type;
            this.MaxLifeTime  = maxLifeTime;
            this.Factor       = multiplier;
            this.Amount       = amount;
            this.State        = PowerUpStatus.Deactivated;
            this.newRound     = newRound;
            BoundingRectangle = new Rectangle(
                PixelPosition.ToPoint(),
                new Point(FrameWidth / 8, FrameHeight / 8));

            #region Get Default Values
            TilePlayer          player        = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));
            TilePlayerTurret    playerTurret  = (TilePlayerTurret)Game.Services.GetService(typeof(TilePlayerTurret));
            List <SentryTurret> sentryTurrets = (List <SentryTurret>)Game.Services.GetService(typeof(List <SentryTurret>));

            if (player != null)
            {
                defaultMaxVelocity        = player.MaxVelocity;
                defaultPlayerAcceleration = player.Acceleration;
                defaultPlayerDeceleration = player.Deceleration;
                defaultTurnSpeed          = player.turnSpeed;
            }

            foreach (SentryTurret turret in sentryTurrets)
            {
                if (turret != null)
                {
                    // Finds first enemy tank in list that's not NULL and takes those as default values.
                    defaultPlayerDamageRate = turret.Bullet.playerDamageRate;
                    defaultRadius           = turret.DetectRadius;
                    break;
                }
            }

            if (playerTurret != null)
            {
                defaultSentryDamageRate = playerTurret.Bullet.sentryDamageRate;
                defaultBullet           = playerTurret.Bullet;
                defaultShellSnd         = playerTurret.ShellSound;
            }
            #endregion

            #region Handle Audio
            this.pickupSnd = pickupSnd;
            pickupSndInst  = this.pickupSnd.CreateInstance();
            #endregion

            #region Setup OrbLight
            PenumbraComponent penumbra = Game.Services.GetService <PenumbraComponent>();
            penumbra.Lights.Add(OrbLight);

            switch (type)
            {
            case PowerUpType.Regen:
            case PowerUpType.Heal:
                OrbLight.Color = Color.LimeGreen;
                break;

            case PowerUpType.DefenseBoost:
                OrbLight.Color = Color.LightBlue;
                break;

            case PowerUpType.SpeedBoost:
                OrbLight.Color = Color.Orange;
                break;

            case PowerUpType.ExtraDamage:
                OrbLight.Color = Color.Red;
                break;

            case PowerUpType.Camouflage:
                OrbLight.Color = Color.Purple;
                break;

            default:
                OrbLight.Color = Color.White;
                break;
            }
            #endregion

            #region Setup Duration Bar
            if (Type == PowerUpType.Camouflage)
            {
                durationBar      = new HealthBar(game, CentrePos);
                durationBar.Name = Type.ToString();
                durationBar.txHealthBar.SetData(new[] { durationBarColor });
                AddHealthBar(durationBar);
                Health = (int)Duration;

                this.camoSnd       = camoSnd;
                camoSndInst        = this.camoSnd.CreateInstance();
                camoSndInst.Volume = 0.8f;
            }
            #endregion
        }
Exemple #31
0
        private void Affect(GameTime gameTime, TilePlayer other, TilePlayerTurret otherTurret, List <SentryTurret> sentryTurrets)
        {
            switch (Type)
            {
            case PowerUpType.Heal:
                Frames.Add(new TileRef(13, 2, 0));
                other.Health += Amount * (int)Factor;
                State         = PowerUpStatus.Depleted;
                break;

            case PowerUpType.Regen:
                Frames.Add(new TileRef(13, 2, 0));
                //Duration = 0;
                RegenTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (other.Health < 100 && other.Health > 0 && RegenTimer > 1)
                {
                    other.Health += Amount * (int)Factor;
                    RegenTimer    = 0;
                }
                break;

            case PowerUpType.DefenseBoost:
                Frames.Add(new TileRef(13, 1, 0));
                foreach (SentryTurret turret in sentryTurrets)
                {
                    if (turret != null)
                    {
                        turret.Bullet.playerDamageRate /= (int)Factor;
                    }
                }
                State = PowerUpStatus.ExecuteOnce;
                break;

            case PowerUpType.SpeedBoost:
                Frames.Add(new TileRef(13, 3, 0));
                other.MaxVelocity *= Factor;
                //other.Acceleration = other.Acceleration * Factor; // Immediately gain speed
                other.Deceleration *= Factor;
                other.turnSpeed    *= (Factor + (Factor / 2));
                State = PowerUpStatus.ExecuteOnce;
                break;

            case PowerUpType.ExtraDamage:
                Frames.Add(new TileRef(13, 0, 0));
                if (newRound != null)
                {
                    otherTurret.Bullet = newRound;
                }
                otherTurret.Bullet.sentryDamageRate *= (int)Factor;
                otherTurret.ShellSound = newRound.shellSoundAlt;
                State = PowerUpStatus.ExecuteOnce;
                break;

            case PowerUpType.Camouflage:
                Frames.Add(new TileRef(13, 4, 0));

                other.Alpha       = 0.5f;
                otherTurret.Alpha = 0.5f;

                foreach (SentryTurret turret in sentryTurrets)
                {
                    if (turret != null)
                    {
                        turret.DetectRadius = Amount * (int)Factor;
                    }
                }

                List <Sentry> otherTanks = (List <Sentry>)Game.Services.GetService(typeof(List <Sentry>));
                foreach (Sentry tank in otherTanks)
                {
                    if (tank != null)
                    {
                        tank.StayVisible = true;
                    }
                }

                State = PowerUpStatus.ExecuteOnce;
                break;
            }
        }
Exemple #32
0
        public override void Update(GameTime gameTime)
        {
            float deltaTime = (float)gameTime.ElapsedGameTime.Milliseconds;

            switch (CurrentScreen)
            {
            case ActiveScreen.MAIN:
                if (Active)
                {
                    if (MediaPlayer.State == MediaState.Stopped)
                    {
                        MediaPlayer.Play(MenuTrack);
                    }
                }
                else
                {
                    MediaPlayer.Stop();
                    MediaPlayer.Play(BackingTrack);
                    CurrentScreen = ActiveScreen.PLAY;
                }

                // Check Input
                if (InputEngine.IsKeyPressed(ActivationKey) ||
                    InputEngine.IsButtonPressed(ActivationButton))
                {
                    Active = !Active;
                    BlinkPlay.Play();
                    Helper.CurrentGameStatus = GameStatus.PLAYING;
                }
                break;

            case ActiveScreen.PLAY:
                TilePlayer player = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

                if (Active)
                {
                    MediaPlayer.Stop();
                    PauseTime     = gameTime.TotalGameTime;
                    CurrentScreen = ActiveScreen.PAUSE;
                }

                // Check Input
                if (InputEngine.IsKeyPressed(PauseKey) ||
                    InputEngine.IsButtonPressed(PauseButton))
                {
                    Active = !Active;
                    BlinkPause.Play();
                    Helper.CurrentGameStatus = GameStatus.PAUSED;
                }

                if (player.Health > 0 && TimeRemaining > 0)
                {
                    TimeRemaining -= deltaTime;
                }
                else
                {
                    MediaPlayer.Stop();
                    Active = !Active;
                    CurrentGameCondition = GameCondition.LOSE;
                    CurrentScreen        = ActiveScreen.LOSE;
                }

                if (CurrentGameCondition == GameCondition.WIN)
                {
                    MediaPlayer.Stop();
                    Active        = !Active;
                    CurrentScreen = ActiveScreen.WIN;
                }
                break;

            case ActiveScreen.PAUSE:
                if (MediaPlayer.State == MediaState.Stopped)
                {
                    MediaPlayer.Play(PauseTrack);
                }

                if (!Active)
                {
                    MediaPlayer.Stop();
                    MediaPlayer.Play(BackingTrack);
                    CurrentScreen          = ActiveScreen.PLAY;
                    gameTime.TotalGameTime = PauseTime;
                }

                // Check Input
                if (InputEngine.IsKeyPressed(PauseKey) ||
                    InputEngine.IsButtonPressed(PauseButton))
                {
                    Active = !Active;
                    BlinkPause.Play();
                    Helper.CurrentGameStatus = GameStatus.PLAYING;
                }
                break;

            case ActiveScreen.LOSE:

                if (MediaPlayer.State == MediaState.Stopped && TrackPlayCount < 1)
                {
                    MediaPlayer.Play(GameOverTrack);
                    TrackPlayCount++;
                    MediaPlayer.IsRepeating = false;
                }
                Helper.CurrentGameStatus = GameStatus.PAUSED;
                break;

            case ActiveScreen.WIN:
                if (MediaPlayer.State == MediaState.Stopped && TrackPlayCount < 1)
                {
                    MediaPlayer.Play(WinTrack);
                    TrackPlayCount++;
                }
                Helper.CurrentGameStatus = GameStatus.PAUSED;
                break;

            default:
                break;
            }

            base.Update(gameTime);
        }
Exemple #33
0
	public bool tryToMovePlayerToRoom(TilePlayer player, Tile.Direction dir){

		int targetX = player.col;
		int targetY = player.row;

		if (dir == Tile.Direction.Up) targetY = 0;
		if (dir == Tile.Direction.Down) targetY = gridSize-1;
		if (dir == Tile.Direction.Left) targetX = gridSize-1;
		if (dir == Tile.Direction.Right) targetX = 0;

		//if that spot clear?
		if (grid [targetX, targetY] == null) {
			player.moveToNewRoom (this, targetX, targetY, dir);
			player.audioSource.clip = player.moveSounds[ (int)Random.Range(0, player.moveSounds.Length)];
			player.audioSource.Play ();
			return true;
		} else {

			//try moving whatever is in there to see if they can - or not. this will take too long

			//play the bonk sound
			player.audioSource.clip = player.bonkSound;
			player.audioSource.Play ();
			//if not, bounce it without doing anything
			return false;
		}

	}