示例#1
0
int main(int argc, char **argv) {
	DARNIT_KEYS keys;
	DARNIT_MOUSE mouse;
	//particle_emitter_new(30, 5000, 8000, 10000, 255, 0, 0, PARTICLE_TYPE_PULSE, 400, 240, 0, -100, 100);
	//particle_emitter_new(30, 5000, 8000, 10000, 255, 255, 0, PARTICLE_TYPE_PULSE, 400, 240, 0, -100, 100);
	
	init();
	gamestate(GAMESTATE_MENU);
	
	while(_gamestate!=GAMESTATE_QUIT) {
		keys=d_keys_get();
		mouse=d_mouse_get();
		
		if(handle[_gamestate])
			handle[_gamestate](&keys, &mouse);
		d_render_begin();
		if(render[_gamestate])
			render[_gamestate]();
		d_render_end();
		d_loop();
	}
	
	d_quit();
	return 0;
}
示例#2
0
int main(int argc, char **argv) {
	d_init("pong", "Pong!", NULL);

	if (!init()) {
		fprintf(stderr, "libDarnit didn't init\n");
		return -1;
	}

	d_render_clearcolor_set(0, 0, 192);

	for (;;) {
		player_loop();
		ball_loop();

		d_render_begin();

		d_render_tile_blit(p.player_ts, 0, p.player.x, p.player.y / 1000);
		d_render_end();
		d_loop();
	}

	d_quit();

	return 0;
}
示例#3
0
int main(int argc, char **argv) {
	DARNIT_SPRITE *sprite;

	if (argc <3) {
		fprintf(stdout, "Usage: %s <sprite> <direction>\n", argv[0]);
		return -1;
	}

	if (d_init("libDarnit spriteview", "spriteview", NULL) == NULL) {
		fprintf(stderr, "libDarnit failed to init\n");
		return -1;
	}

	if ((sprite = d_sprite_load(argv[1], atoi(argv[2]), DARNIT_PFORMAT_RGB5A1)) == NULL) {
		fprintf(stderr, "Unable to open sprite %s\n", argv[1]);
		d_quit();
		return -1;
	}

	d_sprite_move(sprite, 0, 0);
	d_sprite_animate_start(sprite);
	d_render_blend_enable();
	
	for (;;) {
		d_render_begin();
		d_sprite_draw(sprite);
		d_render_end();
		d_loop();
	}

	return 0;
}
示例#4
0
int main(int argc, char **argv) {
	DARNIT_TILESHEET *ts;
	DARNIT_TILEMAP *tm;
	int i, t;

	d_init("orthotest", "orthotest", NULL);
	ts = d_render_tilesheet_load("grid.png", 24, 24, DARNIT_PFORMAT_RGB5A1);
	tm = d_tilemap_new(0xFFF, ts, 0xFFF, 10, 18);
	for (i = 0; i < 180; i++)
		tm->data[i] = 1;
	d_tilemap_recalc(tm);
	d_tilemap_camera_move(tm, -1, 0);

	t = d_time_get();
	for (i = 0;; i++) {
		fprintf(stderr, "Moving camera %i\n", -i / 30);
		d_tilemap_camera_move(tm, 0, -i / 30);
		d_render_begin();
		d_tilemap_draw(tm);
		d_render_end();
		d_loop();
	}

	d_quit();
}
示例#5
0
int main(int argc, char **argv) {
	char fps[6];
	init();

	d_tilemap_camera_move(ppt.tm, -ppt.ui.offset_x, -ppt.ui.offset_y);
	*fps = 0;

	for (;;) {
		d_render_begin();

		state_loop();

		/* FIXME: Remove */
		sprintf(fps, "%i", d_fps());
		d_text_surface_reset(ppt.fps);
		d_text_surface_string_append(ppt.fps, fps);
		d_render_blend_enable();
		d_text_surface_draw(ppt.fps);
		d_render_blend_disable();

		d_render_end();
		d_loop();
	}

	return 0;
}
示例#6
0
int main(int argc, char **argv) {
	DARNIT_TILEMAP *tm;
	DARNIT_TILESHEET *ts;
	int i, j;

	d_init("isotest", "isotest", NULL);
	ts = d_render_tilesheet_isom_load("isosheet.png", 64, 64, DARNIT_PFORMAT_RGB5A1);
	tm = d_tilemap_isom_new(0, ts, 0xFF, 32, 16, 32);

	d_render_blend_enable();
	d_tilemap_recalc(tm);
	
	for (i = 0;; i++) {
		j = i % 1200;
		if (j > 600)
			j = j + (2*(j - 600)) * -1;
		j *= -1;
		j += 300;
		d_tilemap_camera_move(tm, 0, 0);
		d_render_begin();
		d_render_blend_enable();
		d_tilemap_draw(tm);
		d_render_end();
		d_loop();
	}

	d_quit();
}
示例#7
0
文件: Robot.c 项目: slaeshjag/kiruna
int main(int argc, char **argv) {

	d_init_custom("AutoKorg", WINDOW_WIDTH, WINDOW_HEIGHT, 0, "robot", NULL);
	//Calling an initiating function. Said function creates a window
	//with resolution 800x600, that's now full-screen and with the title AutoKorg.
	
	DARNIT_FONT *kgfont = d_font_load("KGRayofSunshine.ttf", 60, 256, 256);
	//We create a font handle.
	
	DARNIT_TEXT_SURFACE *papper = d_text_surface_new(kgfont, 100 , 800, 10, 0);
	//Here we create a handle to a text surface, using the font previously handled.
	
	/*pthread_t threads[1];
	hello = pthread_create(&threads[0], NULL, musikka, (void *) NULL);*/
	
	d_cursor_show(1); //Call a funciton which shows the cursor in the window.
	
	initiate_buttons();
	initiate_serial_port();
	
	for(;;) {
		
		//Program loop.
		
		d_render_begin(); 
		//Call to start rendering.
		
		d_render_blend_enable(); 
		//Enable blend, a call to a function apparently needed.
		
		if(state < DISCO){
			d_render_tint(255,255,255,255);
		} 
		else {
			d_render_tint(rand() & 0xF0, rand() & 0xF0, rand() & 0xF0, 255);
		}
		//Another call to a needed function. Don't question the libdarnit.
		
		//d_text_surface_string_append(papper, svar);
		
		do_stuff(papper); 
		//Call to a function which does stuff.
		
		draw_interface();
		//Draws us some graphics.
		
		d_render_end(); 
		//Call to a function which you do at the stop of rendering.
		
		d_loop(); 
		//Call to a function that is to be called inbetween frames.
		
		d_text_surface_reset(papper); 
		//Lastly we clear the textsurface.
	}
	return 0;

	//End of show.
}
示例#8
0
int main(int argc, char **argv) {
	DARNIT_IMAGE_DATA img;
	DARNIT_TILESHEET *ts;
	IMG_STRUCT **imgs, **tmp;
	DARNIT_KEYS keys;
	int images, image_disp, i;

	imgs = NULL;
	images = 0;
	image_disp = 0;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s <image to analyze>\n", argv[0]);
		return -1;
	}

	d_init("algdata", "algdata", NULL);
	if (!((img = d_img_load_raw(argv[1])).data)) {
		fprintf(stderr, "Unable to load %s\n", argv[1]);
		d_quit();
	}

	d_render_clearcolor_set(255, 255, 255);
	do {
		i = 0;
		ts = next_image(img, &i);
		if (ts) {
			if (!(tmp = realloc(imgs, sizeof(IMG_STRUCT **) * (images + 1))))
				d_quit();
			imgs = tmp;
			imgs[images] = new_image(ts, i);
			images++;
		}
	} while (ts);

	if (!imgs)
		d_quit();

	sort_image(imgs, images);

	for (;;) {
		keys = d_keys_get();
		if (keys.start) {
			image_disp = (image_disp + 1 >= images) ? 0 : image_disp + 1;
			d_keys_set(keys);
		}
			
		d_render_begin();

		d_render_tile_blit(imgs[image_disp]->ts, 0, 0, 0);

		d_render_end();
		d_loop();
	}

	return 0;
}
示例#9
0
文件: menu.c 项目: slaeshjag/svgestim
void gameover_handle(DARNIT_KEYS *keys, DARNIT_MOUSE *mouse) {
	if (highscore_is_new(score)) {
		d_render_begin();
		if (d_menu_loop(highscore.name) != -1) {
			if (*highscore.name_buff < 0x20)
				sprintf(highscore.name_buff, "arne.");
			highscore_add(score, highscore.name_buff);
			gamestate(GAMESTATE_HIGHSCORE);
		}
		d_render_end();
	}

	else if(keys->start)
		gamestate(GAMESTATE_MENU);
}
示例#10
0
文件: uppg8.c 项目: h4xxel/algdat
int main(int argc, char **argv) {
	int i, j;
	struct GRAPH *g, *tree=NULL;
	struct VERTEX *v;
	struct POINT p;
	DARNIT_KEYS keys;
	srand(time(NULL));
	d_init("Graphs", "uppg8", NULL);
	
	for(i=0; i<256; i++) {
		circle[i]=d_render_circle_new(32, 1);
		line[i]=d_render_line_new(1, 1);
	}
	
	for(j=0; j<4; j++)
		for(i=0; i<7; i++) {
			p.x=i*100+50;//(rand()%80)*10;
			p.y=j*100+50;//(rand()%48)*10;
			v=graph_add_vertex(&graph, p);
			for(g=graph; g; g=g->next)
				if(!(rand()%6))
					graph_add_edge(v, g->vertex, rand()%100, DIRECTION_DOUBLE);
		}
	tree=graph_prim(graph);
	draw_graph(graph);
	for(g=graph;;) {
		keys=d_keys_get();
		if(keys.start) {
			g=g==graph?tree:graph;
			draw_graph(g);
		}
		d_keys_set(keys);
		d_render_begin();
		d_render_tint(0xFF, 0xFF, 0xFF, 0xFF);
		for(i=0; i<vertices; i++)
			d_render_circle_draw(circle[i]);
		for(i=0; i<edges; i++) {
			d_render_tint(length[i], 0x7F, 0x0, 0xFF);
			d_render_line_draw(line[i], 1);
		}
		
		d_render_end();
		d_loop();
	}
	
	d_quit();
	return 0;
}
示例#11
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;
}
示例#12
0
文件: main.c 项目: h4xxel/birdie26
int main(int argc, char  **argv) {
	char font_path[512];
	char *tmp;
	bool fullscreen = false;
	
	if (argc >= 2 && !strcmp(argv[1], "-fs"))
		fullscreen = true;
		

	d_init_custom("Fascister i grönsakslandet ~ //achtung fulkod", DISPLAY_WIDTH, DISPLAY_HEIGHT, fullscreen, "birdie26", NULL);
	
	sprintf(font_path, "%s", d_fs_exec_path());
	chdir(tmp = dirname(font_path));
	sprintf(font_path, "%s/res/font.ttf", tmp);
	gfx.font.large = d_font_load(font_path, 36, 256, 256);
	gfx.font.small = d_font_load(font_path, 16, 256, 256);
	s = malloc(sizeof(*s));

	ui_init(4);
	menu_init();
	gameroom_init();
	lobby_init();
	character_room_init();
	game_over_init();
	
	gamestate_pane[GAME_STATE_MENU] = &menu.pane;
	gamestate_pane[GAME_STATE_SELECT_NAME] = &select_name.pane;
	gamestate_pane[GAME_STATE_CHARACTERS] = &character_room.pane;
	gamestate_pane[GAME_STATE_LOBBY] = &lobby.pane;
	gamestate_pane[GAME_STATE_ENTER_IP] = &enter_ip.pane;
	gamestate_pane[GAME_STATE_GAMEROOM] = &gameroom.pane;
	gamestate_pane[GAME_STATE_GAME_OVER] = &game_over.pane;
	
	
	signal(SIGINT, d_quit); //lol
	network_init(PORT);
	
	d_cursor_show(1);
	d_render_clearcolor_set(0x7F, 0x7F, 0x7F);
	
	if(argc > 1) {
		snprintf(player_name, NAME_LEN_MAX, "%s", argv[1]);
		game_state(GAME_STATE_MENU);
	} else
		game_state(GAME_STATE_SELECT_NAME);
	while(gamestate!=GAME_STATE_QUIT) {
		if(state_network_handler[gamestate])
			state_network_handler[gamestate]();
		
		d_render_begin();
		d_render_blend_enable();
		
		d_render_tint(20, 20, 20, 255);
		
		if(gamestate_pane[gamestate])
			ui_events(gamestate_pane[gamestate], 1);
	
		d_render_tint(255, 255, 255, 255);
		if(state_render[gamestate])
			state_render[gamestate]();
		
		if(state_network_handler[gamestate])
			state_network_handler[gamestate]();
	
		d_render_end();
		d_loop();
	}

	d_quit();
	return 0;
}