Esempio n. 1
0
File: map.c Progetto: cosmo-ray/yirl
static char getPrintableChar(Entity *mapCases, Entity *res)
{
  size_t ret = ywMapGetIdByElem(yeGet(mapCases, yeLen(mapCases) - 1));

  res = yeGet(yeGet(res, ret), "map-char");
  return res != NULL ? yeGetString(res)[0] : '-';
}
Esempio n. 2
0
File: sdl.c Progetto: IGLOU-EU/yirl
static SDL_Texture *sdlLoasAndCachImg(Entity *elem)
{
  const char *path;
  SDL_Texture *texture = yeGetData(yeGet(elem, "$sdl-img"));
  Entity *data;

  if (texture)
    return texture;
  SDL_Surface *image;

  path = yeGetString(yeGet(elem, "map-srite"));
  if (!path) {
    return NULL;
  }

  image = IMG_Load(path);
  if (!image) {
    return NULL;
  }

  texture = SDL_CreateTextureFromSurface(sg.renderer, image);
  data = yeCreateData(texture, elem, "$sdl-img");
  yeSetDestroy(data, sdlFreeTexture);
  SDL_FreeSurface(image);
  return texture;
}
Esempio n. 3
0
// I have no index...
static void create_tild_multi_layers(Entity *mod_description, int tild,
				     Entity **map, Entity *desc, int pos,
				     int width)
{
  Entity *sp = yeGetByStrFast(desc, "start_pos");
  int start_pos = yeGetInt(yeGetByIdx(sp, 0)) +
    yeGetInt(yeGetByIdx(sp, 0)) * (width ? width : 8000);

  if (start_pos == pos) {
    yePushBack(yeCreateArrayAt(map[1], NULL, pos),
	       yeGetByStrFast(desc, "start_id"), NULL);
  }

  Y_BLOCK_ARRAY_FOREACH_PTR(YE_TO_ARRAY(mod_description)->values, tmp,
			    it, ArrayEntry) {
    const char *char_str;

    if (!tmp)
      continue;

    char_str = yeGetString(yeGetByStr(tmp->entity, "map-char"));
    if (char_str[0] == tild) {
      if (yeStringIndexChar(yeGetByStrFast(desc, "ground_char"), char_str) >= 0) {
	yeCreateInt(it, yeCreateArrayAt(map[0], NULL, pos), NULL);
      } else {
	yeCreateInt(it, yeCreateArrayAt(map[2], NULL, pos), NULL);
      }
      return;
    }
  }
  yeCreateInt(tild, yeCreateArrayAt(map[0], NULL, pos), NULL);
}
Esempio n. 4
0
void *load_map(int nb, void **args)
{
  const char *file_name = yeGetString(args[0]);
  int fd = open(file_name, O_RDONLY);
  int width = 0;
  Entity *mod_description = nb > 1 ? args[1] : NULL;
  char *name = nb > 3 ? args[3] : NULL;
  Entity *father = nb > 2 ? args[2] : yeCreateArray(NULL, name);
  Entity *map = yeCreateArray(father, "map");

  if (fd < 0) {
    DPRINT_ERR("error when opening '%s'\n", file_name);
    goto error;
  }

  if (!read_map(fd, map, mod_description, file_name, &width, NULL, NULL)) {
    yeReCreateInt(width, father, "width");
    return father;
  }

 error:
  if (nb > 2)
    YE_DESTROY(father);
  YE_DESTROY(map);
  return NULL;
}
Esempio n. 5
0
File: game.c Progetto: IGLOU-EU/yirl
static int ygParseStartAndGame(GameConfig *config, Entity *mainMod)
{
  Entity *type = yeGet(mainMod, "type");
  Entity *file = yeGet(mainMod, "file");
  Entity *starting_widget = yeGet(mainMod, "starting widget");
  Entity *preLoad = yeGet(mainMod, "pre-load");
  Entity *initScripts = yeGet(mainMod, "init-scripts");
  YWidgetState *wid;

  alive = 1;

  YE_ARRAY_FOREACH(preLoad, var) {
    Entity *tmpType = yeGet(var, "type");
    Entity *tmpFile = yeGet(var, "file");

    if (yuiStrEqual0(yeGetString(tmpType), "lua")) {
      if (ysLoadFile(luaManager, yeGetString(tmpFile)) < 0) {
	DPRINT_ERR("Error when loading '%s': %s\n",
		   yeGetString(tmpFile), ysGetError(luaManager));
      }
    }
  }
Esempio n. 6
0
File: map.c Progetto: IGLOU-EU/yirl
static int mapInit(YWidgetState *opac, Entity *entity, void *args)
{
  const char *action;
  Entity *initer = yeGet(entity, "init");

  ywidGenericInit(opac, t);

  ((YMapState *)opac)->resources = yeGet(entity, "resources");
  ((YMapState *)opac)->pos = ywMapCreatePos(0, 0, NULL, NULL);

  ((YMapState *)opac)->actionIdx = ywidAddSignal(opac, "action");
  action = yeGetString(yeGet(entity, "action"));
  ywidBind(opac, "action", action);
  if (initer) {
    YCallback *callback = ywinGetCallbackByStr(yeGetString(initer));

    if (callback)
      ywidCallCallback(callback, opac, NULL, entity);
  }
  (void)args;
  return 0;
}
Esempio n. 7
0
static void create_tild(Entity *mod_description, int tild, Entity *map)
{
  if (mod_description) {
    Y_BLOCK_ARRAY_FOREACH_PTR(YE_TO_ARRAY(mod_description)->values, tmp,
			      it, ArrayEntry) {
      const char *char_str;

      if (!tmp)
	continue;

      char_str = yeGetString(yeGetByStr(tmp->entity, "map-char"));
      if (char_str[0] == tild) {
	yeCreateInt(it, yeCreateArray(map, NULL), NULL);
	return;
      }
    }
  }
  yeCreateInt(tild, yeCreateArray(map, NULL), NULL);
}
Esempio n. 8
0
File: sdl.c Progetto: IGLOU-EU/yirl
int sdlDisplaySprites(SDLWid *wid, int x, int y, Entity *elem,
		      int w, int h, int thresholdX)
{
  SDL_Color color = {0,0,0,255};
  SDL_Rect DestR;
  SDL_Texture *texture = sdlLoasAndCachImg(elem);


  if (texture) {
    DestR.x = x * w + wid->rect.x + thresholdX;
    DestR.y = y * h + wid->rect.y;
    DestR.w = w;
    DestR.h = h;
    SDL_RenderCopy(sg.renderer, texture, NULL, &DestR);
  } else {
    return sdlPrintText(wid, yeGetString(yeGet(elem, "map-char")),
			2, color, x * w, y * h);
  }
  return 0;
}
Esempio n. 9
0
void *load_entity(int nb, void **args)
{
  Entity *desc = args[0];

  if (nb != 1) {
    DPRINT_ERR("numbers of arguments incorect\n");
    return NULL;
  }

  const char *file_name = yeGetString(yeGetByStrFast(desc, "map"));
  int fd = open(file_name, O_RDONLY);
  int width = 0, len = 0;
  Entity *resources = ywMapGetResourcesFromEntity(desc);
  char *name = nb > 2 ? args[2] : NULL;
  Entity *father = nb > 1 ? args[1] : NULL;
  int ret = 0;
  Entity *entries;

  if (fd < 1) {
    DPRINT_ERR("error when opening '%s'\n", file_name);
    goto error;
  }

  yeReCreateString("container", desc, "<type>");
  yeCreateString("stacking", desc, "cnt-type");
  entries = yeCreateArray(desc, "entries");

  yeCreateArray(entries, NULL);
  yeCreateArray(entries, NULL);
  yeCreateArray(entries, NULL);

  if (read_map(fd, entries, resources, file_name, &width, &len, desc))
    goto error;

  YE_ARRAY_FOREACH(entries, map) {
    yeCreateString("map", map, "<type>");
    yeCreateInt(width, map, "width");
    yeCreateInt(len, map, "len");
    yePushBack(map, resources, "resources");
  }
Esempio n. 10
0
File: game.c Progetto: IGLOU-EU/yirl
 YE_ARRAY_FOREACH(initScripts, var2) {
   ysCall(luaManager, yeGetString(var2), 1, mainMod);
 }