Esempio n. 1
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            if (enable)
            {

                #region BARRIER INTERSECTION
                if (position.Y > 720 - frameSize.Y)
                {
                    enable = false;
                    Game.Exit();
                }
                #endregion

                #region RIGHT MOVE
                if (speed.X > 0)
                {
                    if (SCREENTHEND < spaceRight + frameSize.X)
                    {
                        speed = new Vector2(speed.X * -1, speed.Y);
                        position.Y += (frameSize.Y / LINESPACE);
                    }
                }
                #endregion

                #region LEFT MOVE
                if (speed.X < 0)
                {
                    if (spaceLeft < SCREENWIDTH)
                    {
                        speed = new Vector2(speed.X * -1, speed.Y);
                        position.Y += (frameSize.Y / LINESPACE);
                    }
                }
                #endregion

               timeSinceLastMove += gameTime.ElapsedGameTime.Milliseconds;
                if (timeSinceLastMove > timeToMove)
                {
                    timeSinceLastMove = 0;
                    position.X += speed.X;
                }

                #region RANDOM SHOOT
               // timeSicenLastShoot += gameTime.ElapsedGameTime.Milliseconds;
                //if (timeSicenLastShoot > timeToShoot)
                {
                    //timeSicenLastShoot += gameTime.ElapsedGameTime.Milliseconds;
                    //if (timeSicenLastShoot > timeToShoot)
                    {
                        timeSicenLastShoot = 0;
                        //random = new Random(this.GetHashCode());
                        int ran = random.Next(0, 15000);
                        ///ANTES DE DISPARAR COMPROBAR SI COLISIONA
                        if (ran <= (shootquick) && shootin && !die) //&& WeAreYoureFriend())
                        {
                            if (!Game.Components.Contains((IGameComponent)shooter))
                            {
                                shoot = Game.Content.Load<Texture2D>(@"Shoot\" + "shoot_sheet");
                                shooter = new Shoot(Game, ref shoot,
                                    new Vector2(position.X + frameSize.X / 2,
                                        position.Y + SHOOTSIZE + frameSize.Y), -1);
                                Game.Components.Add(shooter);

                                shootEffect.Play();
                            }
                        }
                    }
                }
                #endregion

            }

            base.Update(gameTime);
        }
Esempio n. 2
0
        /// <summary>
        /// Update the Tank position
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(GameTime gameTime)
        {
            if (enable)
            {
                #region UPDATEPOSITION
                if (!die)
                {
                    GamePadState gamePadState = GamePad.GetState(PlayerIndex.One);
                    KeyboardState keyboardState = Keyboard.GetState();

                    bool left, right, shootGreen;

                    shootGreen = (oldKeyBoardState.IsKeyDown(Keys.S) &&
                        (keyboardState.IsKeyUp(Keys.S)));

                    //                left = (oldKeyBoardState.IsKeyDown(Keys.Left) &&
                    //                    (keyboardState.IsKeyUp(Keys.Left)));

                    shootGreen |= (oldGamePadState.Buttons.A == ButtonState.Pressed) &&
                        (gamePadState.Buttons.A == ButtonState.Released);

                    //              left |= (oldGamePadState.DPad.Left == ButtonState.Pressed) &&
                    //                (gamePadState.DPad.Left == ButtonState.Released);

                    left = (gamePadState.DPad.Left == ButtonState.Pressed ||
                        keyboardState.IsKeyDown(Keys.Left));
                    right = (gamePadState.DPad.Right == ButtonState.Pressed ||
                        keyboardState.IsKeyDown(Keys.Right));

                    if (shootGreen)
                    {
                        #region SHOOT
                        //if (!Game.Components.Contains((IGameComponent)shooter))
                        //{
                        shoot = Game.Content.Load<Texture2D>(@"Shoot\" + "shoot_sheet");
                        shooter = new Shoot(Game, ref shoot,
                            new Vector2(position.X + frameSize.X / 2, position.Y - SHOOTSIZE), 1);
                        Game.Components.Add(shooter);
                        //}
                        #endregion

                    }

                    if (left)
                    {
                        this.position.X -= 3;//(float)Math.PI;
                    }

                    if (right)
                    {
                        this.position.X += 3;//(float)Math.PI;
                    }

                    oldKeyBoardState = keyboardState;
                    oldGamePadState = gamePadState;
                }
                #endregion

                #region SCREENBOUNDSCONTROL
                if (position.X < SCREENWIDTH)//screenBounds.Left)
                {
                    position.X = SCREENWIDTH;//screenBounds.Left;
                }
                if (position.X > SCREENTHEND - frameSize.X)//screenBounds.Width - frameSize.X)
                {
                    position.X = SCREENTHEND - frameSize.X; //- frameSize.X;//screenBounds.Width - frameSize.X;
                }
                if (position.Y < screenBounds.Top)
                {
                    position.Y = screenBounds.Top;
                }
                if (position.Y > screenBounds.Height - frameSize.Y)
                {
                    position.Y = screenBounds.Height - frameSize.Y;
                }
                #endregion
            }

            base.Update(gameTime);
        }
Esempio n. 3
0
        /// <summary>
        /// Update the Tank position
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(GameTime gameTime)
        {
            if (enable)
            {
                #region UPDATEPOSITION
                if (!die)
                {
                    GamePadState  gamePadState  = GamePad.GetState(PlayerIndex.One);
                    KeyboardState keyboardState = Keyboard.GetState();

                    bool left, right, shootGreen;

                    shootGreen = (oldKeyBoardState.IsKeyDown(Keys.S) &&
                                  (keyboardState.IsKeyUp(Keys.S)));

                    //                left = (oldKeyBoardState.IsKeyDown(Keys.Left) &&
                    //                    (keyboardState.IsKeyUp(Keys.Left)));

                    shootGreen |= (oldGamePadState.Buttons.A == ButtonState.Pressed) &&
                                  (gamePadState.Buttons.A == ButtonState.Released);

                    //              left |= (oldGamePadState.DPad.Left == ButtonState.Pressed) &&
                    //                (gamePadState.DPad.Left == ButtonState.Released);

                    left = (gamePadState.DPad.Left == ButtonState.Pressed ||
                            keyboardState.IsKeyDown(Keys.Left));
                    right = (gamePadState.DPad.Right == ButtonState.Pressed ||
                             keyboardState.IsKeyDown(Keys.Right));

                    if (shootGreen)
                    {
                        #region SHOOT
                        //if (!Game.Components.Contains((IGameComponent)shooter))
                        //{
                        shoot   = Game.Content.Load <Texture2D>(@"Shoot\" + "shoot_sheet");
                        shooter = new Shoot(Game, ref shoot,
                                            new Vector2(position.X + frameSize.X / 2, position.Y - SHOOTSIZE), 1);
                        Game.Components.Add(shooter);
                        shootEffect.Play();
                        //}
                        #endregion
                    }

                    if (left)
                    {
                        this.position.X -= 3;//(float)Math.PI;
                    }

                    if (right)
                    {
                        this.position.X += 3;//(float)Math.PI;
                    }

                    oldKeyBoardState = keyboardState;
                    oldGamePadState  = gamePadState;
                }
                #endregion

                #region SCREENBOUNDSCONTROL
                if (position.X < SCREENWIDTH)               //screenBounds.Left)
                {
                    position.X = SCREENWIDTH;               //screenBounds.Left;
                }
                if (position.X > SCREENTHEND - frameSize.X) //screenBounds.Width - frameSize.X)
                {
                    position.X = SCREENTHEND - frameSize.X; //- frameSize.X;//screenBounds.Width - frameSize.X;
                }
                if (position.Y < screenBounds.Top)
                {
                    position.Y = screenBounds.Top;
                }
                if (position.Y > screenBounds.Height - frameSize.Y)
                {
                    position.Y = screenBounds.Height - frameSize.Y;
                }
                #endregion
            }

            base.Update(gameTime);
        }