Exemple #1
0
    void checkLightSources()
    {
        List <Color> listOfColors = new List <Color>();

        Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, colliderRadius);

        foreach (Collider2D collider in colliders)
        {
            // If player's spotlight colliding
            if (collider.name == "SpotlightCollider")
            {
                listOfColors.Add(collider.transform.parent.GetComponent <PlayerController>().playerColor);
                continue;
            }

            Torch torch = collider.GetComponentInParent <Torch>(); // If torch
            if (torch != null && torch.on)
            {
                listOfColors.Add(torch.GetComponent <SpriteRenderer>().color);
            }
        }

        if (listOfColors.Count > 0)
        {
            illuminate(listOfColors);
        }
        else
        {
            darken();
        }
    }
Exemple #2
0
        void Update()
        {
            // keyboard shortcuts

            if (Input.GetKeyDown("space") && Time.realtimeSinceStartup > 3.0f)
            {
                //GetComponent<CharacterMotor>().enabled = true;
            }

            if (Input.GetKeyDown("v"))
            {
                Engine.SaveWorldInstant();
            }

            if (Input.GetKeyDown("f"))
            {
                if (Flashlight.GetComponent <Light>().enabled == true)
                {
                    Flashlight.GetComponent <Light>().enabled = false;
                }
                else
                {
                    Flashlight.GetComponent <Light>().enabled = true;
                }
            }

            if (Input.GetKeyDown("t"))
            {
                if (Torch.GetComponent <Light>().enabled == true)
                {
                    Torch.GetComponent <Light>().enabled = false;
                }
                else
                {
                    Torch.GetComponent <Light>().enabled = true;
                }
            }


            // world save timer
            if (saveTimer < 0.0f)
            {
                saveTimer = 60.0f;
                Engine.SaveWorld();
            }
            else
            {
                saveTimer -= Time.deltaTime;
            }
        }
Exemple #3
0
        private void EnableTorch(bool on)
        {
            Torch.GetComponent <Light>().enabled = on;

            var screenManager = Service.Get <ScreenManager>();

            if (screenManager != null)
            {
                var gameScreen = screenManager.GetScreen("GameScreen") as GameScreen;

                if (gameScreen != null)
                {
                    gameScreen.ToggleTorch(on);
                }
            }
        }
    private void Door_OnTorchLitEvent(Torch torch)
    {
        var entityIdComponent = torch.GetComponent <EntityId>();

        if (entityIdComponent == null || !_torchesToTrack.Contains(entityIdComponent.Id))
        {
            Debug.Log("Not Found");
            // This is not the enemy you're looking for...
            return;
        }

        _torchesToLit--;
        if (_torchesToLit <= 0)
        {
            Unlock();
            Unregister();
        }
    }
Exemple #5
0
    private void ThrowTorch(GameObject throwingObject)
    {
        Vector3 worldMousePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f));
        Vector3 faceDirection      = worldMousePosition - transform.position;
        var     aimAngle           = Mathf.Atan2(faceDirection.y, faceDirection.x);

        if (aimAngle < 0f)
        {
            aimAngle = Mathf.PI * 2 + aimAngle;
        }
        var aimDirection = Quaternion.Euler(0, 0, aimAngle * Mathf.Rad2Deg) * Vector2.right;
        // Vector2 dir = (Vector2)throwingObject.transform.position * faceDirection ;
        Torch t = throwingObject.GetComponent <Torch>();

        if (t)
        {
            t.rb.AddForce(aimDirection.normalized * t.force, ForceMode2D.Impulse);
            Physics2D.IgnoreCollision(this.GetComponent <Collider2D>(), t.GetComponent <Collider2D>());
            SoundManager.instance.PlaySFX("Throw", this.gameObject, 2f);

            /*
             * torch.ThrowTorch(faceDirection);*/
        }
    }
    //where type 0 is tutorial and type 1 is dungeon and type 2 is arena.
    IEnumerator CreateLevel(int type)
    {
        if (inGameCameraObject == null)
        {
            inGameCameraObject = Instantiate(inGameCameraPrefab);
            mainCamera         = inGameCameraObject.GetComponentInChildren <Camera> ();
        }

        yield return(new WaitForSeconds(.1f));

        if (!PlayerPrefs.HasKey("TexturesRandomized") || RandomizeTexturesAllowed)
        {
            RandomizeTextures();
            PlayerPrefs.SetInt("TexturesRandomized", 1);
        }

        if (type == 1)
        {
            int cappedDungeonLevel = dungeonLevel;
            if (cappedDungeonLevel > 40)
            {
                cappedDungeonLevel = 40;
            }
            masterGenerator = new MasterGenerator(this.gameObject, dungeonData.dungeonParameters[cappedDungeonLevel], radius, maxlength, timeout);
            masterGenerator.LoadPrefabs();
            masterGenerator.Constructing();
        }
        else if (type == 0)
        {
            tutorialObject = Instantiate(tutorialPrefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            levelTransform = tutorialObject.transform;
        }
        else if (type == 2)
        {
            arenaObject    = Instantiate(arenaPrefab, new Vector3(-150f, 0f, 150f), Quaternion.identity) as GameObject;
            levelTransform = arenaObject.transform;
        }

        if (ui == null)
        {
            ui          = Instantiate(UIPrefab);
            uiInventory = ui.uiInventory;
        }

        TorchFOV = Instantiate(TorchFOVPrefab);

        triggerFloorObject = Instantiate(triggerFloorPrefab, levelTransform) as GameObject;

        torch = Instantiate(torchPrefab) as Torch;
        Instantiate(torchMinimapIndicator, torch.transform.position + new Vector3(0f, -3f, 0f), Quaternion.Euler(new Vector3(90f, 0f, 0f)), torch.transform);


        camTarget         = torch.gameObject;
        enemyTarget       = torch.gameObject;
        torch.health      = torchStartingHealth;
        torch.gameManager = this;
        torch.ui          = ui;
        torch.TorchFOV    = TorchFOV.GetComponentInChildren <Animator> ();

        collectedKeys = 0;

        for (int i = 0; i < playerManagers.Length; i++)
        {
            if (playerManagers [i].playerInstance == null)
            {
//				Debug.Log ("Create Player with id:" + i);
                playerManagers [i].playerInstance = Instantiate(playerPrefab) as GameObject;
                playerManagers [i].playerNumber   = i + 1;
                playerManagers [i].Setup();
                playerManagers [i].playerMovement.mainCamera = mainCamera;
                playerManagers [i].gameManager = this;
            }
            else
            {
                //			playerManagers [i].playerInstance.transform.position = masterGenerator.dungeon_instantiate.startPos;
                playerManagers [i].Setup();
                playerManagers [i].playerInstance.SetActive(true);
            }
        }

        ApplySkins();

        SetNumberOfPlayers(numberOfPlayers);

        //Moving players, torch and Bold to the correct place
        Vector3 startpoint = new Vector3(0f, 0f, 0f);

        if (type == 1)
        {
            startpoint        = masterGenerator.MovePlayersToStart();
            torch.isDamagable = true;
        }
        else if (type == 0)
        {
            startpoint = tutorialObject.transform.Find("Spawnpoint").transform.position;
            playerManagers [0].playerInstance.transform.position = startpoint;
            playerManagers [1].playerInstance.transform.position = startpoint + new Vector3(-2f, 0f, -2f);
            torch.isDamagable = false;
        }
        else if (type == 2)
        {
            startpoint = arenaObject.transform.Find("Spawnpoint").transform.position;
            playerManagers [0].playerInstance.transform.position = startpoint;
            playerManagers [1].playerInstance.transform.position = startpoint + new Vector3(-2f, 0f, -2f);
            torch.isDamagable = true;
        }
        RespawnPosition          = startpoint;
        torch.transform.position = startpoint + new Vector3(6, .5f, 0);

        if (type == 1 || type == 2)
        {
            Pet.transform.position = playerManagers [0].playerInstance.transform.position + new Vector3(3f, 0f, 0f);
            Pet.SetActive(true);
            Bold.SetActive(false);
        }
        else if (type == 0)
        {
            Pet.SetActive(false);
            Bold.SetActive(true);
            Bold.transform.position = playerManagers [0].playerInstance.transform.position;
        }

        torch.torchPickUp.cam = mainCamera;
        if (type == 1)
        {
            ui.dungeonLevelText.text = "Dungeon level " + dungeonLevel;
        }
        else if (type == 0)
        {
            ui.dungeonLevelText.text = "Dungeon Tutorial";
            BoldPetScript.speechCanvas.SetActive(true);
            BoldPetScript.speechText.text = "Welcome to this tutorial! My name is Bold. Use the WASD-keys to move.";
            BoldPetScript.speechImage.gameObject.SetActive(true);
        }
        else if (type == 2)
        {
            ui.dungeonLevelText.text = "ArenaMode";
            arenaManager.StartArena();
        }

        audioSourceMusic.clip = audioDungeon [UnityEngine.Random.Range(0, audioDungeon.Length)];
        if (torch.GetComponent <PartyTorch> () != null)
        {
            audioSourceMusic.clip = audioPartyTorch;
        }
        if (torch.GetComponent <GoldenTorch> () != null)
        {
            audioSourceMusic.clip = audioGoldenTorch;
        }
        audioSourceMusic.Play();
        score = 0;
        SetScore(totalScore);
        SetInGameCoin(coinsInGame);
        homeScreenCam.SetActive(false);
        loadingScreenCanvas.SetActive(false);

        minimap = Instantiate(minimapPrefab);

        ui.timer.Reset();

        StartTime = Time.time;
        mainCamera.GetComponent <CameraController> ().SetMode("Normal");

        yield return(null);
    }
Exemple #7
0
        void Update()
        {
            if (!chrCtrl.enabled && !ChunkManager.SpawningChunks)
            {
                chrCtrl.enabled = true;
            }

            energy -= Time.deltaTime;

            UpdateEnergy();

            // keyboard shortcuts

            if (Input.GetKeyDown("space") && Time.realtimeSinceStartup > 3.0f)
            {
                GetComponent <CharacterMotor>().enabled = true;
            }

            //if (Input.GetKeyDown("v")) {
            //    Engine.SaveWorldInstant();
            //}

            if (Input.GetKeyDown("f"))
            {
                if (Flashlight.GetComponent <Light>().enabled == true)
                {
                    EnableFlashlight(false);
                }
                else
                {
                    EnableFlashlight(true);
                }

                var audioManager = Service.Get <AudioManager>();

                if (audioManager != null)
                {
                    audioManager.PlaySound("UI_SELECTOR");
                }

                EnableTorch(false);
            }

            if (Input.GetKeyDown("t"))
            {
                if (Torch.GetComponent <Light>().enabled == true)
                {
                    EnableTorch(false);
                }
                else
                {
                    EnableTorch(true);
                }

                var audioManager = Service.Get <AudioManager>();

                if (audioManager != null)
                {
                    audioManager.PlaySound("UI_SELECTOR");
                }

                EnableFlashlight(false);
            }

            // world save timer
            //if (saveTimer < 0.0f) {
            //    saveTimer = 60.0f;
            //    Engine.SaveWorld();
            //}
            //else {
            //    saveTimer -= Time.deltaTime;
            //}
        }