Ejemplo n.º 1
0
    public void handleCollision(Tile tile, Map theMap)
    {
        // If tile contains an item
        if (tile.GetTileEntityType() == (int)Tile.TileEntityTypes.ITEM)
        {
            //Debug.Log("Walked Over Item: " + tile.tileEntityObj.name);
            if (tile == player.lastClickedTile)
            {    // if we clicked an item tile and pass over it
                // Debug.Log("Picking up " + tile.tileEntityObj.name);
                IngameUI.logPrint("Picked up " + tile.tileEntityObj.name);
                bool wasPickedUp = Inventory.instance.Add(tile.itemSpawn);    // Add to inventory

                // If successfully picked up
                if (wasPickedUp)
                {
                    tile.itemSpawn = null;
                    Destroy(tile.tileEntityObj);    // Destroy item from scene
                    tile.SetTileEntity((int)Tile.TileEntityTypes.NONE, null);
                }
            }
        }
        else if (tile.GetTileEntityType() == (int)Tile.TileEntityTypes.ENTRANCE && tile == player.lastClickedTile)
        {
            // Go to previous level
            StartCoroutine(waitForPlayerOnEntranceTile());
        }
        else if (tile.GetTileEntityType() == (int)Tile.TileEntityTypes.EXIT && tile == player.lastClickedTile)
        {
            // Go to next level
            StartCoroutine(waitForPlayerOnExitTile());
        }
    }
Ejemplo n.º 2
0
    public int Fight(Player player, GameObject enemy, bool playerAttack, EnemyManager enemyManagerScript)
    {
        int result = (int)FightOutcomes.ALIVE;

        // IngameUI.logPrint("FIGHT! between " + player.name + " and Enemy " + enemy.GetComponent<Enemy>().enemyID);
        // if player atacking
        if (playerAttack)
        {
            enemyScript = enemy.GetComponent <Enemy>();

            //StartTimer();
            PlayEnemyHitAnimation(enemyScript);

            enemyScript.enemyHP -= player.playerAttackDmg;
            IngameUI.logPrint("Attacked " + enemy.name + " for " + player.playerAttackDmg); // + " and enemy HP reduced to " + enemyScript.enemyHP);

            if (enemyScript.enemyHP <= 0)
            {
                IngameUI.logPrint(enemy.name + " was killed!");
                result = (int)FightOutcomes.KILLED;
                player.grantXP(2);

                GameObject skeletonPrefab = enemyManagerScript.skeletonPrefab;
                GameObject skeletonClone  = Instantiate(skeletonPrefab);
                skeletonClone.transform.SetParent(this.transform);
                skeletonClone.transform.position = new Vector2(enemy.transform.position.x, enemy.transform.position.y);
            }
            //enemyScript.animator.speed = 0;
        }
        // if enemy attacking
        else
        {
            Player.updateHealth(-enemy.GetComponent <Enemy>().enemyAttackDmg);
            IngameUI.logPrint(enemy.name + " attacks Player for " + enemy.GetComponent <Enemy>().enemyAttackDmg);

            if (player.playerHP <= 0)
            {
                IngameUI.health.text = "DEAD";
                if (!player.dead)
                {
                    player.dead = true;
                    IngameUI.logPrint("You have died!");
                }
                result = (int)FightOutcomes.KILLED;
            }
        }

        return(result);
    }