public void Follow(TilePlayer p)
 {
     //if (inChaseZone(p) == true)
     //{
     this.angleOfRotation = TurnToFace(PixelPosition,
                                       p.PixelPosition, angleOfRotation, 1f);
 }
        public void Follow(TilePlayer p)
        {
            if (inChaseZone(p) == true)
            {
                playerFound          = true;
                this.angleOfRotation = TurnToFace(PixelPosition,
                                                  p.PixelPosition, angleOfRotation, 1f);

                float x = p.PixelPosition.X - PixelPosition.X;
                float y = p.PixelPosition.Y - PixelPosition.Y;

                float towardsPlayer = (float)Math.Atan2(y, x);

                if (SentrySuperProjectile != null)
                {
                    // fire the rocket in the direction the player is pointing.
                    if (SentrySuperProjectile.ProjectileState == SuperProjectile.PROJECTILE_STATE.STILL && angleOfRotation == towardsPlayer)
                    {
                        SentrySuperProjectile.Fire(direction);
                    }
                }
            }

            else
            {
                playerFound = false;
            }
        }
Example #3
0
        public void FireAt(GameTime gameTime, TilePlayer player)
        {
            if (Bullet != null && Bullet.ProjectileState == Projectile.PROJECTILE_STATUS.Idle)
            {
                Bullet.PixelPosition = (this.PixelPosition - new Vector2(WIDTH_IN, 0));
            }

            if (Bullet != null)
            {
                if (Bullet.ProjectileState == Projectile.PROJECTILE_STATUS.Idle &&
                    this.angleOfRotation != 0 && Math.Round(this.angleOfRotationPrev, 2) == Math.Round(this.angleOfRotation, 2))
                {
                    // Send this direction to the projectile
                    Bullet.GetDirection(Direction);
                    // Shoot at the specified position
                    Bullet.Shoot(player.CentrePos);
                    // Draw muzzleflash
                    muzzleFlash.angleOfRotation  = this.angleOfRotation;
                    muzzleFlash.PixelPosition    = this.PixelPosition - new Vector2(10, 0) + (this.Direction * (FrameWidth - 10));
                    muzzleFlash.Visible          = true;
                    muzzleFlash.OrbLight.Enabled = true;
                    muzzleFlash.Draw(gameTime);
                }
                else
                {
                    muzzleFlash.Visible          = false;
                    muzzleFlash.OrbLight.Enabled = false;
                }
            }
        }
Example #4
0
        private void UpdateCollisions()
        {
            sentries          = (List <Sentry>)Game.Services.GetService(typeof(List <Sentry>));
            player            = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));
            playerProjectile  = (Projectile)Game.Services.GetService(typeof(Projectile));
            projectile        = (Ricochet)Game.Services.GetService(typeof(Ricochet));
            sentryProjectiles = (List <Projectile>)Game.Services.GetService(typeof(List <Projectile>));

            CollideWithProjectile(playerProjectile);
            CollideWithProjectile(projectile);
            CollideWithTank(player);

            for (int i = 0; i < sentries.Count; i++)
            {
                if (!sentries[i].IsDead)
                {
                    CollideWithTank(sentries[i]);
                }
            }

            for (int i = 0; i < sentryProjectiles.Count; i++)
            {
                CollideWithProjectile(sentryProjectiles[i]);
            }
        }
Example #5
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            // assumes dirt is 0
            Texture2D dirt = Content.Load <Texture2D>("Tiles/se_free_dirt_texture");

            tileTextures.Add(dirt);

            Texture2D grass = Content.Load <Texture2D>("Tiles/se_free_grass_texture");

            tileTextures.Add(grass);

            Texture2D ground = Content.Load <Texture2D>("Tiles/se_free_ground_texture");

            tileTextures.Add(ground);

            tileTextures.Add(Content.Load <Texture2D>("Tiles/se_free_mud_texture"));
            tileTextures.Add(Content.Load <Texture2D>("Tiles/se_free_road_texture"));
            tileTextures.Add(Content.Load <Texture2D>("Tiles/se_free_rock_texture"));
            tileTextures.Add(Content.Load <Texture2D>("Tiles/se_free_wood_texture"));

            tilePlayer = new TilePlayer(Content.Load <Texture2D>("player"), new Vector2(64, 64));
            Services.AddService(tilePlayer);
            SetColliders(TileType.Ground);
            SetColliders(TileType.Dirt);
            SetColliders(TileType.Road);
            //SetColliders(TileType.Ground);
            // TODO: use this.Content to load your game content here
        }
Example #6
0
        public override void Update(GameTime gameTime)
        {
            TilePlayer p = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

            if (p == null)
            {
                return;
            }
            else
            {
                switch (Name.ToUpper())
                {
                case "EXIT":
                    if (p.BoundingRectangle.Intersects(CollisionField) && SentryTurret.Count <= 0)
                    {
                        TileBasedPlayer20172018.GameRoot.MainScreen.CurrentGameCondition = GameCondition.WIN;
                    }
                    break;

                default:
                    break;
                }
            }

            base.Update(gameTime);
        }
Example #7
0
        private void CollideWithPlayer(TilePlayer obj)
        {
            if (obj == null)
            {
                return;
            }
            else
            {
                Rectangle overlap = Rectangle.Intersect(this.CollisionField, obj.BoundingRectangle);

                #region Minkowski sum of B and A
                float w  = 0.5f * (obj.BoundingRectangle.Width + CollisionField.Width);
                float h  = 0.5f * (obj.BoundingRectangle.Height + CollisionField.Height);
                float dx = obj.BoundingRectangle.Center.X - CollisionField.Center.X;
                float dy = obj.BoundingRectangle.Center.Y - CollisionField.Center.Y;

                if (Math.Abs(dx) <= w && Math.Abs(dy) <= h)
                {
                    /* collision! */
                    float wy = w * dy;
                    float hx = h * dx;

                    if (wy > hx)
                    {
                        if (wy > -hx)
                        {
                            /* collision at the top */
                            obj.PixelPosition += new Vector2(0, overlap.Height);
                        }
                        else
                        {
                            /* on the left */
                            obj.PixelPosition -= new Vector2(overlap.Width, 0);
                        }
                    }
                    else
                    {
                        if (wy > -hx)
                        {
                            /* on the right */
                            obj.PixelPosition += new Vector2(overlap.Width, 0);
                        }
                        else
                        {
                            /* at the bottom */
                            obj.PixelPosition -= new Vector2(0, overlap.Height);
                        }
                    }
                }
                #endregion

                /// OLD COLLISION METHOD
                //if (obj.BoundingRectangle.Intersects(CollisionField))
                //{
                //    //obj.PixelPosition = obj.PreviousPosition;
                //}
                ///
            }
        }
Example #8
0
        private Vector2 ContainTurretAngle(Vector2 CrosshairPosition)
        {
            TilePlayerTurret playerTurret = (TilePlayerTurret)Game.Services.GetService(typeof(TilePlayerTurret));
            TilePlayer       player       = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

            TankPosition = player.PixelPosition;

            return((playerTurret.Direction * Vector2.Distance(TankPosition, CrosshairPosition)));
        }
        public bool inChaseZone(TilePlayer p)
        {
            float distance = Math.Abs(Vector2.Distance(this.PixelPosition, p.PixelPosition));

            if (distance <= chaseRadius)
            {
                return(true);
            }
            return(false);
        }
Example #10
0
        private void Detect(GameTime gameTime, TilePlayer player)
        {
            if (IsInRadius(player))
            {
                this.angleOfRotation = TurnToFace(this.CentrePos, player.CentrePos, this.angleOfRotation, turnSpeed);

                // Shoot at the player
                FireAt(gameTime, player);
            }
        }
Example #11
0
        private void MoveWithMouse(TilePlayer player, TilePlayerTurret playerTurret)
        {
            Vector2 MousePos = InputEngine.MousePosition - new Vector2(FrameWidth / 2, FrameHeight / 2);

            Position = (MousePos + Camera.CamPos);
            Vector2 TransformPosition = ContainTurretAngle(player, playerTurret, Position);

            TransformPosition += TankPosition;
            PixelPosition      = TransformPosition;
        }
Example #12
0
        public override void Update(GameTime gameTime)
        {
            TilePlayer p          = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));
            Projectile projectile = (Projectile)Game.Services.GetService(typeof(Projectile));

            CollideWithPlayer(p);
            CollideWithProjectile(projectile);

            Shadow.Position = (WorldPosition / 2) + new Vector2(WorldPosition.X / 2, WorldPosition.Y / 2) + new Vector2(texture.Width / 2, texture.Height / 2) - Camera.CamPos;

            base.Update(gameTime);
        }
Example #13
0
        public bool IsInRadius(TilePlayer player)
        {
            float distance = Math.Abs(Vector2.Distance(this.CentrePos, player.CentrePos));

            if (distance <= DetectRadius)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void SpawnPlayer(TileType t)
        {
            // Declare bool to keep track of whether or not the home tile has been found on the map.
            bool homeTileFound = false;

            // Declare float values to convert the x and y value of the home tile to floats. This will allow the TilePlayer constructor to take a copy of the home tile's x and y value and spawn the player on that tile.
            float xFloatVer = 0;
            float yFloatVer = 0;

            for (int x = 0; x < tileMap.GetLength(1); x++)
            {
                for (int y = 0; y < tileMap.GetLength(0); y++)
                {
                    // If the current position on the map matches 4, the value for the home tile enumeration...
                    if (tileMap[y, x] == (int)t)
                    {
                        // ...Take a copy of that position and convert the values to float.
                        xFloatVer = (float)x;
                        yFloatVer = (float)y;


                        // Spawn the player, the vector2 constructor takes floats only, this is why the previous step is necessary.
                        //The Vector2 constructor sets the position of the player to that of the home tile.
                        Services.AddService(player1 = new TilePlayer(this, new Vector2(xFloatVer, yFloatVer), 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));

                        homeTileFound = true;

                        // Exit the inner for loop when the home tile has been found, there's no need to search any more of the map.
                        break;
                    }
                }

                // If the home tile has already been found...
                if (homeTileFound == true)
                {
                    break;
                    //..Exit the outer for loop.
                }
            }
        }
Example #15
0
        private bool IsSpotted()
        {
            TilePlayer player = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

            float distance = Math.Abs(Vector2.Distance(this.CentrePos, player.CentrePos));

            if (distance <= DetectRadius)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void follow(TilePlayer p)
        {
            bool inchaseZone = inChaseZone(p);

            if (inchaseZone)
            {
                this.angleOfRotation = TurnToFace(PixelPosition, p.PixelPosition, angleOfRotation, .3f);
                this.following       = true;
                target = p.PixelPosition;
            }
            else
            {
                this.following = false;
            }
        }
Example #17
0
        private void CollisionCheck()
        {
            // Projectile is out of tile map bounds
            if (this.PixelPosition.X < 0 || this.PixelPosition.Y < 0 ||
                this.PixelPosition.X > Camera.WorldBound.X ||
                this.PixelPosition.Y > Camera.WorldBound.Y ||
                flyTimer > flyingLifeSpan)
            {
                flyTimer        = 0f;
                projectileState = PROJECTILE_STATUS.Exploding;
            }

            // Ensure the sentry doesn't shoot itself !
            if (Parent != "PLAYER")
            {
                Camera     thisCamera = (Camera)Game.Services.GetService(typeof(Camera));
                TilePlayer player     = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

                if (CollideWith(player))
                {
                    //playerDamageRate = damageRate.Next(5, 15);
                    flyTimer        = 0f;
                    projectileState = PROJECTILE_STATUS.Exploding;
                    player.Health  -= playerDamageRate;
                    thisCamera.Shake(7.5f, 0.25f);
                    InputEngine.ShakePad(0.75f, 1.0f, 1.0f);
                    _sndPierce.Play();
                }
            }
            else
            {
                // Reference Collision Objects
                List <SentryTurret> SentryTurretList = (List <SentryTurret>)Game.Services.GetService(typeof(List <SentryTurret>));

                // Check collision with Sentry
                foreach (SentryTurret otherSentry in SentryTurretList)
                {
                    if (CollideWith(otherSentry))
                    {
                        //sentryDamageRate = damageRate.Next(30, 40);
                        flyTimer            = 0f;
                        projectileState     = PROJECTILE_STATUS.Exploding;
                        otherSentry.Health -= sentryDamageRate;
                        _sndPierce.Play();
                    }
                }
            }
        }
Example #18
0
        public override void Update(GameTime gameTime)
        {
            if (Helper.CurrentGameStatus == GameStatus.PLAYING)
            {
                if (IsSpotted())
                {
                    UPDATE_TIME_MAX = 0.1f;
                    TilePlayer player = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

                    Target = player.CentrePos;
                    React();

                    // Show self
                    Alpha           += fadeAmount;
                    OrbLight.Enabled = true;
                }
                else
                {
                    UPDATE_TIME_MAX = 1.0f;
                    if (SentryState != State.Idle && SentryState != State.Patrol)
                    {
                        SentryState = State.Idle;
                        CanMove     = false;
                    }

                    // Hide
                    if (Alpha > 0 && !StayVisible)
                    {
                        Alpha -= fadeAmount;
                    }
                    OrbLight.Enabled = false;
                }

                Alpha = MathHelper.Clamp(Alpha, 0, 2);

                CheckState(gameTime);

                //PlaySounds();
                //SetSoundForCamera(TrackSoundInstance, CentrePos, 0.1f);
                //SetSoundForCamera(HumSoundInstance, CentrePos, 0.1f);

                base.Update(gameTime);
            }
            else
            {
                StopSounds();
            }
        }
Example #19
0
        private void Detect(GameTime gameTime)
        {
            TilePlayer player = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

            if (IsInRadius(player))
            {
                angleOfRotation = TurnToFace(CentrePos, player.CentrePos, this.angleOfRotation, turnSpeed);

                // Shoot at the player
                FireAt(gameTime, player);
            }
            else
            {
                angleOfRotation = TurnToFace(CentrePos, CentrePos + parentBody.Direction, angleOfRotation, turnSpeed);
            }
        }
Example #20
0
        public override void Update(GameTime gameTime)
        {
            if (Helper.CurrentGameStatus == GameStatus.PLAYING)
            {
                if (Health > 0 && !isDead)
                {
                    TilePlayer    player   = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));
                    List <Sentry> Sentries = (List <Sentry>)Game.Services.GetService(typeof(List <Sentry>));

                    foreach (Sentry sentry in Sentries)
                    {
                        // Props this turret onto the appropiate tank body
                        if (this.Name == sentry.Name && sentry != null)
                        {
                            AddSelfToBody(sentry.PixelPosition + new Vector2(WIDTH_IN, 0f));
                            sentry.DetectRadius = this.DetectRadius;
                            this.Alpha          = sentry.Alpha;
                            healthBar.Alpha     = this.Alpha;
                            //this.Visible = sentry.Visible;
                        }
                    }

                    angleOfRotationPrev = this.angleOfRotation;

                    this.Direction = new Vector2((float)Math.Cos(this.angleOfRotation), (float)Math.Sin(this.angleOfRotation));

                    Bullet.GetDirection(this.Direction);

                    // Face and shoot at the player when player is within radius
                    Detect(gameTime, player);
                    PlaySounds();

                    base.Update(gameTime);
                }
                else if (!isDead)
                {
                    TurnSoundInstance.Stop();
                    Interlocked.Decrement(ref Count);
                    ExplosionSound.Play();
                    isDead = true;
                }
            }
            else
            {
                TurnSoundInstance.Stop();
            }
        }
        public override void Update(GameTime gameTime)
        {
            TilePlayer p = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

            if (p == null)
            {
                return;
            }
            else
            {
                if (p.BoundingRectangle.Intersects(CollisionField))
                {
                    p.PixelPosition = p.previousPosition;
                }
            }

            base.Update(gameTime);
        }
Example #22
0
        public override void Update(GameTime gameTime)
        {
            if (!Disabled && Helper.CurrentGameStatus == GameStatus.PLAYING)
            {
                TilePlayer       player       = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));
                TilePlayerTurret playerTurret = (TilePlayerTurret)Game.Services.GetService(typeof(TilePlayerTurret));

                if (InputEngine.UsingKeyboard)
                {
                    MoveWithMouse(player, playerTurret);
                }
                else
                {
                    MoveWithRadius(playerTurret);
                }

                Disabled = playerTurret.IsDead;

                base.Update(gameTime);
            }
        }
Example #23
0
        public override void Update(GameTime gameTime)
        {
            if (Helper.CurrentGameStatus == GameStatus.PLAYING)
            {
                if (!IsDead)
                {
                    TilePlayer player = (TilePlayer)Game.Services.GetService(typeof(TilePlayer));

                    // Props this turret onto the underside tank body if it exists
                    if (player != null)
                    {
                        Track(player.PixelPosition + new Vector2(WIDTH_IN, 0f));
                    }

                    angleOfRotationPrev = this.angleOfRotation;

                    // Alternate controls.
                    HandleTurns();

                    // Get direction for projectiles.
                    Direction = new Vector2((float)Math.Cos(this.angleOfRotation), (float)Math.Sin(this.angleOfRotation));

                    Fire(gameTime);
                    PlaySounds();

                    base.Update(gameTime);
                }
                else
                {
                    ExplosionSound.Play();
                    IsDead = true;
                }
            }
            else
            {
                TurnSoundInstance.Stop();
            }
        }
Example #24
0
        private Vector2 ContainTurretAngle(TilePlayer player, TilePlayerTurret playerTurret, Vector2 CrosshairPosition)
        {
            TankPosition = player.PixelPosition;

            return((playerTurret.Direction * Vector2.Distance(TankPosition, CrosshairPosition)));
        }
Example #25
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // 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"));

            // Tile References to be drawn on the Map corresponding to the entries in the defined
            // Tile Map
            // "free", "pavement", "ground", "blue", "home", "grass" "end"
            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(0, 1, 5));
            TileRefs.Add(new TileRef(0, 4, 6));
            // Names fo the Tiles

            new SimpleTileLayer(this, backTileNames, tileMap, TileRefs, tileWidth, tileHeight);
            List <Tile> found = SimpleTileLayer.getNamedTiles("home");

            new SimpleTileLayer(this, backTileNames, tileMap, TileRefs, tileWidth, tileHeight);
            List <Tile> foundSentry = SimpleTileLayer.getNamedTiles(backTileNames[(int)TileType.GREENBOX]);

            Services.AddService(new TilePlayer(this, new Vector2((int)TileType.HOME), 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));
            SetColliders(TileType.GREENBOX);
            SetColliders(TileType.BLUEBOX);

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

            tilePlayer.AddHealthBar(new HealthBar(tilePlayer.Game, tilePlayer.PixelPosition));

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

            Projectile playerProjectile = new Projectile(this, new List <TileRef>()
            {
                new TileRef(8, 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);

            player.LoadProjectile(playerProjectile);


            for (int i = 0; i < foundSentry.Count; i++)
            {
                sentryTurret = new Sentry(this, new Vector2(foundSentry[i].X * tileWidth, foundSentry[i].Y * tileHeight), new List <TileRef>()
                {
                    new TileRef(20, 2, 0),
                    new TileRef(20, 3, 0),
                    new TileRef(20, 4, 0),
                    new TileRef(20, 5, 0),
                    new TileRef(20, 6, 0),
                    new TileRef(20, 6, 0),
                    new TileRef(20, 8, 0),
                }, 64, 64, 0);
                sentryList.Add(sentryTurret);
            }

            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);

                sentryList[i].LoadProjectile(projectile);
                sentryList[i].Health = 20;
            }


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

            //Background
            backgroundMusic = Content.Load <Song>(@"Audio/bckGroundMusic");
            MediaPlayer.Play(backgroundMusic);
            MediaPlayer.Volume      = 0.4f;
            MediaPlayer.IsRepeating = true;

            //Sound FX
            sfx[0] = Content.Load <SoundEffect>(@"Audio/Explosion 2"); //Player Shot
            sfx[1] = Content.Load <SoundEffect>(@"Audio/Beep");        //Sentry Shot
            sfx[2] = Content.Load <SoundEffect>(@"Audio/Explosion");   //Projectile Explosion
            sfx[3] = Content.Load <SoundEffect>(@"Audio/Ching");       //Victory
            sfx[4] = Content.Load <SoundEffect>(@"Audio/Error");       //Fail

            //Screens
            victory  = Content.Load <Texture2D>(@"Images/Victory");
            gameOver = Content.Load <Texture2D>(@"Images/GameOver");
        }