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; }
void loadimages(Page *p) { Cimage *ci; Iimage *i; Rune *src; addrefresh(p, "loading images..."); reverseimages(&p->doc->images); for(i=p->doc->images; i!=nil; i=i->nextimage){ if(p->aborting) break; src = urlcombine(getbase(p), i->imsrc); ci = findimg(src); if(ci == nil){ ci = loadimg(src, i->imwidth, i->imheight); qlock(&cimagelock); ci->next = cimages; cimages = ci; qunlock(&cimagelock); } free(src); incref(ci); i->aux = ci; p->cimage = erealloc(p->cimage, ++p->ncimage*sizeof(Cimage *)); p->cimage[p->ncimage-1] = ci; p->changed = TRUE; addrefresh(p, ""); } }
SDL_Texture *setpic(SDL_Renderer *r, char *filename) { SDL_Texture *tex; SDL_Surface *surf = loadimg(filename, 96, 112, 0); if (surf == NULL) return NULL; tex = SDL_CreateTextureFromSurface(r, surf); if (tex == NULL) { printf("SDL_Error: %s\n", SDL_GetError()); } SDL_FreeSurface(surf); return tex; }
int main(int argc, char *argv[]) { char **code; char *p; int codelines, maxline; if (argc != 2) die("Incorrect invocation"); p = strstr(argv[1], ".png"); if (p && p[4] == '\0') loadimg(argv[1], &code, &codelines, &maxline); else loadtext(argv[1], &code, &codelines, &maxline); run(code, codelines, maxline); free(code); return 0; }
struct EnemyEdit *NewEnemyEdit(struct EnemyEdit *ee, SDL_Renderer *r, char *name, char *imgfile) { IPaddress ip; /* 1 means auto-detect the boundaries of the sprite */ SDL_Surface *surf = loadimg(imgfile, 160, 192, 1); if (surf == NULL) { printf("Failed to load %s\n", imgfile); return NULL; } ee->w = surf->w; ee->h = surf->h; ee->tex = SDL_CreateTextureFromSurface(r, surf); if (ee->tex == NULL) { printf("Failed to create texture from %s\n", imgfile); return NULL; } SDL_FreeSurface(surf); /* connect to server */ if (SDLNet_ResolveHost(&ip, "localhost", PORT) == -1) { printf("SDLNet_ResolveHost: %s\n", SDLNet_GetError()); return NULL; } ee->socket = SDLNet_TCP_Open(&ip); if (ee->socket == NULL) { printf("SDLNet_TCP_Open: %s\n", SDLNet_GetError()); return NULL; } ee->active = 1; ee->hp = 0; ee->weakness = 0; ee->x = 0; ee->y = 0; ee->drag = 0; memset(ee->desc, 0, sizeof(ee->desc)); strcpy(ee->name, name); return ee; }
static void load_sprites (void){ char *peasant = "img/human/peasant.png"; char *swordsman = "img/human/swordsman.png"; char *foot_knight = "img/human/foot_knight.png"; char *poor_archer = "img/human/poor_archer.png"; char *scout = "img/human/scout.png"; char *goblin = "img/goblin/normal.png"; char *goblin_slinger = "img/goblin/slinger.png"; char *goblin_scout = "img/goblin/scout.png"; char *orc = "img/orc/normal.png"; char *armored_orc = "img/orc/armored.png"; char *crazy_orc = "img/orc/crazy.png"; char *troll = "img/troll/normal.png"; img_units[U_PEASANT ] = loadimg(peasant); img_units[U_SWORDSMAN ] = loadimg(swordsman); img_units[U_FOOT_KNIGHT ] = loadimg(foot_knight); img_units[U_POOR_ARCHER ] = loadimg(poor_archer); img_units[U_SCOUT ] = loadimg(scout); img_units[U_GOBLIN ] = loadimg(goblin); img_units[U_GOBLIN_SLINGER] = loadimg(goblin_slinger); img_units[U_GOBLIN_SCOUT ] = loadimg(goblin_scout); img_units[U_ORC ] = loadimg(orc); img_units[U_ARMORED_ORC ] = loadimg(armored_orc); img_units[U_CRAZY_ORC ] = loadimg(crazy_orc); img_units[U_TROLL ] = loadimg(troll); img_tiles[T_GRASS ] = loadimg("img/grass.png" ); img_tiles[T_FOREST ] = loadimg("img/tree.png" ); img_tiles[T_WATER ] = loadimg("img/water.png" ); img_tiles[T_HILLS ] = loadimg("img/hills.png" ); img_tiles[T_MOUNTAINS] = loadimg("img/mounteen.png" ); img_arrow = loadimg("img/arrow.png" ); img_selected_hex = loadimg("img/sel.png" ); img_reacheble = loadimg("img/reacheble.png" ); img_fog_of_war = loadimg("img/fog.png" ); img_rings[0] = loadimg("img/ring_red.png" ); img_rings[1] = loadimg("img/ring_blue.png" ); img_rings[2] = loadimg("img/ring_green.png"); }
static void init_characters(Screen *screen) { screen->characters[CHAR_ARROW_UP] = loadimg(DATA("img/arrows/up.png")); screen->characters[CHAR_ARROW_UP_RIGHT] = loadimg(DATA("img/arrows/up_right.png")); screen->characters[CHAR_ARROW_RIGHT] = loadimg(DATA("img/arrows/right.png")); screen->characters[CHAR_ARROW_DOWN_RIGHT] = loadimg(DATA("img/arrows/down_right.png")); screen->characters[CHAR_ARROW_DOWN] = loadimg(DATA("img/arrows/down.png")); screen->characters[CHAR_ARROW_DOWN_LEFT] = loadimg(DATA("img/arrows/down_left.png")); screen->characters[CHAR_ARROW_LEFT] = loadimg(DATA("img/arrows/left.png")); screen->characters[CHAR_ARROW_UP_LEFT] = loadimg(DATA("img/arrows/up_left.png")); screen->characters[CHAR_AT] = loadimg(DATA("img/chars/at.png")); screen->characters[CHAR_Q] = loadimg(DATA("img/chars/q.png")); screen->characters[CHAR_Z] = loadimg(DATA("img/chars/z.png")); screen->characters[CHAR_HASH] = loadimg(DATA("img/chars/hash.png")); screen->characters[CHAR_POINT] = loadimg(DATA("img/chars/point.png")); }