Пример #1
0
int highscore_init() {
	DARNIT_FILE *f;
	int i;
	char buff[64];

	highscore.enter_name = d_text_surface_new(font.vectroid, 600, 400, 150, 160);
	d_text_surface_string_append(highscore.enter_name, "New highscore! Enter your name");
	*highscore.name_buff = 0;
	highscore.name = d_menu_textinput_new(100, 200, font.vectroid, highscore.name_buff, 32, 400);

	for (i = 0; i < HIGHSCORE_CAP; i++) {
		highscore_table[i].score = 0;
		*highscore_table[i].name = 0;
	}
	d_text_surface_string_append(highscore.title = d_text_surface_new(font.univox, 64, 800, 16, 16), "highscores");
	highscore.text = d_text_surface_new(font.vectroid, 600, 800, 40, 150);
	if (!(f = d_file_open("highscore.txt", "rb"))) {
		fprintf(stderr, "Warning: Unable to open highscore table\n");
		return 0;
	}

	for (i = 0; i < HIGHSCORE_CAP && !d_file_eof(f); i++) {
		d_file_gets(buff, 64, f);
		sscanf(buff, "%i %s\n", &highscore_table[i].score, highscore_table[i].name);
	}

	return 1;
}
Пример #2
0
void lobby_init() {
	lobby.line = d_render_line_new(1, 2);
	d_render_line_move(lobby.line, 0, config.platform.screen_w - 320, 0, config.platform.screen_w - 320, config.platform.screen_h);
	
	lobby.list_players = d_text_surface_color_new(config.font_std, 2048, 300, 64, 0);
	lobby.list_games = d_text_surface_color_new(config.font_std, 2048, 300, config.platform.screen_w - 300, 0);
	
	lobby_join.list_players = d_text_surface_color_new(config.font_std, 2048, 300, 64, 0);
	lobby_host.start_game = d_text_surface_color_new(config.font_std, 32, 300, 64, config.platform.screen_h - 96);
	d_text_surface_color_next(lobby_host.start_game, 255, 0, 0);
	d_text_surface_string_append(lobby_host.start_game, "Press enter to start game");
	
	update_lists(NULL, lobby_client.client);
	
	lobby_playername.text_playername = d_text_surface_new(config.font_std, 64, 1024, 64, 64);
	lobby_playername.inputfield_playername = d_menu_textinput_new(64, 128, config.font_std, config.player_name, PROTO_PLAYER_NAME - 1, config.platform.screen_w);
	
	d_text_surface_string_append(lobby_playername.text_playername, "Enter your player name:");
	
	lobby.selected_game = 0;
	lobby.selected_player = 0;
}
Пример #3
0
void lobby_playername_wait() {
	//d_menu_selection_wait(lobby_playername.inputfield_playername);
	lobby_playername.inputfield_playername = d_menu_textinput_new(64, 128, config.font_std, config.player_name, PROTO_PLAYER_NAME - 1, config.platform.screen_w);
	lobby.selected_game = 0;
}
Пример #4
0
int main(int argc, char **argv) {
	int i, j, js0_x, js0_y, js1_x, js1_y;
	void *font, *surface, *text, *mapsheet, *sprite, *textinput, *mtsprite, *fps_text, *tilebuf, *fancy_text;
	void *music;
	char test[256], fps[16];
	char *test_text;
	DARNIT_MOUSE mouse;
	DARNIT_KEYS keys;
	DARNIT_MAP *map;
	DARNIT_SPRITE *mapsprite;

	if (!d_init("TESTAPP - libDarnit", "testapp", NULL))
		return -1;

	compression_test();

	/* Sound/music */
	music = d_sound_tracked_load("latyl-greasy_duck_v1.mod", DARNIT_AUDIO_STREAM, DARNIT_AUDIO_STEREO);
	d_sound_play(music, 0, 127, 127, 0);

	/* Text rendering */
	test_text = malloc(64);
	font = d_font_load("dejavu_sans.ttf", 28, 512, 512);
	text = d_text_surface_new(font, 80, 800, 0, 460);
	fancy_text = d_text_surface_color_new(font, 16, 800, 0, 420);
	colorTest(fancy_text);
	fps_text = d_text_surface_new(font, 16, 200, 0, 40);


	/* Menutk test */
	surface = d_menu_vertical_new("Hello\nGoodbye\nOther\nNothing\nLess than nothing", 50, 100, font, 200, 10, 3);
	sprintf(test_text, "Héllo, world. Modify m€! Test of offsets");
	textinput = d_menu_textinput_new(0, 0, font, test_text, 64, 200);

	/* Sprites */
	sprite = d_sprite_load("test.spr", 0, DARNIT_PFORMAT_RGB5A1);
	mapsprite = d_sprite_load("baurn.spr", 0, DARNIT_PFORMAT_RGB5A1);
	d_sprite_move(sprite, 50, 50);
	d_sprite_move(mapsprite, 0, 0);
	d_sprite_animate_start(sprite);
	d_sprite_animate_start(mapsprite);
	
	mtsprite = d_mtsprite_load("testspr.mts");
	d_mtsprite_animate_start(mtsprite);

	/* Maps */

	mapsheet = d_render_tilesheet_load("mapsheet.png", 32, 32, DARNIT_PFORMAT_RGBA8);
	if ((map = d_map_load("testmap_iso.ldmz")) == NULL)
		fprintf(stderr, "Map load failed\n");
	d_tilemap_sprite_add(map->layer[0].tilemap, mapsprite);

	/* Tile caches */
	tilebuf = d_render_tile_new(1, mapsheet);
	d_render_tile_move(tilebuf, 0, 64, 64);
	d_render_tile_tilesheet_coord_set(tilebuf, 0, 16, 16, 32, 32);

	/* Misc */
	fprintf(stderr, "String lenght: %i\n", d_font_string_w(font, "ASDFÅÄÖ,,"));


	for (i = j = 0;;) {
		d_sprite_move(mapsprite, 64, j * 4);
		keys = d_keys_get();
		d_text_surface_reset(text); d_text_surface_reset(fps_text);
		mouse = d_mouse_get();
		d_joystick_get(&js0_x, &js0_y, &js1_x, &js1_y);
		sprintf(test, "X: %i, Y: %i, W: %i;; TX: %i, TY: %i;; nub0 (%i,%i) ;; nub1(%i,%i)", mouse.x, mouse.y, mouse.wheel, i*4, j*4, js0_x, js0_y, js1_x, js1_y);
		sprintf(fps, "%i", d_last_frame_time());
		d_text_surface_string_append(text, test);
		d_text_surface_string_append(fps_text, "ASDFÅÄÖ,,");

		if (keys.lmb)
			d_render_fade_in(1000, 1.0f, 0.0f, 0.0f);
		if (keys.rmb)
			d_render_fade_out(1000);

		d_render_begin();

		if (keys.left == 1)
			i--;
		if (keys.right == 1)
			i++;
		if (keys.up == 1)
			j--;
		if (keys.down == 1)
			j++;
		if (keys.select)
			fprintf(stderr, "Blololol\n");

		if (keys.r == 1)
			d_tilemap_camera_move(map->layer->tilemap, i*4, j*4);
		d_render_blend_enable();
		d_tilemap_draw(map->layer->tilemap);
		if (keys.l == 1)
			if (d_menu_loop(surface) != -1)
				return 0;
		d_menu_loop(textinput); 
		d_sprite_draw(sprite);
		d_text_surface_draw(text);
		d_text_surface_draw(fancy_text);
		d_text_surface_draw(fps_text);

		d_render_offset(-200, -200);
		d_mtsprite_draw(mtsprite);
		d_render_offset(0, 0);

		d_render_blend_disable();
		d_render_tile_draw(tilebuf, 1);
		d_render_end();
		d_loop();
	}


	return 0;
}