Example #1
0
        internal override void updateCollisionWith(Entity a_collider)
        {
            if (a_collider is Player)
            {
                Player t_player = (Player) a_collider;

                if (Game.keyClicked(GameState.getActionKey()) && !t_player.isChase()
                    && t_player.getLastState() != Player.State.Hiding && t_player.getCurrentState() != Player.State.Jumping
                    && t_player.getCurrentState() != Player.State.Slide && t_player.getCurrentState() != Player.State.Climbing)
                {

                    Vector2 t_playerGlobal = a_collider.getPosition().getGlobalCartesianCoordinates();
                    float t_myPositionX = m_position.getGlobalCartesianCoordinates().X;

                    if (t_playerGlobal.X < t_myPositionX)
                    {

                        t_player.setNextPositionX(t_myPositionX - a_collider.getHitBox().getOutBox().Width);
                        t_player.setFacingRight(true);
                    }
                    else
                    {
                        t_player.setNextPositionX(t_myPositionX + m_img.getSize().X);
                        t_player.setFacingRight(false);
                    }

                    t_player.setState(Player.State.Hiding);
                    t_player.setHidingImage(Player.STANDHIDINGIMAGE);
                    t_player.setSpeedX(0);
                }
            }
        }
Example #2
0
 internal override void updateCollisionWith(Entity a_collider)
 {
     if (a_collider is Player)
     {
         Player t_player = (Player)a_collider;
         Vector2 t_playerGlobalPosition = a_collider.getPosition().getGlobalCartesian();
         Rectangle t_playerOutBox = a_collider.getHitBox().getOutBox();
         if (CollisionManager.Contains(this.getHitBox(),
             new Vector2(t_playerGlobalPosition.X + t_playerOutBox.Width / 2, t_playerGlobalPosition.Y + t_playerOutBox.Height / 2))
             && !t_player.isChase()
             && t_player.getLastState() != Player.State.Hiding
             && t_player.getCurrentState() != Player.State.Rolling
             )
         {
             if (KeyboardHandler.keyClicked(GameState.getActionKey()))
             {
                 t_player.setState(Player.State.Hiding);
                 t_player.setHidingImage(Player.DUCKHIDINGIMAGE);
                 t_player.setSpeedX(0);
                 t_player.setInteractionVisibility(false);
                 t_player.getHideSound().play();
             }
             else if (t_player.getCurrentState() != Player.State.Hiding)
             {
                 t_player.setInteractionVisibility(true);
             }
         }
     }
 }
Example #3
0
 public void changeMode(Entity a_collider)
 {
     float t_startX = m_line.getStartPoint().getGlobalX();
     float t_startY = m_line.getStartPoint().getGlobalY();
     float t_endX = m_line.getEndPoint().getGlobalX();
     float t_endY = m_line.getEndPoint().getGlobalY();
     float t_colliderY = a_collider.getPosition().getGlobalY() + a_collider.getHitBox().getOutBox().Height;
     m_isReady = true;
     setStartPoint(new Vector2(((-t_startX * t_endY)	+ (t_startX	* t_colliderY) + (t_startY * t_endX) - (t_endX * t_colliderY)) / (t_startY -t_endY), t_colliderY - 1));
     setEndPoint(m_player.getPosition().getGlobalCartesian() + new Vector2(m_player.getHitBox().getOutBox().Width / 2, m_player.getHitBox().getOutBox().Height / 2));
     m_rotate = m_startPosition.getAngleTo(m_endPosition.getGlobalCartesian());
     LinkedList<GameObject> t_gameObjects = Game.getInstance().getState().getCurrentList();
     bool t_isStartAtPlatform = false;
     foreach (GameObject t_go in t_gameObjects)
     {
         if (t_go is Platform)
             if (((Platform)t_go).getBox().Contains((int)m_startPosition.getGlobalX(), (int)m_startPosition.getGlobalY()))
             {
                 t_isStartAtPlatform = true;
                 break;
             }
     }
     if (t_isStartAtPlatform)
     {
         m_player.setState(Player.State.Swinging);
         if (!(Vector2.Distance(m_player.getPosition().getGlobalCartesian(), m_line.getStartPoint().getGlobalCartesian())
             < Math.Min(Vector2.Distance(new Vector2(m_player.getPosition().getGlobalCartesian().X + m_player.getHitBox().getOutBox().Width, m_player.getPosition().getGlobalCartesian().Y), m_line.getStartPoint().getGlobalCartesian()),
             Vector2.Distance(new Vector2(m_player.getPosition().getGlobalCartesian().X + m_player.getHitBox().getOutBox().Width / 2, m_player.getPosition().getGlobalCartesian().Y), m_line.getStartPoint().getGlobalCartesian()))))
         {
             if (Vector2.Distance(new Vector2(m_player.getPosition().getGlobalCartesian().X + m_player.getHitBox().getOutBox().Width, m_player.getPosition().getGlobalCartesian().Y), m_line.getStartPoint().getGlobalCartesian())
                 < Vector2.Distance(new Vector2(m_player.getPosition().getGlobalCartesian().X + m_player.getHitBox().getOutBox().Width / 2, m_player.getPosition().getGlobalCartesian().Y), m_line.getStartPoint().getGlobalCartesian()))
             {
                 m_player.addPositionXAfterDraw(m_player.getHitBox().getOutBox().Width);
             }
             else
             {
                 m_player.addPositionXAfterDraw(m_player.getHitBox().getOutBox().Width / 2);
             }
         }
         m_player.setRope(this);
         m_player.changePositionToPolar();
         m_player.getPosition().setParentPositionWithoutMoving(m_line.getStartPoint());
         m_player.setState(Player.State.Swinging);
         if (m_player.getPosition().getLength() < 50)
         {
             m_player.getPosition().setLength(50);
         }
         m_moveToStart = false;
     }
     else
     {
         m_moveToStart = true;
     }
 }
Example #4
0
        internal override void updateCollisionWith(Entity a_collider)
        {
            if (a_collider is Player)
            {
                Player t_player = (Player) a_collider;
                if (!t_player.isChase()
                    && t_player.getLastState() != Player.State.Hiding && t_player.getCurrentState() != Player.State.Jumping
                    && t_player.getCurrentState() != Player.State.Slide && t_player.getCurrentState() != Player.State.Climbing)
                {
                    if (!t_player.isStunned())
                    {
                        if (KeyboardHandler.keyClicked(GameState.getActionKey()))
                        {

                            Vector2 t_playerGlobal = a_collider.getPosition().getGlobalCartesian();
                            float t_myPositionX = m_position.getGlobalCartesian().X;

                            float t_newPos;
                            if (t_playerGlobal.X < t_myPositionX)
                            {
                                t_newPos = t_myPositionX - a_collider.getHitBox().getOutBox().Width;
                                t_player.setFacingRight(true);
                            }
                            else
                            {
                                t_newPos = t_myPositionX + m_img.getSize().X;
                                t_player.setFacingRight(false);
                            }

                            Game.getInstance().m_camera.getPosition().plusXWith(t_player.getPosition().getGlobalX() - t_newPos);

                            t_player.setNextPositionX(t_newPos);

                            t_player.setState(Player.State.Hiding);
                            t_player.setHidingImage(Player.STANDHIDINGIMAGE);
                            t_player.setSpeedX(0);
                            t_player.getHideSound().play();
                            t_player.getImg().setSprite("Images//Sprite//Hero//hero_wallhide");
                            t_player.updateFlip();
                        }
                        else if (t_player.getCurrentState() != Player.State.Hiding)
                        {
                            t_player.setInteractionVisibility(true);
                        }
                    }
                }
            }
        }
Example #5
0
 internal override void updateCollisionWith(Entity a_collider)
 {
     if (a_collider is Player)
     {
         Player t_player = (Player)a_collider;
         Vector2 t_playerGlobalPosition = a_collider.getPosition().getGlobalCartesianCoordinates();
         Rectangle t_playerOutBox = a_collider.getHitBox().getOutBox();
         if (CollisionManager.Contains(this.getHitBox(),
             new Vector2(t_playerGlobalPosition.X + t_playerOutBox.Width/2, t_playerGlobalPosition.Y + t_playerOutBox.Height/2)))
         {
             if (Game.keyClicked(GameState.getActionKey()) && !t_player.isChase()
                 && t_player.getLastState() != Player.State.Hiding)
             {
                 t_player.setState(Player.State.Hiding);
                 t_player.setHidingImage(Player.DUCKHIDINGIMAGE);
                 t_player.setSpeedX(0);
             }
         }
     }
 }
Example #6
0
 internal override void updateCollisionWith(Entity a_collid)
 {
     if (a_collid is Player)
     {
         Vector2 t_playerGlobalCoordinate = a_collid.getPosition().getGlobalCartesianCoordinates();
         if (CollisionManager.Contains(this.getHitBox(), t_playerGlobalCoordinate))
         {
             Player t_player = (Player)a_collid;
             if (
                 (Game.keyClicked(GameState.getUpKey()) && (t_player.getCurrentState() == Player.State.Walking || t_player.getCurrentState() == Player.State.Stop))
                 || (t_player.getCurrentState() != Player.State.Walking && t_player.getCurrentState() != Player.State.Stop)
             )
             {
                 if (this.m_spriteEffects == SpriteEffects.FlipHorizontally)
                     t_player.setIsOnLadderWithDirection(Player.Direction.Left);
                 else
                     t_player.setIsOnLadderWithDirection(Player.Direction.Right);
             }
         }
     }
 }
Example #7
0
 public void hang(Entity a_collider)
 {
     if (!m_stunned)
     {
         Rectangle t_colliderBox = a_collider.getHitBox().getOutBox();
         Rectangle t_playerBox = getHitBox().getOutBox();
         if (!t_colliderBox.Contains((int)m_lastPosition.X + t_playerBox.Width + 4, (int)m_lastPosition.Y)
             && t_colliderBox.Contains((int)m_position.getGlobalX() + t_playerBox.Width + 4, (int)m_position.getGlobalY())
             && m_lastPosition.Y < t_colliderBox.Y
             && m_speed.Y >= 0
             && (m_currentState == State.Jumping || m_currentState == State.Slide))
         {
             m_position.setLocalY(a_collider.getPosition().getGlobalY());
             m_nextPosition.Y = m_position.getGlobalY();
             m_speed.Y = 0;
             m_speed.X = 0;
             m_currentState = State.Hanging;
             m_facingRight = true;
             m_hangSound.play();
         }
         else if (!t_colliderBox.Contains((int)m_lastPosition.X - 4, (int)m_lastPosition.Y)
             && t_colliderBox.Contains((int)m_position.getGlobalX() - 4, (int)m_position.getGlobalY())
             && m_lastPosition.Y < t_colliderBox.Y
             && m_speed.Y >= 0
             && (m_currentState == State.Jumping || m_currentState == State.Slide))
         {
             m_position.setLocalY(a_collider.getPosition().getGlobalY());
             m_nextPosition.Y = m_position.getGlobalY();
             m_speed.Y = 0;
             m_speed.X = 0;
             m_currentState = State.Hanging;
             m_facingRight = false;
             m_hangSound.play();
         }
     }
 }