Esempio n. 1
0
    /// <summary>
    /// Use for the keyboardMode
    /// </summary>
    private void InputManager()
    {
        // left, right
        float x = Input.GetAxisRaw("Horizontal");

        // up, down
        float y = Input.GetAxisRaw("Vertical");

        // move direction
        Vector2 direction = new Vector2(x, y).normalized;

        spaceship.Move(direction);

        //Color Switch
        if (Input.GetKeyUp(KeyCode.Space))
        {
            currentColor = (currentColor == Spaceship.ColorType.firstColor) ? Spaceship.ColorType.secondColor : Spaceship.ColorType.firstColor;
            ColorSwitch();
        }

        //Suicide
        if (Input.GetKeyUp(KeyCode.RightControl))
        {
            Destruction();
        }
    }
Esempio n. 2
0
    void Start()
    {
        spaceship    = this.GetComponent <Spaceship>();
        currentColor = Spaceship.ColorType.secondColor;

        spaceShipRenderer = gameObject.GetComponent <SpriteRenderer>();
        playerBullet      = spaceship.bullet;
        this.GetComponent <Animator>().SetBool("isAlive", isAlive);
        Respawn();

        gameManager = GameObject.FindWithTag("GameManager").GetComponent <Manager>();

        currentColor = Spaceship.ColorType.firstColor;
        ColorSwitch();

        StartCoroutine(Shoot());
    }
Esempio n. 3
0
    /// <summary>
    /// Switch between the player's colors, and corrected his position
    /// </summary>
    private void ColorManagement()
    {
        if (ColorDetection.yellowTuple.Item1 < -10000)
        {
            currentColor = Spaceship.ColorType.secondColor;
            ColorSwitch();
        }
        else if (ColorDetection.blueTuple.Item1 < -10000)
        {
            currentColor = Spaceship.ColorType.firstColor;
            ColorSwitch();
        }

        //Debug.Log("yellow : " + x + " - " + y);
        //resolution de la webcam : 620 x 460
        //taille de la camera : 40 x 20
        //ce sont les calcul pour cadrer les vaisseau dans la camera
        float x, y, posX, posY;

        switch (currentColor)
        {
        case Spaceship.ColorType.firstColor:

            x = ColorDetection.yellowTuple.Item1;
            y = ColorDetection.yellowTuple.Item2;

            posX = ((x - 310f) / 310.0f) * 3.5f;
            posY = (((y - 230) / 230.0f) * 2.6f) * -1.0f;

            gameObject.transform.position = new Vector3(posX, posY);
            break;

        case Spaceship.ColorType.secondColor:
            x = ColorDetection.blueTuple.Item1;
            y = ColorDetection.blueTuple.Item2;

            posX = ((x - 310f) / 310.0f) * 3.5f;
            posY = (((y - 230) / 230.0f) * 2.6f) * -1.0f;

            gameObject.transform.position = new Vector3(posX, posY);
            break;

        default:
            break;
        }
    }