예제 #1
0
 public bool isDirectlyNext(bool player, spaceComponent theSpace)
 {
     if (player)
     {
         if (theSpace == left || theSpace == right)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         if (theSpace == backLeft || theSpace == backRight)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
예제 #2
0
    public override void objectSpawned(spaceComponent startingPoint, bool isPlayer)
    {
        maxHealth = health;

        myHealthBar = Instantiate(healthBar, GameObject.Find("Canvas").transform);
        Vector2 barSpot = Camera.main.WorldToScreenPoint(transform.position);

        myHealthBar.transform.position = new Vector2(barSpot.x, barSpot.y + barOffset);

        playerUnit = isPlayer;
        mySpace    = startingPoint;

        if (playerUnit)
        {
            myManager = GameObject.Find("PlayerObject").GetComponent <playerManager>();
        }
        else
        {
            myManager = GameObject.Find("EnemyObject").GetComponent <playerManager>();
        }
        currentMoney = myManager.money;

        AudioMan.inst.PlayThief();

        mySpace.addUnit(this);
        StartCoroutine(waitToAct(0.001F));
    }
예제 #3
0
    protected override void act()
    {
        //move or attack
        spaceComponent nextSpace = mySpace.choseSpaceWithAheads(playerUnit);

        if (!nextSpace)
        {
            return;
        }
        else if (nextSpace == mySpace)
        {
            // player takes damage
            if (playerUnit)
            {
                GameObject.Find("EnemyObject").GetComponent <playerManager>().health--;
                if (evolved)
                {
                    GameObject.Find("EnemyObject").GetComponent <playerManager>().health--;
                }
            }
            else
            {
                GameObject.Find("PlayerObject").GetComponent <playerManager>().health--;
                if (evolved)
                {
                    GameObject.Find("PlayerObject").GetComponent <playerManager>().health--;
                }
            }

            AudioMan.inst.PlayHit();

            mySpace.removeUnit();
            Destroy(myHealthBar);
            Destroy(gameObject);
            return;
        }

        if (nextSpace.unit)
        {
            if (nextSpace.unit.takeDamage(damage))
            {
                nextSpace.removeUnit();
            }
        }
        else
        {
            mySpace.removeUnit();
            mySpace = nextSpace;
            nextSpace.addUnit(this);

            // move the dude
            GetComponent <Animator>().SetTrigger("Jump");
            location = nextSpace.transform.position;
            Invoke("setMove", 0.2F);
        }
    }
예제 #4
0
    public void tryToSpawn()
    {
        int indecisive = Random.Range(0, 10);

        if (indecisive < 3)
        {
            //Debug.Log("Eh, gonna wait another second.");
            return;
        }

        if (goldCountWait <= manager.money)
        {
            waiting = false;
        }
        if (!waiting)
        {
            if (manager.money >= units[myChoice].transform.GetChild(0).GetComponent <unitBehavior>().cost&& !spawnCooldowns[myChoice])
            {
                // spawwwwwwwwwwwn it
                //Debug.Log("Spawning " + units[myChoice].name);

                spaceComponent spawn = mySpawns[Random.Range(0, mySpawns.Length)];
                while (spawn.unit)
                {
                    spawn = mySpawns[Random.Range(0, mySpawns.Length)];
                }

                GameObject unit = Instantiate(units[myChoice], spawn.transform.position, Quaternion.Euler(0, 180, 0));
                unit.transform.GetChild(0).GetComponent <unitBehavior>().objectSpawned(spawn, false);

                cooldowns[myChoice]      = unit.transform.GetChild(0).GetComponent <unitBehavior>().cooldown;
                spawnCooldowns[myChoice] = true;

                manager.money -= units[myChoice].transform.GetChild(0).GetComponent <unitBehavior>().cost;

                chooseNewChoice();
                waiting = false;
                tryToSpawn();

                return;
            }
        }
        if (indecisive > 8)
        {
            //Debug.Log("Gonna try something else");
            chooseNewChoice();
            tryToSpawn();
        }
    }
예제 #5
0
    public virtual void objectSpawned(spaceComponent startingPoint, bool isPlayer)
    {
        maxHealth = health;

        myHealthBar = Instantiate(healthBar, GameObject.Find("Canvas").transform);
        Vector2 barSpot = Camera.main.WorldToScreenPoint(transform.position);

        myHealthBar.transform.position = new Vector2(barSpot.x, barSpot.y + barOffset);

        playerUnit = isPlayer;
        mySpace    = startingPoint;

        mySpace.addUnit(this);
        StartCoroutine(waitToAct(0.001F));
    }
예제 #6
0
파일: unitIcon.cs 프로젝트: Lebrra/summaJam
    public void OnEndDrag(PointerEventData eventData)
    {
        // if dropped on starting point (and can buy), buy and spawn a dude

        if (purchaseAllowed)
        {
            // get starting point
            spaceComponent start = myPlayer.buyAUnit(cost);
            if (start)
            {
                // place dude
                GameObject newUnit = Instantiate(myUnitPrefab, start.transform.position, Quaternion.identity);
                //start.addUnit(newUnit.GetComponent<unitBehavior>());
                newUnit.transform.GetChild(0).GetComponent <unitBehavior>().objectSpawned(start, true);

                buyCooldown = true;
                fillImage.gameObject.SetActive(true);
            }

            myPlayer.showStartingPos(false);
            myIcon.SetActive(false);
            purchaseAllowed = false;
        }
    }
예제 #7
0
    public spaceComponent choseSpaceWithAheads(bool player)
    {
        spaceComponent leftLeft = null, rightRight = null, middle = null;

        if (player)
        {
            // First check for attacks:

            if (left)
            {
                if (left.left)
                {
                    leftLeft = left.left;
                }
                if (left.right)
                {
                    middle = left.right;
                }
            }
            if (right)
            {
                if (right.right)
                {
                    rightRight = right.right;
                }
                if (right.left && !middle)
                {
                    middle = right.left;
                }
            }

            if (middle)
            {
                if (middle.unit && !middle.unit.playerUnit)
                {
                    return(middle);
                }
            }
            if (leftLeft)
            {
                if (leftLeft.unit && !leftLeft.unit.playerUnit)
                {
                    return(leftLeft);
                }
            }
            if (rightRight)
            {
                if (rightRight.unit && !rightRight.unit.playerUnit)
                {
                    return(rightRight);
                }
            }

            // Check for moving:

            if (left == null && right == null)
            {
                Debug.Log("Player score!");
                return(this);
            }

            bool canLeft = false, canRight = false;
            if (left != null && left.unit == null)
            {
                canLeft = true;
            }
            if (right != null && right.unit == null)
            {
                canRight = true;
            }

            if (canLeft && canRight)
            {
                int rand = Random.Range(0, 100);
                if (rand % 2 == 0)
                {
                    return(left);
                }
                else
                {
                    return(right);
                }
            }

            if (canLeft)
            {
                return(left);
            }
            if (canRight)
            {
                return(right);
            }

            return(null);
        }
        else
        {
            // First check for attacks:

            if (backLeft)
            {
                if (backLeft.backLeft)
                {
                    leftLeft = backLeft.backLeft;
                }
                if (backLeft.backRight)
                {
                    middle = backLeft.backRight;
                }
            }
            if (backRight)
            {
                if (backRight.backRight)
                {
                    rightRight = backRight.backRight;
                }
                if (backRight.backLeft && !middle)
                {
                    middle = backRight.backLeft;
                }
            }

            if (middle)
            {
                if (middle.unit && !middle.unit.playerUnit)
                {
                    return(middle);
                }
            }
            if (leftLeft)
            {
                if (leftLeft.unit && !leftLeft.unit.playerUnit)
                {
                    return(leftLeft);
                }
            }
            if (rightRight)
            {
                if (rightRight.unit && !rightRight.unit.playerUnit)
                {
                    return(rightRight);
                }
            }

            // Check for movement

            if (backLeft == null && backRight == null)
            {
                Debug.Log("Enemy score!");
                return(this);
            }

            bool canLeft = false, canRight = false;
            if (backLeft != null && backLeft.unit == null)
            {
                canLeft = true;
            }
            if (backRight != null && backRight.unit == null)
            {
                canRight = true;
            }

            if (canLeft && canRight)
            {
                int rand = Random.Range(0, 100);
                if (rand % 2 == 0)
                {
                    return(backLeft);
                }
                else
                {
                    return(backRight);
                }
            }

            if (canLeft)
            {
                return(backLeft);
            }
            if (canRight)
            {
                return(backRight);
            }

            return(null);
        }
    }
예제 #8
0
    protected override void act()
    {
        //move or attack
        spaceComponent nextSpace = mySpace.chooseSpace(playerUnit);

        if (!nextSpace)
        {
            //Debug.Log("Unable to move, wating for next turn.");
            return;
        }
        else if (nextSpace == mySpace)
        {
            AudioMan.inst.PlayHit();

            // player takes damage
            if (playerUnit)
            {
                GameObject.Find("EnemyObject").GetComponent <playerManager>().health--;
                if (evolved)
                {
                    GameObject.Find("EnemyObject").GetComponent <playerManager>().health--;
                }
            }
            else
            {
                GameObject.Find("PlayerObject").GetComponent <playerManager>().health--;
                if (evolved)
                {
                    GameObject.Find("PlayerObject").GetComponent <playerManager>().health--;
                }
            }

            mySpace.removeUnit();
            Destroy(myHealthBar);
            Destroy(gameObject);
            return;
        }

        bool killed = false;

        if (nextSpace.unit)
        {
            //Debug.Log("Attacking!");
            peacefulSpaces = 1;

            if (nextSpace.unit.takeDamage(damage))
            {
                killed = true;
                nextSpace.removeUnit();
            }
        }
        if (!nextSpace.unit || killed)
        {
            //Debug.Log("Moving to a new space");
            if (!killed)
            {
                peacefulSpaces++;
            }

            mySpace.removeUnit();
            mySpace = nextSpace;
            nextSpace.addUnit(this);

            // move the dude
            GetComponent <Animator>().SetTrigger("Jump");
            location = nextSpace.transform.position;
            Invoke("setMove", 0.2F);
        }
    }