Ejemplo n.º 1
0
static int screen_init(lua_State *L) {
  Screen *screen;
  int w, h, bpp;
  screen = check_screen(L, 1);
  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    fprintf(stderr,
        "Couldn't initialize SDL: %s\n",
        SDL_GetError());
    /* TODO: Don't die, just return error */
    exit(1);
  }
  lua_getfield(L, 2, "y");
  h = lua_tointeger(L, -1);
  lua_getfield(L, 2, "x");
  w = lua_tointeger(L, -1);
  bpp = lua_tointeger(L, 3);
  screen->screen = SDL_SetVideoMode(
      w, h, bpp, SDL_RESIZABLE);
  SDL_WM_SetCaption("Marauder_rl", NULL);
  if (!screen) {
    fprintf(stderr, "SDL_SetVideoMode() error: %s\n",
        SDL_GetError());
    exit(1);
  }
  IMG_Init(IMG_INIT_PNG);
  init_colors(screen);
  init_characters(screen);
  screen->font = build_font(loadimg("img/font_8x12.png"), 8, 12);
  return 0;
}
Ejemplo n.º 2
0
pgsStringGen::pgsStringGen(USHORT w_size_min, USHORT w_size_max,
                           const UCHAR &nb_words, const long &seed, pgsVectorChar characters) :
	pgsObjectGen(seed), m_nb_words(nb_words), m_characters(characters)
{
	init_characters(); // Initialize vector if it is empty

	const USHORT w_size_aux = w_size_min;
	w_size_min = wxMin(w_size_aux, w_size_max);
	w_size_max = wxMax(w_size_aux, w_size_max);

	size_t char_count = m_characters.GetCount();
	m_w_size_randomizer = pgsRandomizer(pnew pgsIntegerGen(w_size_min,
	                                    w_size_max, false, seed));
	m_letter_randomizer = pgsRandomizer(pnew pgsIntegerGen(0,
	                                    wx_static_cast(long, char_count) - 1, false, seed));
}
Ejemplo n.º 3
0
// main
int main(int argc, char * argv[])
{
	// command line input
	if (argc != 3)
	{
		fprintf(stderr, "ERROR - wrong number of arguments\n");
		fprintf(stderr, "usage: %s in_file_path out_file_path\n", argv[0]);

		return 1;
	}

	sprintf(g_nframe_file_path, argv[1]);
	sprintf(g_bmp_file_path, argv[2]);

	// characters
	init_characters();

	// nframe
	if (init_frame())
	{
		fprintf(stderr, "ERROR - could not open %s\n", g_nframe_file_path);

		return 1;
	}

	// bmp
	g_px_w = g_nframe_col * CURSOR_W;
	g_px_h = g_nframe_row * CURSOR_H;

	// bitmap file header
	uint16_t BM = 0x4d42;
	uint32_t file_size = 54 + g_px_w * g_px_h * 3;
	uint16_t reserve1 = 8;
	uint16_t reserve2 = 8;
	uint32_t pixel_array_start = 54;

	// bitmap information header
	uint32_t bm_info_size = 40;
	int32_t pixel_wd = g_px_w;
	int32_t pixel_ht = g_px_h;
	uint16_t color_planes = 1;
	uint16_t bits_per_pixel = 24;
	uint32_t compression = 0;
	uint32_t image_size = g_px_w * g_px_h * 3;
	int32_t hor_res = g_px_w;
	int32_t ver_res = g_px_h;
	uint32_t palette_colors = 0;
	uint32_t important_colors = 0;

	// declare and open the bmp file
	FILE * bmp_file = fopen(g_bmp_file_path, "wb");

	// write out the bitmap file header
	fwrite(&BM, 2, 1, bmp_file);
	fwrite(&file_size, 4, 1, bmp_file);
	fwrite(&reserve1, 2, 1, bmp_file);
	fwrite(&reserve2, 2, 1, bmp_file);
	fwrite(&pixel_array_start, 4, 1, bmp_file);

	// write out the bitmap information header
	fwrite(&bm_info_size, 4, 1, bmp_file);
	fwrite(&pixel_wd, 4, 1, bmp_file);
	fwrite(&pixel_ht, 4, 1, bmp_file);
	fwrite(&color_planes, 2, 1, bmp_file);
	fwrite(&bits_per_pixel, 2, 1, bmp_file);
	fwrite(&compression, 4, 1, bmp_file);
	fwrite(&image_size, 4, 1, bmp_file);
	fwrite(&hor_res, 4, 1, bmp_file);
	fwrite(&ver_res, 4, 1, bmp_file);
	fwrite(&palette_colors, 4, 1, bmp_file);
	fwrite(&important_colors, 4, 1, bmp_file);

	// bmp pixel array
	char clr;
	char chr;

	uint8_t red;
	uint8_t green;
	uint8_t blue;

	int c;
	int r;
	int w;
	int h;
	for (r = 0; r < g_nframe_row; r++)
	{
		for (h = 0; h < CURSOR_H; h++)
		{
			for (c = 0; c < g_nframe_col; c++)
			{
				for (w = 0; w < CURSOR_W; w++)
				{
					int index = CH_BYTS * ((g_nframe_row - r - 1) * g_nframe_col + c);

					clr = g_frame[index];
					chr = g_frame[index + 1];

					if (g_character_array[chr - 32].pxl[(CURSOR_H - h - 1) * CURSOR_W + w])
					{
						switch (clr)
						{
							case 1:
								red = 0;
								green = 0;
								blue = 255;
								break;
							case 2:
								red = 0;
								green = 255;
								blue = 0;
								break;
							case 3:
								red = 0;
								green = 255;
								blue = 255;
								break;
							case 4:
								red = 255;
								green = 0;
								blue = 0;
								break;
							case 5:
								red = 255;
								green = 0;
								blue = 255;
								break;
							case 6:
								red = 255;
								green = 255;
								blue = 0;
								break;
							case 7:
								red = 255;
								green = 255;
								blue = 255;
								break;
							default:
								red = 0;
								green = 0;
								blue = 0;
								break;
						}

						fwrite(&blue, 1, 1, bmp_file);
						fwrite(&green, 1, 1, bmp_file);
						fwrite(&red, 1, 1, bmp_file);
					}
					else
					{
						red = 0;
						green = 0;
						blue = 0;

						fwrite(&blue, 1, 1, bmp_file);
						fwrite(&green, 1, 1, bmp_file);
						fwrite(&red, 1, 1, bmp_file);
					}
				}
			}
		}
	}

	// close the bmp file
	fclose(bmp_file);

	return 0;
}