Ejemplo n.º 1
0
        public static IEnumerable <Tower> ConvertStringToTowerStatus(string towers)
        {
            //16-bit unsigned integer
            //┌─┬─┬─┬─┬─────────────────────── Not used.
            //│ │ │ │ │ ┌───────────────────── Ancient Top
            //│ │ │ │ │ │ ┌─────────────────── Ancient Bottom
            //│ │ │ │ │ │ │ ┌───────────────── Bottom Tier 3
            //│ │ │ │ │ │ │ │ ┌─────────────── Bottom Tier 2
            //│ │ │ │ │ │ │ │ │ ┌───────────── Bottom Tier 1
            //│ │ │ │ │ │ │ │ │ │ ┌─────────── Middle Tier 3
            //│ │ │ │ │ │ │ │ │ │ │ ┌───────── Middle Tier 2
            //│ │ │ │ │ │ │ │ │ │ │ │ ┌─────── Middle Tier 1
            //│ │ │ │ │ │ │ │ │ │ │ │ │ ┌───── Top Tier 3
            //│ │ │ │ │ │ │ │ │ │ │ │ │ │ ┌─── Top Tier 2
            //│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ┌─ Top Tier 1
            //│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
            //0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

            ushort bs = ushort.Parse(towers);

            for (int i = 0; i < 11; i++)
            {
                bool          alive    = IsBitSet16(bs, i);
                TowerPosition position = (TowerPosition)i;
                yield return(new Tower {
                    Alive = alive, Position = position
                });
            }
        }
Ejemplo n.º 2
0
 // Update is called once per frame
 void Update()
 {
     timeSinceLastFired -= Time.deltaTime;
     if (timeSinceLastFired <= 0f)
     {
         GameObject target = GameObject.FindWithTag("Target");
         if (target != null)
         {
             GameObject    fired = Instantiate(missile);
             TowerPosition tp    = GetComponent <TowerPosition> ();
             fired.transform.position = new Vector3(tp.x + .5f, 1f, tp.y + .5f);
             timeSinceLastFired       = delay;
         }
     }
 }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        Vector2 pos;
        string  hitname = GetMouseGridPosition(out pos);

        if (hitname != null)
        {
            int curx = (int)Mathf.Floor(pos.x);
            int cury = (int)Mathf.Floor(pos.y);
            text.text = string.Format("Cursor Square: {0}, {1}", curx, cury);
            highlighter.transform.position = new Vector3(Mathf.Floor(pos.x) + .5f, 1f, Mathf.Floor(pos.y) + .5f);
            highlighter.SetActive(true);
            if (Input.GetMouseButtonDown(0) && hitname == "Field" && tilemap[cury, 9 - curx] == 4)
            {
                bool isTowerHere = false;
                foreach (GameObject obj in GameObject.FindGameObjectsWithTag("Tower"))
                {
                    TowerPosition tower = obj.GetComponent <TowerPosition> ();
                    if (tower.x == curx && tower.y == cury)
                    {
                        if (!placing)
                        {
                            Destroy(obj);
                        }
                        isTowerHere = true;
                    }
                }
                if (!isTowerHere && placing)
                {
                    Instantiate(towerPrefab).transform.position = new Vector3(0.89f + curx, 0, 0.89f + cury);
                }
            }
        }
        else
        {
            text.text = "Out of bounds!";
            highlighter.SetActive(false);
        }
    }