Пример #1
0
 public void DrawFrames(SpriteBatch batch, Fighter fighter)
 {
     if (!fighter.onLeft)
     {
         batch.Draw(texture[currentFrame], fighter.truePos, Color.White);
     }
     if (fighter.onLeft)
     {
         batch.Draw(texture[currentFrame], fighter.truePos, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.FlipHorizontally, 1f);
     }
 }
Пример #2
0
 public InputParser(Fighter passedFighter)
 {
 }
Пример #3
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            p1Char = new Character(p1Selection);
            p2Char = new Character(p2Selection);

            p1CharName = p1Char.name;
            p2CharName = p2Char.name;

            f1AniTexture = new TextureHandler(p1CharName);
            f2AniTexture = new TextureHandler(p2CharName);

            f1AniTexture.Load(GraphicsDevice, Content);
            f2AniTexture.Load(GraphicsDevice, Content);

            fighter1 = new Fighter(f1AniTexture, screenRectangle, 1, viewBox);
            fighter2 = new Fighter(f2AniTexture, screenRectangle, 2, viewBox);

            background = Content.Load<Texture2D>("Background1");
        }
Пример #4
0
 public void Draw(SpriteBatch batch, Fighter fighter)
 {
     fighterTexture.DrawFrames(batch, fighter);
 }
Пример #5
0
        public void Movement(Fighter opponent)
        {
            Rectangle opponentHitBox;
            opponentHitBox = opponent.hitBox;

            if (hitBox.Center.X < opponentHitBox.Center.X)
            {
                if (!onLeft)
                    onLeft = true;

            }
            else if (hitBox.Center.X >= opponentHitBox.Center.X)
            {
                if (onLeft)
                    onLeft = false;
            }

            if (!grounded)
            {
                switch (playerIndex)
                {
                    case 1:

                            gamePadState = GamePad.GetState(PlayerIndex.One);
                            if (keyboardState.IsKeyDown(Keys.D) || gamePadState.DPad.Right == ButtonState.Pressed)
                            {
                                rightPressed = true;
                                if (!inAir)
                                {
                                    walkspeed = 4f;
                                    if (!crouching)
                                        walking = true;
                                    if (!onLeft)
                                        blocking = true;
                                    if (!CheckWall() && !crouching)
                                    {
                                        if (!onLeft)
                                        {
                                            position.X += walkspeed;
                                        }
                                        else if (onLeft && !CheckCollision(opponent))
                                        {
                                            position.X += walkspeed;
                                        }
                                    }
                                }
                            }
                            else
                                rightPressed = false;
                            if (keyboardState.IsKeyDown(Keys.A) || gamePadState.DPad.Left == ButtonState.Pressed)
                            {
                                leftPressed = true;
                                if (!inAir)
                                {
                                    walkspeed = -4f;
                                    if (!crouching)
                                        walking = true;
                                    if (onLeft)
                                        blocking = true;
                                    if (!CheckWall() && !crouching)
                                    {
                                        if (onLeft)
                                        {
                                            position.X += walkspeed;
                                        }
                                        else if (!onLeft && !CheckCollision(opponent))
                                        {
                                            position.X += walkspeed;
                                        }
                                    }
                                }
                            }
                            else
                                leftPressed = false;
                            if (keyboardState.IsKeyDown(Keys.W) || gamePadState.DPad.Up == ButtonState.Pressed && inAir == false)
                            {
                                upPressed = true;
                                if (!inAir)
                                {
                                    inAir = true;
                                    jumped = true;
                                    position.Y--;
                                    if (walking)
                                    {
                                        wasWalking = true;
                                    }
                                }
                            }
                            else
                                upPressed = false;
                            if (keyboardState.IsKeyDown(Keys.S) || gamePadState.DPad.Down == ButtonState.Pressed)
                            {
                                downPressed = true;
                                if (!inAir)
                                    crouching = true;
                            }
                            else
                            {
                                downPressed = false;
                                if (!inAir)
                                    crouching = false;
                            }

                        break;
                    case 2:
                        gamePadState = GamePad.GetState(PlayerIndex.Two);

                            if (keyboardState.IsKeyDown(Keys.Right) || gamePadState.DPad.Right == ButtonState.Pressed)
                            {
                                rightPressed = true;
                                if (!inAir)
                                {
                                    walkspeed = 4f;
                                    if (!crouching)
                                        walking = true;
                                    if (!onLeft)
                                        blocking = true;
                                    if (!CheckWall() && !crouching)
                                    {
                                        if (!onLeft)
                                        {
                                            position.X += walkspeed;
                                        }
                                        else if (onLeft && !CheckCollision(opponent))
                                        {
                                            position.X += walkspeed;
                                        }
                                    }
                                }
                            }
                            else
                                rightPressed = false;
                            if (keyboardState.IsKeyDown(Keys.Left) || gamePadState.DPad.Left == ButtonState.Pressed)
                            {
                                leftPressed = true;
                                if (!inAir)
                                {
                                    walkspeed = -4f;
                                    if (!crouching)
                                        walking = true;
                                    if (onLeft)
                                        blocking = true;

                                    if (!CheckWall() && !crouching)
                                    {
                                        if (onLeft)
                                        {
                                            position.X += walkspeed;
                                        }
                                        else if (!onLeft && !CheckCollision(opponent))
                                        {
                                            position.X += walkspeed;
                                        }
                                    }
                                }
                            }
                            else
                                leftPressed = false;
                            if (keyboardState.IsKeyDown(Keys.Up) || gamePadState.DPad.Up == ButtonState.Pressed && inAir == false)
                            {
                                upPressed = true;
                                if (!inAir)
                                {
                                    inAir = true;
                                    position.Y--;
                                    if (walking)
                                    {
                                        wasWalking = true;
                                    }
                                    if (!opponent.inAir)
                                    {
                                        jumped = true;
                                    }
                                }

                            }
                            else
                                upPressed = false;
                            if (keyboardState.IsKeyDown(Keys.Down) || gamePadState.DPad.Down == ButtonState.Pressed)
                            {
                                downPressed = true;
                                if (!inAir)
                                    crouching = true;
                            }
                            else
                            {
                                downPressed = false;
                                if (!inAir)
                                    crouching = false;
                            }

                        break;

                }

                //Jumping!
                if (inAir)
                {

                    if (position.Y < groundPosition)
                    {
                        if (wasWalking)
                        {
                            if (!CheckWall())
                            {
                                position.X += walkspeed;
                            }
                        }
                        jumpSpeed -= 0.7f;
                        position.Y -= jumpSpeed;
                        //If goes below ground, put on the ground
                        if (position.Y >= groundPosition)
                        {
                            position.Y = groundPosition;
                            inAir = false;
                            jumpSpeed = 14f;
                            wasWalking = false;
                            jumped = true;
                        }

                    }
                }
                if (jumped)
                {
                    if (onLeft)
                    {
                        if (hitBox.Right > opponentHitBox.Left)
                            position.X = opponentHitBox.Left - fighterTexture.Width;

                    }
                    else if (!onLeft)
                    {

                        if (hitBox.Left <= opponentHitBox.Right)
                            position.X = opponentHitBox.Right;

                    }
                    jumped = false;
                }

                if (walking)
                {
                    if (blocking)
                        backward = true;
                    if (!blocking)
                        foreward = true;
                }

            }

                truePos.X = position.X;
                truePos.Y = position.Y - fighterTexture.Height;
        }
Пример #6
0
        private bool CheckCollision(Fighter opponent)
        {
            float destination;
            Rectangle opponentHitBox;
            opponentHitBox = opponent.hitBox;
            destination = position.X + walkspeed;

            if (!opponent.inAir)
            {
                if (onLeft)
                {

                    if (hitBox.Right > opponentHitBox.Left)
                    {
                        if (GetState() != "Backward")
                        {
                            if (!opponent.CheckWall())
                            {
                                opponent.position.X += 0.7f;
                            }
                            return true;
                        }
                        else
                            return false;

                    }
                    else
                        return false;

                }
                else if (!onLeft)
                {
                    if (hitBox.Left < opponentHitBox.Right)
                    {
                        if (GetState() != "Backward")
                        {
                            if (!opponent.CheckWall())
                            {
                                opponent.position.X -= 0.7f;
                            }
                            return true;
                        }
                        else
                            return false;
                    }
                    else
                        return false;

                }
                else
                    return false;
            }
            else
                return false;
        }
Пример #7
0
 public void Update(float elapsed, float totalElapsed, Fighter opponent)
 {
     //Console.WriteLine(elapsed.ToString());
     fighterTexture.Update(elapsed, this.GetState());
     hitBox = new Rectangle((int)position.X, (int)position.Y, fighterTexture.Width, fighterTexture.Height);
     keyboardState = Keyboard.GetState();
     walking = false;
     blocking = false;
     backward = false;
     foreward = false;
     Movement(opponent);
     inputParser.Update(upPressed, downPressed, leftPressed, rightPressed, totalElapsed);
 }