Example #1
0
    public Int2D GetGridsUnderPoint(Creature crt, Vector2 pt)
    {
        Rect rc_check = new Rect(pt, new Vector2(crt.Proto.Dim.X * FightGrid.UnitSize, crt.Proto.Dim.Y * FightGrid.UnitSize));

        Int2D pt_ref   = Int2D.zero;
        float min_dist = float.MaxValue;

        for (int x = 0; x <= (FightGrid.UnitCount.X - crt.Proto.Dim.X); ++x)
        {
            for (int y = 0; y <= (FightGrid.UnitCount.Y - crt.Proto.Dim.Y); ++y)
            {
                Vector2 orig = Vector2.zero;
                for (int dx = 0; dx < crt.Proto.Dim.X; ++dx)
                {
                    for (int dy = 0; dy < crt.Proto.Dim.Y; ++dy)
                    {
                        Vector2 curt = FGrid.Units[dy + y, dx + x].Position;
                        orig += curt;
                    }
                }
                orig /= (crt.Proto.Dim.X * crt.Proto.Dim.Y);

                if (Vector2.Distance(orig, pt) < min_dist)
                {
                    pt_ref   = new Int2D(x, y);
                    min_dist = Vector2.Distance(orig, pt);
                }
            }
        }
        return(pt_ref);
    }
Example #2
0
    public void OnDrag(PointerEventData data)
    {
        //Debug.Log(data.pressPosition.ToString());


        Vector2 delta = data.position - data.pressPosition;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(
            transform.parent as RectTransform,
            data.position, data.pressEventCamera, out delta);

        delta -= m_drag_offset;

        transform.localPosition  = m_drag_start;
        transform.localPosition += new Vector3(delta.x, delta.y, 0);

        Vector2 in_world = Vector2.zero;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(
            transform.parent as RectTransform,
            data.position, data.pressEventCamera, out in_world);
        Int2D pt = FGridView.GetGridsUnderPoint(Crt, in_world);

        if (FGridView.FGrid.CanBeReplace(Crt, pt))
        {
            FGridView.SetUnitColor(pt, Crt.Proto.Dim, Color.green);
        }
        else
        {
            FGridView.SetUnitColor(pt, Crt.Proto.Dim, Color.red);
        }
    }
Example #3
0
    void OnAddCreature(Creature crt, Int2D pt)
    {
        CreatureView crtv = ResMgr.Instance.CreateGameObject("UI/Crt", Launcher.Instance.CanvasUI.gameObject).GetComponent <CreatureView>();

        crtv.Create(crt, this);
        crtv.UpdateTransform(pt);
        m_crts[crt] = crtv;
    }
Example #4
0
    public override bool Equals(object obj)
    {
        if (!(obj is Int2D))
        {
            return(false);
        }
        Int2D d2 = (Int2D)obj;

        return(this == d2);
    }
Example #5
0
 void LeaveCreature(Creature crt)
 {
     for (int x = 0; x < crt.Proto.Dim.X; ++x)
     {
         for (int y = 0; y < crt.Proto.Dim.Y; ++y)
         {
             Int2D dest = new Int2D(crt.Index.X + x, crt.Index.Y + y);
             Units[dest.Y, dest.X].Creature = null;
         }
     }
     crt.Index = new Int2D(-1, -1);
 }
Example #6
0
 void EnterCreature(Creature crt, Int2D pt)
 {
     crt.Index = pt;
     for (int x = 0; x < crt.Proto.Dim.X; ++x)
     {
         for (int y = 0; y < crt.Proto.Dim.Y; ++y)
         {
             Int2D dest = new Int2D(pt.X + x, pt.Y + y);
             Units[dest.Y, dest.X].Creature = crt;
         }
     }
 }
Example #7
0
    void SetupFightCtller()
    {
        //ResMgr.Instance.CreateGameObject("BG/BG01", gameObject);

        m_fc = new FightCtller();
        m_fc.Create();

        GameObject ctl = Util.NewGameObject("FCtller", CanvasUI.gameObject);

        m_fcv = ctl.AddComponent <FightCtllerView>();
        m_fcv.Create(m_fc);

        string[] keys = null;
        Int2D[]  pts  = null;

        keys = new string[] { "Hadis", "Cretos", "Aflotiter", "Bosadon", "Giant", "Bosadon", "Bosadon", "Bosadon", "Bosadon" };
        pts  = new Int2D[] { new Int2D(0, 0), new Int2D(2, 0), new Int2D(0, 1), new Int2D(2, 1), new Int2D(3, 1), new Int2D(4, 1), new Int2D(2, 2), new Int2D(3, 2), new Int2D(4, 2) };
        for (int p = 0; p < keys.Length; ++p)
        {
            string       k    = keys[p];
            InfoCreature info = new InfoCreature(ProtoMgr.Instance.GetByKey <ProtoCreature>(k));
            info.Skills = new InfoSkill[info.Proto.Skills.Length];
            for (int s = 0; s < info.Skills.Length; ++s)
            {
                info.Skills[s] = new InfoSkill(ProtoMgr.Instance.GetByID <ProtoSkill>(info.Proto.Skills[s]));
            }


            Creature ac = new Creature();
            ac.Create(info);
            m_fc.FGrids[0].AddCreature(ac, pts[p]);
        }

        keys = new string[] { "Hadis", "Kerboros", "Aflotiter", "Bosadon", "Giant", "Bosadon", "Bosadon", "Cretos" };
        pts  = new Int2D[] { new Int2D(0, 0), new Int2D(2, 0), new Int2D(3, 0), new Int2D(0, 1), new Int2D(1, 1), new Int2D(0, 2), new Int2D(1, 2), new Int2D(2, 2) };
        for (int p = 0; p < keys.Length; ++p)
        {
            string       k    = keys[p];
            InfoCreature info = new InfoCreature(ProtoMgr.Instance.GetByKey <ProtoCreature>(k));
            info.Skills = new InfoSkill[info.Proto.Skills.Length];
            for (int s = 0; s < info.Skills.Length; ++s)
            {
                info.Skills[s] = new InfoSkill(ProtoMgr.Instance.GetByID <ProtoSkill>(info.Proto.Skills[s]));
            }

            Creature ac = new Creature();
            ac.Create(info);
            m_fc.FGrids[1].AddCreature(ac, pts[p]);
        }

        m_fc.Idle();
    }
Example #8
0
    public void UpdateTransform(Int2D pt)
    {
        if (Crt.FGrid.Dir == FightGrid.DirType.Up)
        {
            pt.Y += (Crt.Proto.Dim.Y - 1);
        }
        Vector3 s = m_crt.FGrid.Units[pt.Y, pt.X].Position;

        s.x -= FightGrid.UnitSize * 0.5f;
        s.y += FightGrid.UnitSize * 0.5f;
        s.x += m_crt.Info.Proto.Dim.X * FightGrid.UnitSize * 0.5f;
        s.y -= m_crt.Info.Proto.Dim.Y * FightGrid.UnitSize * 0.5f;
        transform.localPosition = s;
    }
Example #9
0
 public static Vector3 CalcUnitPosition(Int2D idx, DirType dir)
 {
     Vector3 pos = Vector3.zero;
     pos.x = -UnitCount.X * UnitSize / 2;
     pos.x += idx.X * UnitSize;
     pos.z = -300; //-(FightCtller.Dim.Y / 2) + (UnitCount.Y * UnitSize) + 50;
     pos.z -= idx.Y * UnitSize;
     pos.x += UnitSize / 2;
     //pos.y -= UnitSize / 2;
     if (dir == DirType.Up)
     {
         pos.z = -pos.z;
     }
     return pos;
 }
Example #10
0
 public void SetUnitColor(Int2D pt, Int2D dim, Color clr)
 {
     foreach (Unit u in m_units)
     {
         if (pt.X <= u.UnitView.Unit.Index.X && pt.Y <= u.UnitView.Unit.Index.Y &&
             pt.X + dim.X > u.UnitView.Unit.Index.X && pt.Y + dim.Y > u.UnitView.Unit.Index.Y)
         {
             u.UnitView.BodyColor = clr;
         }
         else
         {
             u.UnitView.BodyColor = Color.white;
         }
     }
 }
Example #11
0
    /// <summary>
    /// Changes win line parameters to suite win conditions (rotation, size, position, color).
    /// </summary>
    /// <param name="type"></param>
    private void GenerateWinLine(LineType type)
    {
        Cell lineOrigin;

        Int2D lastCellIndex = GetCellMatrixIndex(lastClickedCell);

        switch (type)
        {
        case LineType.HORIZONTAL:
            lineOrigin = cellMatrix[lastCellIndex.x, 0];
            winLine.transform.eulerAngles = Vector3.zero;
            winLine.SetStraight(true);
            break;

        case LineType.VERTICAL:
            lineOrigin = cellMatrix[0, lastCellIndex.y];
            winLine.transform.eulerAngles = new Vector3(0f, 0f, -90f);
            winLine.SetStraight(true);
            break;

        case LineType.DIAGONAL_M:
            lineOrigin = cellMatrix[0, 0];
            winLine.transform.eulerAngles = new Vector3(0f, 0f, -45f);
            winLine.SetStraight(false);
            break;

        case LineType.DIAGONAL_S:
            lineOrigin = cellMatrix[2, 0];
            winLine.transform.eulerAngles = new Vector3(0f, 0f, 45f);
            winLine.SetStraight(false);
            break;

        default:
            lineOrigin = cellList[0];
            break;
        }

        if (curPlayerSymbol == PlayerSymbol.X)
        {
            winLine.GetComponent <Image>().color = xColor;
        }
        else
        {
            winLine.GetComponent <Image>().color = oColor;
        }

        winLine.transform.position = lineOrigin.transform.position;
    }
Example #12
0
    public static Vector3 CalcUnitPosition(Int2D idx, DirType dir)
    {
        Vector3 pos = Vector3.zero;

        pos.x  = -UnitCount.X * UnitSize / 2;
        pos.x += idx.X * UnitSize;
        pos.y  = -FightSize;// -(FightCtller.Dim.Y / 2) + (UnitCount.Y * UnitSize) + 50;
        pos.y -= idx.Y * UnitSize;
        pos.x += UnitSize / 2;
        pos.y -= UnitSize / 2;
        if (dir == DirType.Up)
        {
            pos.y = -pos.y;
        }
        return(pos);
    }
Example #13
0
    public bool Replace(Creature crt, Int2D dest_pt)
    {
        Int2D dest_offset;

        if (!CanBeReplace(crt, dest_pt, out dest_offset))
        {
            return(false);
        }

        Debug.Log(dest_offset.ToString());

        Int2D src_pt = crt.Index;

        Dictionary <Creature, Int2D> dics = new Dictionary <Creature, Int2D>();

        for (int x = 0; x < crt.Proto.Dim.X; ++x)
        {
            for (int y = 0; y < crt.Proto.Dim.Y; ++y)
            {
                Int2D          dest = new Int2D(dest_pt.X + x, dest_pt.Y + y);
                FightGrid.Unit u    = Units[dest.Y, dest.X];
                if (u.Creature == null || u.Creature == crt)
                {
                    continue;
                }
                if (dics.ContainsKey(u.Creature))
                {
                    continue;
                }
                dics[u.Creature] = u.Creature.Index - dest_offset;
            }
        }

        LeaveCreature(crt);
        foreach (Creature c in dics.Keys)
        {
            LeaveCreature(c);
        }

        EnterCreature(crt, dest_pt);
        foreach (KeyValuePair <Creature, Int2D> pair in dics)
        {
            EnterCreature(pair.Key, pair.Value);
        }

        return(true);
    }
Example #14
0
    public void AddCreature(Creature crt, Int2D pt)
    {
        if (!CheckCreature(crt, pt))
        {
            return;
        }

        crt.FGrid = this;
        m_crts.Add(crt, new Member(crt));

        EnterCreature(crt, pt);

        if (OnAddCreature != null)
        {
            OnAddCreature(crt, pt);
        }
    }
Example #15
0
    void SetupFightCtller()
    {
        //ResMgr.Instance.CreateGameObject("BG/BG01", gameObject);

        m_fc = new FightCtller();
        m_fc.Create();

        GameObject ctl = Util.NewGameObject("FCtller", RootSprite);
        m_fcv = ctl.AddComponent<FightCtllerView>();
        m_fcv.Create(m_fc);

        string[] keys = null;
        Int2D[] pts = null;

        keys = new string[] { "M01", "N01", "N01", "N01", "N01", "N01", "N01", "N01", "N01", "N01", "N01", "N01", "N01", "N01" };
        pts = new Int2D[] { new Int2D(0, 0), new Int2D(2, 0), new Int2D(3, 0), new Int2D(4, 0), new Int2D(0, 1), new Int2D(1, 1), new Int2D(2, 1), new Int2D(3, 1), new Int2D(4, 1), new Int2D(0, 2), new Int2D(1, 2), new Int2D(2, 2), new Int2D(3, 2), new Int2D(4, 2)};
        for (int p = 0; p < keys.Length; ++ p)
        {
            string k = keys[p];
            InfoCreature info = new InfoCreature(ProtoMgr.Instance.GetByKey<ProtoCreature>(k));

            Creature ac = new Creature();
            ac.Create(info);
            m_fc.FGrids[0].AddCreature(ac, pts[p]);
        }

        keys = new string[] { "M01", "N01", "N01", "N01", "N01", "N01", "N01", "N01", "N01", "N01", "N01", "N01", "N01", "N01" };
        pts = new Int2D[] { new Int2D(0, 0), new Int2D(2, 0), new Int2D(3, 0), new Int2D(4, 0), new Int2D(0, 1), new Int2D(1, 1), new Int2D(2, 1), new Int2D(3, 1), new Int2D(4, 1), new Int2D(0, 2), new Int2D(1, 2), new Int2D(2, 2), new Int2D(3, 2), new Int2D(4, 2) };
        for (int p = 0; p < keys.Length; ++p)
        {
            string k = keys[p];
            InfoCreature info = new InfoCreature(ProtoMgr.Instance.GetByKey<ProtoCreature>(k));
            //info.Guns = new InfoGun[info.Proto.Guns.Length];
            //for (int i = 0; i < info.Guns.Length; ++i)
            //{
            //    info.Guns[i] = new InfoGun(info.Proto.ProtoGuns[i]);
            //}

            Creature ac = new Creature();
            ac.Create(info);
            m_fc.FGrids[1].AddCreature(ac, pts[p]);
        }

        m_fc.Fight();
    }
Example #16
0
    public void OnEndDrag(PointerEventData data)
    {
        Vector2 in_world = Vector2.zero;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(
            transform.parent as RectTransform,
            data.position, data.pressEventCamera, out in_world);
        Int2D pt = FGridView.GetGridsUnderPoint(Crt, in_world);

        FGridView.FGrid.Replace(Crt, pt);

        foreach (CreatureView cv in FGridView.Creatures.Values)
        {
            cv.UpdateTransform();
        }

        FGridView.SetVisible(false);
    }
Example #17
0
    /// <summary>
    /// Returns <see cref="Int2D"/> index of a specified cell in the 2-dimensional array.
    /// </summary>
    /// <param name="c"></param>
    /// <returns></returns>
    public Int2D GetCellMatrixIndex(Cell c)
    {
        Int2D index = new Int2D();

        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (c == cellMatrix[i, j])
                {
                    index.x = i;
                    index.y = j;
                }
            }
        }

        return(index);
    }
Example #18
0
 public bool CheckCreature(Creature crt, Int2D pt)
 {
     for (int y = 0; y < crt.Info.Proto.Dim.Y; ++y)
     {
         for (int x = 0; x < crt.Info.Proto.Dim.X; ++x)
         {
             Int2D curt = pt + new Int2D(x, y);
             if (curt.X < 0 || curt.Y < 0 || curt.X >= UnitCount.X || curt.Y >= UnitCount.Y)
             {
                 return(false);
             }
             if (m_units[curt.Y, curt.X].Creature != null)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Example #19
0
    public void UpdateTransform(Int2D pt)
    {
        Vector3 s = m_ac.FGrid.Units[pt.Y, pt.X].Position;
        s.x -= FightGrid.UnitSize * 0.5f;
        s.z += FightGrid.UnitSize * 0.5f;
        s.x += m_ac.Info.Proto.Dim.X * FightGrid.UnitSize * 0.5f;
        s.z -= m_ac.Info.Proto.Dim.Y * FightGrid.UnitSize * 0.5f;
        transform.localPosition = s * Launcher.SpriteScale;

        Vector3 pt_prog = transform.position;
        //pt_prog += m_ac.FGrid.Dir == FightGrid.DirType.Up ? new Vector3(0, FightGrid.UnitSize * Launcher.SpriteScale / 2, 0) : new Vector3(0, -FightGrid.UnitSize * Launcher.SpriteScale / 2, 0);
        pt_prog += new Vector3(0, 2, 0);
        pt_prog = RectTransformUtility.WorldToScreenPoint(Launcher.Instance.MainCamera, pt_prog);
        m_prog_hp.GetComponent<RectTransform>().position = pt_prog;

        if (m_ac.FGrid.Dir == FightGrid.DirType.Up)
        {
            transform.localRotation = Quaternion.Euler(0, 180, 0);
        }
    }
Example #20
0
File: Grid.cs Project: choephix/G11
    internal void Build( Int2D size )
    {
        this.size = size;

        float tileSize = 1f;
        tiles = new GridTile[size.x, size.y];
        for( short i=0; i<size.y; i++ ) {
            for( short j=0; j<size.x; j++ ) {
                tiles[j, i] = Instantiate( SampleTile,
                    new Vector3( ( j - size.x / 2 ) * tileSize, 0, ( i - size.y ) * tileSize ),
                    SampleTile.transform.rotation )
                    as GridTile;
                tiles[j, i].location = new Int2D( j, i );
                tiles[j, i].transform.parent = transform;
            }
        }

        ResetTiles();

        God.OnReady_Grid();
    }
Example #21
0
    public List<Unit> PickGrid(Vector2 start, Vector2 dir)
    {
        Int2D s = new Int2D();
        s.X = Mathf.RoundToInt(start.x / FightGrid.UnitSize);
        s.Y = Mathf.RoundToInt(start.y / FightGrid.UnitSize);

        dir = dir.normalized;

        List<Unit> rets = null;

        float k = dir.x / (dir.x + dir.y);

        for (int i = 0; i < (FightSize / UnitSize + UnitCount.Y) * 2; ++i)
        {
            Vector2 pt = CalcUnitPosition(s, Dir);
            pt.x = start.x + pt.y * k;
            Unit u = GetUnitByPos(pt);
            if (u != null)
            {
                rets.Add(u);
            }
            NextStep(ref s, dir);
        }

        return rets;
    }
Example #22
0
 public Unit(Int2D idx, Creature crt)
 {
     Index    = idx;
     Creature = crt;
 }
Example #23
0
 public Unit(Int2D idx, FightGridUnitView uv)
 {
     Index    = idx;
     UnitView = uv;
 }
Example #24
0
 private int GetDistanceSqr( Int2D a, Int2D b )
 {
     return Mathf.Abs( a.x - b.x ) > Mathf.Abs( a.y - b.y ) ? Mathf.Abs( a.x - b.x ) : Mathf.Abs( a.y - b.y );
 }
Example #25
0
    public bool CanBeReplace(Creature crt, Int2D dest, out Int2D dest_offset)
    {
        dest_offset = new Int2D(-1, -1);

        // find all creature and calc bounder in area of dest
        Int2D dest_min = new Int2D(+int.MaxValue, +int.MaxValue);
        Int2D dest_max = new Int2D(-int.MaxValue, -int.MaxValue);
        HashSet <Creature> dest_crts     = new HashSet <Creature>();
        HashSet <Int2D>    will_occupied = new HashSet <Int2D>();

        for (int x = 0; x < crt.Proto.Dim.X; ++x)
        {
            for (int y = 0; y < crt.Proto.Dim.Y; ++y)
            {
                Int2D dest_curt = new Int2D(dest.X + x, dest.Y + y);
                will_occupied.Add(dest_curt);

                FightGrid.Unit dest_u = Units[dest_curt.Y, dest_curt.X];
                if (dest_u.Creature == null || dest_u.Creature == crt)
                {
                    continue;
                }

                dest_min.X = Mathf.Min(dest_min.X, dest_u.Creature.Index.X);
                dest_min.Y = Mathf.Min(dest_min.Y, dest_u.Creature.Index.Y);
                dest_max.X = Mathf.Max(dest_max.X, dest_u.Creature.Index.X + dest_u.Creature.Proto.Dim.X);
                dest_max.Y = Mathf.Max(dest_max.Y, dest_u.Creature.Index.Y + dest_u.Creature.Proto.Dim.Y);
                if (!dest_crts.Contains(dest_u.Creature))
                {
                    dest_crts.Add(dest_u.Creature);
                }
            }
        }

        List <Int2D> for_checks = new List <Int2D>();

        for_checks.Add(new Int2D(0, 0));
        for (int x = 0; x < crt.Proto.Dim.X; ++x)
        {
            for (int y = 0; y < crt.Proto.Dim.Y; ++y)
            {
                for_checks.Add(new Int2D(x, y));
            }
        }
        for (int x = dest_min.X; x < dest_max.X; ++x)
        {
            for (int y = dest_min.Y; y < dest_max.Y; ++y)
            {
                for_checks.Add(new Int2D(x - crt.Index.X, y - crt.Index.Y));
            }
        }


        Unit[,] temp_unit = SnapUnits();
        foreach (Unit u in temp_unit)
        {
            if (dest_crts.Contains(u.Creature) || u.Creature == crt)
            {
                u.Creature = null;
            }
        }

        for (int x = 0; x < crt.Proto.Dim.X; ++x)
        {
            for (int y = 0; y < crt.Proto.Dim.Y; ++y)
            {
                Int2D curt = dest + new Int2D(x, y);
                if (curt.X >= FightGrid.UnitCount.X || curt.Y >= FightGrid.UnitCount.Y)
                {
                    return(false);
                }
                temp_unit[curt.Y, curt.X].Creature = crt;
            }
        }

        for (int i = 0; i < for_checks.Count; ++i)
        {
            // check possible in curt orig
            bool  can_fit   = true;
            Int2D curt_orig = new Int2D(crt.Index.X + for_checks[i].X, crt.Index.Y + for_checks[i].Y);
            foreach (Creature dest_crt in dest_crts)
            {
                for (int dx = 0; dx < dest_crt.Proto.Dim.X; ++dx)
                {
                    for (int dy = 0; dy < dest_crt.Proto.Dim.Y; ++dy)
                    {
                        Int2D check_pt = Int2D.zero;
                        if (i == 0)
                        {
                            Int2D offset = new Int2D(dest_crt.Index.X - dest.X, dest_crt.Index.Y - dest.Y);
                            check_pt = new Int2D(curt_orig.X + dx + offset.X, curt_orig.Y + dy + offset.Y);
                        }
                        else
                        {
                            Int2D offset = new Int2D(dest_crt.Index.X - dest_min.X, dest_crt.Index.Y - dest_min.Y);
                            check_pt = new Int2D(curt_orig.X + dx + offset.X, curt_orig.Y + dy + offset.Y);
                        }
                        if (check_pt.X < 0 || check_pt.Y < 0 || check_pt.X >= FightGrid.UnitCount.X || check_pt.Y >= FightGrid.UnitCount.Y)
                        {
                            can_fit = false;
                            break;
                        }
                        FightGrid.Unit check = temp_unit[check_pt.Y, check_pt.X];
                        //if (check.Creature == null || (check.Creature == crt && !will_occupied.Contains(check_pt)) ||
                        //    dest_crts.Contains(check.Creature))
                        if (check.Creature == null)
                        {
                            continue;
                        }
                        else
                        {
                            can_fit = false;
                            break;
                        }
                    }
                    if (!can_fit)
                    {
                        break;
                    }
                }
                if (!can_fit)
                {
                    break;
                }
            }
            if (can_fit)
            {
                dest_offset = (i == 0) ? dest - crt.Index : dest - ((crt.Index + for_checks[i]) + (dest - dest_min));
                return(true);
            }
        }
        return(false);
    }
Example #26
0
    public bool CanBeReplace(Creature crt, Int2D dest)
    {
        Int2D orig;

        return(CanBeReplace(crt, dest, out orig));
    }
Example #27
0
 public Unit(Int2D idx, FightGridUnitView uv)
 {
     Index = idx;
     UnitView = uv;
 }
Example #28
0
 void OnAddCreature(Creature ac, Int2D pt)
 {
     CreatureView av = Util.NewGameObject("Creature", gameObject).AddComponent<CreatureView>();
     av.Create(ac);
     av.UpdateTransform(pt);
 }
Example #29
0
    object TryGetValue(Type t, string v)
    {
        object final = null;

        try
        {
            Type vt = v.GetType();

            if (t == typeof(int))
            {
                final = int.Parse(v);
            }
            else if (t == typeof(float))
            {
                final = float.Parse(v);
            }
            else if (t == typeof(double))
            {
                final = double.Parse(v);
            }
            else if (t == typeof(string))
            {
                final = (string)v;
            }
            else if (t == typeof(Int2D))
            {
                string[] xy = v.Split(new char[] { '_' });
                final = new Int2D(int.Parse(xy[0]), int.Parse(xy[1]));
            }
            else if (t.IsEnum)
            {
                string s = (string)v;
                final = Enum.Parse(t, s);
            }
            else if (t.IsArray)
            {
                string   s     = (string)v;
                string[] elems = s.Split(';');

                if (t == typeof(int[]))
                {
                    int[] arr = new int[elems.Length];
                    for (int i = 0; i < elems.Length; ++i)
                    {
                        if (!int.TryParse(elems[i], out arr[i]))
                        {
                            return(null);
                        }
                    }
                    final = arr;
                }
                else if (t == typeof(float[]))
                {
                    float[] arr = new float[elems.Length];
                    for (int i = 0; i < elems.Length; ++i)
                    {
                        if (!float.TryParse(elems[i], out arr[i]))
                        {
                            return(null);
                        }
                    }
                    final = arr;
                }
                else if (t == typeof(double[]))
                {
                    double[] arr = new double[elems.Length];
                    for (int i = 0; i < elems.Length; ++i)
                    {
                        if (!double.TryParse(elems[i], out arr[i]))
                        {
                            return(null);
                        }
                    }
                    final = arr;
                }
                else if (t == typeof(string[]))
                {
                    final = elems;
                }
            }
        }
        catch (Exception e)
        {
            throw new Exception(e.ToString() + "  " + t.ToString() + "  " + v);
        }

        return(final);
    }
Example #30
0
 public bool CheckCreature(Creature ac, Int2D pt)
 {
     for (int i = 0; i < ac.Info.Proto.Occupies.Length; ++i)
     {
         int idx = ac.Info.Proto.Occupies[i];
         int x = idx % ac.Info.Proto.Dim.X;
         int y = idx / ac.Info.Proto.Dim.X;
         if (x < 0 || y < 0 || x >= UnitCount.X || y >= UnitCount.Y)
             return false;
     }
     return true;
 }
Example #31
0
File: Grid.cs Project: choephix/G11
 public bool HasTile( Int2D v )
 {
     return HasTile( v.x, v.y );
 }
Example #32
0
File: Grid.cs Project: choephix/G11
 public GridTile GetTile( Int2D v )
 {
     return GetTile( v.x, v.y );
 }
Example #33
0
    public void AddCreature(Creature ac, Int2D pt)
    {
        if (!CheckCreature(ac, pt))
            return;

        ac.FGrid = this;
        ac.Index = pt;
        m_acs.Add(ac, new Unit(pt, ac));

        for (int i = 0; i < ac.Info.Proto.Occupies.Length; ++i)
        {
            int idx = ac.Info.Proto.Occupies[i];
            int x = idx % ac.Info.Proto.Dim.X;
            int y = idx / ac.Info.Proto.Dim.X;
            Units[pt.Y + y, pt.X + x].Creature = ac;
        }

        if (OnAddCreature != null)
        {
            OnAddCreature(ac, pt);
        }
    }
Example #34
0
 void NextStep(ref Int2D s, Vector2 dir)
 {
     if (dir.x < dir.y)
     {
         if (dir.y > 0)
         {
             s.Y += 1;
         }
         else
         {
             s.Y -= 1;
         }
     }
     else
     {
         if (dir.y > 0)
         {
             s.X += 1;
         }
         else
         {
             s.X -= 1;
         }
     }
 }
Example #35
0
 public Unit(Int2D idx, Creature ac)
 {
     Index = idx;
     Creature = ac;
 }