Example #1
0
/************************************************
Render the currently selected item list to screen
************************************************/
void screen_display(context_t * ctx)
{
	SDL_Event event;
	int i;

	for(i=0; i<SCREEN_LAST; i++) {
		virtual_x[i] = INT_MAX;
		virtual_y[i] = INT_MAX;
		virtual_z[i] = -1.0;
	}

	while( screen_end == -1) {

		frame_start(ctx);

		if(compose) {
			compose = 0;
			compose_scr(ctx);
		}

		display_fps();

		while (SDL_PollEvent(&event)) {
			compose |= sdl_screen_manager(ctx->window, ctx->render, &event);
			sdl_mouse_manager(ctx->render,&event,item_list);
			sdl_keyboard_manager(&event);
		}

		sdl_mouse_position_manager(ctx->render,item_list);

		SDL_RenderClear(ctx->render);

		sdl_blit_item_list(ctx->render,item_list);

		sdl_blit_to_screen(ctx->render);

		sdl_loop_manager();
	}

	return;
}
Example #2
0
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;
}