Beispiel #1
0
    private void OnTriggerEnter2D(Collider2D collider)
    {
        const int itemLayer            = 10;
        const int enemyLayer           = 11;
        const int sinkLayer            = 12;
        const int playerCollisionLayer = 13;
        const int dontCollideLayer     = 14;
        const int powerupLayer         = 15;

        Player playerObj = gameObject.GetComponent <Player>();
        int    gameMode  = GetGameMode();

        switch (collider.gameObject.layer)
        {
        // Check collistion with treasures
        case itemLayer:
            Treasure treasure = collider.GetComponent <Treasure>();
            // Untaken treasure
            if (!treasure.GetIsPickedUp())
            {
                TakeTreasure(collider.gameObject);
                DataTransformer.sendDDA(Time.realtimeSinceStartup, Event.pickup, playerObj, treasure.GetID(), 0, gameMode);
            }
            break;

        // Check collistion with enemies
        case enemyLayer:
            int enemyID = collider.GetComponent <Enemy>().GetID();
            collider.gameObject.layer = dontCollideLayer;
            if (enemyID == ID || enemyID == -1)
            {
                SetEnemyHit(collider.GetComponent <Enemy>());
            }
            else
            {
                DataTransformer.sendDDA(Time.realtimeSinceStartup, Event.blockDamage, playerObj, 0, enemyID, gameMode);
            }
            break;

        case sinkLayer:
            if (!IsInventoryEmpty(MyItemInventory))
            {
                for (int i = 0; i < MyItemInventory.Length; i++)
                {
                    int itemID = MyItemInventory[i].GetID();
                    if (RemoveItem(MyItemInventory[i]))
                    {
                        collider.GetComponent <ItemSink>().SetScore(playerObj);
                        DataTransformer.sendDDA(Time.realtimeSinceStartup, Event.dropitem, playerObj, itemID, 0, gameMode);
                        break;
                    }
                }
            }
            break;

        case playerCollisionLayer:
            Player otherPlayer = collider.transform.parent.gameObject.GetComponent <Player>();
            if (!IsInventoryEmpty(OthersItemInventory))
            {
                if (!otherPlayer.IsInventoryFull(otherPlayer.GetMyItemInventory()))
                {
                    for (int i = 0; i < OthersItemInventory.Length; i++)
                    {
                        if (OthersItemInventory[i].GetID() == otherPlayer.GetID())
                        {
                            // Give item to other player
                            OthersItemInventory[i].SetDisown();
                            OrderCarriedItems();
                            otherPlayer.TakeTreasure(OthersItemInventory[i].gameObject);
                            RemoveItem(OthersItemInventory[i]);
                            DataTransformer.sendDDA(Time.realtimeSinceStartup, Event.giveItem, playerObj, otherPlayer.GetID(), 0, gameMode);
                        }
                    }
                }
            }
            // If it's a cooperative mode AND if the other player needs revival
            if (OthersItemInventory.Length != 0 && otherPlayer.GetComponent <Player>().GetHealth() == 0)
            {
                FixBoatTime = 0;
            }
            break;

        case powerupLayer:

            if (gameMode == 1)
            {
                // Competitive mode
                immuneTimer = 5;
                collider.GetComponent <Powerup>().SetPickedUp();
                gameObject.GetComponentsInChildren <Animator>()[1].SetBool("Aura", true);
                Destroy(collider.gameObject);
                StartCoroutine(Countdown());
            }
            else
            {
                // Cooperative mode
                collider.GetComponent <Powerup>().SetPickedUp();
                Destroy(collider.gameObject);
                GameObject[] gameObjects = GameObject.FindGameObjectsWithTag("Player");
                foreach (var g in gameObjects)
                {
                    g.GetComponent <Player>().SetHealth();
                }
            }
            DataTransformer.sendDDA(Time.realtimeSinceStartup, Event.powerupTaken, playerObj, 0, 0, gameMode);
            break;

        default:
            break;
        }
    }
Beispiel #2
0
    public bool TrackObjLocation()
    {
        const int itemLayer   = 10;
        const int enemyLayer  = 11;
        const int playerLayer = 9;
        float     posX;
        float     posY;

        GameObject[] gameObjects = FindObjectsOfType <GameObject>();
        for (int i = 0; i < gameObjects.Length; i++)
        {
            switch (gameObjects[i].layer)
            {
            case itemLayer:
                Treasure item = gameObjects[i].GetComponent <Treasure>();
                posX = item.transform.position.x;
                posY = item.transform.position.y;
                if (item.GetIsPickedUp())
                {
                    DataTransformer.sendTracker(Time.realtimeSinceStartup, Event.takenItemLoc, item.GetCarrierID(), posX, posY, item.GetID(), 0, (int)GetMode());
                }
                else
                {
                    DataTransformer.sendTracker(Time.realtimeSinceStartup, Event.itemLoc, -1, posX, posY, item.GetID(), 0, (int)GetMode());
                }
                break;

            case enemyLayer:
                Enemy enemy = gameObjects[i].GetComponent <Enemy>();
                posX = enemy.transform.position.x;
                posY = enemy.transform.position.y;
                DataTransformer.sendTracker(Time.realtimeSinceStartup, Event.enemyLoc, -1, posX, posY, 0, enemy.GetID(), (int)GetMode());
                break;

            case playerLayer:
                Player   player = gameObjects[i].GetComponent <Player>();
                ItemSink sink   = GameObject.Find("ItemSink").GetComponent <ItemSink>();
                DataTransformer.sendTracker(Time.realtimeSinceStartup, Event.playerLocHealth, player, player.GetHealth(), sink.GetPlayerScore(player.GetID()), (int)GetMode());

                // Send click count in the past 5 sec
                DataTransformer.sendTracker(Time.realtimeSinceStartup, Event.playerClickCount, player, player.GetClickCounter(), 0, (int)GetMode());

                // Reset clicks
                player.ResetClickCounter();
                break;

            default:
                break;
            }
        }

        return(true);
    }