/* This function will help in debugging error messages, and also helps finding what the plugin is doing in debug mode. */ basic_string GetModuleNameFromMemoryAddress ( DWORD mem_address ) { #ifdef WIN32 HMODULE module; if( GetModuleHandleExA ( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast<LPSTR>(mem_address), &module ) ) { char buf[ 1024 ]; GetModuleFileNameA ( module, buf, 1023 ); buf[ 1023 ] = '\0'; // Windows XP does not null-terminate string when truncated ... I do this even if we don't target XP. basic_string filename ( buf ); size_t path_end ( filename.find_last_of ( "/\\" ) ); if( path_end != basic_string::npos ) { filename.remove ( 0, path_end ); } return filename; } else { return "<error determining module>"; } #else Dl_info info; dladdr ( reinterpret_cast<void*>( mem_address ), &info ); basic_string filename ( info.dli_fname ); size_t path_end ( filename.find_last_of ( "/\\" ) ); if( path_end != basic_string::npos ) { filename.remove ( 0, path_end ); } return filename; #endif }
void move() { // Для алгоритма поиска поути if(!path_find()) { if(playSound) soundBadMove(); return; } if(showPath) { // Рисуем шаги на экране path_save(); while(1) { switch(path_nextStep()) { case 1: drawSpriteStep(path_x, path_y+1, 0); break; case 2: drawSpriteStep(path_x, path_y-1, 1); break; case 3: drawSpriteStep(path_x+1, path_y, 2); break; case 4: drawSpriteStep(path_x-1, path_y, 3); break; } drawSprite(path_x, path_y, path_c); if(path_n==LAST_STEP) break; if(playSound) soundJumpSel(); delay(STEP_SPEED); }; // Удаляем нарисованные шаги с экрана path_load(); while(1) { drawSprite(path_x, path_y, 0); path_nextStep(); if(path_n==LAST_STEP) break; }; } else { drawSprite(selX, selY, 0); drawSprite(cursorX, cursorY, path_c); } // Реально перемещаем шарик. Все выше было лишь анимацией. game[cursorX][cursorY] = path_c; // Снимаем курсор selX = -1; // Очищаем игровое поле от временных значений path_end(); // Добавляем 3 шарика gameStep(); }
uchar path_find() { register uchar* p; path_c = game[selX][selY]; game[selX][selY] = 255; game[cursorX][cursorY] = PATH_START_VAL; // Ищем путь for(path_n = PATH_START_VAL; path_n != PATH_START_VAL+GAME_WIDTH*GAME_HEIGHT; ++path_n) for(p = &game[0][0], path_x=0; path_x != GAME_WIDTH; ++path_x) for(path_y=0; path_y != GAME_HEIGHT; ++path_y, ++p) if(*p == path_n) { if(path_y != 0 ) { p-=1; if(*p==255) { --path_y; path_p=p; return 1; } else if(*p==0) *p=path_n+1; p+=1; } if(path_y != GAME_HEIGHT-1) { p+=1; if(*p==255) { ++path_y; path_p=p; return 1; } else if(*p==0) *p=path_n+1; p-=1; } if(path_x != 0 ) { p-=GAME_HEIGHT; if(*p==255) { --path_x; path_p=p; return 1; } else if(*p==0) *p=path_n+1; p+=GAME_HEIGHT; } if(path_x != GAME_WIDTH -1) { p+=GAME_HEIGHT; if(*p==255) { ++path_x; path_p=p; return 1; } else if(*p==0) *p=path_n+1; p-=GAME_HEIGHT; } } // Путь не найден path_end(); game[selX][selY] = path_c; return 0; }