void GUI::render_canvas() { clear_screen(); TilePointerMatrix tm = game.get_canvas(); for(size_t i = 0; i < tm.size(); i++) { for(size_t j = 0; j < tm[i].size(); j++) { if(game.visibility_on) { //If the tile is visible, render it fully. if(tm[i][j]->visible) { drawChr(j, i, tm[i][j]->char_count, ascii, screen, tm[i][j]->color); //If the tile is not visible, but has been seen, render it in //grey. } else if(tm[i][j]->seen) { drawChr(j, i, tm[i][j]->char_count, ascii, screen, VERY_DARK_GRAY); //We probably shouldn't draw the chara layer on non-visible //tiles. } else { //Draw an empty tile drawChr(j, i, 0, ascii, screen, 0); } } else { drawChr(j, i, tm[i][j]->char_count, ascii, screen, tm[i][j]->color); } } } }
void NESEditor::drawTile(TileId index, const Vector2& pos) { auto chr1 = m_tilesets[0][index]; auto chr2 = m_tilesets[1][index]; auto chr3 = m_tilesets[2][index]; auto chr4 = m_tilesets[3][index]; drawChr(static_cast<Chr>(chr1), pos); drawChr(static_cast<Chr>(chr2), {pos.x + 8.f, pos.y}); drawChr(static_cast<Chr>(chr3), {pos.x, pos.y + 8.f}); drawChr(static_cast<Chr>(chr4), {pos.x + 8.f, pos.y + 8.f}); }
void GUI::render_debug() { std::unordered_map<std::string, Tile>* tileset = &Tileset::instance()->get_tileset(); for(int i=0;i<GAME_WIDTH;i++) { drawChr(i, GAME_HEIGHT-3, (*tileset)["BLOCK_WALL"].char_count, ascii, screen, BLACK); drawChr(i, GAME_HEIGHT-2, (*tileset)["BLOCK_WALL"].char_count, ascii, screen, BLACK); } drawChr(input.size(), GAME_HEIGHT-2, (*tileset)["BLOCK_WALL"].char_count, ascii, screen, WHITE); drawStr(0, GAME_HEIGHT-3, debug.get_message().c_str(), ascii, screen, WHITE); drawStr(0, GAME_HEIGHT-2, input.c_str(), ascii, screen, WHITE); }
int main(int argc, char* argv[]) { SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO ); //Set up screen SDL_Surface* screen = SDL_SetVideoMode( 100, 100, 32, SDL_SWSURFACE ); //Load ascii characters SDL_Surface* asciiBase = SDL_LoadBMP( "ascii.bmp" ); //Create an optimized image SDL_Surface* ascii = SDL_DisplayFormat( asciiBase ); //Free the old image SDL_FreeSurface( asciiBase ); //Map the color key Uint32 colorkey = SDL_MapRGB( ascii->format, 0xFF, 0, 0xFF ); //Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent SDL_SetColorKey( ascii, SDL_SRCCOLORKEY, colorkey ); SDL_SetColorKey( ascii, SDL_SRCCOLORKEY, colorkey ); bool running = true; if(argc<2) { std::cout << "No option specified" << std::endl; } else { int number; sscanf(argv[1], "%d", &number); SDL_Event e; while(running) { while(SDL_PollEvent(&e)) { switch(e.type) { case SDL_QUIT: running = false; } } drawChr(5, 5, number, ascii, screen, BROWN); SDL_Flip(screen); SDL_Delay(50); } } SDL_Quit(); return 0; }
void GUI::render_characters() { Tile current_tile; IntPoint current_point; TilePointerMatrix tm = game.get_canvas(); std::vector<Character*> tl = game.get_vis_characters(); for(size_t i = 0; i < tl.size(); i++) { IntPoint temp_chunk = IntPoint(tl[i]->get_chunk_y(),tl[i]->get_chunk_x()); IntPoint temp_coords = IntPoint(tl[i]->get_y(), tl[i]->get_x()); current_tile = tl[i]->get_char(); current_point = game.get_canvas_coords(temp_chunk, temp_coords); if(tm[current_point.row][current_point.col]->visible) { drawChr(current_point.col, current_point.row, current_tile.char_count, ascii, screen, current_tile.color); } } }
void GUI::render_target() { TilePointerMatrix tm = game.get_canvas(); if(game.main_char.get_target() != NULL) { Character* chara = game.main_char.get_target(); IntPoint temp_chunk = chara->get_chunk(); std::vector<IntPoint> sight = chara->sight_tiles(); for(int i=0;i<sight.size();i++) { IntPoint point = game.get_canvas_coords(temp_chunk, sight[i]); if(game.is_vis(point) && tm[point.row][point.col]->visible) { drawChr(point.col, point.row, tm[point.row][point.col]->char_count, ascii, screen, YELLOW); } } } }
void GUI::OnRender() { if(current_screen == MENU_SCREEN) { render_menu(menu); } else if(current_screen == MAP_SCREEN) { std::vector<std::vector<MapTile> > map_canvas = world_map_gui.get_canvas(); for(size_t i = 0; i < map_canvas.size(); i++) { for(size_t j = 0; j < map_canvas[i].size(); j++) { drawChr(j, i, map_canvas[i][j].char_count, ascii, screen, map_canvas[i][j].color); } } drawStr(0, GAME_HEIGHT - 2, std::string("Use the arrow keys to move the cursor.").c_str(), ascii, screen, WHITE); drawStr(0, GAME_HEIGHT - 1, std::string("Press ENTER to spawn on the selected map tile.").c_str(), ascii, screen, WHITE); } else if (current_screen == GAME_SCREEN) { render_canvas(); render_target(); render_characters(); render_main_char(); render_animations(); clear_area(IntPoint(0, UI_START), IntPoint(UI_HEIGHT, UI_WIDTH)); render_interface(); render_message(); } else if(current_screen == DIRECTION_SCREEN) { drawStr(0, 0, std::string("Pick a direction to perform the action.").c_str(), ascii, screen, WHITE); } else if (current_screen == DEATH_SCREEN) { clear_screen(); drawStr(GAME_WIDTH/2 - 12, GAME_HEIGHT/2, std::string("You suck, uninstall bro.").c_str(), ascii, screen, WHITE); } else if (current_screen == DEBUG_CONSOLE) { render_canvas(); render_target(); render_characters(); render_main_char(); render_debug(); } if(game.is_paused()) { drawStr(GAME_WIDTH-20, 0, std::string("Paused").c_str(), ascii, screen, WHITE); } SDL_Flip(screen); }
void GUI::render_animations() { std::vector<Animation> anims = game.get_animations(); TilePointerMatrix tm = game.get_canvas(); for(int i=0;i<anims.size();i++) { Frame f = anims[i].get_frame(); IntPoint coords = IntPoint(anims[i].get_y(), anims[i].get_x()); IntPoint chunk = IntPoint(anims[i].get_chunk_y(), anims[i].get_chunk_x()); IntPoint vis = game.get_canvas_coords(chunk, coords); for(int j=0;j<f.get_actors().size();j++) { Actor a = f.actor(j); coords = vis + IntPoint(a.get_y(), a.get_x()); if(game.is_vis(coords) && tm[coords.row][coords.col]->visible) { drawChr(coords.col, coords.row, a.get_char(), ascii, screen, a.get_color()); } } } }
void drawStr(int x, int y, const char s[], SDL_Surface* source, SDL_Surface* destination, Uint32 color) { size_t i; for ( i = 0; i < strlen(s); i++) { drawChr( x+i, y, s[i], source, destination, color); } }
//WHEN DID THIS GET SO BIG?? REFACTOR THIS! void GUI::render_menu(Menu* menu) { //menus will always be rendered in the middle of the screen, fyi //clear the background in the specified height/width //width is automatically 20 int height = menu->options.size() + menu->padding; int width = utility::get_max_width(menu->options) + menu->padding; int start_row = (GAME_HEIGHT - height) / 2; int start_col = (GAME_WIDTH - width) / 2; int end_row = (GAME_HEIGHT + height) / 2; int end_col = (GAME_WIDTH + width) / 2; int extra_row = start_row - menu->padding; int extra_end_row = start_row + menu->num_extra_lines() + menu->padding; int extra_width = utility::get_max_width(menu->get_extra_lines()) + menu->padding; int extra_col = (GAME_WIDTH - extra_width)/2; int extra_end_col = (GAME_WIDTH + extra_width)/2; if(menu->num_extra_lines() != 0) { start_row = start_row + menu->num_extra_lines() + 2; end_row = start_row + menu->num_extra_lines() + 2; for(int row = extra_row; row <= extra_end_row; row++) { for(int col = extra_col; col <= extra_end_col; col++) { drawChr(col, row, menu->border.char_count, ascii, screen, BLACK); } } } //draw a box around the menu for(int row = start_row; row <= end_row; row++) { for(int col = start_col; col <= end_col; col++) { drawChr(col, row, menu->border.char_count, ascii, screen, BLACK); } } //draw a box around the extra lines int starting_col; starting_col = (GAME_WIDTH - menu->title.size()) / 2; //draw the title drawStr(starting_col, (GAME_HEIGHT/4), menu->title.c_str(), ascii, screen, RED); int color, string_size; //draw the extra lines for(int i = 0; i< menu->num_extra_lines(); i++) { string option = menu->get_extra_lines()[i]; if(option.size() % 2 != 0) { option = " " + option; } color = RED; drawStr(extra_col, extra_row + menu->padding + i, option.c_str(), ascii, screen, color); } //Render selections for(int i = 0; i < menu->options.size(); i++) { string option = menu->options[i]; if(option.size() % 2 != 0) { option = " " + option; } string_size = option.size(); starting_col = (GAME_WIDTH - string_size) / 2; if(menu->selection == i) { color = WHITE; } else { color = DARK_GRAY; } drawStr(starting_col, start_row + menu->padding + i, option.c_str(), ascii, screen, color); } }
void GUI::render_main_char() { drawChr(GAME_WIDTH/2, GAME_HEIGHT/2, game.main_char.get_char().char_count, ascii, screen, game.main_char.get_char().color); }