Exemplo n.º 1
0
 private static int[] CheckCollideWith(int clusterId, Map map)
 {
     for (int i = 0; i < map.Height; i++)
     {
         for (int j = 0; j < map.Width; j++)
         {
             if (map.map[i, j].ClusterId == clusterId)
             {
                 for (int k = -1; k < 2; k += 2)
                 {
                     if (Helper.SafeCoords(new int[2] { i + k, j }, map.Height, map.Width))
                     {
                         if (map.map[i + k, j].mass > 0 && map.map[i + k, j].ClusterId != clusterId)
                         {
                             return new int[2] { i + k, j };
                         }
                     }
                     if (Helper.SafeCoords(new int[2] { i, j + k }, map.Height, map.Width))
                     {
                         if (map.map[i, j + k].mass > 0 && map.map[i, j + k].ClusterId != clusterId)
                         {
                             return new int[2] { i, j + k };
                         }
                     }
                 }
             }
         }
     }
     throw null;
 }
Exemplo n.º 2
0
 public Map(Map newMap)
 {
     Height = newMap.Height;
     Width = newMap.Width;
     map = new Tile[Height, Width];
     CleanMap();
     SetMap(newMap);
 }
Exemplo n.º 3
0
 public GameWindowObj(Map map)
 {
     ImageGrid = new Image[map.Height,map.Width];
     GWindow = new Window();
     GWindow.Background = System.Windows.Media.Brushes.Black;
     GameMap = map;
     RefreshGameMap.Elapsed += tick;
     GameWindow.Build(GWindow, ImageGrid, TileTypes.GetProcessedIds(GameMap), GameMap.Height, GameMap.Width);
 }
Exemplo n.º 4
0
 private static void UpdateGravity(int[] coords1, int[] coords2, Map map)
 {
     int[] displacement = Helper.GetDisplacement(coords1, coords2);
     double gravity = GetGravity(Helper.GetDistance(displacement), map.tile(coords2).mass);
     Fraction[] vectorComplexe = Helper.GetVectorComplexe(displacement);
     vectorComplexe[0].Value *= gravity;
     vectorComplexe[1].Value *= gravity;
     map.tile(coords1).velocity[0] += vectorComplexe[0].Value;
     map.tile(coords1).velocity[1] += vectorComplexe[1].Value;
 }
Exemplo n.º 5
0
 /// <summary>
 /// cannot change Height/Width
 /// </summary>
 /// <param name="newMap"></param>
 private void SetMap(Map newMap)
 {
     for (int i = 0; i < Height; i++)
     {
         for (int j = 0; j < Width; j++)
         {
             map[i, j].SetTile(newMap.map[i, j]);
         }
     }
     ClusterIdList.SetClusterIdList(newMap.ClusterIdList);
 }
Exemplo n.º 6
0
 public static int[,] GetProcessedIds(Map map)
 {
     int[,] IdsMap = new int[map.Width,map.Height];
     for(int i = 0;i < map.Height;i++)
     {
         for (int j = 0; j < map.Width; j++)
         {
             IdsMap[i, j] = GetProcessedTextureId(map.map[i,j]);
         }
     }
     return IdsMap;
 }
Exemplo n.º 7
0
 public static void SetClusterId(int clusterId,int newClusterId,Map map)
 {
     for (int i = 0; i < map.Height; i++)
     {
         for (int j = 0; j < map.Width; j++)
         {
             if (map.map[i, j].ClusterId == clusterId)
             {
                 map.map[i, j].ClusterId = newClusterId;
             }
         }
     }
 }
Exemplo n.º 8
0
 public static void UpdateGravity(Map map)
 {
     for (int i = 0;i < map.Height;i++)
     {
         for (int j = 0; j < map.Width; j++)
         {
             if (map.map[i, j].mass != 0)
             {
                 UpdateGravity(new int[2] { i, j }, map);
             }
         }
     }
 }
Exemplo n.º 9
0
 private static void UpdateGravity(int[] coords,Map map)
 {
     for (int i = 0; i < map.Height; i++)
     {
         for (int j = 0; j < map.Width; j++)
         {
             if (map.map[i, j].mass != 0 && (coords[0] != i || coords[1] != j))
             {
                 UpdateGravity(coords, new int[2] { i, j }, map);
             }
         }
     }
 }
Exemplo n.º 10
0
 public static void SetClusterHasMoved(int clusterId,bool hasMoved,Map map)
 {
     for (int i = 0; i < map.Height; i++)
     {
         for (int j = 0; j < map.Width; j++)
         {
             if(map.map[i,j].ClusterId == clusterId)
             {
                 map.map[i, j].HasMoved = hasMoved;
             }
         }
     }
 }
Exemplo n.º 11
0
 public static void SetClusterId(int[] coords,int newClusterId,Map map)
 {
     bool[,] boolMap = GetBoolMapOfCluster(coords,map);
     for (int i = 0; i < map.Height; i++)
     {
         for (int j = 0; j < map.Width; j++)
         {
             if (boolMap[i,j])
             {
                 map.map[i, j].ClusterId = newClusterId;
             }
         }
     }
 }
Exemplo n.º 12
0
 public static void CollisionFluidLike(int clusterId1,int[] cluster1VelocityMatrixRelativeLeft,short[] flashVector,int clusterId2,Map map)
 {
     short[] vector = flashVector;
     int[] velocity = cluster1VelocityMatrixRelativeLeft;
     velocity[0] /= 2;
     velocity[1] /= 2;
     CollisionFluidLike(clusterId1, vector, velocity,map);
     /*
     vector[0] *= -1;
     vector[1] *= -1;
     velocity[0] *= -1;
     velocity[1] *= -1;
     CollisionFluidLike(clusterId2, vector, velocity,map);
     */
 }
Exemplo n.º 13
0
 public static int[] GetClusterVelocityRounded(int clusterId,Map map)
 {
     for (int i = 0; i < map.Height; i++)
     {
         for (int j = 0; j < map.Width; j++)
         {
             if (map.map[i, j].ClusterId == clusterId)
             {
                 return map.map[i, j].VelocityRoundedActual();
             }
         }
     }
     System.Windows.MessageBox.Show("Cluster.GetClusterVelocityMatrixRounded.size = 0!");
     return new int[2];
 }
Exemplo n.º 14
0
 /// <summary>
 /// return equels collide With
 /// </summary>
 /// <param name="clusterId"></param>
 /// <param name="flashVector"></param>
 /// <param name="map"></param>
 /// <returns></returns>
 public static int CheckCollide(int clusterId,short[] flashVector,Map map)
 {
     for (int i = 0; i < map.Height; i++)
     {
         for (int j = 0; j < map.Width; j++)
         {
             if (map.map[i, j].ClusterId == clusterId && Helper.SafeCoords(new int[2] {i + flashVector[0],j + flashVector[1] },map.Height,map.Width))
             {
                 if (map.map[i + flashVector[0], j + flashVector[1]].BaseMass != 0 && map.map[i + flashVector[0], j + flashVector[1]].ClusterId != clusterId)
                 {
                     return map.map[i + flashVector[0], j + flashVector[1]].ClusterId;
                 }
             }
         }
     }
     return -1;
 }
Exemplo n.º 15
0
 public Screen(Map map)
 {
     window = new Window();
     gridHeight = map.height;
     gridWidth = map.width;
     window.Height = gridHeight * TileTypes.textureSize;
     window.Width = gridWidth * TileTypes.textureSize;
     ConstructGrid();
     UpdateGridMap(map);
     UpdateGrid();
     grid.ShowGridLines = showGridLines;
     window.WindowStyle = WindowStyle.None;
     window.Content = grid;
     if(!started)
     {
         started = true;
         window.Show();
     }
 }
Exemplo n.º 16
0
 public static void SetClusterId(ClusterIdList clusterIdList,Map map)
 {
     clusterIdList.Reset();
     for (int i = 0; i < map.Height; i++)
     {
         for (int j = 0; j < map.Width; j++)
         {
             map.map[i, j].ClusterId = -1;                
         }
     }
     for (int i = 0; i < map.Height; i++)
     {
         for (int j = 0; j < map.Width; j++)
         {
             if (map.map[i, j].ClusterId == -1 && map.map[i, j].BaseMass != 0)
             {
                 SetClusterId(new int[2] { i, j }, clusterIdList.GetNewClusterId(),map);
             }
         }
     }
 }
Exemplo n.º 17
0
 private static int[] CheckCollideWith(int clusterId, short[] flashVector, Map map)
 {
     for (int i = 0; i < map.Height; i++)
     {
         for (int j = 0; j < map.Width; j++)
         {
             if (map.map[i, j].ClusterId == clusterId && Helper.SafeCoords(new int[2] { i + flashVector[0], j + flashVector[1] }, map.Height, map.Width))
             {
                 for(int k = -1;k < 2;k += 2)
                 {
                     for (int h = -1; h < 2; h += 2)
                     {
                         if(map.map[i + flashVector[0], j + flashVector[1]].mass > 0 && map.map[i + flashVector[0], j + flashVector[1]].ClusterId != clusterId)
                         {
                             return new int[2] { i, j };
                         }
                     }
                 }
             }
         }
     }
     return CheckCollideWith(clusterId, map);
 }
Exemplo n.º 18
0
 public MainWindow()
 {
     Debug.StartCounter();
     //InitializeComponent();
     world = new Map(100,100);
     //world.PlaceOneTile(new int[2] { 2, 2 });
     //world.start();
     //world.PlaceOneTile(new int[2] { 4, 4 });
     //world.PlacePlayer(new int[2] { 20, 20 },1);
     //world.PlaceOneTile(new int[2] { 2, 2 }, new Tile(2, new double[2] { 0, 0.2 }));
     //world.PlaceOneTile(new int[2] { 4, 2 }, new Tile(2, new double[2] { 0, 0.4 }));
     //world.PlaceOneTile(new int[2] { 6, 2 }, new Tile(2, new double[2] { 0, 0.8 }));
     //world.PlaceOneTile(new int[2] { 8, 2 }, new Tile(2, new double[2] { 0, 1.6 }));
     world.PlaceOneTile(new int[2] { 50, 50 }, new Tile(10000));
     world.PlaceOneTile(new int[2] { 50, 55 }, new Tile(1, new double[2] { 0.5,0 }));
     //world.PlaceOneTile(new int[2] { 15, 10 });
     //world.PlaceOneTile(new int[2] { 10, 15 });
     //world.PlaceOneTile(new int[2] { 20, 15 });
     //world.PlaceOneTile(new int[2] { 15, 17 }, new Tile(1, new double[2] { -0.01, 0 }));
     Input player = new Input(world);
     //tileTypes.GetImage needs work!
     //gravity needs work
 }
Exemplo n.º 19
0
 private static void CollideTileElastic(int[] coords1,int[] coords2,Map map)
 {
     //baseValues
     double[] velocity1 = map.tile(coords1).velocity;
     double[] force2 = Helper.GetForce(map.tile(coords2));
     double[] forceTotal = Helper.GetForce(map.tile(coords1));
     forceTotal[0] += force2[0];
     forceTotal[1] += force2[1];
     int mass2 = map.tile(coords2).mass;
     CollideTileElastic(map.tile(coords1),map.tile(coords2), velocity1, forceTotal, mass2);
 }
Exemplo n.º 20
0
 private static void MoveTile(int[] coords,int[] velocityMatrixRoundedActual,Map map)
 {
     int[] velocity = velocityMatrixRoundedActual;
     int distance = Helper.GetDistance(velocity);
     int[] flashCoords = coords;
     short[] flashVector;
     for(int i = 0;i < distance;i++)
     {
         flashVector = Helper.GetFlashVector(velocity);
         velocity[0] -= flashVector[0];
         velocity[1] -= flashVector[1];
         if(Helper.SafeCoords(new int[2] { flashCoords[0] + flashVector[0], flashCoords[1] + flashVector[1] }, map.Height, map.Width))
         {
             if (map.IsObject(flashCoords, flashVector))
             {
                 CollideTile(flashCoords, new int[2] { flashCoords[0] + flashVector[0], flashCoords[1] + flashVector[1] }, map);
             }
             else
             {
                 map.tile(flashCoords, flashVector).SetTile(map.tile(flashCoords));
                 map.tile(flashCoords).SetTile(new Tile());
             }
         }
         else
         {
             map.tile(flashCoords).SetTile(new Tile());
             return;
         }
         flashCoords[0] -= flashVector[0];
         flashCoords[1] -= flashVector[1];
         if(!Helper.SafeCoords(new int[2] { flashCoords[0], flashCoords[1] }, map.Height, map.Width))
         {
             return;
         }
     }
 }
Exemplo n.º 21
0
 private static void CollisionFluidLike(int clusterId, short[] vector, int[] velocityMatrixRounded, Map map)
 {
     bool updating = true;
     while (updating)
     {
         updating = false;
         for (int i = 0; i < map.Height; i++)
         {
             for (int j = 0; j < map.Width; j++)
             {
                 if (map.map[i, j].ClusterId == clusterId)
                 {
                     updating = true;
                     map.map[i, j].ClusterId = -2048;
                     MoveTile(new int[2] { i, j }, velocityMatrixRounded, map);
                 }
             }
         }
     }
     for (int i = 0; i < map.Height; i++)
     {
         for (int j = 0; j < map.Width; j++)
         {
             if (map.map[i, j].ClusterId == -2048)
             {
                 map.map[i, j].ClusterId = clusterId;
             }
         }
     }
 }
Exemplo n.º 22
0
 private static bool[,] GetBoolMapOfCluster(int[] coords,Map map)
 {
     int[] velocity = map.tile(coords).VelocityRoundedActual();
     int[] flashVelocity;
     bool stillFinding = true;
     bool[,] boolMap = new bool[map.Height, map.Height];
     boolMap[coords[0], coords[1]] = true;
     while(stillFinding)
     {
         stillFinding = false;
         for (int i = 0; i < map.Height; i++)
         {
             for (int j = 0; j < map.Width; j++)
             {
                 if (map.map[i, j].mass != 0)
                 {
                     flashVelocity = map.map[i, j].VelocityRoundedActual();
                     if (!boolMap[i, j] && flashVelocity[0] == velocity[0] && flashVelocity[1] == velocity[1])
                     {
                         if (IsAdjacent(boolMap, new int[2] { i, j },map.Height,map.Width))
                         {
                             boolMap[i, j] = true;
                             stillFinding = true;
                         }
                     }
                 }
             }
         }
     }
     return boolMap;
 }
Exemplo n.º 23
0
 private static void CollideTile(int[] coords1,int[] coords2,Map map)
 {
     if(map.tile(coords1).BaseMass == map.tile(coords2).BaseMass)
     {
         CollideTilePressure(coords1, coords2,map);
         return;
     }
     CollideTileElastic(coords1, coords2,map);
 }
Exemplo n.º 24
0
 public void Update(Map map)
 {
     UpdateGridMap(map);
     UpdateGrid();
     grid.ShowGridLines = showGridLines;
     window.WindowStyle = WindowStyle.None;
     window.Content = grid;
 }
Exemplo n.º 25
0
 private void UpdateGridMap(Map map)
 {
     int Id;
     for(int i = 0;i < gridHeight;i++)
     {
         for(int j = 0;j < gridWidth;j++)
         {
             Id = map.map[i, j].mass;
             if (map.map[i, j].isPlayer)
             {
                 gridMap[i, j] = (int)TileTypes.textures.player;
             }
             else if (Id >= (int)TileTypes.textures.player)
             {
                 gridMap[i, j] = (int)TileTypes.textures.player - 1;
             }
             else
             {
                 gridMap[i, j] = Id;
             }
         }
     }
 }
Exemplo n.º 26
0
 public static void SetClusterId(int[] coords,ClusterIdList clusterIdList,Map map) => SetClusterId(coords,clusterIdList.GetNewClusterId(),map);
Exemplo n.º 27
0
 /// <summary>
 /// needs work
 /// </summary>
 /// <param name="coords1"></param>
 /// <param name="coords2"></param>
 private static void CollideTilePressure(int[] coords1,int[] coords2,Map map)
 {
     double[] forceRelative = Helper.GetForce(map.tile(coords1), map.tile(coords2));
     int transferAmount = Convert.ToInt32(Math.Round(Helper.AddValues(forceRelative)));
     if(map.tile(coords1).mass <= transferAmount)
     {
         map.tile(coords2).pressure += map.tile(coords1).pressure;
         map.tile(coords2).velocity[0] += map.tile(coords1).velocity[0];
         map.tile(coords2).velocity[1] += map.tile(coords1).velocity[1];
         map.tile(coords1).SetTile(new Tile());
         return;
     }
     else
     {
         map.tile(coords2).pressure += transferAmount;
         map.tile(coords1).pressure -= transferAmount;
         CollideTileElastic(coords1, coords2,map);
         return;
     }
 }
Exemplo n.º 28
0
 public static void SetClusterId(Map map) => SetClusterId(map.ClusterIdList, map);