Exemplo n.º 1
0
    public void resetGame()
    {
        isLive   = false;
        gameOver = false;
        if (cam.transform.position != pos4)
        {
            cam.transform.position = Vector3.Lerp(cam.transform.position, pos4, 3.0f * Time.deltaTime);
        }

        GameObject demoPlayer = GameObject.Find("ShipIcon");

        demoPlayer.tag = "shipIcon";
        LevelLogic LL = (LevelLogic)levelScreen.GetComponent(typeof(LevelLogic));

        LL.gameOver = false;

        gameOver = false;
        gameOverPrefab.SetActive(false);


        // enable the renderer
        levelScreen.SetActive(false);
        levelScreen.SetActive(true);

        highestWave = LL.currentWave;

        LL.reset();
        LL.enableTimer();
        LL.currentWave = highestWave;

        //LL.c

        isLive = true;
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.R))
        {
            Application.LoadLevel(0);
        }
        // CONTROLLING THE SCREEN CAMERA
        if ((Input.GetKeyDown(KeyCode.Space) || Input.GetButtonDown("joystick button 1")) && currentScreen != 3)
        {
            if (currentScreen == 0 || currentScreen == -1)
            {
                // advance a screen
                currentScreen += 1;

                AudioSource.PlayClipAtPoint(screenTransition, transform.position);
            }
            else if (currentScreen == 1)
            {
                // only if middle ship is selected
                int shipCheck = PlayerPrefs.GetInt("SelectedShip");
                //Debug.Log("shipcheck: " + shipCheck);
                if (shipCheck == 2)
                {
                    currentScreen += 1;
                    AudioSource.PlayClipAtPoint(screenTransition, transform.position);
                }
                else
                {
                    AudioSource.PlayClipAtPoint(errorSound, transform.position);
                }
            }
            else if (currentScreen == 2)
            {
                // if we are on go!
                MissionControl mC = (MissionControl)missionScreen.GetComponent(typeof(MissionControl));
                //Debug.Log(mC.curRow);
                if (mC.curRow == 5)
                {
                    if (mC.curCol == 3)
                    {
                        AudioSource.PlayClipAtPoint(screenTransition, transform.position);
                        currentScreen += 1;
                    }
                }
            }

            if (currentScreen > 3)
            {
                currentScreen = 0;
            }
        }
        else if ((Input.GetKeyDown(KeyCode.Backspace) || Input.GetButtonDown("joystick button 2")) && currentScreen != 3)
        {
            currentScreen -= 1;

            if (currentScreen <= -1)
            {
                currentScreen = -1;
            }

            if (currentScreen == 0)
            {
                AudioSource.PlayClipAtPoint(screenTransition, transform.position);
            }
            else if (currentScreen == 1)
            {
                //currentScreen += 1;
                AudioSource.PlayClipAtPoint(screenTransition, transform.position);
            }
        }

        if (currentScreen == -1)
        {
            cam.transform.position = Vector3.Lerp(cam.transform.position, pos0, 3.0f * Time.deltaTime);
        }

        // GAMESTATES
        if (currentScreen == 0)           // title
        {
            cam.transform.position = Vector3.Lerp(cam.transform.position, pos1, 3.0f * Time.deltaTime);
        }

        if (currentScreen == 1)           // hanger
        {
            cam.transform.position = Vector3.Lerp(cam.transform.position, pos2, 3.0f * Time.deltaTime);
        }

        if (currentScreen == 2)           // customize
        {
            cam.transform.position = Vector3.Lerp(cam.transform.position, pos3, 3.0f * Time.deltaTime);

            GameObject demoPlayer = GameObject.FindGameObjectWithTag("shipIcon");
            if (demoPlayer)
            {
                demoPlayer.tag = "Player";
            }

            // disable game cause we are customizing yo!
            if (isLive)
            {
                gameOverPrefab.SetActive(false);
                levelScreen.SetActive(false);
                LevelLogic LL = (LevelLogic)levelScreen.GetComponent(typeof(LevelLogic));
                LL.disableTimer();
                isLive = false;
            }
        }

        if (currentScreen == 3)           // play

        {
            if (cam.transform.position != pos4)
            {
                cam.transform.position = Vector3.Lerp(cam.transform.position, pos4, 3.0f * Time.deltaTime);
            }

            GameObject demoPlayer = GameObject.Find("ShipIcon");
            demoPlayer.tag = "shipIcon";
            LevelLogic LL = (LevelLogic)levelScreen.GetComponent(typeof(LevelLogic));


            if (isLive && LL.gameOver == true)
            {
                gameOver = true;
                gameOverPrefab.SetActive(true);
            }
            else
            {
                gameOver = false;
                gameOverPrefab.SetActive(false);
            }


            // trigger is live
            if (!isLive)
            {
                // enable the renderer
                levelScreen.SetActive(true);
                LL.reset();
                LL.enableTimer();
                isLive         = true;
                LL.currentWave = highestWave;
            }
        }
    }
Exemplo n.º 3
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
    }