/* This process initializes the starting air velocities and accelerations for every lemming after an explosion It can be seen as if an array of pointers to lemming classes is passed in, as well as the x and y coordinates of the explosion These are then used to calculate the starting dX and dY for each lemming, and an the standard function is used for all trajectories to set ddX and ddY */ void Explosion_Initialize_Physics(Lemming* lemmings[], int explosion_x, int explosion_y) { int dX; int dY; Lemming** lemming_pointer = lemmings; // Pointer to a pointer to a lemming, initialize to the beginning of the array of pointers passed in for( int i = 0; i < g_number_lemmings; i++ ) { // Iterate through the array of lemmings lemming_pointer = lemmings + i; if (((**lemming_pointer).state != 0x19) // Check if lemming is a magno-booter && ((**lemming_pointer).x_pos != -1)) { // and check if lemming is dead (x = -1) y_coordinate_difference = (**lemming_pointer).y_pos - explosion_y; // Find difference in y coordinates of lemming and explosion if (abs(y_coordinate_difference) < 0x30 ) { // Check to make sure lemming is within explosion range in y direction (48 pixels) // LAB_0000_0cc5: x_coordinate_difference = (**lemming_pointer).x_pos - explosion_x; // Repeat same process for x coordinates, first find difference in x coordinates for lemming and explosion if (abs(x_coordinate_difference) < 0x30) { // Check to make sure lemming is within explosion range in x direction (48 pixels) // LAB_0000_0cd7: if (x_coordinate_difference != explosion_x) { // If lemming is not at the explosion's x-coordinate if (x_coordinate_difference < 0) { // Lemming is to the left of the explosion dX = x_coordinate_difference * -1; dX = dX / 8; dX -= 6; // Lemming dX is equal to the absolute value of the difference, divided by 8, -6 lemming_pointer->*lemming.direction = -1; // Set lemming direction facing to the left } else { // Lemming is to the right of the explosion dX = x_coordinate_difference / 8; dX = dX * -1; dX += 6; // Lemming dX is equal to the difference divided by 8, negated, +6 lemming_pointer->*lemming.direction = 1; // Because lemming is to the right of the explosion, set lemming direction to the right } } else { dX = 0; // Lemming is at the same x-coordinate as the explosion, so the dX should be 0 (lemming will travel only vertically) } if(dX == 0) { // If lemming is at same x-coordinate as the explosion, set dY to -5 dY = -5; } else { dY = dX; // Set working dY to dX if(dY > 0) { // If dY is greater than 0 dY = dY * -1; // Negate dY; this means dY will always be negative after an explosion, so a lemming will always be flung vertically } dY++; // Increment dY to get final dY } Air_Physics_Initialization(*lemming_pointer, dX, dY); // Use calculated dX and dY to initialize the lemming's dX, dY, ddX, and ddY (**lemming_pointer).y_pos -= 1; // Moves lemming up by 1, regardless of position. This could be a potential cause of the glitch where lemmings are flung into terrain Change_Lemming_State(0x41); // This calls to the function which changes a lemming's state, passes 0x41 to change to a Flinger } } } } }