Пример #1
0
void initiate_buttons(void){
	
	buttonlist = d_bbox_new(8);
	//We make space for a list containing 8 boxes.
	
	button_up = d_bbox_add(buttonlist, 0, 0, 1000, 180);
	//Then we add a box (button) to the button list.
	//The placement is: X = 50, Y = 100 relative to the program window.
	//The size is X = 400, Y = 150, reaching out from the placement point.
	
	button_left = d_bbox_add(buttonlist, 0, 0, 240, 400);
	button_right = d_bbox_add(buttonlist, 560, 0, 260, 400);
	button_down = d_bbox_add(buttonlist, 150, 400, 500, 200);
	button_menu = d_bbox_add(buttonlist, MENU_X, MENU_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
	button_color = d_bbox_add(buttonlist, COLOR_X, COLOR_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
	//And here we add not three, not four, but five more buttons! Didn't see that coming, did you?
	
	ui1 = d_render_tilesheet_load("UI thing.gif", 28, 10, 1);
	ui2 = d_render_tilesheet_load("UI thing 2.gif", 12, 29, 1);
	//Here we also load up our graphic sprites. These are just some lines.

	graphic_button_menu  = d_render_tilesheet_load("button_menu.gif", BUTTON_WIDTH, BUTTON_HEIGHT, 1);
	graphic_button_back  = d_render_tilesheet_load("button_back.gif", BUTTON_WIDTH, BUTTON_HEIGHT, 1);
	graphic_button_color = d_render_tilesheet_load("button_color.gif", BUTTON_WIDTH, BUTTON_HEIGHT, 1);
	//Loads button graphics.
	
	imgdat.w = IMAGE_WIDTH;
	imgdat.h = IMAGE_HEIGHT;
	imgdat.data = malloc(sizeof(int) * imgdat.w * imgdat.h);
	ts = d_render_tilesheet_new(1, 1, imgdat.w, imgdat.h, DARNIT_PFORMAT_RGBA8);
	d_render_tilesheet_scale_algorithm(ts, DARNIT_SCALE_LINEAR);
	//Initiate some image graphics. 
}
Пример #2
0
int init() {

	if (!(p.player_ts = d_render_tilesheet_load("bat.png", 16, 64, DARNIT_PFORMAT_RGB5A1)))
		return 0;
	if (!(p.ball_ts = d_render_tilesheet_load("ball.png", 32, 32, DARNIT_PFORMAT_RGB5A1)))
		return 0;

	player_init();

	return 1;
}
Пример #3
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();
}
Пример #4
0
void meterSetup() {
	s->var.meter.ts = d_render_tilesheet_load("assets/meters.png", METER_WIDTH, METER_HEIGHT, DARNIT_PFORMAT_RGB5A1);
	s->var.meter.player_health = meterInit(s->var.meter.ts, 0, 0);
	s->var.meter.player_weapon = meterInit(s->var.meter.ts, METER_WIDTH, 0);
	s->var.meter.boss_health = meterInit(s->var.meter.ts, s->var.screen_w - METER_WIDTH, 0);

	return;
}
Пример #5
0
void view_init() {
	sidebar_width=platform_lowres?3*SIDEBAR_WIDTH_MAX/4:SIDEBAR_WIDTH_MAX;
	font_std=d_font_load("res/FreeMonoBold.ttf", platform_lowres?8:12, 512, 512);
	mouse_tilesheet=d_render_tilesheet_load("res/mouse.png", 16, 16, DARNIT_PFORMAT_RGB5A1);
	mouse_target_tilesheet=d_render_tilesheet_load("res/target.png", 32, 32, DARNIT_PFORMAT_RGB5A1);
	
	//Menu background
	int scale=config.plasma==0?1:(1<<(5-config.plasma));
	view_background_w=platform.screen_w/scale;
	view_background_h=platform.screen_h/scale;
	view_background_ts=d_render_tilesheet_new(1, 1, view_background_w, view_background_h, DARNIT_PFORMAT_RGB5A1);
	view_background_tile=d_render_tile_new(1, view_background_ts);
	view_background_pixbuf=malloc(view_background_w*view_background_h*sizeof(unsigned int));
	d_render_tilesheet_scale_algorithm(view_background_ts, DARNIT_SCALE_LINEAR);
	d_render_tile_move(view_background_tile, 0, 0, 0);
	d_render_tile_tilesheet_coord_set(view_background_tile, 0, 0, 0, view_background_w, view_background_h);
	d_render_tile_size_set(view_background_tile, 0, platform.screen_w, platform.screen_h);
	view_background_update(0);
	
	menu_init();
	lobby_init();
	game_view_init();
	gameover_init();
	chat_init();
	
	gamestate_pane[GAME_STATE_MENU]=&panelist_menu_sidebar;
	gamestate_pane[GAME_STATE_CREDITS]=&panelist_credits;
	gamestate_pane[GAME_STATE_CONNECTING]=&panelist_multiplayer_connecting;
	gamestate_pane[GAME_STATE_LOBBY]=&panelist_lobby_players;
	gamestate_pane[GAME_STATE_GAME]=&panelist_game_sidebar;
	gamestate_pane[GAME_STATE_GAME_MENU]=&panelist_game_menu;
	gamestate_pane[GAME_STATE_GAME_OVER]=&panelist_gameover_sidebar;
	gamestate_pane[GAME_STATE_QUIT]=NULL;
	
	map=NULL;
}
Пример #6
0
void stageSelectInit() {
	int x_u, y_u, i, j;

	x_u = (s->var.screen_w / 2) - 224;
	y_u = (s->var.screen_h / 2) - 224;

	s->var.stage.stage_gfx = d_render_tilesheet_load("assets/stage_select.png", 128, 128, DARNIT_PFORMAT_RGB5A1);
	s->var.stage.stage = d_render_tile_new(10, s->var.stage.stage_gfx);
	s->var.stage.selected_stage = 0;
	d_render_tile_init(s->var.stage.stage, 9, 9, x_u, y_u);

	for (i = 0; i < 3; i++)
		for (j = 0; j < 3; j++)
			d_render_tile_init(s->var.stage.stage, i * 3 + j, i * 3 + j, x_u + 160 * j, y_u + i * 160);
	stageSelectMoveCursor();
	return;
}
Пример #7
0
static void init() {
	int i;
	DARNIT_INPUT_MAP map;

	d_init("pewpewtris", "pewpewtris", NULL);
	d_fs_mount_self();
	d_fs_mount("music.ldi");
	d_fs_mount("sounds.ldi");
	config_init();
	
	ppt.ui.offset_x = 288;
	ppt.ui.offset_y = 0;

	for (i = 0; i < 180; ppt.tile_lookup[i++] = -1);

	ppt.block = d_render_tilesheet_load("res/block.png", 24, 24, DARNIT_PFORMAT_RGB5A1);
	ppt.tile = d_render_tile_new(10 * 18, ppt.block);
	ppt.bbox = d_bbox_new(180);
	d_bbox_set_indexkey(ppt.bbox);
	ppt.tm = d_tilemap_new(0xFFF, ppt.block, 0xFFF, 10, 18);
	ppt.request_new = 0;
	ppt.font = d_font_load("res/font.ttf", 28, 256, 256);
	ui_init();
	bullet_init(30);
	highscore_init();
	state_init();
	music_init();
	
	ppt.ui.play_background = d_map_load("res/playfield_background.ldmz");
	ppt.ui.menu_background = d_map_load("res/mainmenu_background.ldmz");
	ppt.ui.highscore_background = d_map_load("res/highscore_background.ldmz");

	/* Re-map B to space */
	if (!(d_platform_get().platform & DARNIT_PLATFORM_PANDORA)) {
		map = d_keymapping_get();
		map.b = TPW_KEY_SPACE;
		d_keymapping_set(map);
	}

	block_particle_init();

	/* FIXME: Remove */
	ppt.fps = d_text_surface_new(ppt.font, 6, 1000, 0, 0);
}
Пример #8
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;
}
Пример #9
0
void game_view_init() {
	building_place=-1;
	ability_place=0;
	attacker_target=0;
	
	building[0].name="";
	building[1].name=T("Generator");
	building[2].name=T("Scout");
	building[3].name=T("Attacker");
	building[4].name=T("Pylon");
	building[5].name=T("Wall");
	building[6].name=T("Buildsite");
	building[7].name=T("Missile silo");
	building[8].name=T("Radar");
	
	game_attacklist_blink_semaphore=0;
	/*Game sidebar*/
	panelist_game_sidebar.pane=ui_pane_create(platform.screen_w-sidebar_width, 0, sidebar_width, platform.screen_h, NULL);
	ui_pane_set_root_widget(panelist_game_sidebar.pane, ui_widget_create_vbox());
	panelist_game_sidebar.next=&panelist_game_abilitybar;
	if(!platform_lowres)
		ui_vbox_add_child(panelist_game_sidebar.pane->root_widget, ui_widget_create_label(font_std, T("Muon")), 0);
	game_sidebar_minimap=ui_widget_create_imageview_raw(sidebar_width-8, sidebar_width-8, DARNIT_PFORMAT_RGB5A1);
	game_sidebar_minimap->render=map_minimap_render;
	game_sidebar_minimap->event_handler->add(game_sidebar_minimap, game_sidebar_minimap_mouse_down, UI_EVENT_TYPE_MOUSE_DOWN);
	if(!(platform.platform&DARNIT_PLATFORM_PANDORA))
		ui_vbox_add_child(panelist_game_sidebar.pane->root_widget, game_sidebar_minimap, 0);
	if(!platform_lowres)
		ui_vbox_add_child(panelist_game_sidebar.pane->root_widget, ui_widget_create_label(font_std, T("Buildings:")), 0);
	
	int i;
	for(i=0; i<4; i++)
		game_sidebar_label_build[i]=ui_widget_create_label(font_std, building[i+BUILDING_SCOUT].name);
	game_sidebar_label_build[4]=ui_widget_create_label(font_std, T("Battle support"));
	
	for(i=0; i<5; i++) {
		game_sidebar_button_build[i]=ui_widget_create_button(game_sidebar_label_build[i]);
		ui_vbox_add_child(panelist_game_sidebar.pane->root_widget, game_sidebar_button_build[i], 0);
		game_sidebar_button_build[i]->event_handler->add(game_sidebar_button_build[i], game_sidebar_button_build_click, UI_EVENT_TYPE_UI_WIDGET_ACTIVATE);
	}
	game_sidebar_progress_build=ui_widget_create_progressbar(font_std);
	
	game_sidebar_status.spacer=ui_widget_create_spacer();
	game_sidebar_status.label_name=ui_widget_create_label(font_std, "name");
	game_sidebar_status.progress_shield=ui_widget_create_progressbar(font_std);
	game_sidebar_status.progress_health=ui_widget_create_progressbar(font_std);
	game_sidebar_status.label_shield=ui_widget_create_label(font_std, T("Shields"));
	game_sidebar_status.label_health=ui_widget_create_label(font_std, T("Health"));
	
	ui_vbox_add_child(panelist_game_sidebar.pane->root_widget, game_sidebar_status.spacer, 1);
	
	if(platform.platform&DARNIT_PLATFORM_PANDORA)
		ui_vbox_add_child(panelist_game_sidebar.pane->root_widget, game_sidebar_minimap, 0);
	
	/*Special buildings for control points*/
	if(platform_lowres)
		panelist_game_specialbar.pane=ui_pane_create(config.screen_w-sidebar_width*2, platform.screen_h-72, sidebar_width, 72, ui_widget_create_vbox());
	else
		panelist_game_specialbar.pane=ui_pane_create(config.screen_w-sidebar_width*2, game_sidebar_button_build[4]->y-64, sidebar_width, 128, ui_widget_create_vbox());
	panelist_game_specialbar.next=&panelist_game_abilitybar;
	
	for(i=0; i<3; i++) {
		game_specialbar_label_build[i]=ui_widget_create_label(font_std, building[i+BUILDING_BUILDSITE].name);
		game_specialbar_button_build[i]=ui_widget_create_button(game_specialbar_label_build[i]);
		ui_vbox_add_child(panelist_game_specialbar.pane->root_widget, game_specialbar_button_build[i], 0);
		game_specialbar_button_build[i]->event_handler->add(game_specialbar_button_build[i], game_sidebar_button_build_click, UI_EVENT_TYPE_UI_WIDGET_ACTIVATE);
	}
	
	/*Special abilities*/
	UI_WIDGET *iconwidget;
	int iconsize=32;//platform_lowres?16:32;
	if(platform_lowres)
		panelist_game_abilitybar.pane=ui_pane_create(2, 2, 44, 128+16, ui_widget_create_vbox());
	else
		panelist_game_abilitybar.pane=ui_pane_create(2, 64, 52, 128+44, ui_widget_create_vbox());
	panelist_game_abilitybar.next=NULL;
	ability[0].name=T("Flare");
	ability[0].icon=d_render_tilesheet_load("res/flare.png", 32, 32, DARNIT_PFORMAT_RGB5A1);
	ability[0].action=NULL;
	iconwidget=ui_widget_create_imageview_file("res/flare.png", iconsize, iconsize, DARNIT_PFORMAT_RGB5A1);
	iconwidget->render=game_abilitybar_icon_render;
	ability[0].button=ui_widget_create_button(iconwidget);
	ability[0].button->event_handler->add(ability[0].button, game_abilitybar_button_click, UI_EVENT_TYPE_UI_WIDGET_ACTIVATE);
	ability[0].ready=100;
	ability[1].name=T("Nuke");
	ability[1].icon=d_render_tilesheet_load("res/nuke.png", 32, 32, DARNIT_PFORMAT_RGB5A1);
	ability[1].action=NULL;
	iconwidget=ui_widget_create_imageview_file("res/nuke.png", iconsize, iconsize, DARNIT_PFORMAT_RGB5A1);
	iconwidget->render=game_abilitybar_icon_render;
	ability[1].button=ui_widget_create_button(iconwidget);
	ability[1].button->enabled=0;
	ability[1].button->event_handler->add(ability[1].button, game_abilitybar_button_click, UI_EVENT_TYPE_UI_WIDGET_ACTIVATE);
	ability[1].ready=-1;
	ability[2].name=T("Radar");
	ability[2].icon=d_render_tilesheet_load("res/radar.png", 32, 32, DARNIT_PFORMAT_RGB5A1);
	ability[2].action=NULL;
	iconwidget=ui_widget_create_imageview_file("res/radar.png", iconsize, iconsize, DARNIT_PFORMAT_RGB5A1);
	iconwidget->render=game_abilitybar_icon_render;
	ability[2].button=ui_widget_create_button(iconwidget);
	ability[2].button->enabled=0;
	ability[2].button->event_handler->add(ability[2].button, game_abilitybar_button_click, UI_EVENT_TYPE_UI_WIDGET_ACTIVATE);
	ability[2].ready=-1;
	for(i=0; i<3; i++) {
		ui_vbox_add_child(panelist_game_abilitybar.pane->root_widget, ability[i].button, 0);
		ability[i].text=d_text_surface_new(font_std, 4, 64, ability[i].button->x, ability[i].button->y+24);
	}
	
	ui_event_global_add(game_view_mouse_release, UI_EVENT_TYPE_MOUSE_RELEASE);
}