Ejemplo n.º 1
0
    public float SlopeButton(int player)
    {
        if (player < players)
        {
            switch (types[player])
            {
            case ControllerType.WiiMote:
                if (WiiMoteControl.wiimote_isExpansionPortEnabled(playerControllerId[player]))
                {
                    return((float)-WiiMoteControl.wiimote_getRoll(playerControllerId[player]));
                }
                else
                {
                    return((float)(WiiMoteControl.wiimote_getPitch(playerControllerId[player])));
                }

            case ControllerType.Keyboard:
                Vector3 dir = new Vector3(Input.GetAxis("Horizontal"), -Input.GetAxis("Vertical"), 0);
                dir.Normalize();
                return(((Vector3.Cross(Vector3.up, dir).z < 0)? 1f : -1f) * Vector3.Angle(Vector3.up, dir));

            default:
                break;
            }
        }
        else
        {
            Debug.LogError("Player id does not exist. id " + player);
        }

        return(0f);
    }
Ejemplo n.º 2
0
    public bool PauseButton(int player)
    {
        if (player < players)
        {
            switch (types[player])
            {
            case ControllerType.WiiMote:
                if (WiiMoteControl.wiimote_isExpansionPortEnabled(playerControllerId[player]))
                {
                    return(WiiMoteControl.wiimote_getButton1(playerControllerId[player]));
                }
                else
                {
                    return(WiiMoteControl.wiimote_getButtonMinus(playerControllerId[player]));
                }

            case ControllerType.Keyboard:
                return(Input.GetKeyDown(KeyCode.P));

            default:
                break;
            }
        }
        else
        {
            Debug.LogError("Player id does not exist. id " + player);
        }

        return(false);
    }
Ejemplo n.º 3
0
    // Use this for initialization
    void Awake()
    {
        DontDestroyOnLoad(gameObject);
        wiiControl = (WiiMoteControl)GetComponent("WiiMoteControl");

        types = new ControllerType[4];

        playerControllerId = new int[4];
        playerAxis         = new axis[4];
        pressedTime        = new float[7, 4];
        lastPressed        = new bool[7, 4];
        actualSlope        = new float[4];

        for (int i = 0; i < 4; ++i)
        {
            types[i] = ControllerType.Undefined;
            for (int j = 0; j < 7; ++j)
            {
                pressedTime[j, i] = Time.time;
                lastPressed[j, i] = false;
            }
            actualSlope[i] = 0;
        }

        if (automaticRegisterId.Length == automaticRegisterPlayer.Length && automaticRegisterType.Length == automaticRegisterId.Length)
        {
            for (int i = 0; i < automaticRegisterId.Length; ++i)
            {
                int p = RegisterPlayer(automaticRegisterType[i], automaticRegisterId[i]);
                automaticRegisterPlayer[i].BroadcastMessage("SetPlayer", p);
            }
        }
    }
Ejemplo n.º 4
0
    public bool AbilityPowerUpButton(int player)
    {
        if (player < players)
        {
            switch (types[player])
            {
            case ControllerType.WiiMote:
                if (WiiMoteControl.wiimote_isExpansionPortEnabled(playerControllerId[player]))
                {
                    return(WiiMoteControl.wiimote_getButtonNunchuckZ(playerControllerId[player]));
                }
                else
                {
                    return(WiiMoteControl.wiimote_getButtonPlus(playerControllerId[player]));
                }

            case ControllerType.Keyboard:
                return(Input.GetButtonDown("Fire2"));

            default:
                break;
            }
        }
        else
        {
            Debug.LogError("Player id does not exist. id " + player);
        }

        return(false);
    }
Ejemplo n.º 5
0
    public int RegisterPlayer(ControllerType type, int id)
    {
        if (players < 4)
        {
            types[players] = type;

            //TODO diferent types of controller
            switch (type)
            {
            case ControllerType.WiiMote:
                playerControllerId[players] = id;

                if (!WiiMoteControl.wiimote_isExpansionPortEnabled(id))
                {
                    playerAxis[players].init();
                }

                break;

            default:
                break;
            }
            //Debug.Log(players);
            return(players++);
        }
        else
        {
            Debug.LogError("4 Players cap reached");
        }

        return(-1);
    }
Ejemplo n.º 6
0
    /*
     * Returns a value between -1 and 1
     * LEFT <= -1 .. 1 <= RIGHT
     */
    public float HorizontalAxis(int player)
    {
        if (player < players)
        {
            switch (types[player])
            {
            case ControllerType.WiiMote:
                if (WiiMoteControl.wiimote_isExpansionPortEnabled(playerControllerId[player]))
                {
                    return(Mathf.Clamp(((float)(WiiMoteControl.wiimote_getNunchuckStickX(playerControllerId[player]) - NUNCHUCK_MARGIN - NUNCHUCK_RANGE / 2))
                                       / ((float)(NUNCHUCK_RANGE) / 2f), -1f, 1f));
                }
                else
                {
                    return(playerAxis[player].h);
                }

            case ControllerType.Keyboard:
                return(Input.GetAxis("Horizontal"));

            default:
                break;
            }
        }
        else
        {
            Debug.LogError("Player id does not exist. id " + player);
        }

        return(0);
    }
Ejemplo n.º 7
0
    // Use this for initialization
    void Start()
    {
        Control control = GameObject.FindGameObjectWithTag("Control").GetComponent <Control>();

        count = WiiMoteControl.wiimote_count();

        bi = GameObject.FindGameObjectWithTag("BattleInformer").GetComponent <BattleInformer>();
    }
Ejemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        time += Time.deltaTime;

        if (time > firsTime)
        {
            if (firsTime > 0)
            {
                control  = GameObject.FindGameObjectWithTag("Control").GetComponent <Control>();
                firsTime = -1;
            }

            switch (state)
            {
            case IntroState.Detecting:
                if (WiiMoteControl.wiimote_count() > 1)
                {
                    SetState(IntroState.Studio);
                }
                break;

            case IntroState.Studio:
                if (time > studioTime)
                {
                    SetState(IntroState.Credits);
                }
                break;

            case IntroState.Credits:
                if (time > creditsTime)
                {
                    SetState(IntroState.Video);
                }
                break;

            case IntroState.Video:
                if (control.Accept())
                {
                    Application.LoadLevel(Application.loadedLevel + 1);
                }
                if (!((MovieTexture)renderer.material.mainTexture).isPlaying && !audio.isPlaying)
                {
                    Application.LoadLevel(Application.loadedLevel + 1);
                }
                break;
            }
        }
    }
Ejemplo n.º 9
0
    // Use this for initialization
    void Start()
    {
        Physics.gravity = new Vector3(0, -9.81f, 0);
        Time.timeScale  = 1.0f;
        Control        control = GameObject.FindGameObjectWithTag("Control").GetComponent <Control>();
        BattleInformer bi      = GameObject.FindGameObjectWithTag("BattleInformer").GetComponent <BattleInformer>();

        int c = WiiMoteControl.wiimote_count();

        if (c > 0)
        {
            for (int i = 0; i <= c - 1; i++)
            {
                //control.RegisterPlayer(Control.ControllerType.WiiMote, i);
                bi.changePlayer(standardAvatar, i, 0);
            }
        }
        else
        {
            Debug.Log("No hay mandos, tolai!");
        }
    }
Ejemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        if (automaticDetect)
        {
            int c = WiiMoteControl.wiimote_count();
            //Debug.Log("AutomaticDetecting_ "+c);
            if (c > players)
            {
                for (int i = players; i <= Mathf.Min(c - 1, 4); i++)
                {
                    RegisterPlayer(ControllerType.WiiMote, i);
                }
            }

            automaticDetect = false;
        }

        //Debug.Log(WiiMoteControl.wiimote_getButton2(playerControllerId[0]));

        for (int i = 0; i < 4; ++i)
        {
            if (types[i] == ControllerType.Undefined)
            {
                continue;
            }

            switch (types[i])
            {
            case ControllerType.WiiMote:
                int id = playerControllerId[i];

                for (int j = 0; j < 7; ++j)
                {
                    bool button = false;
                    switch (j)
                    {
                    case 0:
                        button = JumpButton(i); break;

                    case 1:
                        button = AttackButton(i); break;

                    case 2:
                        button = AbilityWorldButton(i); break;

                    case 3:
                        button = AbilityGravityButton(i); break;

                    case 4:
                        button = AbilityPowerUpButton(i); break;

                    case 5:
                        button = AbilitySkillButton(i); break;

                    case 6:
                        button = PauseButton(i); break;
                    }
                    if (button && !lastPressed[j, i])
                    {
                        pressedTime[j, i] = Time.time;
                    }
                    lastPressed[j, i] = button;
                }
                //AXIS
                //Case not nunchuck
                if (!WiiMoteControl.wiimote_isExpansionPortEnabled(id))
                {
                    if (WiiMoteControl.wiimote_getButtonRight(id))                               // UP
                    {
                        if (playerAxis[i].v < 0.0f)
                        {
                            playerAxis[i].v = 0.0f;
                        }
                        playerAxis[i].v = Mathf.Lerp(playerAxis[i].v, 1.0f, AXIS_SPEED * Time.deltaTime);
                    }
                    else if (WiiMoteControl.wiimote_getButtonLeft(id))                               // DOWN
                    {
                        if (playerAxis[i].v > 0.0f)
                        {
                            playerAxis[i].v = 0.0f;
                        }
                        playerAxis[i].v = Mathf.Lerp(playerAxis[i].v, -1.0f, AXIS_SPEED * Time.deltaTime);
                    }
                    else
                    {
                        playerAxis[i].v = Mathf.Lerp(playerAxis[i].v, 0f, AXIS_SPEED * 2f * Time.deltaTime);
                    }

                    if (WiiMoteControl.wiimote_getButtonDown(id))                               // RIGHT
                    {
                        if (playerAxis[i].h < 0.0f)
                        {
                            playerAxis[i].h = 0.0f;
                        }
                        playerAxis[i].h = Mathf.Lerp(playerAxis[i].h, 1.0f, AXIS_SPEED * Time.deltaTime);
                    }
                    else if (WiiMoteControl.wiimote_getButtonUp(id))                               // LEFT
                    {
                        if (playerAxis[i].h > 0.0f)
                        {
                            playerAxis[i].h = 0.0f;
                        }
                        playerAxis[i].h = Mathf.Lerp(playerAxis[i].h, -1.0f, AXIS_SPEED * Time.deltaTime);
                    }
                    else
                    {
                        playerAxis[i].h = Mathf.Lerp(playerAxis[i].h, 0, AXIS_SPEED * 2f * Time.deltaTime);
                    }
                }
                break;

            default:
                break;
            }

            actualSlope[i] = SlopeButton(i);
        }
    }
Ejemplo n.º 11
0
 public bool isNunchuckEnabled(int player)
 {
     return(WiiMoteControl.wiimote_isExpansionPortEnabled(playerControllerId[player]));
 }
Ejemplo n.º 12
0
    // Use this for initialization
    void Awake()
    {
        DontDestroyOnLoad(gameObject);
        wiiControl = (WiiMoteControl)GetComponent("WiiMoteControl");

        types = new ControllerType[4];

        playerControllerId = new int[4];
        playerAxis = new axis[4];
        pressedTime = new float[7,4];
        lastPressed = new bool[7,4];
        actualSlope = new float[4];

        for (int i = 0; i < 4; ++i) {
            types[i] = ControllerType.Undefined;
            for (int j = 0; j < 7; ++j) {
                pressedTime[j,i] = Time.time;
                lastPressed[j,i] = false;
            }
            actualSlope[i] = 0;
        }

        if (automaticRegisterId.Length == automaticRegisterPlayer.Length && automaticRegisterType.Length == automaticRegisterId.Length) {
            for (int i = 0; i < automaticRegisterId.Length; ++i) {
                int p = RegisterPlayer(automaticRegisterType[i], automaticRegisterId[i]);
                automaticRegisterPlayer[i].BroadcastMessage("SetPlayer", p);
            }
        }
    }