/*at some point this library will be rebuilt into advilib*/ #include #include #include #include #include #include #include #include #include #include #include "AdviLib.h" #define SDLKES SDLK_ESCAPE #define SDLKUP SDLK_UP #define SDLKDN SDLK_DOWN #define SDLKLF SDLK_LEFT #define SDLKRT SDLK_RIGHT #define SDLKEN SDLK_RETURN #define SDLKLS SDLK_LSHIFT #define SDLKSP SDLK_SPACE #define SDLKCM SDLK_COMMA #define SDLKTB SDLK_TAB #define SDLKPR SDLK_PERIOD #define SDLMBL SDL_BUTTON_LEFT #define SDLMBR SDL_BUTTON_RIGHT #define SDL_RENDERER_INIT SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC #define GetRandomDrawColor(ren) SDL_SetRenderDrawColor(ren, static_cast(randomWithinRange(255)), static_cast(randomWithinRange(255)), static_cast(randomWithinRange(255)), 255) /// /// literally just a dump of strings for test, placeholder, or filler purposes(size 16) /// std::vector JankList{ "WRITE", "PokemonMasterSex", "Where's the shotgun?!?!", "GROUDON", "KYOGRE", "PALKIA", "ZEKROM", "RESHIRAM", "HOENN", "Jank", "What is the time CV-11", "Lv. 100", "#FreeCivvie", "GS Ball", "Ruby & Sapphire", "HeartGold and SoulSilver" }; /// /// saves a bitmap of the current state of the SDL window containing r /// void Screenshot(SDL_Renderer* r, string name, int w, int h) { const uint32_t format{ SDL_PIXELFORMAT_ARGB8888 }; SDL_Surface* sur{ SDL_CreateRGBSurfaceWithFormat(0, w, h, 32, format) }; SDL_RenderReadPixels(r, NULL, format, sur->pixels, sur->pitch); SDL_SaveBMP(sur, name.c_str()); SDL_FreeSurface(sur); std::cout << "captured!"; } /// /// goes to point of rect defined by (TileX * 10) and (TileY * 10), and gets the local area defined by size(assuming the rect goes with an image) /// void GetTile(SDL_Rect& tile, int TileX, int TileY, int size) { // multiply TileX and TileY and put those number into tile.x and tile.y TileX *= 10; TileY *= 10; tile.x = TileX; tile.y = TileY; // put 10 in TileX and TileY and put those number into tile.w and tile.h TileX = size; TileY = size; tile.w = TileX; tile.h = TileY; } /// /// inits SDL2(everything), SDL_ttf, and SDL_image(png, jpg) /// void Init() { SDL_Init(SDL_INIT_EVERYTHING); IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG); TTF_Init(); } /// /// clears up SDL data in use. /// /// the window to destroy(only destroys a single window as of right now) /// the renderer to destroy(only destroys a single renderer as of right now) /// an array of surfaces to free up(depends on next parameter) /// the amount of surfaces in the array of surfaces(can be passed using std::size() function) /// an array of textures to destroy(depends on next parameter) /// the amount of textures in the array of textures(can be passed using std::size() function) /// an array of fonts to close(depends on next parameter) /// the amount of fonts in the array of fonts(can be passed using std::size() function) void QuitSDL(SDL_Window* w[] = nullptr, int numWindows = 0, SDL_Renderer* r[] = nullptr, int numRenderers = 0, SDL_Surface* s[] = nullptr, int numSurfaces = 0, SDL_Texture* t[] = nullptr, int numTextures = 0, TTF_Font* f[] = nullptr, int NumFonts = 0) { if (t != nullptr) for (int nt = 0; nt < numTextures; nt++) SDL_DestroyTexture(t[nt]); if (s != nullptr) for (int ns = 0; ns < numSurfaces; ns++) SDL_FreeSurface(s[ns]); if (f != nullptr) for (int nf = 0; nf < NumFonts; nf++) TTF_CloseFont(f[nf]); if (r != nullptr) for (int nr = 0; nr < numRenderers; nr++) SDL_DestroyRenderer(r[nr]); if (w != nullptr) for (int nw = 0; nw < numWindows; nw++) SDL_DestroyWindow(w[nw]); TTF_Quit(); IMG_Quit(); SDL_Quit(); } /// /// mostly just for fun, doesnt provide anything use to your program. also doesnt print addresses /// /// the amount of time in between printing a character void PutText(string txt, int delay) // should try to convert this to print out text on SDL window, will require more parameters { unsigned int tsize{ std::size(txt) }; for (unsigned int i = 0; i < tsize; i++) { std::cout << txt.at(i); SDL_Delay(delay); } }