示例#1
0
 public FuelCarrier(string modelName, GameState state)
     : base(modelName, state)
 {
     ForwardDirection = 0.0f;
     MaxRange = GameConstants.MaxRange;
     PrimaryCannon = new MountedGun(state, 100);
 }
示例#2
0
 public Pawn(string modelName, GameState state)
     : base(state)
 {
     Model = null;
     Position = Vector3.Zero;
     IsActive = false;
     ModelName = modelName;
     LoadContent();
 }
示例#3
0
        public static void DrawAll(GameState state, SpriteBatch spriteBatch, Camera gameCamera)
        {
            BasicEffect effect = Fireball.GetEffect(state.GraphicsDevice);
            effect.Projection = gameCamera.ProjectionMatrix;
            spriteBatch.Begin(0, null, null, DepthStencilState.DepthRead, RasterizerState.CullNone, effect);

            foreach (Fireball ball in state.Projectiles)
            {
                Vector3 viewSpacePosition = Vector3.Transform(ball.Position, gameCamera.ViewMatrix * Fireball.World);
                Vector2 locationOffset = new Vector2(viewSpacePosition.X - (Fireball.Texture.Width / 2) * Fireball.Scale, viewSpacePosition.Y - Fireball.Texture.Height * Fireball.Scale);
                spriteBatch.Draw(Fireball.Texture, locationOffset, null, Color.White, 0, Vector2.Zero, Fireball.Scale, 0, viewSpacePosition.Z);
            }
            spriteBatch.End();
        }
示例#4
0
        public static Barrier BarrierFromType(BarrierType type, GameState state)
        {
            string modelName = string.Empty;
            switch (type)
            {
                case BarrierType.Cube:
                    modelName = GameConstants.MdlCube;
                    break;
                case BarrierType.Cylinder:
                    modelName = GameConstants.MdlCylinder;
                    break;
                case BarrierType.Pryamid:
                    modelName = GameConstants.MdlPryamid;
                    break;
                default:
                    break;
            }

            return new Barrier(modelName, state, type);
        }
示例#5
0
 public Barrier(string modelName, GameState state, BarrierType type)
     : base(modelName, state)
 {
     BarrierType = type;
     double rateOfFire = 0;
     switch (BarrierType)
     {
         case BarrierType.Cube:
             rateOfFire = 650;
             break;
         case BarrierType.Cylinder:
             rateOfFire = 100;
             break;
         case BarrierType.Pryamid:
             rateOfFire = 650;
             break;
         default:
             break;
     }
     Cannon = new MountedGun(state, rateOfFire);
 }
        private void ResetGame(GameTime gameTime, float aspectRatio)
        {
            fuelCarrier.Reset();
            bullets = new List<Bullet>();
            gameCamera.Update(fuelCarrier.ForwardDirection, fuelCarrier.AimDirection,
                fuelCarrier.Position, aspectRatio);
            InitializeGameField();

            fuelRemaining = maxFuelAmount;

            currentGameState = GameState.Running;
        }
        /// <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)
        {
            float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
            lastKeyboardState = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();
            lastGamePadState = currentGamePadState;
            currentGamePadState = GamePad.GetState(PlayerIndex.One);

            mouseState = Mouse.GetState();//<<<<<<<<<<

            // Allows the game to exit
            if ((currentKeyboardState.IsKeyDown(Keys.Escape)) ||
                (currentGamePadState.Buttons.Back == ButtonState.Pressed))
                this.Exit();
            if (currentGameState == GameState.Start)
            {
                if ((lastKeyboardState.IsKeyUp(Keys.Enter) &&
                    (currentKeyboardState.IsKeyDown(Keys.Enter)))||
                    currentGamePadState.Buttons.Start == ButtonState.Pressed)
                {
                    laserSound2.Play();
                    currentGameState = GameState.Instruction;
                }
                lastKeyboardState = currentKeyboardState;
            }
            if (currentGameState == GameState.Instruction)
            {
                if ((lastKeyboardState.IsKeyUp(Keys.Enter) &&
                    (currentKeyboardState.IsKeyDown(Keys.Enter))) ||
                    currentGamePadState.Buttons.Start == ButtonState.Pressed)
                {
                    laserSound2.Play();
                    currentGameState = GameState.Controls;
                }
                lastKeyboardState = currentKeyboardState;
            }
            if (currentGameState == GameState.Controls)
            {
                if ((lastKeyboardState.IsKeyUp(Keys.Enter) &&
                    (currentKeyboardState.IsKeyDown(Keys.Enter))) ||
                    currentGamePadState.Buttons.Start == ButtonState.Pressed)
                {
                    laserSound2.Play();
                    currentGameState = GameState.Running;
                }
                lastKeyboardState = currentKeyboardState;
            }

            if ((currentGameState == GameState.Running))
            {
                checkPauseKey(currentKeyboardState); //[i]
                if (!paused)
                {
                    fuelCarrier.Update(currentGamePadState,
                        currentKeyboardState, barriers);

                    gameCamera.Update(fuelCarrier.ForwardDirection, fuelCarrier.AimDirection,
                        fuelCarrier.Position, aspectRatio);
                    //UPDATED CAMERA.UPDATE PARAMETER

                    if (fuelCarrier.CheckForFuelCollision(fuelCells))
                    {
                        refuel.Play();
                        if ((fuelRemaining + 500) > maxFuelAmount)
                        {
                            fuelRemaining = 2500;
                        }
                        else
                        {
                            fuelRemaining += 500;
                        }
                    }

                    //DECREASE THE FUEL
                    fuelRemaining -= level;

                    if (fuelRemaining > 0 && isAllDestroyed())
                    {
                        currentGameState = GameState.Won;
                    }
                    else if ((fuelRemaining <= 0) &&
                        (!isAllDestroyed()))
                    {
                        currentGameState = GameState.Lost;
                    }

                    if (bulletTimer != 0)
                    {
                        bulletTimer--;
                    }
                    if (bulletTimer == 0)
                    {
                        shoot();
                        bulletTimer = 10;
                    }

                    if (bullets.Count != 0)
                    {
                        for (int i = 0; i < bullets.Count; i++)
                        {
                            bullets[i].Update(barriers);

                            if (bullets[i].CheckForCollision(bullets[i].BoundingSphere, barriers))
                            {
                                explosion.Play();
                                score += 50;
                            }
                            if (bullets[i].timer == 25)
                            {
                                bullets.RemoveAt(i);
                                i--;
                            }
                        }
                    }
                }
            }

            if (currentGameState == GameState.Won)
            {
                // Reset the world for a new game
                if ((lastKeyboardState.IsKeyDown(Keys.Enter) &&
                    (currentKeyboardState.IsKeyUp(Keys.Enter))))
                {
                    ResetGame(gameTime, aspectRatio);
                    level++;
                }
            }
            else if (currentGameState == GameState.Lost)
            {
                // Reset the world for a new game
                if ((lastKeyboardState.IsKeyDown(Keys.Enter) &&
                    (currentKeyboardState.IsKeyUp(Keys.Enter))))
                {
                    ResetGame(gameTime, aspectRatio);
                    level = 1;
                    score = 0;
                }
            }

            base.Update(gameTime);
        }
示例#8
0
 public Actor(GameState state)
 {
     gameState = state;
 }
示例#9
0
 public MountedGun(GameState state, double rateOfFire)
     : base(state)
 {
     this.rateOfFire = rateOfFire;
 }
示例#10
0
 public Terrain(string modelName, GameState state)
     : base(modelName, state)
 {
 }
示例#11
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()
        {
            TouchPanel.EnabledGestures = GestureType.Tap;
            gameCamera = new Camera();
            frameRate = new FrameRateCounter(this, new Vector2(0, 0), Color.Wheat, Color.Wheat);
            gameState = new GameState(Content, GraphicsDevice);

            base.Initialize();
        }
示例#12
0
 public Fireball(GameState state, Vector3 position, Quaternion rotation, Pawn parent)
     : base(state, position, rotation)
 {
     ShotBy = parent;
     GameState.Projectiles.Add(this);
 }
示例#13
0
 public Projectile(GameState state, Vector3 position, Quaternion rotation)
     : base(state)
 {
     Position = position;
     Rotation = rotation;
 }
示例#14
0
 public FuelCell(string modelName, GameState state)
     : base(modelName, state)
 {
     Retrieved = false;
 }