Esempio n. 1
0
        public void Initialize(Viewport viewport, Texture2D texture, Vector2 position, float angle, Player owner, List<Texture2D> textures)
        {
            uniqueID = currentUniqueID;
            currentUniqueID++;

            Owner = owner;

            Texture = texture;
            Position = position;
            Angle = angle;
            this.viewport = viewport;

            Active = true;

            Damage = 2;

            //projectileMoveSpeed = 6f;
            power = 10f;

            particleEngine = new ParticleEngine(textures, new Vector2(2000, 2000));

            Vector2 up = new Vector2(0, -1);
            Matrix rotMatrix = Matrix.CreateRotationZ(Angle);
            Direction = Vector2.Transform(up, rotMatrix);
            Direction *= power;
        }
Esempio n. 2
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()
        {
            graphics.PreferredBackBufferWidth = ScreenWidth;
            graphics.PreferredBackBufferHeight = ScreenHeight;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();

            Window.Title = "LCCS Tank Shooter";

            // Initialize the player class
            player = new Player();

            // Initialize the list of projectiles
            projectiles = new List<Projectile>();

            // Set the laser to fire every quarter second
            fireTime = TimeSpan.FromSeconds(.5f);

            base.Initialize();
        }
Esempio n. 3
0
        private void UpdatePlayer(Player player, GameTime gameTime)
        {
            player.Update(gameTime);

            // Use the Keyboard / Dpad
            if (currentKeyboardState.IsKeyDown(Keys.Left))
            {
                player.Position.X -= playerMoveSpeed;
                player.PlayerAnimation.Active = true;
            }
            else if (currentKeyboardState.IsKeyDown(Keys.Right))
            {
                player.Position.X += playerMoveSpeed;
                player.PlayerAnimation.Active = true;
            }
            else
                player.PlayerAnimation.Active = false;

            if (currentKeyboardState.IsKeyDown(Keys.Up))
            {
                player.CannonAngle += 0.01f;

                //if (player.CannonAngle > MathHelper.ToRadians(359))
                //{
                //    player.CannonAngle = MathHelper.ToRadians(359);
                //}

            }
            else if (currentKeyboardState.IsKeyDown(Keys.Down))
            {
                player.CannonAngle -= 0.01f;

                //if (player.CannonAngle < MathHelper.ToRadians(270))
                //{
                //    player.CannonAngle = MathHelper.ToRadians(270);
                //}

            }

            if (currentKeyboardState.IsKeyDown(Keys.Space))
            {
                // Fire only every interval we set as the fireTime
                if (gameTime.TotalGameTime - previousFireTime > fireTime)
                {
                    // Reset our current time
                    previousFireTime = gameTime.TotalGameTime;

                    // Add the projectile, but add it to the front and center of the player
                    //AddProjectile(player.Position +player.CannonTip);
                    AddProjectile( player.CannonTip);
                }
            }

            // Make sure that the player does not go out of bounds
            player.Position.X = MathHelper.Clamp(player.Position.X, 0, ScreenWidth - player.Width);
            //player.Position.Y = MathHelper.Clamp(player.Position.Y, 0, ScreenHeight - player.Height);

            player.CannonAngle = MathHelper.Clamp(player.CannonAngle, MathHelper.ToRadians(270), MathHelper.ToRadians(359));
        }
Esempio n. 4
0
        private void UpdateProjectiles(Player player1, Player player2)
        {
            // Update the Projectiles
            for (int i = projectiles.Count - 1; i >= 0; i--)
            {
                projectiles[i].Update();

                //if (projectiles[i].BoundingBox.Intersects(player1.BoundingBox)
                //    || projectiles[i].BoundingBox.Intersects(player2.BoundingBox))
                if (projectiles[i].BoundingBox.Intersects(player2.BoundingBox))
                {
                    if (projectiles[i].Owner != player2)
                    {
                        //collision detected
                        projectiles[i].Active = false;
                        //Console.WriteLine("Collision!!");
                        AddExplosion(player2.Position);
                        player2.Active = false;
                    }

                }

                //if (projectiles[i].BoundingBox.Intersects(player1.BoundingBox)
                //    || projectiles[i].BoundingBox.Intersects(player2.BoundingBox))
                if (projectiles[i].BoundingBox.Intersects(player1.BoundingBox))
                {
                    if (projectiles[i].Owner != player1)
                    {
                        //collision detected
                        projectiles[i].Active = false;
                        Console.WriteLine("Collision!!");
                        AddExplosion(player1.Position);
                        player1.Active = false;
                    }

                }

                if (projectiles[i].BoundingBox.Intersects(wallBox))
                {

                        //collision detected
                        projectiles[i].Active = false;
                        Console.WriteLine("Collision!!");
                }

                if (projectiles[i].Active == false)
                {
                    // Add an explosion
                    // Make sure to update the location to take account of the size of the Animation frames size!
                    Vector2 location = new Vector2(projectiles[i].Position.X - 75, (projectiles[i].Position.Y - 60));
                    AddExplosion(location);
                    projectiles.RemoveAt(i);
                }

            }
        }
Esempio n. 5
0
        private void UpdatePlayer(Player player, GameTime gameTime)
        {
            if (player == player1)
            {

                player.Update(gameTime);

                // Use the Keyboard / Dpad
                if (currentKeyboardState.IsKeyDown(Keys.Left) || (GamePad1.ThumbSticks.Left.X < 0))
                {
                    player.Position.X -= playerMoveSpeed;
                    player.PlayerAnimation.Active = true;
                }
                else if (currentKeyboardState.IsKeyDown(Keys.Right) || (GamePad1.ThumbSticks.Left.X > 0))
                {
                    player.Position.X += playerMoveSpeed;
                    player.PlayerAnimation.Active = true;
                }
                else
                    player.PlayerAnimation.Active = false;

                if (currentKeyboardState.IsKeyDown(Keys.Up) || (GamePad1.ThumbSticks.Right.Y > 0))
                {
                    player.CannonAngle += 0.01f;

                }
                else if (currentKeyboardState.IsKeyDown(Keys.Down) || (GamePad1.ThumbSticks.Right.Y < 0))
                {
                    player.CannonAngle -= 0.01f;
                }

                if (currentKeyboardState.IsKeyDown(Keys.Space) || (GamePad1.Triggers.Right > 0))
                {
                    // Fire only every interval we set as the fireTime
                    if (gameTime.TotalGameTime - previousFireTime > fireTime)
                    {
                        // Reset our current time
                        previousFireTime = gameTime.TotalGameTime;

                        // Add the projectile, but add it to the front and center of the player
                        //AddProjectile(player.Position +player.CannonTip);
                        AddProjectile(player.CannonTip, player.CannonAngle, player);
                    }
                }

                // Make sure that the player does not go out of bounds
                player.Position.X = MathHelper.Clamp(player.Position.X, wallPosition.X + (wall.Width / 2), ScreenWidth - player.Width);

                player.CannonAngle = MathHelper.Clamp(player.CannonAngle, MathHelper.ToRadians(270), MathHelper.ToRadians(359));
            }

            else
            {
                player.Update(gameTime);

                // Use the Keyboard / Dpad
                // Use the Keyboard / Dpad
                if (currentKeyboardState.IsKeyDown(Keys.A) || (GamePad2.ThumbSticks.Left.X < 0))
                {
                    player.Position.X -= playerMoveSpeed;
                    player.PlayerAnimation.Active = true;
                }
                else if (currentKeyboardState.IsKeyDown(Keys.D) || (GamePad2.ThumbSticks.Left.X > 0))
                {
                    player.Position.X += playerMoveSpeed;
                    player.PlayerAnimation.Active = true;
                }
                else
                    player.PlayerAnimation.Active = false;

                if (currentKeyboardState.IsKeyDown(Keys.W) || (GamePad2.ThumbSticks.Right.Y < 0))
                {
                    player.CannonAngle += 0.01f;

                }
                else if (currentKeyboardState.IsKeyDown(Keys.S) || (GamePad2.ThumbSticks.Right.Y > 0))
                {
                    player.CannonAngle -= 0.01f;
                }

                if (currentKeyboardState.IsKeyDown(Keys.Q) || (GamePad2.Triggers.Right > 0))
                {
                    // Fire only every interval we set as the fireTime
                    if (gameTime.TotalGameTime - previousFireTime2 > fireTime2)
                    {
                        // Reset our current time
                        previousFireTime2 = gameTime.TotalGameTime;

                        // Add the projectile, but add it to the front and center of the player
                        //AddProjectile(player.Position +player.CannonTip);
                        AddProjectile(player.CannonTip, player.CannonAngle, player);
                    }
                }

                // Make sure that the player does not go out of bounds
                player.Position.X = MathHelper.Clamp(player.Position.X, 0, wallPosition.X + (wall.Width / 2) - player.Width);
                player.CannonAngle = MathHelper.Clamp(player.CannonAngle, MathHelper.ToRadians(0), MathHelper.ToRadians(90));
            }
        }
Esempio n. 6
0
        private void AddProjectile(Vector2 position, float angle, Player player)
        {
            Projectile projectile = new Projectile();
            projectile.Initialize(GraphicsDevice.Viewport, projectileTexture, position, angle, player, textures);

            projectiles.Add(projectile);

            tankFire.Play(0.6f, 0, 0);
        }