Пример #1
0
        public override void updt(GameTime gameTime, Rectangle recti) // keyboard movement and collisions
        {
            if (recti == null)
            {
                throw new NullReferenceException("parameter can't be null : recti");
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Right))      //movement to th right
            {                                                   //Resumen
                if (pos.X < (pos.Width * 5))                    // this will allow the character to move 725 (check) pixels to the right to make the aperance its accelerating  1
                {
                    pos.X += speed;
                    if (estado != State.jump)
                    {
                        estado = State.run;
                    }
                }
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Left)) //movement to the left
            {                                                  //Resumen
                if (pos.X > 5)                                 // this will alow the character to move back to the inicial posicion faster to make the aperance of deceleration
                {
                    pos.X -= speed;
                    if (estado != State.jump)
                    {
                        estado = State.run;
                    }
                }
            }
            else if (pos.X > 5)                              // this will alow the character to move back to the inicial posicion faster to make the aperance of deceleration
            {
                pos.X -= (speed / 2);
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Space) && !saltar)   // jump
            {
                //Resumen
                estado = State.jump;
                ymax   = pos.Y - (pos.Height + 80);                                  // this will alow the character to jump one time
                ymin   = pos.Y;
                saltar = true;
            }
            if (saltar)
            {
                pos.Y -= jumpSpeed;

                if (pos.Y <= ymax)
                {
                    jumpSpeed *= -1;
                }
                if (pos.Y >= ymin)
                {
                    jumpSpeed *= -1;
                    saltar     = false;
                    estado     = State.run;
                }
                if (vida.LIFE == 0)
                {
                    vivo = false;
                }
            }
            vida.updt();
            base.updt(gameTime, pos);
            //things to do
            //the collisions haven't been implemented yet
            //when the hero dies changes the animation to agony
        }
Пример #2
0
        public override void updt(Rectangle rect)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Right))      //movement to th right
            {                                                   //Resumen
                if (pos.X < (pos.Width * 2))                    // this will allow the character to move 725 (check) pixels to the right to make the aperance its accelerating  1
                {
                    pos.X += speed;
                }
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Left)) //movement to the left
            {                                                  //Resumen
                if (pos.X > 5)                                 // this will alow the character to move back to the inicial posicion faster to make the aperance of deceleration
                {
                    pos.X -= speed;
                }
            }
            else if (pos.X > 5)                              // this will alow the character to move back to the inicial posicion faster to make the aperance of deceleration
            {
                pos.X -= (speed / 2);
            }
            if (prote)
            {
                proteccion.updt(pos);
            }
            base.updt(pos);
            vida.updt();

            Rectangle posrec = SOURCE;

            if (vida.LIFE >= 100 && vida.LIFE < 60)
            {
                if (prote)
                {
                    prote = true;
                }
                vida.BarHPColor = Color.Blue;
            }
            if (vida.LIFE < 60 && vida.LIFE > 40)
            {
                prote           = false;
                posrec.X        = 80;
                vida.BarHPColor = Color.Green;
            }
            else if (vida.LIFE < 40 && vida.LIFE > 20)
            {
                prote           = false;
                posrec.X        = 160;
                vida.BarHPColor = Color.Yellow;
            }
            else if (vida.LIFE < 20 && vida.LIFE > 0)
            {
                prote           = false;
                posrec.X        = 240;
                vida.BarHPColor = Color.Red;
            }
            if (vida.LIFE == 0)
            {
                vivo = false;
            }
            SOURCE = posrec;
        }