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); }
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; }
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; }
private static void UpdatePlayer(int[] coords, short[] flashVector, Map map) { if (Helper.SafeCoords(coords, flashVector, map.Height, map.Width)) { if (map.tile(coords, flashVector).mass == 0) { map.tile(coords, flashVector).SetTile(map.tile(coords)); map.tile(coords).SetTile(new Tile()); } } }
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); }
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; } } }
private static void UpdatePlayer(int[] coords, double[] playerAcceleration, Map map) { map.tile(coords).velocity[0] += playerAcceleration[0]; map.tile(coords).velocity[1] += playerAcceleration[1]; int[] velocity = Helper.GetRoundedVelocity(playerAcceleration); playerAcceleration = new double[2]; int distance = Helper.GetDistance(velocity); short[] flashVector; int[] flashCoords = coords; for (int i = 0; i < distance; i++) { flashVector = Helper.GetFlashVector(velocity); UpdatePlayer(flashCoords, flashVector, map); velocity[0] -= flashVector[0]; velocity[1] -= flashVector[1]; flashCoords[0] += flashVector[0]; flashCoords[1] += flashVector[1]; playerAcceleration[0] = 0; playerAcceleration[1] = 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); }
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; }
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; } } }
/// <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; } }
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); }
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); }
/// <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; } }