Beispiel #1
0
 public void PickupItem(GameObject item)
 {
     if (playerInventory == null)
     {
         playerInventory = InstanceDatabase.GetMainInventoryReference().GetComponent <InventoryFunctions> ();
     }
     //This does not check the resourcereference property of the attached script as a comparison, only the tag.  Consider changing later.
     if (item.CompareTag("ExpNodule"))
     {
         transform.parent.gameObject.GetComponent <PlayerHealthPanelManager> ().OnExperienceNodulePickedUp();
         Destroy(item);
     }
     else if (item.CompareTag("Coin"))
     {
         transform.parent.gameObject.GetComponent <PlayerHealthPanelManager> ().OnCoinPickedUp(1);
         Destroy(item);
     }
     else
     {
         ResourceReferenceWithStack pendingObject = item.GetComponent <DroppedItemProperties> ().localResourceReference;
         if (!playerInventory.AssignNewItemToBestSlot(pendingObject))
         {
             Debug.LogError("ERROR WHEN ASSIGNING OBJECT");
         }
         else
         {
             Destroy(item);
         }
     }
 }
Beispiel #2
0
 //Set references to the playerIcon, start necessary coroutines, etc.
 void InitializeNPCPanelController()
 {
     playerTransform   = InstanceDatabase.GetPlayerReference().transform;
     playerIcon        = transform.FindChild("FlippingItem").FindChild("Character").FindChild("Head").GetComponent <SpriteRenderer> ().sprite;
     mainSpeechControl = InstanceDatabase.GetLevelUIReference().transform.FindChild("Speech Bubble").GetComponent <SpeechControl> ();
     mainInteractablePanelController = InstanceDatabase.GetLevelUIReference().transform.FindChild("InteractablePanels").gameObject.GetComponent <InteractablePanelController> ();
     StartCoroutine("CheckForAndAttemptToSpeakToPlayer");
 }
Beispiel #3
0
    protected override void InitializeCharacter()
    {
        //Set required variables for the enemy to function.
        player = InstanceDatabase.GetPlayerReference().transform;

        InitializeEnemy();

        enemyControlCoroutine = EnemyControl();
        StartCoroutine(enemyControlCoroutine);
    }
Beispiel #4
0
    //Assigns a new item to the best possible slot.
    public bool AssignNewItemToBestSlot(ResourceReferenceWithStack item)
    {
        //Has to be here for the return statement
        bool successfullyAssigned = false;

        //Make sure that the prerequisites are met.
        if (initialized && item != null)
        {
            SlotScript bestAvailableSlot = FindBestAvailableSlot(item);

            if (bestAvailableSlot != null)
            {
                //Set successfully assigned.
                successfullyAssigned = true;
                //Add the new stack to the current item stack.
                bestAvailableSlot.ModifyCurrentItemStack(item.stack);
                Debug.Log("Assigned " + item.uiSlotContent.itemScreenName + " to slot with items of same type.");
                //Check whether an objective has been completed
            }
            else
            {
                Debug.Log("Could not stack item: Attempting to add to an empty slot");
                bestAvailableSlot = FindBestAvailableNullSlot();
                if (bestAvailableSlot != null)
                {
                    successfullyAssigned = true;
                    bestAvailableSlot.AssignNewItem(item);
                    //Update the hotbar item.
                    InstanceDatabase.GetLevelUIReference().transform.FindChild("Hotbar").GetComponent <HotbarManager> ().UpdateSelectedItem();
                    //Check whether an objective has been completed
                }
                else
                {
                    Debug.LogError("No slots are empty!");
                }
            }
        }
        else
        {
            if (initialized == false && item == null)
            {
                Debug.LogError("Not initialized and item is null");
            }
            else if (initialized == false)
            {
                Debug.LogError("Not initialized");
            }
            else
            {
                Debug.LogError("Item is null");
            }
        }

        return(successfullyAssigned);
    }
Beispiel #5
0
 //Look into initializing this once the player comes into activation distance.
 //Has to be public for Thuk Guards.  Could be extended though.
 public virtual void InitializeHealthBar()
 {
     player        = InstanceDatabase.GetPlayerReference().transform;
     currentHealth = lifePoints;
     //Create panel
     uiHealthController = InstanceDatabase.GetLevelUIReference().transform.FindChild("Health Controller").gameObject.GetComponent <UIHealthController> ();
     //Initialize icon
     characterHeadSprite = transform.GetChild(0).GetChild(0).FindChild("Head").GetComponent <SpriteRenderer> ().sprite;
     //Start the coroutine that manages the active state of the health bar item.
     StartCoroutine(ControlHealthBarState());
 }
Beispiel #6
0
    //Initializing the NPC
    protected override void InitializeCharacter()
    {
        //Get required components.
        playerTransform = InstanceDatabase.GetPlayerReference().transform;
        playerInventory = InstanceDatabase.GetMainInventoryReference().GetComponent <InventoryFunctions> ();

        //Initialize the NPC before starting to walk around.
        InitializeNPC();
        //Create and start the coroutine.
        walkAroundCoroutine = WalkAround();
        StartCoroutine(walkAroundCoroutine);
    }
Beispiel #7
0
    IEnumerator MoveElevatorCoroutine()
    {
        //Make sure that the player moves with the elevator.
        InstanceDatabase.GetPlayerReference().transform.SetParent(transform.GetChild(0).FindChild("Elevator"));

        Animator anim = transform.GetChild(0).GetComponent <Animator> ();

        //Wait until the elevator is above the terrain.
        anim.SetTrigger("MoveUp");
        while (movedUp == false)
        {
            yield return(null);
        }

        //Make it look to the player that the elevator is still moving.
        anim.SetBool("AppearMoving", true);

        //Move the elevator below the terrain
        transform.position = new Vector3(transform.position.x, -35.13f, 0);

        transform.GetChild(0).FindChild("Elevator").transform.localPosition = Vector3.zero;

        transform.SetParent(null);

        //Create the level.  HAS TO BE PREINCREMENT NOT POSTINCREMENT
        LevelGenerator.instance.CreateLevel(++LevelGenerator.instance.currentLevel);

        yield return(new WaitForSeconds(6));

        //Move back up to the receiver.
        anim.SetBool("AppearMoving", false);
        anim.SetTrigger("MoveBack");

        //Unparent the player so that he/she will not be destroyed as well.
        while (movedToNextLevel == false)
        {
            yield return(null);
        }

        InstanceDatabase.GetPlayerReference().transform.SetParent(null);

        //Wait until the player leaves the level.
        int currentLevel = LevelGenerator.instance.currentLevel;

        while (LevelGenerator.instance.currentLevel == currentLevel)
        {
            yield return(null);
        }

        //Remove the elevator after the level changes so that they are not cluttering the scene.
        Destroy(gameObject);
    }
Beispiel #8
0
    //When an item drop hits the player.
    void OnTriggerEnter2D(Collider2D externalTrigger)
    {
        if (playerInventory == null)
        {
            playerInventory = InstanceDatabase.GetMainInventoryReference().GetComponent <InventoryFunctions> ();
        }

        if (((externalTrigger.gameObject.GetComponent <DroppedItemProperties> () != null || externalTrigger.gameObject.CompareTag("Coin") ||
              externalTrigger.gameObject.CompareTag("ExpNodule"))) && playerInventory.IsInitialized())
        {
            PickupItem(externalTrigger.gameObject);
        }
    }
Beispiel #9
0
    /******************************* MOUSE CLICK MANAGER *******************************/

    public void OnPointerClick(PointerEventData data)
    {
        if (data.button == PointerEventData.InputButton.Left)
        {
            if (currentlyAssigned != null)
            {
                if (InstanceDatabase.GetPlayerReference().GetComponent <PlayerHealthPanelManager> ().GiveMoneyToPlayer(-currentlyAssigned.price))
                {
                    //Add the deassigned item to the player inventory and deduct the price of the item.
                    InstanceDatabase.GetMainInventoryReference().GetComponent <InventoryFunctions> ().AssignNewItemToBestSlot(new ResourceReferenceWithStack(currentlyAssigned.mainContentReference.uiSlotContent, 1));
                    ModifyCurrentItemStack(-1);
                }
            }
        }
    }
Beispiel #10
0
    public override void InitializeHealthBar()
    {
        if (lifePoints <= 0)
        {
            Debug.Log("Player health is " + lifePoints + " which is an invalid value.  Switching to 10.");
            lifePoints = 10;
        }
        currentHealth = lifePoints;
        //Create panel
        uiHealthController         = InstanceDatabase.GetLevelUIReference().transform.FindChild("Health Controller").gameObject.GetComponent <UIHealthController> ();
        playerHealthPanelReference = uiHealthController.GetPlayerHealthPanelReference();
        //Initialize icon
        characterHeadSprite = transform.FindChild("FlippingItem").GetChild(0).FindChild("Head").GetComponent <SpriteRenderer> ().sprite;
        playerHealthPanelReference.InitializePanel(characterHeadSprite, lifePoints, currentHealth);

        //Give player money obtained previously.
        GiveMoneyToPlayer(GameData.GetPlayerMoney());
    }
    public IEnumerator LoadEverything()
    {
        //Add the main game UI
        AsyncOperation loadingOperation = SceneManager.LoadSceneAsync("MainGameUI", LoadSceneMode.Additive);

        while (!loadingOperation.isDone)
        {
            yield return(null);
        }

        //Initialize the instances of the newly created objects.
        InstanceDatabase.SetLevelReferences();
        //Initialize the UI
        UIInitializationSequence.instance.Initialize();
        //Create the level (the turrets require the player).
        LevelGenerator.instance.Initialize();

        if (InitializeCostume != null)
        {
            InitializeCostume();
        }
        else
        {
            Debug.LogError("InitializeCostume was null!");                                                              //Used for PlayerCostumeManager
        }
        if (InitializePlayer != null)
        {
            InitializePlayer();
        }
        else
        {
            Debug.LogError("InitializePlayer was null!");                                                             //Used for initializing the HumanoidBaseReferenceClass.
        }
        if (InitializeCameraFunctions != null)
        {
            InitializeCameraFunctions();
        }
        else
        {
            Debug.LogError("InitializeCameraFunctions was null!");                                                                               // Used for camera controller.
        }
    }
Beispiel #12
0
    //Called by LevelEventManager.
    void InitializeHotbarManager()
    {
        //Define player and hotbar slots.
        Transform slotParent = transform.FindChild("Slots");

        playerObject         = InstanceDatabase.GetPlayerReference();
        playerCostumeManager = playerObject.transform.FindChild("FlippingItem").FindChild("Character").GetComponent <PlayerCostumeManager>();
        hotbarSlots          = new HotbarSlotScript[slotParent.childCount];
        for (int i = 0; i < slotParent.childCount; i++)
        {
            hotbarSlots[i] = slotParent.GetChild(i).GetComponent <HotbarSlotScript> ();
            hotbarSlots[i].masterHotbarManager = this;
        }

        previouslyActiveSlot = -1;
        currentlyActiveSlot  = 0;

        StartCoroutine(CheckForActiveItemKey());
        StartCoroutine(CheckForPlayerDropItem());
    }
Beispiel #13
0
    public virtual void Initialize(Vector2 positionToFireToward, float velocity, float power)
    {
        playerObject = InstanceDatabase.GetPlayerReference();
        //Get the Rigidbody component so that physics can be used.
        rb2d = GetComponent <Rigidbody2D> ();

        //Calculate the heading to the fire location.
        float radianAngleToTarget = Mathf.Atan2((positionToFireToward.y - transform.position.y), (positionToFireToward.x - transform.position.x));
        float degreeAngleToTarget = radianAngleToTarget * Mathf.Rad2Deg;

        //Turn to the heading and move in that direction.
        transform.localRotation = Quaternion.Euler(new Vector3(0, 0, degreeAngleToTarget));
        rb2d.velocity           = new Vector2(velocity * Mathf.Cos(ScriptingUtilities.DegreesToRadians(degreeAngleToTarget)), velocity * Mathf.Sin(ScriptingUtilities.DegreesToRadians(degreeAngleToTarget)));

        //Set the strength of the arrow.
        this.power = power;

        //Start the coroutine that checks when the arrow should be destroyed (takes up memory space)
        StartCoroutine(DestroyIfDistanceFromPlayer());
    }
Beispiel #14
0
 //Just added.
 protected void ChangeStackOfCurrentHotbarItem(int stackToChangeBy)
 {
     InstanceDatabase.GetLevelUIReference().transform.FindChild("Hotbar").GetComponent <HotbarManager> ().ModifyStackOfSelectedItem(1);
 }
Beispiel #15
0
 public void Initialize()
 {
     player = InstanceDatabase.GetPlayerReference().transform;
     StartCoroutine(MoveTowardsPlayer());
 }