Example #1
0
        public void Grapple()
        {
            if (level.getPlayer() == null)
            {
                return;
            }

            //Check if it's alreday grappling, if so - stop the grapple and return.
            Entity curGrap = getCurrentGrapple();

            if (curGrap != null)
            {
                interruptGrapple(curGrap);
                return;
            }

            PositionComponent playerPos = ( PositionComponent )level.getPlayer().getComponent(GlobalVars.POSITION_COMPONENT_NAME);

            //Get the direction
            double dir = 0;


            float mouseX = level.getInputSystem().mouseX + level.sysManager.drawSystem.getMainView().x;
            float mouseY = level.getInputSystem().mouseY + level.sysManager.drawSystem.getMainView().y;

            float xDiff = mouseX - playerPos.x;
            float yDiff = mouseY - playerPos.y;

            dir = Math.Atan(yDiff / xDiff);

            if (mouseX < playerPos.x)
            {
                dir += Math.PI;
                if (!level.getPlayer().isLookingLeft())
                {
                    level.getPlayer().faceLeft();
                }
            }
            else if (mouseX > playerPos.x && !level.getPlayer().isLookingRight())
            {
                level.getPlayer().faceRight();
            }

            //Add the entity
            //Console.WriteLine( "Grapple Direction: " + dir );
            GrappleEntity grap = new GrappleEntity(level, new Random().Next(), playerPos.x, playerPos.y, dir);

            level.addEntity(grap);
            level.curGrap = grap;
            VelocityComponent velComp = ( VelocityComponent )level.getPlayer().getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);

            velComp.x = 0;
            level.getPlayer().removeComponent(GlobalVars.PLAYER_INPUT_COMPONENT_NAME);
            if (level.sysManager.grapSystem.removeGravity == 1)
            {
                level.getPlayer().removeComponent(GlobalVars.GRAVITY_COMPONENT_NAME);
            }
        }
        public void Grapple()
        {
            PositionComponent playerPos = (PositionComponent)level.getPlayer().getComponent(GlobalVars.POSITION_COMPONENT_NAME);

            //Get the direction
            double dir = 0;


            float mouseX = level.getInputSystem().mouseX + level.sysManager.drawSystem.mainView.x;
            float mouseY = level.getInputSystem().mouseY + level.sysManager.drawSystem.mainView.y;

            float xDiff = mouseX - playerPos.x;
            float yDiff = mouseY - playerPos.y;

            dir = Math.Atan(yDiff / xDiff);

            if (mouseX < playerPos.x)
            {
                dir += Math.PI;
                if (!level.getPlayer().isLookingLeft())
                {
                    level.getPlayer().faceLeft();
                }
            }
            else if (mouseX > playerPos.x && !level.getPlayer().isLookingRight())
            {
                level.getPlayer().faceRight();
            }

            //Add the entity
            GrappleEntity grap = new GrappleEntity(level, new Random().Next(), playerPos.x, playerPos.y, dir);

            level.addEntity(grap);
            VelocityComponent velComp = (VelocityComponent)level.getPlayer().getComponent(GlobalVars.VELOCITY_COMPONENT_NAME);

            velComp.x = 0;
            level.getPlayer().removeComponent(GlobalVars.PLAYER_INPUT_COMPONENT_NAME);
            if (level.sysManager.grapSystem.removeGravity == 1)
            {
                level.getPlayer().removeComponent(GlobalVars.GRAVITY_COMPONENT_NAME);
            }
        }