Example #1
0
    // Update is called once per frame
    void Update()
    {
        //mySprite.color.a += .1f;

        // controls
        if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
        {
            if (transform.position.x <= -50)
            {
                transform.position = new Vector3(-50, transform.position.y, transform.position.z);
            }
            if (transform.position.x >= 50)
            {
                transform.position = new Vector3(50, transform.position.y, transform.position.z);
            }
            if (transform.position.y <= -25)
            {
                transform.position = new Vector3(transform.position.x, -25, transform.position.z);
            }
            if (transform.position.y >= 25)
            {
                transform.position = new Vector3(transform.position.x, 25, transform.position.z);
            }


            dir.x = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
            dir.y = Input.GetAxis("Vertical") * speed * Time.deltaTime;
            transform.position += dir;

            thruster.particleSystem.enableEmission = true;             // turn ON thrusters
        }
        else
        {
            thruster.particleSystem.enableEmission = false;             // turn OFF thrusters
        }

        // which direction to spin?
        if (!Input.GetKey(KeyCode.Space))
        {
            if (!Input.GetButton("joystick button 1"))
            {
                //if (!Input.GetButton("joystick button 1")) {
                if (dir.x > 0)
                {
                    lastDir = 0;
                }
                else if (dir.x < 0)
                {
                    lastDir = 1;
                }
            }


            //}
        }

        if (Input.GetKey(KeyCode.Space) || Input.GetButton("joystick button 1"))
        {
            if (restartMode)
            {
                //screenManager.currentScreen = 2;
                levelLogic.killWave();
                //levelLogic.reset();
                isRestarting = false;
                screenManager.resetGame();

                levelLogic.enableTimer();
                //levelLogic.killWave();
                //levelLogic.restartLevel();
                //levelLogic.enableTimer();

                restartMode  = false;
                isRestarting = false;


                if (gameObject != null)
                {
                    Destroy(gameObject);
                }

                levelLogic.killWave();
            }
        }

        if (lastDir == 0)
        {
            endingRotation     = Quaternion.Euler(new Vector3(0, 0, 0));         // rotate right
            transform.rotation = Quaternion.Lerp(transform.rotation, endingRotation, Time.deltaTime * rotationSpeed);
        }
        else if (lastDir == 1)
        {
            endingRotation     = Quaternion.Euler(new Vector3(0, -180, 0));         // rotate left
            transform.rotation = Quaternion.Lerp(transform.rotation, endingRotation, Time.deltaTime * rotationSpeed);
        }


        // weapons
        if ((Input.GetKey(KeyCode.Space) || Input.GetButton("joystick button 1")) && !restartMode && !isDead)
        {
            if (Time.time >= NextFireAt)              // if the cooldown has been reached
            {
                AudioSource.PlayClipAtPoint(playerFireSound, transform.position);

                if (currentWeapon == 3)                   // laser

                {
                    LaserGun lG = laser.GetComponent <LaserGun>();

                    lG.fire();

                    NextFireAt = Time.time + LaserFireRate - fireRateMod;
                }

                if (currentWeapon == 1)                   // scatter
                {
                    GameObject.Instantiate(tripleShot, laserSpawn.transform.position, Quaternion.identity);
                    NextFireAt = Time.time + TripleFireRate - fireRateMod;
                }

                if (currentWeapon == 2)                   // melee
                {
                    GameObject.Instantiate(melee, laserSpawn.transform.position, Quaternion.identity);
                    NextFireAt = Time.time + MeleeFireRate - fireRateMod;
                }
                if (currentWeapon == 4)                   // mortar
                {
                    GameObject.Instantiate(mortarShot, laserSpawn.transform.position, Quaternion.identity);

                    NextFireAt = Time.time + MeleeFireRate - fireRateMod;
                }
            }
        }
        else if ((Input.GetKeyDown(KeyCode.Backspace) || Input.GetButton("joystick button 2")) && restartMode == true)
        {
            stopRestartTimer();

            screenManager.currentScreen = 2;

            isRestarting = false;

            restartMode = false;


            if (gameObject != null)
            {
                Destroy(gameObject);
            }

            levelLogic.killWave();
        }


        // are we dead yet?
        if (isDead)
        {
            transform.renderer.enabled             = false;
            thruster.particleSystem.enableEmission = false;             // turn OFF thrusterss


            restartTimer -= Time.deltaTime;
            isRestarting  = true;
            //pauseRestartTimer();

            //restartMode = true;
            if (restartTimer < 0)
            {
                Debug.Log("timer reached!");
                stopRestartTimer();
                //pauseRestartTimer();
                //pauseRestartTimer();
            }
        }
        else
        {
            transform.renderer.enabled = true;
        }


        // render the health bar
    }