コード例 #1
0
ファイル: World.cs プロジェクト: Corey255A1/Kolonize
        public World(int size)
        {
            WORLD_SIZE           = size;
            Terrain              = new WorldCell[WORLD_SIZE, WORLD_SIZE];
            Objects              = new WorldObject[WORLD_SIZE, WORLD_SIZE];
            double[,] rawTerrain = new double[WORLD_SIZE, WORLD_SIZE];
            for (int x = 0; x < WORLD_SIZE; ++x)
            {
                for (int y = 0; y < WORLD_SIZE; ++y)
                {
                    rawTerrain[x, y] = WorldCell.ComplexRandomNumber(x, y);
                }
            }

            rawTerrain = ApplyFilter(rawTerrain, 25);
            var maxmin = FindBounds(rawTerrain);

            Normalize(ref rawTerrain, maxmin.Item1, 0.3);


            for (int x = 0; x < WORLD_SIZE; ++x)
            {
                for (int y = 0; y < WORLD_SIZE; ++y)
                {
                    Terrain[x, y] = new WorldCell(WorldCell.GetCellTypeByWeight(rawTerrain[x, y]), x, y);
                }
            }


            MoverThread = new Thread(MoverUpdates);
            MoverThread.Start();
        }
コード例 #2
0
ファイル: World.cs プロジェクト: Corey255A1/Kolonize
 public WorldCell[,] GetRegion(int x1, int x2, int y1, int y2)
 {
     if (x1 < 0)
     {
         x1 = 0;
     }
     else if (x1 > WORLD_SIZE)
     {
         x1 = WORLD_SIZE - 2;
     }
     if (x2 < 0)
     {
         x2 = 1;
     }
     else if (x2 > WORLD_SIZE)
     {
         x2 = WORLD_SIZE - 1;
     }
     if (y1 < 0)
     {
         y1 = 0;
     }
     else if (y1 > WORLD_SIZE)
     {
         y1 = WORLD_SIZE - 2;
     }
     if (y2 < 0)
     {
         y2 = 1;
     }
     else if (x2 > WORLD_SIZE)
     {
         y2 = WORLD_SIZE - 1;
     }
     if (x1 < x2 && y1 < y2)
     {
         int width  = x2 - x1;
         int height = y2 - y1;
         var region = new WorldCell[width, height];
         for (int x = 0; x < width; ++x)
         {
             for (int y = 0; y < height; ++y)
             {
                 region[x, y] = Terrain[x + x1, y + y1];
             }
         }
         return(region);
     }
     return(null);
 }
コード例 #3
0
        public virtual void Move(WorldCell[,] map, WorldObject[,] objects)
        {
            //if we have no velocity, don't move
            if (Vx == 0 && Vy == 0)
            {
                return;
            }

            futureX = (int)(X + Vx);
            futureY = (int)(Y + Vy);
            //Bound Check;
            if (futureX < 0 || futureX > map.Length - 1 || futureY < 0 || futureY > map.Length - 1)
            {
                SetVelocity(0, 0);
                return;
            }

            WorldCell next  = map[futureX, futureY];
            bool      apply = false;

            switch (next.WorldCellType)
            {
            case CellType.WATER:
                if (CanSwim)
                {
                    apply = true;
                }
                break;

            case CellType.SAND:
            case CellType.DIRT:
                if (CanWalk)
                {
                    apply = true;
                }
                break;

            case CellType.ROCK:
                if (CanClimb)
                {
                    apply = true;
                }
                break;
            }
            if (apply)
            {
                bool invoke = false;
                if ((int)X != futureX || (int)Y != futureY)
                {
                    //We moved a cell
                    WorldObject wobj = objects[futureX, futureY];
                    //Only One Object per Cell!
                    if (wobj != null)
                    {
                        apply = false;
                        SetVelocity(0, 0);
                        return;
                    }
                    //tell everyone
                    invoke = true;
                    //Clear our Current Cell
                    objects[(int)X, (int)Y] = null;
                    //Move to our new cell
                    objects[futureX, futureY] = this;
                }
                //update our pos
                X = (X + Vx);
                Y = (Y + Vy);
                //then tell everyone
                if (invoke)
                {
                    PositionUpdated?.Invoke(this);
                }
            }
            else
            {
                SetVelocity(0, 0);
            }
        }