Example #1
0
bool graphics_init(gfx_t* gfx)
{
    memset(gfx, 0, sizeof *gfx);

    if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
        return false;
    }

    if (!window_init(&gfx->window, "Spielbub", SCREEN_WIDTH, SCREEN_HEIGHT)) {
        return false;
    }

    gfx->background = create_surface();
    gfx->sprites_bg = create_surface();
    gfx->sprites_fg = create_surface();

    if (!gfx->background || !gfx->sprites_bg || ! gfx->sprites_fg) {
        goto error;
    }

    gfx->layers[0] = gfx->background;
    gfx->layers[1] = gfx->sprites_bg;
    gfx->layers[2] = gfx->sprites_fg;
    gfx->state = OAM;

    window_clear(&gfx->window);
    window_draw(&gfx->window);

    return true;

    error: {
        graphics_destroy(gfx);
        return false;
    }
}
Example #2
0
void window_handle(WnckWindow *window, gboolean want_tiled)
{
	if (!WNCK_IS_WINDOW (window)) {
		fprintf(stderr, "[bonnye] Trying to rehandle something that is not a window\n");
		return;
	}
	int spaceid = workspace_get_from_window(window);
	gboolean is_tiled = workspace_has_tiled_window(spaceid, window);
	if (want_tiled) {
		if (is_tiled) {
			fprintf(stderr, "[bonnye] Trying to tile a tiled window. Doing nothing\n");
			return;
		}
		workspace_add_window(spaceid, window);
		window_init(spaceid, window);
	} else {
		if (!is_tiled) {
			fprintf(stderr, "[bonnye] Trying to untile an untiled window. Doing nothing\n");
			return;
		}
		workspace_remove_window(spaceid, window);
		window_clear(window);
	}
	tile(spaceid);
}
Example #3
0
void window_gets(Window_t *win, char *buff, int n)
{
	int my = 0, mx = 0;
	int y, x;
	
	wgetnstr(win->win_in, buff, n);
	wrefresh(win->win_in);

	getmaxyx(win->win_in, my, mx);
	getyx(win->win_in, y, x);
	//if (y > my-2)
		window_clear(win->win_in);
	
	wrefresh(win->win_in);	
}
Example #4
0
void window_puts(Window_t *win, const char *str, int pair)
{
	int my = 0, mx = 0;
	int x, y;

	getmaxyx(win->win_out, my, mx);
	getyx(win->win_out, y, x);
	if (y > my-2)
		window_clear(win->win_out);

	wattron(win->win_out, COLOR_PAIR(pair));
	waddstr(win->win_out, str);
	wrefresh(win->win_out);
	wattroff(win->win_out, COLOR_PAIR(pair));
}
Example #5
0
static void cmd_clear(void)
{
	GUI_WINDOW_REC *gui;

	gui = WINDOW_GUI(active_win);

	if (is_window_visible(active_win))
		window_clear(gui);

	gui->ypos = -1;
	gui->bottom_startline = gui->startline = g_list_last(gui->lines);
	gui->bottom_subline = gui->subline = gui->last_subline+1;
	gui->empty_linecount = gui->parent->last_line-gui->parent->first_line+1;
	gui->bottom = TRUE;
}
Example #6
0
void window_show_list(Window_t *win, const char *list[], int len)
{
	int i;

	window_clear(win->win_list);

	wattron(win->win_list, COLOR_PAIR(PAIR_RED));
	wprintw(win->win_list, "User Online: %d\n\n", len);

	wattron(win->win_list, COLOR_PAIR(PAIR_BLUE));
	for (i = 0; i < len; i++)
		wprintw(win->win_list, "%2d. %s\n", i+1, list[i]);
	wattroff(win->win_list, COLOR_PAIR(PAIR_BLUE));

	wrefresh(win->win_list);

}
Example #7
0
/* SYNTAX: CLEAR */
static void cmd_clear(const char *data)
{
	GHashTable *optlist;
	void *free_arg;

	g_return_if_fail(data != NULL);

	if (!cmd_get_params(data, &free_arg, PARAM_FLAG_OPTIONS,
			    "clear", &optlist)) return;

	if (g_hash_table_lookup(optlist, "all") != NULL)
		g_slist_foreach(windows, (GFunc) window_clear, NULL);
	else
                window_clear(active_win);

	cmd_params_free(free_arg);
}
Example #8
0
// i would like to apologise for this crappy crappy code.. but at least it checks for buffer overflows
void list_print(u8 **list, TPOS *pos, AGISIZE *size, int status, int up, int down)
{
	int i;
	
	u8 str[500];
	
	window_clear(pos->row, pos->col, pos->row+size->h-1, 
			pos->col+size->w-1, 0xFF);
	
	for (i=0; i<size->h; i++)
	{
		goto_row_col(pos->row+i, pos->col);
		
		if ((strlen(list[i]) > 550) || (size->w >= 500))
			agi_printf(" - *TOO LONG*");
		else
		{
			sprintf(str, " - %s", list[i]);
			str[size->w] = 0;
			agi_printf("%s", str);
		}
	}
	
	if (status)
	{
		goto_row_col(pos->row, pos->col+size->w+1);
		if (up)
			agi_printf("U");
		else
			agi_printf(" ");
		
		goto_row_col(pos->row+size->h-1, pos->col+size->w+1);
		if (down)
			agi_printf("D");
		else
			agi_printf(" ");
	}
}
Example #9
0
void
test(void) {
    Window* window = window_new("omikuji", 400, 300);
    Ticket* ticket = ticket_new_file("../res/omikuji.txt");

    while (window_is_open(window)) {
        WindowEvent event = window_poll_events(window);
        switch (event.type) {
            case WE_CLOSE: goto end; break;
            case WE_KEYBOARD:
                if (event.value == WE_KEY_A) {
                }
                break;
        }
        window_clear(window);
        window_render_ticket(window, ticket);
        window_display(window);
    }

end:
    ticket_delete(ticket);
    window_delete(window);    
}
Example #10
0
// draw a big window from column 0 to column 39
void window_portion_clear(u16 upper_row, u16 lower_row, u16 attrib)
{
	window_clear(upper_row, 0x00, lower_row, 39, attrib);
}
Example #11
0
int main(int argc, char** argv) {
	init_core();
	debug_message("[hunter] initialized core");

	init_graphic();
	debug_message("[hunter] initialized graphics, mode W%d H%d", window_get_width(global_get(global_get_singleton(), GLOBAL_WINDOW)), window_get_height(global_get(global_get_singleton(), GLOBAL_WINDOW)));

	init_sound();
	debug_message("[hunter] initialized sound");

	init_systems();
	debug_message("[hunter] initialized systems");

	window* window_handle = global_get(global_get_singleton(), GLOBAL_WINDOW);
	input* input_handle = global_get(global_get_singleton(), GLOBAL_INPUT);
	syscontainer* syscontainer_handle = global_get(global_get_singleton(), GLOBAL_SYSCONTAINER);
	text* text_handle = global_get(global_get_singleton(), GLOBAL_TEXT);
	hl_render* hl_render_handle = global_get(global_get_singleton(), GLOBAL_HL_RENDER);
	shader* shader_texture_handle = global_get(global_get_singleton(), GLOBAL_SHADER_TEXTURE);
	camera* camera_handle = global_get(global_get_singleton(), GLOBAL_CAMERA);
	debug_draw* debug_draw_handle = global_get(global_get_singleton(), GLOBAL_DEBUG_DRAW);

	float delta_ref_point = time_get_elapsed(window_handle);
	float delta_accumulator = 0.0f;
	float delta_frame_time = 0.0f;

	float fps_accumulator = 0.0f;
	float fps_value = 0.0f;
	float fps_value_last = fps_value;
	unsigned int fps_counter = 0;

	unsigned int game_kill_flag = 0;

	debug_message("[hunter] posting init event to systems");
	syscontainer_post_event(syscontainer_handle, EVENT_INIT);

	while (!game_kill_flag) {
		delta_frame_time = time_get_elapsed(window_handle) - delta_ref_point;
		delta_ref_point = time_get_elapsed(window_handle);

		window_update(window_handle);

		input_state current_input_state;
		input_get_input_state(input_handle, &current_input_state);

		game_kill_flag |= window_get_should_close(window_handle);
		game_kill_flag |= current_input_state.key_dev;

		window_set_clear_color(window_handle, 1.0f, 0.0f, 1.0f, 0.0f);
		debug_draw_clear(debug_draw_handle);
		window_clear(window_handle);

		delta_accumulator += delta_frame_time;

		if (delta_accumulator < 0.0f) {
			delta_accumulator = 0.0f;
		}

		while (delta_accumulator >= 1.0f / DELTA_REFERENCE_FPS) {
			syscontainer_post_event(syscontainer_handle, EVENT_PRE_LOGIC);
			syscontainer_post_event(syscontainer_handle, EVENT_LOGIC);
			syscontainer_post_event(syscontainer_handle, EVENT_POST_LOGIC);

			delta_accumulator -= 1.0f / DELTA_REFERENCE_FPS;
		}

		syscontainer_post_event(syscontainer_handle, EVENT_DRAW);

		window_set_blend_mode(window_handle, WINDOW_BLEND_ALPHA);

		debug_draw_render_all(debug_draw_handle);

		hl_render_draw(hl_render_handle, shader_texture_handle, camera_handle);
		hl_render_clear(hl_render_handle);

		fps_counter++;
		fps_accumulator += delta_frame_time;

		if (fps_accumulator >= 1.0f) {
			fps_value_last = fps_value;
			fps_value = (float) fps_counter / fps_accumulator;
			fps_counter = 0;
			fps_accumulator = 0.0f;
		}

		text_batch fps_batch = {20, 20, 0.2f, 0.8f, 1.0f, 1.0f, "", "monospace", 12};
		sprintf(fps_batch.text_data, "FPS : %3.2f (%3.2f)", fps_value, fps_value - fps_value_last);

		text_submit_batch(text_handle, &fps_batch);

		text_render_all(text_handle);
		text_flush_batch(text_handle);

		window_swap_buffers(window_handle);
	}

	debug_message("[hunter] posting destroy event to systems");
	syscontainer_post_event(syscontainer_handle, EVENT_DESTROY);

	free_systems();
	free_sound();
	free_graphic();
	free_core();

	h_free_all();

	debug_message("[hunter] terminated cleanly");
	return 0;
}
Example #12
0
void game_display(struct game* game) {
	assert(game);

	int map_w, map_h;

	window_clear();

	if(game->nb_player == 1) {
		map_w = map_get_width(level_get_curr_map(game->curr_level));
		map_h = map_get_height(level_get_curr_map(game->curr_level));
		for(int i = 0; i < map_w; i++)
			for(int j = 0; j < map_h+2; j++)
				window_display_image(sprite_get_empty(), i * SIZE_BLOC, j * SIZE_BLOC);
	}

	level_display(game_get_curr_level(game));

	monster_display(level_get_curr_map(game->curr_level));

	bomb_display(game, level_get_curr_map(game->curr_level));

	game_banner_display(game);

	if(game->nb_player == 1) { // Single player
		struct player* player = game->players[0];

		// Always display
		player_display(player);

		if(game->game_state == PLAYING) {
			player_move(game, player, level_get_curr_map(game->curr_level));
			monster_move(game, level_get_curr_map(game->curr_level), player);

			player_update(player);
			monster_update(level_get_curr_map(game->curr_level));
		}
	}
	else { // Multi player
		struct player* players_in_order[game->nb_player];
		for(int i=0; i<game->nb_player; i++)
			players_in_order[i] = game->players[i];
		game_order_players_array(game, players_in_order);

		for(int i = 0; i < game->nb_player; i++) {

			player_display(players_in_order[i]);

			if(game->game_state == PLAYING) {
				player_move(game, players_in_order[i], level_get_curr_map(game->curr_level));

				player_update(players_in_order[i]);
			}
		} // end for each player


	} // end Multi player

	if(game->game_state == PLAYING) {

		bomb_update(level_get_curr_map(game->curr_level));

	}
	else if(game->game_state == PAUSED) {
		map_w = map_get_width(level_get_curr_map(game->curr_level));
		map_h = map_get_height(level_get_curr_map(game->curr_level));
		int mid_w = map_w / 2 * SIZE_BLOC + map_w%2 * SIZE_BLOC / 2;
		int mid_h = map_h / 2 * SIZE_BLOC + map_h%2 * SIZE_BLOC / 2;
		menu_display(mid_w, mid_h);

	}
	window_refresh();
}
Example #13
0
void multi_display(struct game* game) {
	assert(game);
	struct map* map = NULL;
	int w, h;
	int* scores;

	switch(game_get_state(game)) {
	case PLAYING:
	case PAUSED:
		game_display(game);
		if(player_get_nb_player_alive(game) == 1)
			multi_change_state(game, SCORE);

		break;
	case CHOOSE_MAP:

		map = level_get_curr_map(game_get_curr_level(game));

		w = 10 + 15 + sprite_get_max_width() + 50 + SIZE_BLOC * map_get_width(map);
		h = max(30 * (sprite_get_nb_map_multi() + 1), SIZE_BLOC * map_get_height(map));

		window_resize( w, h);
		window_clear();

		for(int i = 0; i < sprite_get_nb_map_multi(); i++) {
			window_display_image(	sprite_get_map_multi(i),
									10 + 15,
									15 + 30 * i);
		}

		window_display_image(sprite_get_menu(M_S_SELECT_BLACK), 10, 15 + 30 * game_get_pos(game));

		map_display(	map,
						10 + 15 + sprite_get_max_width() + 50,
						(h-(SIZE_BLOC * map_get_height(map))) / 2);
		window_refresh();

		break;
	case SCORE:

		window_clear();
		level_display(game_get_curr_level(game));
		bomb_display(game, level_get_curr_map(game_get_curr_level(game)));
		for(int i = 0; i < game_get_nb_player(game); i++)
			player_display(game_get_player(game, i+1));

		int map_w = map_get_width(level_get_curr_map(game_get_curr_level(game)));
		int map_h = map_get_height(level_get_curr_map(game_get_curr_level(game)));
		int mid_w = map_w / 2 * SIZE_BLOC + map_w%2 * SIZE_BLOC / 2;
		int mid_h = map_h / 2 * SIZE_BLOC + map_h%2 * SIZE_BLOC / 2;

		window_display_image(	sprite_get_menu(M_BG_GREY),
								mid_w - 240,
								mid_h - 262);

		window_display_image(	sprite_get_score(player_get_id_player_alive(game)),
								mid_w - 200,
								mid_h - 222);

		scores = game_get_scores(game);
		for(int i = 0; i < game_get_nb_player(game); i++) {
			window_display_sprite(	sprite_get_players(i+1),
									sprite_get_rect_player_anim(0, i+1, SOUTH),
									mid_w - 200,
									mid_h - 222 + 80 + 80 * i);

			window_display_image(	sprite_get_number_white(scores[i]),
									mid_w - 140,
									mid_h - 222 + 100 + 80 * i);
		}

		window_refresh();

		break;
	}
}