Exemplo n.º 1
0
 // Use this for initialization
 void Awake()
 {
     Portal1 = GameObject.Instantiate(P1Prefab);
     Portal2 = GameObject.Instantiate(P2Prefab);
     Portal1.SetActive(false);
     Portal2.SetActive(false);
     portalLength = Portal1.GetComponent <BoxCollider2D>().size.y *3;
     PPos         = new PortalPosition(Portal1.transform.position, Portal2.transform.position);
 }
Exemplo n.º 2
0
    public GameObject createUnfinishedPortal(Portal2 portal)
    {
        Vector3    p1        = portal.base1.convertBaseCoordsToWorld();
        Vector3    p2        = portal.base2.convertBaseCoordsToWorld();
        GameObject portalObj = createPortal(p1, p1 + (p2 - p1) * .01f, portal);

        portalObj.GetComponent <Renderer>().material = portalBuildingMaterial;
        currentUnfinishedPortals.Add(portal);
        currentUnfinishedPortalObjs.Add(portalObj);
        return(portalObj);
    }
Exemplo n.º 3
0
    public GameObject createPortal(Portal2 portal)
    {
        Vector3 p1 = portal.base1.convertBaseCoordsToWorld();
        Vector3 p2 = portal.base2.convertBaseCoordsToWorld();

        p1 = p1 + (p2 - p1).normalized * Globals.baseRadius;
        p2 = p2 + (p1 - p2).normalized * Globals.baseRadius;
        GameObject pObj = createPortal(p1, p2, portal);

        pObj.GetComponent <Renderer>().material = portalMaterial;
        return(pObj);
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        //Create ray cast from player position to the platform
        if ((Input.GetButtonDown("Fire1") || Input.GetButtonDown("Fire2")) && !paused)
        {
            int platforms = LayerMask.GetMask("PortalPlatform", "Platform", "Barrier");
            int badportal;
            if (Input.GetButtonDown("Fire1"))
            {
                badportal = LayerMask.GetMask("Portal2");
            }
            else
            {
                badportal = LayerMask.GetMask("Portal1");
            }
            int pplatform = LayerMask.NameToLayer("PortalPlatform");

            Vector2 pos = transform.position;

            Vector2 target    = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2 direction = target - pos;

            RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, Mathf.Infinity, platforms | badportal);

            if (hit && hit.collider.gameObject.layer == pplatform)
            {
                Quaternion rotation = GetPortalRotation(hit);

                bool    makePortal = true;
                Vector2 consol     = PortalPositionConsolidation(ref makePortal, hit);
                Vector3 portalPos  = new Vector3(consol.x, consol.y, 0);

                if (Input.GetButtonDown("Fire1") && makePortal) //If right mouse click
                {
                    Portal1.SetActive(true);
                    Portal1.transform.rotation = rotation;
                    Portal1.transform.position = portalPos - (Portal1.transform.right * .2f);

                    PPos.p1   = Portal1.transform.position;
                    PPos.p1Or = shotOr;
                }
                else if (Input.GetButtonDown("Fire2") && makePortal)   //if left mouse click
                {
                    Portal2.SetActive(true);
                    Portal2.transform.rotation = rotation;
                    Portal2.transform.position = portalPos - (Portal2.transform.right * .2f);
                    PPos.p2   = Portal2.transform.position;
                    PPos.p2Or = shotOr;
                }
            }
        }
    }
Exemplo n.º 5
0
        public static void Notify(Enumerations.Events.Notify enumCase)
        {
            switch (Manage.CurrentAnnouncer)
            {
            case Enumerations.SoundPacks.Portal2:
                Portal2.Notify(enumCase);
                break;

            case Enumerations.SoundPacks.StanlyParable:
                StanleyParable.Notify(enumCase);
                break;
            }
        }
Exemplo n.º 6
0
        public static void Structure(Enumerations.Events.Structures enumCase)
        {
            switch (Manage.CurrentAnnouncer)
            {
            case Enumerations.SoundPacks.Portal2:
                Portal2.Structures(enumCase);
                break;

            case Enumerations.SoundPacks.StanlyParable:
                StanleyParable.Structures(enumCase);
                break;
            }
        }
Exemplo n.º 7
0
    // true if portal finished, false if unfinished
    public float getPortalPercentFinished(Portal2 p)
    {
        long buildTimeMilli = (long)(Globals.portalBuildTimeInMins * 60000.0);
        long curTime        = CurrentTime.currentTimeMillis();

        if (p.timeFinished <= curTime)
        {
            // Portal finished
            return(1.0f);
        }
        long startTime = p.timeFinished - buildTimeMilli;

        return(((curTime - startTime) / (buildTimeMilli * 1.0f)) * 1.0f);
    }
Exemplo n.º 8
0
 public void updateMoveTroops()
 {
     if (moveTroopsActions.Count > 0)
     {
         List <MoveTroopsAction> toRemove = new List <MoveTroopsAction> ();
         foreach (MoveTroopsAction a in moveTroopsActions)
         {
             Portal2 p = a.p;
             // If more troops to move
             if (Mathf.Abs(p.troopsToMove) > 0)
             {
                 // Update values based on Time.DeltaTime
                 a.overflowTroopsMoved += Time.deltaTime * p.flowRate;
                 int wholeUnitsMoved = (int)Mathf.Floor(a.overflowTroopsMoved);
                 if (wholeUnitsMoved > 0)
                 {
                     if (wholeUnitsMoved > Mathf.Abs(p.troopsToMove))
                     {
                         wholeUnitsMoved = Mathf.Abs(p.troopsToMove);
                     }
                     if (p.troopsToMove < 0)
                     {
                         wholeUnitsMoved *= -1;
                     }
                     // Update base text wrappers
                     a.p.base1.units       -= wholeUnitsMoved;
                     a.p.base2.units       += wholeUnitsMoved;
                     a.overflowTroopsMoved -= Mathf.Abs(wholeUnitsMoved);
                     p.troopsToMove        -= wholeUnitsMoved;
                 }
             }
             else
             {
                 // Remove action from list
                 toRemove.Add(a);
                 // Restore portal color
                 a.p.gameObject.GetComponent <Renderer>().material = PortalHandler.instance.portalMaterial;
                 // Final db sync
                 StartCoroutine("finishMoveTroops", a);
             }
         }
         foreach (MoveTroopsAction p in toRemove)
         {
             moveTroopsActions.Remove(p);
         }
     }
 }
Exemplo n.º 9
0
    public GameObject createPortal(Vector3 p1, Vector3 p2, Portal2 portal)
    {
        GameObject portalObj = (GameObject)Instantiate(portalPrefab, (p1 + p2) / 2, Quaternion.identity);

        if (portal != null)
        {
            portalObj.name    = "Portal" + portal.portalId;
            portal.gameObject = portalObj;
            portalObj.GetComponent <InstanceObjectScript> ().instanceObject = portal;
            ObjectInstanceDictionary.registerGameObject(portalObj.name, portalObj);
        }
        else
        {
            portalObj.name = "Portal" + -1;
        }

        scalePortalBetweenPoints(portalObj, p1, p2);
        rotatePortalBetweenPoints(portalObj, p1, p2);
        return(portalObj);
    }
 //sets pause screen active and unactive when escape is pressed
 public void Resume()
 {
     if (Canvas.gameObject.activeInHierarchy == false)
     {
         Canvas.gameObject.SetActive(true);
         Time.timeScale = 0;
         Portal1.GetComponent <Spin>().enabled = false;
         Portal2.GetComponent <Spin>().enabled = false;
         //Player.GetComponent<PlayerShoot>().enabled = false;
         //Sounds.GetComponent<AudioSource>().Pause();
     }
     else
     {
         Canvas.gameObject.SetActive(false);
         Time.timeScale = 1;
         Portal1.GetComponent <Spin>().enabled = true;
         Portal2.GetComponent <Spin>().enabled = true;
         //Player.GetComponent<PlayerShoot>().enabled = true;
         //Sounds.GetComponent<AudioSource>().Play();
     }
 }
Exemplo n.º 11
0
    IEnumerator createPortal(int base2Id)
    {
        WWWForm wwwform = new WWWForm();

        wwwform.AddField("username", Globals.username);
        wwwform.AddField("baseId1", GenerateWorld.instance.lastBase.baseId);
        wwwform.AddField("baseId2", base2Id);
        long finishTime = CurrentTime.currentTimeMillis() + (long)(Globals.portalBuildTimeInMins * 60000.0);

        wwwform.AddField("timeFinished", finishTime + "");
        wwwform.AddField("cost", PortalHandler.instance.costPerPortal);
        WWW request = new WWW("localhost:8080/myapp/world/portals/create", wwwform);

        yield return(request);

        Portal2 portal = LitJson.JsonMapper.ToObject <Portal2> (request.text);

        Debug.Log(portal);
        PortalHandler.instance.createUnfinishedPortal(portal);
        UpdateGold.instance.syncGold();
        DisplayTransactionHandler.instance.setCostText(PortalHandler.instance.costPerPortal);
    }
Exemplo n.º 12
0
    public void addPortal(Portal2 portal)
    {
        // Locations of the two bases
        Vector3 p1 = portal.base1.convertBaseCoordsToWorld();
        Vector3 p2 = portal.base2.convertBaseCoordsToWorld();

        p1 = p1 + (p2 - p1).normalized * Globals.baseRadius;
        p2 = p2 + (p1 - p2).normalized * Globals.baseRadius;
        GameObject portalObj;

        // Create the portal (cylinder prefab)
        // Start new, user created portals at length corresponging to 1% finished
        if (portal.timeFinished <= CurrentTime.currentTimeMillis())
        {
            // Portal finished
            portalObj = createPortal(portal);;
        }
        else
        {
            // Portal unfinished
            portalObj = createUnfinishedPortal(portal);
        }

        GameObject objectInfoPanel = (GameObject)Instantiate(GenerateWorld.instance.objectInfoPanelPrefab, new Vector3(0, 0, 0), Quaternion.identity);

        objectInfoPanel.transform.SetParent(GenerateWorld.instance.canvas.transform, false);
        objectInfoPanel.GetComponent <ObjectInfoPanelScript>().o = portalObj;
        //portalObj.GetComponent<PortalScript>().objectInfoPanel = objectInfoPanel;

        GameObject moveTroopsProgress = (GameObject)Instantiate(GenerateWorld.instance.ProgressBarPrefab, new Vector3(0, 0, 0), Quaternion.identity);

        moveTroopsProgress.transform.SetParent(objectInfoPanel.transform);
        // TODO: change this to a move unit sprite
        moveTroopsProgress.GetComponentInChildren <Image> ().sprite = GenerateWorld.instance.moveTroopSprite;
        moveTroopsProgress.SetActive(false);
        portal.updateTroopsToMove += moveTroopsProgress.GetComponent <OIPProgressScript> ().updateContent;

        currentPortalObjects.Add(portalObj);
    }