void Worldmap::draw(int posx, int posy) { int origx = posx, origy = posy; int xdim, ydim; get_screen_dims(xdim, ydim); Window w_worldmap(0, 0, xdim, ydim); int winx = w_worldmap.sizex(), winy = w_worldmap.sizey(); bool done = false; while (!done) { for (int x = 0; x < winx; x++) { for (int y = 0; y < winy; y++) { int terx = posx + x - (winx / 2), tery = posy + y - (winy / 2); glyph sym = get_glyph(terx, tery); if ((terx == posx && tery == posy) || (terx == origx && tery == origy) ) { sym = sym.invert(); } else if (terx >= 0 && tery >= 0 && terx < WORLDMAP_SIZE && tery < WORLDMAP_SIZE && !tiles[terx][tery].monsters.empty()) { sym = sym.hilite(c_red); } w_worldmap.putglyph(x, y, sym); } } w_worldmap.refresh(); long ch = input(); switch (ch) { case 'j': case '2': case KEY_DOWN: posy++; break; case 'k': case '8': case KEY_UP: posy--; break; case 'h': case '4': case KEY_LEFT: posx--; break; case 'l': case '6': case KEY_RIGHT: posx++; break; case 'y': case '7': posx--; posy--; break; case 'u': case '9': posx++; posy--; break; case 'b': case '1': posx--; posy++; break; case 'n': case '3': posx++; posy++; break; case 'q': case 'Q': done = true; break; } } }
int create_im (char * name, char * string, int * res, int * sub, rgb backg, rgb foreg) { gdImagePtr im; FILE * background; int act[2]; int back; int fore; char * buf; int y = 0; size_t i; act[0] = res[0] / 2 - (sub[0] * gdFontGetLarge ()->w) / 2; act[1] = res[1] / 2 - (sub[1] * gdFontGetLarge ()->h) / 2; buf = (char *) malloc (((int) get_screen_dims ()[1] / gdFontGetLarge ()->w) * sizeof (char)); im = gdImageCreate (res[0], res[1]); back = gdImageColorAllocate (im, backg.r, backg.g, backg.b); fore = gdImageColorAllocate (im, foreg.r, foreg.g, foreg.b); for (i = 0; i < strlen (string); i++) { if (string[i] != '\n') buf[y++] = string[i]; else { buf[y] = '\0'; y = 0; gdImageString (im, gdFontGetLarge (), act[0], act[1], (unsigned char *) buf, fore); act[1] += gdFontGetLarge ()->h; } } buf[y] = '\0'; gdImageString (im, gdFontGetLarge (), act[0], act[1], (unsigned char *) buf, fore); background = fopen (name, "wb"); gdImageJpeg (im, background, -1); fclose (background); gdImageDestroy (im); return 1; }
bool Game::setup() { if (!i_hud.load_from_file("cuss/i_hud.cuss")) { debugmsg("Can't load cuss/i_hud.cuss!"); return false; } int xdim, ydim; get_screen_dims(xdim, ydim); int win_size = ydim; if (win_size % 2 == 0) { win_size--; // Only odd numbers allowed! } w_map = new Window(0, 0, win_size, win_size); w_hud = new Window(win_size, 0, 55, ydim); // Attempt to resize the messages box to be as tall as the window allows cuss::element* messages = i_hud.select("text_messages"); if (!messages) { debugmsg("Couldn't find element text_messages in i_hud"); return false; } messages->sizey = ydim - messages->posy; worldmap = new Worldmap; worldmap->generate(); map = new Map; Point start = worldmap->random_tile_with_terrain("beach"); map->generate(worldmap, start.x, start.y, 0); player = new Player; entities.add_entity(player); game_over = false; new_messages = 0; return true; }