int main(void) { int a[20]; random_array(a, 20); print_array(a, 20); comb_sort(a, 20); print_array(a, 20); return 0; }
void sprite_sort_far_to_close(t_env *e) { int i; i = 0; while (i < SPRITE_NBR) { e->sprite_order[i] = i; e->sprite_dist[i] = ((e->player.pos_x - e->sprite_pos[i].x) * (e->player.pos_x - e->sprite_pos[i].x) + (e->player.pos_y - e->sprite_pos[i].y) * (e->player.pos_y - e->sprite_pos[i].y)); i++; } comb_sort(e->sprite_order, e->sprite_dist, SPRITE_NBR); }
void loop() { // Calculate the position of the map that we are redrawing behind the old cursor map_redraw.x = cursor.position.x - cursor.r; map_redraw.y = cursor.position.y - cursor.r; // Calculate the source tile of the map that we are palcing map_tile.x = map_redraw.x + m_map.x; map_tile.y = map_redraw.y + m_map.y; // Ini redraw parameter, will be used to indicate that a redraw is required bool redraw = 0; // Analog read into joystick parameters JoyStick.x = analogRead(HORZJOY); JoyStick.y = analogRead(VERTJOY); // If there is a deviation from the initial readings, this indicates that there might be some redrawing required if(iniJoy.x != JoyStick.x || iniJoy.y != JoyStick.y) { moveJoystick(&JoyStick, &cursor, &tft, &redraw); moveCursorOff(&map_image, &tft, &cursor, &m_map, &redraw); } if(state) { // Determine the location of the cursor on the image file cursor_map.x = m_map.x + cursor.position.x; cursor_map.y = m_map.y + cursor.position.y; #if DEBUG Serial.print("Mapped (X,Y) Coord> ("); Serial.print(cursor_map.x); Serial.print(","); Serial.print(cursor_map.y); Serial.println(")"); Serial.print("Mapped (LON,LAT) Coord> ("); Serial.print(x_to_lon(cursor_map.x)); Serial.print(","); Serial.print(y_to_lat(cursor_map.y)); Serial.println(")"); #endif // Sets our page number to be zero uint16_t page = 1; // Prints loading screen to tft while loading and sorting get processed loadingScreen(&card, &tft); // Define RestDist structure for holding the distances from the different rest's // NOTE: As rest is an array, it does not need to be dereferenced RestDist rest[TOTAL_REST]; // Load the restraunts from the SD card into the restdist array loadRest(&card, rest, &cursor_map, TOTAL_REST); // Use the comb sort algorithm to sort the list of restraunts comb_sort(rest, TOTAL_REST); // Print page 1 of the sorted list printRest(&card, &tft, rest, page); while(state) { // Reads the current position of the joystick JoyStick.y = analogRead(VERTJOY); /* * Checks whether the joystick has moved (selecting other restraunts from list) and prints the restraunt according the page passed, with added support for checking that you do not go over the amount of restraunts that were loaded. */ if(JoyStick.y > 800 && page != 1) { printRest(&card, &tft, rest, --page); } else if(JoyStick.y < 250 && (page - 1)*PAGESIZE + PAGESIZE < TOTAL_REST) { printRest(&card, &tft, rest, ++page); } } // Redraw the map lcd_image_draw(&map_image, &tft, &m_map, &c_zero, tft.width(), tft.height()); // Redraw the cursor in its old position drawCursor(&tft, &cursor); // Set the redraw parameter to be zero redraw = 0; } /* * This will redraw the map over the old cursor, and redraw the cursor in the new position if the cursor has been indicated as moved. */ if(redraw == 1) { // Included for DEBUG purposes #if DEBUG // Determine the location of the cursor on the image file cursor_map.x = m_map.x + cursor.position.x; cursor_map.y = m_map.y + cursor.position.y; Serial.print("Mapped (X,Y) Coord> ("); Serial.print(cursor_map.x); Serial.print(","); Serial.print(cursor_map.y); Serial.println(")"); Serial.print("Mapped (LON,LAT) Coord> ("); Serial.print(x_to_lon(cursor_map.x)); Serial.print(","); Serial.print(y_to_lat(cursor_map.y)); Serial.println(")"); #endif // Redraw the map in front of the old cursor lcd_image_draw(&map_image, &tft, &map_tile, &map_redraw, cursor.r*2+1, cursor.r*2+1); // Draw the new cursor at the new position drawCursor(&tft, &cursor); } }