Beispiel #1
0
 public void BouncerCollision(Rectangle _bouncerRec, bool _bounceToRight)
 {
     if (wormRectangle.Intersects(_bouncerRec))
     {
         state = wormState.Jumping;
     }
 }
Beispiel #2
0
        public void WorldObjectCollision(Rectangle _worldObjRec)
        {
            if (WormRectangle.TouchTop(_worldObjRec))
            {
                if (state == wormState.Falling)
                {
                    // speed = 1;
                    state   = wormState.Walking;
                    Working = false;
                }
                Velocity = 0;
                OnGround = true;
            }
            if (WormRectangle.TouchRight(_worldObjRec))
            {
                if (!DirectionRight)
                {
                    Velocity = 0;
                    OnGround = true;
                    if (state == wormState.Walking)
                    {
                        speed = 1;
                    }
                }
                if (state == wormState.JetPack)
                {
                    position.X += 1;
                }
            }

            if (WormRectangle.TouchLeft(_worldObjRec))
            {
                Velocity = 0;
                OnGround = true;
                if (state == wormState.Walking)
                {
                    speed = -1;
                }

                if (state == wormState.JetPack)
                {
                    position.X -= 1;
                }
            }
        }
Beispiel #3
0
        private void CheckState()
        {//This should be changed // remove Jumping if schleife
            if (state != wormState.Jumping)
            {
                if (Selected && key.IsKeyDown(Keys.D))
                {
                    state = wormState.Dying;
                }
                else if (state != wormState.Dying)
                {
                    if (Selected && key.IsKeyDown(Keys.B))
                    {
                        state    = wormState.Blocking;
                        Working  = true;
                        Selected = false;
                    }
                    if (Selected && key.IsKeyDown(Keys.I))
                    {
                        state    = wormState.Idle;
                        Working  = true;
                        Selected = false;
                    }
                    if (Selected && key.IsKeyDown(Keys.W))
                    {
                        state    = wormState.Welding;
                        Working  = true;
                        Selected = false;
                    }

                    if (Selected && key.IsKeyDown(Keys.J))
                    {
                        state    = wormState.Bouncing;
                        Working  = true;
                        Selected = false;
                    }

                    if (Selected && key.IsKeyDown(Keys.R))
                    {
                        state    = wormState.Digging;
                        Working  = true;
                        Selected = false;
                    }
                    if (Selected && key.IsKeyDown(Keys.F))
                    {
                        state   = wormState.JetPack;
                        Working = true;
                        // Selected = false;
                    }

                    if (!Working)
                    {
                        if (OnGround)
                        {
                            state = wormState.Walking;
                        }
                        else
                        {
                            state = wormState.Falling;
                        }
                    }

                    // else if (!OnGround) state = wormState.Falling;
                }
            }
        }
Beispiel #4
0
        public void Collision(SpriteBatch spriteBatch, GameTime gameTime, Rectangle _collisionRect, Collision tile)
        {
            if (wormRectangle.TouchTop(/*_collisionRect*/ tile.TileRectangle))
            {
                if (state == wormState.Falling)
                {
                    // speed = 1;
                    state   = wormState.Walking;
                    Working = false;
                }
                Velocity = 0;
                OnGround = true;
                if (state == wormState.Digging)
                {
                    BreakingAnimation.Active = true;
                    BreakingAnimation.IsLoop = false;
                    BreakingAnimation.Update(gameTime);
                    breakingRect = /*_collisionRect*/ tile.TileRectangle;

                    if (BreakingAnimation.IsDead)
                    {
                        Gameplay.BreakTile(tile);
                        BreakingAnimation.Reset();
                    }
                    breakingActive = tile.tileActive;
                }
            }
            if (wormRectangle.TouchRight(/*_collisionRect*/ tile.TileRectangle))
            {
                //if (state == wormState.Digging)
                //tileActive = false;
                if (state != wormState.Digging)
                {
                    if (!DirectionRight)
                    {
                        Velocity = 0;
                        OnGround = true;
                        if (state == wormState.Walking)
                        {
                            speed = 1;
                        }
                    }

                    if (state == wormState.Welding /*&& Gameplay.WeldingActive*/)
                    {
                        Gameplay.BreakTile(tile);
                        Gameplay.WeldingActive = false;
                        // Velocity = 1;
                    }

                    if (state == wormState.JetPack)
                    {
                        position.X += 1;
                    }
                }
                //DirectionRight = true;
            }

            if (wormRectangle.TouchLeft(/*_collisionRect*/ tile.TileRectangle) && DirectionRight)
            {
                if (state != wormState.Digging)
                {
                    Velocity = 0;
                    OnGround = true;
                    if (state == wormState.Walking)
                    {
                        speed = -1;
                    }

                    if (state == wormState.Welding)
                    {
                        Gameplay.WeldingActive = true;
                        Velocity = 0;
                    }
                    if (state == wormState.JetPack)
                    {
                        position.X -= 1;
                    }
                }
                //Gameplay.BreakTile(tile);
                //DirectionRight = false;
            }

            if (wormRectangle.TouchBottom(tile.TileRectangle))
            {
                state = wormState.Falling;
            }
        }
Beispiel #5
0
        public void Update(GameTime gameTime, Vector2 _cameraPos)
        {
            if (!DyingAnimation.IsDead)
            {
                int camPointerX = mouseState.X + (int)_cameraPos.X;
                int camPointerY = mouseState.Y + (int)_cameraPos.Y;
                key        = Keyboard.GetState();
                mouseState = Mouse.GetState();

                position.Y += Velocity;
                //if(state == wormState.Jumping)
                //  Velocity += 0.35f;
                CheckState();
                //CheckDirection();
                OnGround      = false;
                wormRectangle = new Rectangle((int)position.X, (int)position.Y, FallingAnimation.FrameWidth, FallingAnimation.FrameHeight);
                if (wormRectangle.Contains(camPointerX, camPointerY) && mouseState.LeftButton == ButtonState.Pressed)
                {
                    Gameplay.Deselect();
                    Selected = true;
                }

                //ToDo: kill AnimationUpdate when animation.IsDead
                switch (state)
                {
                case wormState.Falling:
                    FallingAnimation.Active = true;
                    FallingAnimation.Update(gameTime);
                    Velocity = 1;
                    CheckDirection(); break;

                case wormState.Idle:
                    IdleAnimation.Active = true;
                    IdleAnimation.Update(gameTime);
                    break;

                case wormState.Walking:
                    WalkingAnimation.Active = true;
                    WalkingAnimation.Update(gameTime);
                    position.X += 1 * speed;
                    CheckDirection(); break;

                case wormState.Blocking:
                    StopperAnimation.Active = true;
                    StopperAnimation.Update(gameTime);
                    speed = 0; break;

                case wormState.Digging:
                    DiggingAnimation.Active = true;
                    DiggingAnimation.Update(gameTime);
                    speed    = 0;
                    Velocity = 1;
                    break;

                case wormState.Welding:
                    WeldingAnimation.Active = true;
                    WeldingAnimation.Update(gameTime);
                    position.X += 0.1f;
                    if (!Gameplay.WeldingActive)
                    {
                        Velocity = 1;
                    }
                    break;

                case wormState.Bouncing:
                    BouncingAnimation.Active = true;
                    BouncingAnimation.Update(gameTime);
                    break;

                case wormState.Jumping:
                    JumpingAnimation.Active = true;
                    JumpingAnimation.IsLoop = false;
                    JumpingAnimation.Update(gameTime);

                    if (!JumpingAnimation.IsDead)
                    {
                        Velocity = 0;
                        if (DirectionRight)
                        {
                            position.X += 1.5f;
                            position.Y -= 2 * speed;
                        }
                        else
                        {
                            position.X -= 1.5f;
                            position.Y += 2 * speed;
                        }
                    }
                    else
                    {
                        state = wormState.Falling;
                        JumpingAnimation.Reset();
                    }
                    break;

                case wormState.JetPack:
                    JetPackAnimation.Active = true;

                    JetPackAnimation.Update(gameTime);
                    JetPackInput();
                    Timer.Update(gameTime, position, _cameraPos);
                    if (Timer.i < 0)
                    {
                        Working = false;
                        state   = wormState.Falling;
                        Timer.i = Timer.totalCountDown;
                    }
                    break;

                case wormState.Dying:
                    DyingAnimation.Active = true;
                    DyingAnimation.IsLoop = false;
                    DyingAnimation.Update(gameTime);
                    if (DyingAnimation.IsDead)
                    {
                        Selected = false;
                    }
                    break;
                }
            }
        }