Ejemplo n.º 1
0
    void Awake()
    {
        if (instance != null && instance != this)
        {
            Destroy(this.gameObject);
        }
        else
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
        }

        PauseGameManager.Instance.register(this, gameObject);

        jump         = GetComponent <Jump>();
        walk         = GetComponent <PlayerWalk>();
        firePivot    = transform.FindChild("FirePivot");
        teleportable = GetComponent <Teleportable>();
        dieAnim      = GetComponent <PlayerDieAnim>();
        crouch       = GetComponent <Crouch>();
        idle         = GetComponent <Idle>();
        lookUpwards  = GetComponent <LookUpwards>();
        body         = GetComponent <ChipmunkBody>();

        walkVelBackup  = walkVelocity;
        rightFireDir.x = 1f;
        rightFireDir.y = -0.5f;
        leftFireDir.x  = -1f;
        leftFireDir.y  = -0.5f;
        fireDir        = rightFireDir;

        collisionGroupSkip = GetComponent <ChipmunkShape>().collisionGroup;
        collisionLayers    = unchecked ((uint)~(1 << gameObject.layer));     // all layers except Player's layer
    }
Ejemplo n.º 2
0
    void OnTriggerStay(Collider other)
    {
        Teleportable tel = other.gameObject.GetComponent <Teleportable> ();

        if (tel == null || !tel.canTeleport)
        {
            return;
        }
        if (pm.portalA == null || pm.portalB == null)
        {
            return;
        }

        if (this.GetInstanceID() == pm.portalA.GetInstanceID())
        {
            Teleport(other.gameObject, pm.portalB.transform.position);
            tel.destPortal = pm.portalB;
        }
        else if (this.GetInstanceID() == pm.portalB.GetInstanceID())
        {
            Teleport(other.gameObject, pm.portalA.transform.position);
            tel.destPortal = pm.portalA;
        }
        other.GetComponent <Teleportable>().canTeleport = false;
    }
Ejemplo n.º 3
0
 private void Awake()
 {
     teleportable  = GetComponent <Teleportable>();
     boxCollider2D = GetComponent <BoxCollider2D>();
     wallMask      = LayerMask.GetMask("Walls");
     boxMask       = LayerMask.GetMask("Boxes");
 }
Ejemplo n.º 4
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (on)
        {
            if (collision.CompareTag("Player") || collision.CompareTag("Other") || collision.CompareTag("Drone") || collision.CompareTag("Bullet"))
            {
                Teleportable tel = collision.GetComponent <Teleportable>();
                if (!tel.CheckTeleported())
                {
                    tel.SetTeleport();
                    collision.transform.position = otherPortal.transform.position;
                }
                //Invoke("ResetCooldown", teleporterCooldown);
            }
        }
        else
        {
            if (otherPortal.on)
            {
                otherPortal.on = false;
            }
        }

        anim.SetBool("On", on);
    }
Ejemplo n.º 5
0
    public void TeleportCollider(Collider2D collision, Vector3 location)
    {
        Teleportable teleportable = collision.GetComponent <Teleportable>();

        if (teleportable && canTeleport)
        {
            OnTeleport?.Invoke();
            teleportable.Teleport(location);
            ClearSelection();
        }
    }
Ejemplo n.º 6
0
    private void OnTriggerEnter(Collider other)
    {
        //Debug.Log("Collision with: " + other.name);
        //verificar que sea algo "teletransportable"
        Teleportable teleportableObject = other.GetComponent <Teleportable>();

        if (teleportableObject)
        {
            AddTraveller(other.gameObject);
            //otherPortalController.addClone(teleportableObject.createDummyClone());
        }
    }
Ejemplo n.º 7
0
    void OnTriggerExit(Collider other)
    {
        Teleportable tel = other.gameObject.GetComponent <Teleportable> ();

        if (tel == null || tel.destPortal == null)
        {
            return;
        }
        if (this.GetInstanceID() == tel.destPortal.GetInstanceID())
        {
            tel.canTeleport = true;
        }
    }
Ejemplo n.º 8
0
    private void OnTriggerEnter(Collider other)
    {
        Teleportable t = other.GetComponent <Teleportable>();

        if (t != null && t.isTeleportable)
        {
            // Get the position of the object that is hitting the barrier
            Vector3 OriginalPosition = other.transform.position;
            // mirror the position
            Vector3 TargetPosition = InvertPosition(OriginalPosition);
            other.gameObject.transform.position = TargetPosition + teleportOffset;
        }
    }
    void OnTriggerEnter(Collider other)
    {
        // Check if other is a Teleportable
        Teleportable teleportable = other.GetComponent <Teleportable>();

        if (teleportable != null)
        {
            if (!teleportable.IsTeleporting())
            {
                // Relative position of current teleportable
                Vector3 localTeleportablePosition = myTransform.InverseTransformPoint(other.transform.position);

                // Invert X to match other portal after rotation
                localTeleportablePosition.x = -localTeleportablePosition.x;

                // Forward direction of current teleportable
                Vector3 localTeleportableForward = myPortal.InverseTransformDirection(other.transform.forward);

                // Set position and rotation of current teleportable
                other.transform.position = reciever.TransformPoint(localTeleportablePosition);
                other.transform.rotation = Quaternion.LookRotation(otherPortal.TransformDirection(localTeleportableForward), otherPortal.up);

                if (other.CompareTag("Player"))
                {
                    PlayerController playerController = other.GetComponent <PlayerController>();
                    if (playerController != null)
                    {
                        // Align player to gravity after teleportation
                        playerController.gravityUp = reciever.up;
                    }
                }

                if (other.CompareTag("Projectile"))
                {
                    Projectile projectile = other.GetComponent <Projectile>();
                    if (projectile != null)
                    {
                        // Clear the trail renderer of the projectile after teleportation
                        projectile.ClearTrail();
                    }
                }
            }
        }
    }
Ejemplo n.º 10
0
    private void initialize()
    {
        jump           = GetComponent <Jump>();
        walk           = GetComponent <PlayerWalk>();
        firePivot      = transform.FindChild("FirePivot");
        teleportable   = GetComponent <Teleportable>();
        dieAnim        = GetComponent <PlayerDieAnim>();
        crouch         = GetComponent <Crouch>();
        idle           = GetComponent <Idle>();
        lookDirections = GetComponent <LookDirections>();
        body           = GetComponent <ChipmunkBody>();

        rightFireDir.x = 1f;
        rightFireDir.y = -0.5f;
        leftFireDir.x  = -1f;
        leftFireDir.y  = -0.5f;
        fireDir        = rightFireDir;

        collisionGroupSkip = GetComponent <ChipmunkShape>().collisionGroup;
        // not sure if ok: all layers except Player's layer
        collisionLayersSkip = unchecked ((uint)(1 << KLayers.PLAYER));
        //collisionLayers = 0;
    }
Ejemplo n.º 11
0
    private void OnTriggerEnter(Collider other)
    {
        if (!m_Active)
        {
            return;
        }
        if (m_OtherPortal == null)
        {
            return;
        }
        if (!m_OtherPortal.m_Active)
        {
            return;
        }

        var direction = m_OtherPortal.m_Spawner.TransformDirection(m_OtherPortal.m_Direction);

        other.transform.position = m_OtherPortal.m_Spawner.position;
        other.transform.rotation = Quaternion.LookRotation(direction);

        Teleportable teleportable = other.GetComponent <Teleportable>();

        teleportable.AddForce(direction, m_Impulse, m_Multiply);
    }
Ejemplo n.º 12
0
    void SearchNearbyPickups()
    {
        if (!cutsceneManager.CutsceneActive && !consoleManager.ConsoleOpen)
        {
            Collider[] hitColliders = Physics.OverlapSphere(transform.position, 2f, LayerMask.GetMask("Pickup"));

            if (hitColliders.Length > 0)
            {
                // something has gone wrong and our array isn't big enough.. let's fix that
                if (currentObject > hitColliders.Length - 1)
                {
                    currentObject = 0;
                }

                // Smart Searching will show the item needed most to the user
                // For example, if the player is on low health then health kits will be the first thing prioritised
                // Smart searching can be stopped by cycling between other items, and will restart when the player moves
                if (smartSearch && allowSmartSearch)
                {
                    bool smartSearchFound = false;
                    if (hitColliders.Length > 1)
                    {
                        // If the player is on 1/2 of their health or less, let's prioritise showing health kits
                        if (entity.CurrentHealth <= (float)(entity.maxHealth / 2))
                        {
                            for (int i = 0; i < hitColliders.Length; i++)
                            {
                                Pickup pickup = hitColliders [i].GetComponent <Pickup> ();

                                if (pickup != null)
                                {
                                    // If this item is rarer, prioritise showing it to the player
                                    if (pickup.pickupType == Pickups.Type.Health)
                                    {
                                        smartSearchFound = true;
                                        currentObject    = i;
                                        break;
                                    }
                                }
                            }
                        }

                        // All other searches failed, so let's give the item with the best rarity
                        if (!smartSearchFound)
                        {
                            int bestRarity = 0;
                            for (int i = 0; i < hitColliders.Length; i++)
                            {
                                Pickup pickup = hitColliders [i].GetComponent <Pickup> ();

                                if (pickup != null)
                                {
                                    // If this item is rarer, prioritise showing it to the player
                                    if (pickup.rarity > bestRarity)
                                    {
                                        bestRarity    = pickup.rarity;
                                        currentObject = i;
                                    }
                                }
                            }
                        }
                    }
                }

                // Show the pickup text near the weapon
                if (!cutsceneManager.CutsceneActive)
                {
                    pickupTextObject.SetActive(true);
                    pickupTextObject.transform.position = hitColliders [currentObject].transform.position;
                    pickupText.text = "[" + inputManager.GetKeyValue("INVENTORY_PICK") + "] " + hitColliders [currentObject].gameObject.name;
                }
                else
                {
                    pickupTextObject.SetActive(false);
                }

                // User presses pickup key
                if (inputManager.InputMatchesKeyup("INVENTORY_PICK"))
                {
                    // Add to inventory, if it's not a readable
                    Readable         readable     = hitColliders[currentObject].GetComponent <Readable>();
                    Listenable       listenable   = hitColliders[currentObject].GetComponent <Listenable>();
                    Teleportable     teleportable = hitColliders[currentObject].GetComponent <Teleportable>();
                    Interactable     interactable = hitColliders[currentObject].GetComponent <Interactable>();
                    StoryTriggerable triggerable  = hitColliders [currentObject].GetComponent <StoryTriggerable> ();
                    if (readable != null)
                    {
                        if (readable.sprite != null && !uiManager.ReadableShowing)
                        {
                            uiManager.ShowReadable(readable);
                        }
                    }
                    else if (listenable != null)
                    {
                        if (listenable.audioSource != null)
                        {
                            if (listenable.useCustomKeys)
                            {
                                soundManager.ToggleSound(listenable.audioSource);
                            }
                            else
                            {
                                soundManager.PlaySound(listenable.audioSource, 0f);
                            }
                            if (listenable.destroyOnActivate)
                            {
                                Destroy(listenable.gameObject);
                            }
                        }
                    }
                    else if (teleportable != null)
                    {
                        if (teleportable.destination != null)
                        {
                            storyManager.TeleportEntity(storyManager.player, teleportable.destination.transform.position);
                        }
                    }
                    else if (interactable != null)
                    {
                        interactable.OnInteraction();
                    }
                    else if (triggerable != null)
                    {
                        triggerable.OnTrigger();
                    }
                    else
                    {
                        inventory.AddItemToInventory(hitColliders [currentObject].gameObject);
                        currentObject = 0;
                    }
                }

                // User presses cycle key
                if (inputManager.InputMatchesKeyup("INVENTORY_CYCLE"))
                {
                    smartSearch   = false;
                    currentObject = (currentObject + 1) % hitColliders.Length;
                }
            }
            else
            {
                pickupTextObject.SetActive(false);
                currentObject = 0;
            }
        }
    }
Ejemplo n.º 13
0
 public static void Remove(Teleportable teleportable)
 {
     _objects.Remove(teleportable);
 }
Ejemplo n.º 14
0
 public static void Register(Teleportable teleportable)
 {
     _objects.Add(teleportable);
 }