コード例 #1
0
void battle_prediction_pane::draw_contents()
{
	// We must align both damage lines.
	int damage_line_skip = std::max<int>(attacker_left_strings_.size(), defender_left_strings_.size()) - 2;

	draw_unit(0, damage_line_skip,
			  attacker_left_strings_width_, attacker_left_strings_, attacker_right_strings_,
			  attacker_label_, attacker_label_width_, attacker_hp_distrib_, attacker_hp_distrib_width_);

	draw_unit(units_width_ + inter_units_gap_, damage_line_skip,
			  defender_left_strings_width_, defender_left_strings_, defender_right_strings_,
			  defender_label_, defender_label_width_, defender_hp_distrib_, defender_hp_distrib_width_);
}
コード例 #2
0
ファイル: mutant3d.c プロジェクト: ozkriff/mutant3d
void draw_units(void)
{
  Node *node;
  FOR_EACH_NODE(units, node) {
    Unit *u = node->data;
    if (unit_mode == UM_MOVING && u == selected_unit) {
      continue;
    }
    draw_unit(u);
  }
コード例 #3
0
ファイル: ui_sdl.c プロジェクト: ozkriff/fantasy-wargame
static void
draw_units (void){
  Node *node;
  FOR_EACH_NODE(units, node){
    Unit *u = node->d;
    if(ui_mode == MODE_SHOW_EVENT){
      if(current_event->t == E_MOVE
      && current_event->e.move.u == u->id)
        continue;
      if(current_event->t == E_MELEE
      && current_event->e.melee.a == u->id)
        continue;
    }
    if(u->is_visible){
      draw_unit(u);
    }
  }
コード例 #4
0
ファイル: mapunit.cpp プロジェクト: kentdev/Trichromic
void draw_units(int scrollx, int scrolly)
{
  int i = 0;
  while (i < 200)
  {
    if (mapunit[i].exist == 1)
    {
      if ((mapunit[i].x >= scrollx) && (mapunit[i].x < scrollx + XTILES))
      {
        if ((mapunit[i].y >= scrolly) && (mapunit[i].y < scrolly + YTILES))
        {
					
          draw_unit(i, (mapunit[i].x - scrollx) * MAP_TILE_SIZE, (mapunit[i].y - scrolly) * MAP_TILE_SIZE);
        }
      }
    }
    i++;
  }
}
コード例 #5
0
ファイル: scr_play.c プロジェクト: Bob-Z/Open-Master-of-Magic
void screen_play(SDL_Renderer * render,game_t * game)
{
	char gold_buf[128];
	char mana_buf[128];
	SDL_Event event;
	int tile_num;
	int unit_num;
	int city_num;
	int encounter_num;
	int i;
	int j;
	int x;
	LBXAnimation_t * anim_ptr;
	city_t * city;

	local_render = render;

	end_screen = -1;

	selected_group = NULL;

	city = (city_t*)game->wiz[0].city->data;
	cur_tile_x = city->x;
	cur_tile_y = city->y;

	load_font();

	/* Load resource */
	if(anim==NULL) {
		anim = load_graphics(render,"MAIN.LBX");
		if(anim == NULL) {
			exit(EXIT_FAILURE);
		}
	}

	/* Load tiles */
	if(tile==NULL) {
		tile = load_graphics(render,"TERRAIN.LBX");
		if(tile == NULL) {
			exit(EXIT_FAILURE);
		}
	}

	/* Load unit */
	if(unit1==NULL) {
		unit1 = load_graphics(render,"UNITS1.LBX");
		if(unit1 == NULL) {
			exit(EXIT_FAILURE);
		}
	}

	if(unit2==NULL) {
		unit2 = load_graphics(render,"UNITS2.LBX");
		if(unit2 == NULL) {
			exit(EXIT_FAILURE);
		}
	}

	/* Concat unit1 and unit2 */
	if(unit==NULL) {
		j=0;
		anim_ptr = unit1;
		for(i=0; i<2; i++) {
			while(anim_ptr->num_frame!=0) {
				unit = (LBXAnimation_t*)realloc(unit,(j+1)*sizeof(LBXAnimation_t));
				memcpy(&unit[j],anim_ptr,sizeof(LBXAnimation_t));
				anim_ptr++;
				j++;
			}
			anim_ptr= unit2;
		}
	}

	/* Load back */
	if(back==NULL) {
		back = load_graphics(render,"MAPBACK.LBX");
		if(back == NULL) {
			exit(EXIT_FAILURE);
		}
	}

	j=0;
	item_init(&item_ui[j]);
	item_set_frame(&item_ui[j],0,0,&anim[j]);
	j++;
	x=7;
	item_init(&item_ui[j]);
	item_set_frame(&item_ui[j],x,4,&anim[j]);
	item_set_frame_click(&item_ui[j],1);
	j++;
	x+=item_ui[j-1].anim->w + 1;
	item_init(&item_ui[j]);
	item_set_frame(&item_ui[j],x,4,&anim[j]);
	item_set_frame_click(&item_ui[j],1);
	j++;
	x+=item_ui[j-1].anim->w + 1;
	item_init(&item_ui[j]);
	item_set_frame(&item_ui[j],x,4,&anim[j]);
	item_set_frame_click(&item_ui[j],1);
	j++;
	x+=item_ui[j-1].anim->w + 1;
	item_init(&item_ui[j]);
	item_set_frame(&item_ui[j],x,4,&anim[j]);
	item_set_frame_click(&item_ui[j],1);
	j++;
	x+=item_ui[j-1].anim->w + 1;
	item_init(&item_ui[j]);
	item_set_frame(&item_ui[j],x,4,&anim[j]);
	item_set_frame_click(&item_ui[j],1);
	j++;
	x+=item_ui[j-1].anim->w + 1;
	item_init(&item_ui[j]);
	item_set_frame(&item_ui[j],x,4,&anim[j]);
	item_set_frame_click(&item_ui[j],1);
	j++;
	x+=item_ui[j-1].anim->w + 1;
	item_init(&item_ui[j]);
	item_set_frame(&item_ui[j],x,4,&anim[j]);
	item_set_frame_click(&item_ui[j],1);
	item_set_click_left(&item_ui[j],cb_plane,NULL);
	j++;

	/* Main loop */
	while( end_screen == -1) {
		tile_num = draw_tile(game);
		city_num = draw_city(game);
		encounter_num = draw_encounter(game);
		unit_num = draw_unit(game);

		/* Print gold */
		item_init(&item_ui[8]);
		item_set_font(&item_ui[8],font);
		sprintf(gold_buf,"%d GP",game->wiz[0].gold);
		item_set_string(&item_ui[8],gold_buf);
		item_set_frame(&item_ui[8],264,71,NULL);

		/* Print mana */
		item_init(&item_ui[9]);
		item_set_font(&item_ui[9],font);
		sprintf(mana_buf,"%d MP",game->wiz[0].mana);
		item_set_string(&item_ui[9],mana_buf);
		item_set_frame(&item_ui[9],300,71,NULL);

		while (SDL_PollEvent(&event)) {
			if(event.type==SDL_KEYDOWN && event.key.keysym.sym==SDLK_ESCAPE) {
				return;
			}

			/* Move selected_unit */
			if(event.type==SDL_KEYDOWN ) {
				move_unit(game,event.key.keysym.sym);
			}

			sdl_screen_manager(&event);
			sdl_mouse_manager(&event,item_ui,ITM_UI_NUM);
			sdl_mouse_manager(&event,item_city,city_num);
			sdl_mouse_manager(&event,item_encounter,encounter_num);
			sdl_mouse_manager(&event,item_tile,tile_num);
			sdl_mouse_manager(&event,item_unit,unit_num);
			sdl_keyboard_manager(&event);
		}

		SDL_RenderClear(render);

		sdl_blit_item_list(item_tile,tile_num);
		sdl_blit_item_list(item_city,city_num);
		sdl_blit_item_list(item_encounter,encounter_num);
		sdl_blit_item_list(item_back,unit_num);
		sdl_blit_item_list(item_unit,unit_num);
		sdl_blit_item_list(item_ui,ITM_UI_NUM);

		sdl_blit_to_screen();

		sdl_loop_manager();
	}

	return;
}
コード例 #6
0
ファイル: Building.cpp プロジェクト: tim099/AOCTDF
void Building::draw(){
	draw_unit();
	draw_hp();
	draw_building();
}
コード例 #7
0
ファイル: poligon.c プロジェクト: semahawk/poligon
int main(int argc, char *argv[])
{
  /* the program's name, d'oh */
  progname = argv[0];
  /* the whole file's name */
  char *fname;
  /* here the file's extension will be stored */
  char fext[FEXT_MAX_SIZE + 1] = { 0 };
  /* the unit's description (it's color, etc) */
  struct unit_desc desc = {{ 0 }};
  /* the user's unit */
  struct unit *unit = nmalloc(sizeof(struct unit));

  /* make sure there is at least one argument supplied */
  if (argc < 2){
    fprintf(stderr, "usage: %s <file>\n", progname);
    return 1;
  }

  fname = argv[1];

  /* fetch the extension, and store it in `fext' */
  {
    /* {{{ */
    int i = strlen(fname) - 1; /* minus one to not start at the '\0' */
    /* search for the first dot, starting from the end of the string */
    int j = 0; /* puts the characters into the `fext' array */

    /* set `i' to the last dot's position */
    for (; fname[i] != '.' && i >= 0; i--)
      ;

    if (fname[i] == '.'){
      /* we found a dot, let's see if it would fit into `fext' */
      /* `i + 1' because `i' points at the dot, not at the very first character
       * after it */
      if (strlen(fname) - (i + 1) > FEXT_MAX_SIZE){
        fprintf(stderr, "%s: file extension too long (max. %u chars)\n", progname, FEXT_MAX_SIZE);
        return 1;
      }

      /* see if there is anything after the dot (like, if it's not something
       * like `filename.') */
      if (fname[i + 1] == '\0'){
        fprintf(stderr, "%s: file extension empty\n", progname);
        return 1;
      }
    } else {
      /* we haven't seen any dots, that's a bummer */
      fprintf(stderr, "%s: file extension not found\n", progname);
      return 1;
    }

    /* here, everything should be all set and ready to roll */
    for (i++ /* skip over the dot */; j < FEXT_MAX_SIZE; j++, i++)
      fext[j] = fname[i];
    /* }}} */
  }

  /* call the function that will handle the file, based on it's extension */
  {
    /* {{{ */
    struct file_handlers *p = file_handlers;
    int found = 0;

    for (; p->fext != NULL && p->handler != NULL; p++){
      if (!strcmp(p->fext, fext)){
        found = 1;
        break;
      }
    }

    if (found){
      /* we know the extension, and can handle it */
      if (p->handler(unit, &desc, fname) == NULL){
        return 1;
      }
    } else {
      /* oops! */
      fprintf(stderr, "%s: file extension `%s' not supported\n", progname, fext);
      return 1;
    }
    /* }}} */
  }

  /* TODO: safety checks for the `desc' values */
  unit->desc = desc;
  /* set the defaults */
  unit->hp = UNIT_MAX_HP / 2;
  /* give the unit an id */
  unit->id = calcid(unit);
  /* push the unit onto the `unit_list' */
  push_unit(unit);
  /* call the `fetch' function to give the user his unit's id */
  unit->fun.fetch(unit->id);

  /* initialize the SDL */
  SDL_Init(SDL_INIT_EVERYTHING);
  /* set the title */
  SDL_WM_SetCaption("Poligon", NULL);
  /* create the window */
  SDL_Surface *screen = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 0, SDL_HWSURFACE | SDL_DOUBLEBUF);

  SDL_Event event;
  int running = 1;

  /* put the unit in the middle of the screen */
  unit->x = screen->w / 2;
  unit->y = screen->h / 2;

  while (running){
    /* fill the background */
    SDL_FillRect(screen, NULL, 0x111111);

    if (SDL_PollEvent(&event)){
      switch (event.type){
        case SDL_QUIT:
          running = 0;
          break;
      }
    }

    draw_unit(screen, unit);
    unit->hp += sge_Random(-3, 3);
    /*unit->rot--;*/

    /* update the screen */
    SDL_UpdateRect(screen, 0, 0, 0, 0);
  }

  /* clean up after SDL */
  SDL_Quit();
  /* clean up after ourselves */
  free_unit_list();

  return 0;
}