Example #1
0
        public void Update(GameTime gametime, int side, List<Platform> Plats, int heightScreen)
        {
            heroRec = new Rectangle((int)position.X, (int)position.Y, frameWidth, frameHeight);

            foreach (Platform plat in Plats)
            {
                if (heroRec.topOf(plat.PlatRec))
                {
                    velocity.Y = 0;
                }
            }

            int k = 0;
            for (int i1 = 0; i1 < Plats.Count(); i1++)
            {
                if (!heroRec.topOf(Plats[i1].PlatRec))
                    k++;
            }
            if ((k == Plats.Count()) && (heroRec.Bottom < heightScreen))
            {
                velocity.Y += 5f;
                k = 0;
            }
            else
                velocity.Y = 0;

            if (!isFight)
            {
                timer += (float)gametime.ElapsedGameTime.TotalMilliseconds;
                if (timer > interval)
                {
                    animRec = new Rectangle(currentFrame * frameWidth, 0, frameWidth, frameHeight);
                    original_Pos = new Vector2(animRec.Width / 2, animRec.Height / 2);
                    position = position + velocity;

                    if (isRight > 9)
                    {
                        goesRight = true;
                    }
                    if (isRight < 0)
                    {
                        goesRight = false;
                    }

                    if (goesRight)
                    {
                        Right(gametime);
                        velocity.X = 10;
                        isRight--;
                    }
                    else if (!goesRight)
                    {
                        Left(gametime);
                        velocity.X = -10;
                        isRight++;
                    }
                    timer = 0;
                }
                if (side == 1)
                    position.X -= 3;
                if (side == -1)
                    position.X += 3;

            }
        }
Example #2
0
        public void Update(GameTime gametime, bool isOnSide, List<Platform>Plats, int heightScreen, int widthScreen, SoundEffect jump,SoundEffect fight, SoundEffect run )
        {
            animRec = new Rectangle(currentFrame * frameWidth, 0, frameWidth, frameHeight);
            original_Pos = new Vector2(animRec.Width / 2, animRec.Height / 2);
            position = position + velocity;
            heroRec = new Rectangle((int)position.X, (int)position.Y, frameWidth, frameHeight);
            healthRec = new Rectangle(widthScreen*(2/7), heightScreen*(1/15), live / 10, 30);

            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                right = true;
                Right(gametime);
                velocity.X = widthScreen/240;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                right = false;
                Left(gametime);
                velocity.X = -widthScreen / 240;
            }
            else
            {
                velocity.X = 0f;
            }

            if ((Keyboard.GetState().IsKeyDown(Keys.R)) && (alreadyJump == false))
            {
                position.Y -= (float)( heightScreen / 10);
                alreadyJump = true;
                velocity.Y -= (float)( heightScreen / 20);
                jump.Play();
            }
            if (alreadyJump == true)
            {
                int i = 1;
                velocity.Y += ((float)(heightScreen/120))*i;
            }

            if (position.Y + animRec.Height >= heightScreen*(1.155f))
            {
                alreadyJump = false;
            }

            if (alreadyJump == false)
            {
                velocity.Y = 0f;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                if (right)
                    ThrowingRight(gametime);
                else
                    ThrowingLeft(gametime);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.F) && State.IsKeyUp(Keys.F))
            {
                fight.Play();
                if (right)
                    FightRight(gametime);
                else
                    FightLeft(gametime);

            }

            State = Keyboard.GetState();

            foreach (Platform plat in Plats)
            {
                if (heroRec.topOf(plat.PlatRec))
                {
                    velocity.Y = 0;
                    alreadyJump = false;
                }
            }

            int k = 0;
            for (int i1 = 0; i1 < Plats.Count(); i1++)
            {
                if (!heroRec.topOf(Plats[i1].PlatRec))
                    k++;
                if ((k == Plats.Count()) && (heroRec.Bottom < heightScreen * (7 / 6)) && (!alreadyJump))
                {
                    velocity.Y += (heightScreen/64f);
                    alreadyJump = true;
                    k = 0;
                }
            }
        }