예제 #1
0
파일: CellIndex.cs 프로젝트: jcf120/Penguin
 public static CellIndex operator -(int lhs, CellIndex rhs)
 {
     CellIndex result = new CellIndex(0);
     result.index = lhs - rhs.index;
     result.rangeCheck();
     return result;
 }
예제 #2
0
 public CellVector(CellIndex dir, int mag)
 {
     if        (dir == CellIndex.topMiddle) {
         i_ = 0;
         j_ = mag;
     } else if (dir == CellIndex.topRight) {
         i_ = mag;
         j_ = 0;
     } else if (dir == CellIndex.bottomRight) {
         i_ = mag;
         j_ = -mag;
     } else if (dir == CellIndex.bottomMiddle) {
         i_ = 0;
         j_ = -mag;
     } else if (dir == CellIndex.bottomLeft) {
         i_ = -mag;
         j_ = 0;
     } else if (dir == CellIndex.topLeft) {
         i_ = -mag;
         j_ = mag;
     } else {
         i_ = 0;
         j_ = 0;
         Debug.LogError("Instantiating CellVector from invalid CellIndex");
     }
 }
예제 #3
0
파일: CellIndex.cs 프로젝트: jcf120/Penguin
 public static CellIndex operator -(CellIndex lhs, int rhs)
 {
     CellIndex result = new CellIndex(0);
     result.index = lhs.index - rhs;
     result.rangeCheck();
     return result;
 }
예제 #4
0
 public CellVector rotated(CellIndex ang)
 {
     CellVector result = new CellVector(0, 0);
     if        (ang == CellIndex.topMiddle) {
         result.i = i_;
         result.j = j_;
     } else if (ang == CellIndex.topRight) {
         result.i = i_ + j_;
         result.j = -i_;
     } else if (ang == CellIndex.bottomRight) {
         result.i = j_;
         result.j = -i_ - j_;
     } else if (ang == CellIndex.bottomMiddle) {
         result.i = -i_;
         result.j = -j_;
     } else if (ang == CellIndex.bottomLeft) {
         result.i = -i_ - j_;
         result.j = i_;
     } else if (ang == CellIndex.topLeft) {
         result.i = -j_;
         result.j = i_ + j_;
     } else {
         Debug.LogError("CellVector can't rotate by invalid angle: "+ang);
     }
     return result;
 }
예제 #5
0
 public void TypeCasting()
 {
     CellIndex c = new CellIndex(0);
     Assert.IsInstanceOfType(typeof(CellIndex), 1+c, "CellIndex + int should return a CellIndex");
 }
예제 #6
0
 public void Arithmetic()
 {
     CellIndex c1 = new CellIndex(4);
     CellIndex c2 = new CellIndex(0) - 2;
     Assert.AreEqual(c1, c2, "CellIndex(0)-2 should equal 4, but is instead "+c2);
 }
예제 #7
0
파일: CellIndex.cs 프로젝트: jcf120/Penguin
        public static CellIndex fromAngle(float degrees)
        {
            CellIndex result = new CellIndex(0);
            // Allow values near 360 to round down to 0
            degrees += 30.0f;
            // Scale and quantise to index
            result.index = Mathf.FloorToInt(degrees / 60.0f);
            if (result.index > 5) result.index -= 6;

            result.rangeCheck();
            return result;
        }