Ejemplo n.º 1
0
    private void ProcessAsteroid(Collider2D other)
    {
        CustomTag ct = other.GetComponent <CustomTag>();

        if (ct != null && !ct.HasTag("grabbed"))
        {
            float amount;
            if (ct.HasTag("ice"))
            {
                AudioManager.Instance.PlayAsteroidCollected(other.transform.position, 1f);
                amount = other.GetComponent <Rigidbody2D>().mass;
                Destroy(other.gameObject);
                ship.ice += amount;
                if (QuestManager.instance.currentQuest.goal.goalType == GoalType.CollectIce)
                {
                    QuestManager.instance.currentQuest.goal.currentAmount = (int)ship.ice;
                }
            }
            else if (ct.HasTag("iron"))
            {
                AudioManager.Instance.PlayAsteroidCollected(other.transform.position, 1f);
                amount = other.GetComponent <Rigidbody2D>().mass;
                Destroy(other.gameObject);
                ship.iron += amount;
                if (QuestManager.instance.currentQuest.goal.goalType == GoalType.CollectIron)
                {
                    QuestManager.instance.currentQuest.goal.currentAmount = (int)ship.iron;
                }
            }
        }
    }
Ejemplo n.º 2
0
    public void Dock(bool showShop)
    {
        if (player.GetComponent <CapsuleController>().isConnected)
        {
            GameObject module = player.GetComponent <CapsuleController>().connected;
            CustomTag  ct     = module.GetComponent <CustomTag>();
            if (ct.HasTag("booster"))
            {
                storedBooster++;
            }
            else if (ct.HasTag("hauler"))
            {
                storedHauler++;
            }
            else if (ct.HasTag("scanner"))
            {
                storedScanner++;
            }
            else if (ct.HasTag("lander"))
            {
                storedLander++;
            }

            GameMaster.Instance.currentCapsule.GetComponent <CapsuleController>().DestroyConnected();
        }
        if (!canDock)
        {
            return;
        }
        AudioManager.Instance.PlayDockingSound();
        joint.connectedBody = player.GetComponent <Rigidbody2D>();
        float   angOffset = joint.angularOffset;
        Vector2 linOffset = joint.linearOffset;

        joint.autoConfigureOffset = true;
        joint.enabled             = true;
        joint.autoConfigureOffset = false;
        joint.angularOffset       = angOffset;
        joint.linearOffset        = linOffset;
        docked  = true;
        canDock = false;
        player.GetComponent <CapsuleController>().enabled = false;
        player.GetComponent <SelectorScript>().enabled    = false;
        player.GetComponent <GravityApplier>().enabled    = false;
        player.GetComponent <BuildingPlacer>().enabled    = false;
        player.GetComponent <HealthManager>().health      = 100;
        player.transform.Find("HUD").gameObject.SetActive(false);
        if (showShop)
        {
            dockingScreen.SetActive(true);
        }
        hangarLight.SetActive(true);
        //gui.SetActive(false);
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (objectsInPickupZone.Count > 0)
        {
            if (Input.GetButtonDown("HandLeft"))
            {
                //check if item is pickupable in one hand or is even able to be picked up first before setting it to the hand.

                //check if item is not to be picked up but instead interacted with
                if (handLeft.GetObjectInHand() == null)
                {
                    CustomTag tag = objectsInPickupZone[0].GetComponent <CustomTag>();
                    if (tag.HasTag("MiscItem"))
                    {
                        //if the inventory can place the item in a slot it will return true.
                        if (inventory.AddToInventory(objectsInPickupZone[0]))
                        {
                            objectsInPickupZone.RemoveAt(0);
                        }
                    }
                    else if (tag.HasTag("SmallItem"))
                    {
                        handLeft.SetObjectInHand(objectsInPickupZone[0]);
                        objectsInPickupZone.RemoveAt(0);
                    }
                    else if (tag.HasTag("LargeItem"))
                    {
                    }
                    else if (tag.HasTag("Backpack"))
                    {
                        inventory.AddBackpackToInventory(objectsInPickupZone[0].GetComponent <BackpackContainer>());
                        objectsInPickupZone.RemoveAt(0);
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.Q))
        {
            handLeft.DropItemInHand();
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            handRight.DropItemInHand();
        }
    }
Ejemplo n.º 4
0
    private void OnCollisionEnter(Collision collision)
    {
        CustomTag tag = collision.gameObject.GetComponent <CustomTag>();

        if (tag != null && tag.HasTag("Enemy"))
        {
            //hurt em
        }
        else
        {
            Destroy(gameObject, 5);
        }
    }
Ejemplo n.º 5
0
    //requires checking if inventory is full before adding.
    public bool AddToInventory(Item item)
    {
        bool placedInInventory;

        CustomTag tag = item.GetComponent <CustomTag>();

        if (tag.HasTag("MiscItem"))
        {
            if (miscSlots.Contains(EmptyItemPrefab))
            {
                miscIndex = miscSlots.IndexOf(EmptyItemPrefab);
                miscSlots.RemoveAt(miscIndex);
                miscSlots.Insert(miscIndex, item);
                item.GetComponent <IVisibility>().SetInvisible();
                item.GetComponent <IInteractionSound>().PlaySound();
                placedInInventory = true;
            }
            else
            {
                placedInInventory = false;
            }
        }
        else if (tag.HasTag("LargeItem"))
        {
            largeSlots.Add(item);
            placedInInventory = true;
        }
        else if (tag.HasTag("SmallItem"))
        {
            smallSlots.Add(item);
            placedInInventory = true;
        }
        else
        {
            placedInInventory = false;
        }

        return(placedInInventory);
    }
Ejemplo n.º 6
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        CustomTag ct = other.gameObject.GetComponent <CustomTag>();

        if (ct == null)
        {
            return;
        }

        if (ct.HasTag("iron"))
        {
            metalResources += other.gameObject.GetComponent <Rigidbody2D>().mass;
            Destroy(other.gameObject);
        }
    }
Ejemplo n.º 7
0
    private void OnTriggerExit(Collider other)
    {
        CustomTag tag = other.GetComponent <CustomTag>();

        if (tag != null)
        {
            if (tag.HasTag("CanPickUp"))
            {
                if (objectsInPickupZone.Contains(other.GetComponent <Item>()))
                {
                    objectsInPickupZone.Remove(other.GetComponent <Item>());
                }
            }
        }
    }
Ejemplo n.º 8
0
 private void OnCollisionEnter2D(Collision2D other)
 {
     if (deadly)
     {
         CustomTag ct = other.gameObject.GetComponent <CustomTag>();
         if (other.gameObject.CompareTag("Player"))
         {
             GameMaster.Instance.DestroyCapsule();
         }
         else if (ct != null && ct.HasTag("killable"))
         {
             Destroy(other.gameObject);
         }
     }
 }
Ejemplo n.º 9
0
 private void OnCollisionEnter2D(Collision2D other)
 {
     if (deadly)
     {
         CustomTag ct = other.gameObject.GetComponent <CustomTag>();
         if (other.gameObject.CompareTag("Player"))
         {
             //GameMaster.Instance.DestroyCapsule();
             other.gameObject.GetComponent <HealthManager>().Damage(Int32.MaxValue, 1);
         }
         else if (ct != null && ct.HasTag("killable"))
         {
             Destroy(other.gameObject);
         }
     }
 }
Ejemplo n.º 10
0
    private void Grab()
    {
        if (overlapped != null)
        {
            CustomTag ct = overlapped.GetComponent <CustomTag>();
            if (ct != null && ct.HasTag("grabbable"))
            {
                hasGrabbed = true;
                //overlapped.gameObject.transform.position = contact.transform.position;
                joint = overlapped.gameObject.AddComponent <FixedJoint2D>();
                joint.connectedBody = transform.root.GetComponent <Rigidbody2D>();

                grabbedObject = overlapped.gameObject;
                ct.AddTag("grabbed");
            }
        }
    }
Ejemplo n.º 11
0
    private void Update()
    {
        if (QuestManager.instance.currentQuest.goal.goalType != GoalType.BuildScanningPost)
        {
            return;
        }

        //TODO: implement function for multiple planets?
        //set planet to currently orbited
        if (GetComponent <GravityApplier>().planets.Count != 0)
        {
            planet = GetComponent <GravityApplier>().planets[0].gameObject.transform;
        }
        else
        {
            selectedBuilding = null;
            Destroy(indicator);
        }

        if (planet == null)
        {
            return;
        }
        CustomTag ct = planet.GetComponent <CustomTag>();

        if (ct == null)
        {
            return;
        }
        if (!ct.HasTag("buildScanner"))
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            Destroy(indicator);
            selectedBuilding = null;
            indicator        = null;
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            Destroy(indicator);
            selectedBuilding = listeningPost;
            indicator        = Instantiate(selectedBuilding, hit.point, quaternion.identity);

            indicator.transform.rotation = Quaternion.FromToRotation(Vector3.left, hit.normal);
            indicator.transform.Rotate(Vector3.forward, 90f);



            indicator.GetComponent <Collider2D>().isTrigger = true;
            indicator.transform.parent = planet;
            Physics2D.IgnoreCollision(indicator.GetComponent <Collider2D>(), GetComponent <Collider2D>());
        }

/*
 *      if (Input.GetKeyDown(KeyCode.Alpha2)){
 *          Destroy(indicator);
 *          selectedBuilding = waterCollector;
 *          indicator = Instantiate(selectedBuilding, hit.point, quaternion.identity);
 *          indicator.GetComponent<Collider2D>().isTrigger = true;
 *          indicator.transform.parent = planet;
 *          Physics2D.IgnoreCollision(indicator.GetComponent<Collider2D>(), GetComponent<Collider2D>());
 *      }*/

        //place building if the indicator is on a planet
        if (selectedBuilding != null && Input.GetMouseButtonDown(0))
        {
            if (hit.collider.gameObject.layer == 11 && canPlace)
            {
                GameObject selectedObject = Instantiate(selectedBuilding, hit.point, quaternion.identity);
                selectedObject.transform.parent   = planet;
                selectedObject.transform.position = indicator.transform.position;
                selectedObject.transform.rotation = indicator.transform.rotation;
                planet.GetComponent <Buildable>().metalResources -= buildingCost;
                planet.GetComponent <Buildable>().buildingCount++;
                Debug.DrawLine(hit.point, (hit.point + hit.normal * 5), Color.red, 10f);
            }
        }
    }