Exemplo n.º 1
0
        /// <summary>
        /// Draws the tank model, using the current animation settings.
        /// </summary>
        public void Draw(Matrix cameraView, Matrix cameraProjection)
        {
            findNormal();
            // Set the world matrix as the root transform of the model.

            tankModel.Root.Transform = world;
            //tankModel.Root.Transform =  Matrix.CreateScale(0.01f) * Matrix.CreateTranslation(position);


            // Calculate matrices based on the current animation position.
            Matrix wheelRotation  = Matrix.CreateRotationX(wheelRotationValue);
            Matrix steerRotation  = Matrix.CreateRotationY(steerRotationValue);
            Matrix turretRotation = Matrix.CreateRotationY(turretRotationValue);
            Matrix cannonRotation = Matrix.CreateRotationX(cannonRotationValue);
            Matrix hatchRotation  = Matrix.CreateRotationX(hatchRotationValue);

            // Apply matrices to the relevant bones.
            leftBackWheelBone.Transform   = wheelRotation * leftBackWheelTransform;
            rightBackWheelBone.Transform  = wheelRotation * rightBackWheelTransform;
            leftFrontWheelBone.Transform  = wheelRotation * leftFrontWheelTransform;
            rightFrontWheelBone.Transform = wheelRotation * rightFrontWheelTransform;
            leftSteerBone.Transform       = steerRotation * leftSteerTransform;
            rightSteerBone.Transform      = steerRotation * rightSteerTransform;
            turretBone.Transform          = turretRotation * turretTransform;
            cannonBone.Transform          = cannonRotation * cannonTransform;
            hatchBone.Transform           = hatchRotation * hatchTransform;

            // Look up combined bone matrices for the entire model.
            tankModel.CopyAbsoluteBoneTransformsTo(boneTransforms);

            view       = cameraView;
            projection = cameraProjection;
            //bulletManager.DrawBalas(view, projection);

            if (bala != null)
            {
                bala.Draw(view, projection);
            }

            //particulas

            sistemaParticulasTraseira.Draw(view, projection);

            // Draw the model.
            foreach (ModelMesh mesh in tankModel.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World      = boneTransforms[mesh.ParentBone.Index];
                    effect.View       = view;
                    effect.Projection = projection;

                    effect.EnableDefaultLighting();
                }
                mesh.Draw();
            }
        }
Exemplo n.º 2
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.CornflowerBlue);

            var viewMatrix = camera.GetViewMatrix();

            camera.Position = camPos;
            camera.Rotation = rotation;
            camera.Zoom     = zoom;

            if (CurrentGameState == GameState.MainMenu)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(background, mainframe, Color.White);
                //spriteBatch.DrawString(font, "press enter to start ", new Vector2(0, 0), Color.Black, 0, new Vector2(0, 0),2 , 0, 0);
                spriteBatch.DrawString(font, "press enter to start", new Vector2((GraphicsDevice.Viewport.Width / 2) - 150, 375), Color.Black);
                spriteBatch.End();
            }

            else if (CurrentGameState == GameState.PlayingLvl1)
            {
                #region GameLvl1;
                spriteBatch.Begin();
                spriteBatch.Draw(background, mainframe, Color.White);

                spriteBatch.DrawString(font, "Score: " + _hero.Score, new Vector2(750, 0), Color.Black);
                spriteBatch.DrawString(font, "Hero Life: x" + _hero.HeroLife, new Vector2(0, 0), Color.Black);
                spriteBatch.End();


                spriteBatch.Begin(transformMatrix: viewMatrix);
                exit_Lvl1.Draw(spriteBatch);
                _hero.Draw(spriteBatch);
                fire.Draw(spriteBatch);
                foreach (coin coin in coins)
                {
                    coin.Draw(spriteBatch);
                }

                foreach (Enemy enemy in _Enemys)
                {
                    if (enemy.isAlive)
                    {
                        enemy.Draw(spriteBatch);
                    }
                }

                foreach (BulletRight Bullet in bulletsright)
                {
                    Bullet.Draw(spriteBatch);
                }
                foreach (BulletLeft Bullet in bulletsleft)
                {
                    Bullet.Draw(spriteBatch);
                }
                map.Draw(spriteBatch);
                foreach (MovingTiles tile in movingTiles)
                {
                    tile.Draw(spriteBatch);
                }

                spriteBatch.End();
                #endregion
            }

            else if (CurrentGameState == GameState.PlayingSecretLvl)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(background, mainframe, Color.White);
                spriteBatch.DrawString(font, "Score: " + _hero.Score, new Vector2(750, 0), Color.Black);
                spriteBatch.DrawString(font, "Hero Life: x" + _hero.HeroLife, new Vector2(0, 0), Color.Black);

                spriteBatch.End();

                spriteBatch.Begin();
                exit_SecretLvl.Draw(spriteBatch);
                _hero.Draw(spriteBatch);
                SecretLvl.Draw(spriteBatch);
                foreach (coin coin in coins_SecretLvl)
                {
                    coin.Draw(spriteBatch);
                }

                spriteBatch.End();
            }

            else if (CurrentGameState == GameState.PlayingLvl2)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(background, mainframe, Color.White);
                spriteBatch.DrawString(font, "Score: " + _hero.Score, new Vector2(750, 0), Color.Black);
                spriteBatch.DrawString(font, "Hero Life: x" + _hero.HeroLife, new Vector2(0, 0), Color.Black);
                spriteBatch.End();

                spriteBatch.Begin(transformMatrix: viewMatrix);
                _hero.Draw(spriteBatch);

                foreach (MovingTiles tile in movingTiles_Lvl2)
                {
                    tile.Draw(spriteBatch);
                }

                foreach (Enemy enemy in _EnemysLvl2)
                {
                    if (enemy.isAlive)
                    {
                        enemy.Draw(spriteBatch);
                    }
                }

                foreach (BulletRight Bullet in bulletsright)
                {
                    Bullet.Draw(spriteBatch);
                }
                foreach (BulletLeft Bullet in bulletsleft)
                {
                    Bullet.Draw(spriteBatch);
                }
                foreach (BulletEnemy Bullet in bulletEnemy)
                {
                    Bullet.Draw(spriteBatch);
                }
                foreach (coin coin in coins_Lvl2)
                {
                    coin.Draw(spriteBatch);
                }
                if (damageEndBoss < 20)
                {
                    endBoss.Draw(spriteBatch);
                }
                else
                {
                    exit_Lvl2.Draw(spriteBatch);
                }



                foreach (Kanon kanon in Kannonen)
                {
                    kanon.Draw(spriteBatch);
                }

                map_Lvl2.Draw(spriteBatch);
                spriteBatch.End();
            }

            else if (CurrentGameState == GameState.Dead)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(background, mainframe, Color.White);
                spriteBatch.DrawString(font, "Game Over!", new Vector2(650, 200), Color.Black);
                spriteBatch.DrawString(font, "Your score: " + _hero.Score, new Vector2(650, 400), Color.Black);
                spriteBatch.End();
            }

            else if (CurrentGameState == GameState.End)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(background, mainframe, Color.White);
                spriteBatch.DrawString(font, "Yes! You did it!", new Vector2(650, 200), Color.Black);
                spriteBatch.DrawString(font, "Your score: " + _hero.Score, new Vector2(650, 400), Color.Black);
                spriteBatch.End();
            }

            base.Draw(gameTime);
        }