コード例 #1
0
ファイル: menu.c プロジェクト: ricardocerq/FEUP-LCOM
int get_player_name_render()
{
	memcpy(get_program_secondary_buf(),get_background()->color,get_vram_size());
	printgr_shade_centered(get_program_secondary_buf(),"Please enter your name",get_v_res()/2-200, 0.75,0xFFFF,5,5, .1, 8);
	printgr_shade_centered(get_program_secondary_buf(),get_program_playername(),get_v_res()/2, 0.75,0xFFFF,5,5, .1,7);
	if(*get_date_str_ptr() != NULL)
		printgr_shade_centered(get_program_secondary_buf(),*get_date_str_ptr(),0, 0.75,0xFFFF,5,5, .1, 1);
	if(darken > 0)
		darken_buf(get_program_secondary_buf(),darken);
	if(darken > 0 && !fade_condition)
	{

		darken-= FADE_RATE;
	}
	if(fade_condition)
	{
		if(darken <= 127)
		{

			darken += FADE_RATE;
		}
		else
		{
			continue_condition = false;
		}
	}
	copy_video_buffer(get_program_video_mem(), get_program_secondary_buf());
	return 0;
}
コード例 #2
0
ファイル: Bitmap.c プロジェクト: pedrofraga/LCOM-FEUP
unsigned char *double_buffering(){

	char* my_double_buffer = (unsigned char *) malloc(get_h_res()*get_v_res()*2);
	char* bufferStartPos = vg_adress();
	memcpy(my_double_buffer, bufferStartPos,get_h_res()*get_v_res()*2);
	return my_double_buffer;

}
コード例 #3
0
ファイル: menu.c プロジェクト: ricardocerq/FEUP-LCOM
void initialize_main_menu_buttons()
{
	main_menu_buttons[0] = initialize_button_t(to_coord_t(get_h_res()/2, get_v_res() / 2 - 50), "Single Player", sp_game, MAIN_MENU_BUTTON_SIZE, 0.9);
	main_menu_buttons[1] = initialize_button_t(to_coord_t(get_h_res()/2, get_v_res() / 2 +50), "Multiplayer", mp_lobby, MAIN_MENU_BUTTON_SIZE,0.9);
	main_menu_buttons[2] = initialize_button_t(to_coord_t(get_h_res()/2, get_v_res() / 2 + 150), "Quit", exit_game, MAIN_MENU_BUTTON_SIZE, 0.9);
	main_menu_buttons[3] = initialize_button_t(to_coord_t(10,get_v_res()-get_line_space(2)),get_program_playername(), get_player_name, 2, 0.9);
	main_menu_buttons[3]->pos.x = 10;
}
コード例 #4
0
ファイル: events.c プロジェクト: bernardobelchior1/feup-lcom
void mouse_event_handler(unsigned char packet[3]) {
	//Middle mouse button pressed/released

	if (!(packet[0] & MOUSE_MB_PRESSED) && mouse_info.mmb_pressed) {
		mouse_info.mmb_pressed = 0;
		mmb_released();
	} else if ((packet[0] & MOUSE_MB_PRESSED) && !mouse_info.mmb_pressed) {
		mouse_info.mmb_pressed = 1;
		mmb_pressed();
	}

	//Right mouse button pressed/released

	if (!(packet[0] & MOUSE_RB_PRESSED) && mouse_info.rmb_pressed) {
		mouse_info.rmb_pressed = 0;
		rmb_released();
	} else if ((packet[0] & MOUSE_RB_PRESSED) && !mouse_info.rmb_pressed) {
		mouse_info.rmb_pressed = 1;
		rmb_pressed();
	}

	//Left mouse button pressed/released

	if (!(packet[0] & MOUSE_LB_PRESSED) && mouse_info.lmb_pressed) {
		mouse_info.lmb_pressed = 0;
		lmb_released();
	} else if ((packet[0] & MOUSE_LB_PRESSED) && !mouse_info.lmb_pressed) {
		mouse_info.lmb_pressed = 1;
		lmb_pressed();
	}

	//Update mouse x position

	if (packet[0] & MOUSE_X_SIGNED) {
		short xdelta = 0xFF00 | packet[1];
		mouse_info.x += xdelta;
		if (mouse_info.x < 0)
			mouse_info.x = 0;
	} else {
		mouse_info.x += packet[1];
		if (mouse_info.x > get_h_res())
			mouse_info.x = get_h_res();
	}

	//Update mouse y position

	if (packet[0] & MOUSE_Y_SIGNED) {
		short ydelta = 0xFF00 | packet[2];
		mouse_info.y -= ydelta;
		if (mouse_info.y > get_v_res())
			mouse_info.y = get_v_res();
	} else {
		mouse_info.y -= packet[2];
		if (mouse_info.y < 0)
			mouse_info.y = 0;
	}
}
コード例 #5
0
ファイル: Bitmap.c プロジェクト: pedrofraga/LCOM-FEUP
int erase_square(Bitmap* bmp, int x, int y, Alignment alignment,unsigned char**double_buffer,unsigned char*background) {
    if (bmp == NULL)
        return 1;
    int width = bmp->bitmapInfoHeader.width;
    int drawWidth = width;
    int height = bmp->bitmapInfoHeader.height;
    if (alignment == ALIGN_CENTER)
        x -= width / 2;
    else if (alignment == ALIGN_RIGHT)
        x -= width;

    if (x + width < 0 || x > get_h_res() || y + height < 0
            || y > get_v_res())
        return 2;

    int xCorrection = 0;
    if (x < 0) {
    	xCorrection = -x;
    	drawWidth -= xCorrection;
    	x = 0;

    	if (drawWidth > get_h_res())
    		drawWidth = get_h_res();
    } else if (x + drawWidth >= get_h_res()) {
    	drawWidth = get_h_res() - x;
    }

    char* bufferStartPos;
    char* imgStartPos;
    int i;
    int a;
    for (i = 0; i < height; i++) {
    	int pos = y + height - 1 - i;
    	if (pos < 0 || pos >= get_v_res())
    		continue;

    	for(a = 0; a < width;a++){
    		bufferStartPos = *double_buffer;
    		bufferStartPos += x * 2 + pos * get_h_res() * 2 + (a*2);
    		imgStartPos = background + x * 2 + pos * get_h_res() * 2 + (a*2);
    		if(*imgStartPos == (int) -32)
    			if(*(imgStartPos+1) == (int) 7)
    				continue;
    			else
    				memcpy(bufferStartPos, imgStartPos,2);
    		else
    			memcpy(bufferStartPos, imgStartPos,2);


    	}
    }

    return 0;
}
コード例 #6
0
ファイル: sprite.c プロジェクト: oindividuo/LCOM
int draw_sprite(Sprite * sp){
	unsigned short xf = sp->x + sp->width;
	unsigned short yf = sp->y + sp->height;

	if (sp->x > get_h_res() || sp->y > get_v_res() || xf > get_h_res() || yf > get_v_res())
		return 1;

	unsigned int i, j, x = 0;
	for (i = sp->y; i < yf; i++) {
		for (j = sp->x; j < xf; j++, x++) {
			if (vg_set_pixel(j, i, sp->map[x]) != 0)
				return 1;
		}
	}
	return 0;
}
コード例 #7
0
ファイル: menu.c プロジェクト: ricardocerq/FEUP-LCOM
int main_menu_render()
{
	memcpy(get_program_secondary_buf(),get_background()->color,get_vram_size());
	//draw_cursor(get_program_secondary_buf(),cursor);
	draw_cursor(get_program_secondary_buf(),get_cursor());
	size_t i;
	for(i = 0; i < NUM_MAIN_MENU_BUTTONS-1; i++)
	{
		draw_button_t_centered(main_menu_buttons[i]);
	}
	draw_name_button_t(main_menu_buttons[i]);

	printgr_shade_centered(get_program_secondary_buf(),"O",get_v_res()/2-325, 0.75,0xFFFF,5,5, .1, 10);
	printgr_shade(get_program_secondary_buf(),"2",get_h_res()/2+35, get_v_res()/2-215, 0.75,0xFFFF,5,5, .1,9);
	if(*get_date_str_ptr() != NULL)
		printgr_shade_centered(get_program_secondary_buf(),*get_date_str_ptr(),0, 0.75,0xFFFF,5,5, .1, 1);
	if(darken > 0)
		darken_buf(get_program_secondary_buf(),darken);
	if(darken > 0 && !fade_condition)
	{
		darken-= FADE_RATE;
	}
	if(fade_condition)
	{
		if(darken <= 127)
		{
			darken += FADE_RATE;
		}
		else
		{
			if(function_to_call == NULL)
				continue_condition = false;
			else
			{
				fade_condition = false;
				function_to_call();
				if(main_menu_buttons[3] != NULL)
					free (main_menu_buttons[3]);
				main_menu_buttons[3] = initialize_button_t(to_coord_t(10,get_v_res()-get_line_space(2)),get_program_playername(), get_player_name, 2, 0.9);
				main_menu_buttons[3]->pos.x = 10;
				function_to_call = NULL;
			}
		}
	}
	copy_video_buffer(get_program_video_mem(), get_program_secondary_buf());
	return 0;
}
コード例 #8
0
ファイル: Bitmap.c プロジェクト: pedrofraga/LCOM-FEUP
int drawBitmap_byLine(Bitmap* bmp, int x, int y, Alignment alignment) {
    if (bmp == NULL)
        return 1;

    int width = bmp->bitmapInfoHeader.width;
    int drawWidth = width;
    int height = bmp->bitmapInfoHeader.height;
    if (alignment == ALIGN_CENTER)
        x -= width / 2;
    else if (alignment == ALIGN_RIGHT)
        x -= width;

    if (x + width < 0 || x > get_h_res() || y + height < 0
            || y > get_v_res())
        return 2;

    int xCorrection = 0;
    if (x < 0) {
    	xCorrection = -x;
    	drawWidth -= xCorrection;
    	x = 0;

    	if (drawWidth > get_h_res())
    		drawWidth = get_h_res();
    } else if (x + drawWidth >= get_h_res()) {
    	drawWidth = get_h_res() - x;
    }

    char* bufferStartPos;
    char* imgStartPos;
    int i;
    int a;
    for (i = 0; i < height; i++) {
        int pos = y + height - 1 - i;
        if (pos < 0 || pos >= get_v_res())
            continue;

        bufferStartPos = vg_adress();
        bufferStartPos += x * 2 + pos * get_h_res() * 2;
        imgStartPos = bmp->bitmapData + xCorrection * 2 + i * width * 2;
        memcpy(bufferStartPos, imgStartPos, drawWidth * 2);
    }

    return 0;
}
コード例 #9
0
ファイル: bullet.c プロジェクト: rsafeup/LCOM-BattalionTanks
int checkScreenCollision(Bullet *b) {
	switch (b->bulletOrientation) {
	case 1:
		return b->x < Border;
	case 2:
		return (b->x < Border || b->y < Border);
	case 3:
		return b->y < Border;
	case 4:
		return (b->y < Border || b->x + b->width > get_h_res() - rightBorder);
	case 5:
		return b->x + b->width > get_h_res() - rightBorder;
	case 6:
		return (b->y + b->height > get_v_res()- Border || b->x + b->width > get_h_res()- rightBorder);
	case 7:
		return b->y + b->height > get_v_res()- Border;
	case 8:
		return (b->y + b->height > get_v_res() - Border || b->x < Border);
	}
}
コード例 #10
0
ファイル: sprite.c プロジェクト: oindividuo/LCOM
Sprite *create_sprite(char * pic[], unsigned short xi, unsigned short yi) {
	Sprite * sp = (Sprite *) malloc(sizeof(Sprite));
	if (sp == NULL)
		return NULL;
	sp->map = read_xpm(pic, &(sp->width), &(sp->height), get_h_res(),
			get_v_res());
	if (sp->map == NULL) {
		free(sp);
		return NULL;
	}
	sp->x = xi;
	sp->y = yi;
	sp->xspeed = 0;
	sp->yspeed = 0;
	return sp;
}
コード例 #11
0
ファイル: turtles.c プロジェクト: Digas29/LCOM-FROGGER
void drawTurtle(Turtles * t, Bitmap * img){
	int width = img->bitmapInfoHeader.width;
	int drawWidth = width/4;
	int height = img->bitmapInfoHeader.height;

	if (t->x + drawWidth < 0.2*get_h_res() || t->x > 0.8*get_h_res() || t->y + height < 0 || t->y > get_v_res())
		return;


	char* bufferStartPos;
	char* imgStartPos;

	int i,j;
	for (i = 0; i < height; i++) {
		int pos = t->y + height - 1 - i;

		if (pos < 0 || pos >= get_v_res())
			continue;

		bufferStartPos = (char*)getBuffer();
		bufferStartPos += t->x * 2 + pos * get_h_res() * 2;

		imgStartPos = img->bitmapData + i * width * 2;

		int sum = t->width * 2 * t->desenho;
		imgStartPos += sum;

		for(j=0; j < drawWidth; j++){
			if(j > 0.2*get_h_res() - t->x && j < 0.8*get_h_res() - t->x){
				if((*imgStartPos) != 0 || (*(imgStartPos+1)) != 0){
					*bufferStartPos = *imgStartPos;
					*(bufferStartPos+1) = *(imgStartPos+1);
				}
			}
			bufferStartPos++;
			bufferStartPos++;
			imgStartPos++;
			imgStartPos++;
		}
	}
}
コード例 #12
0
ファイル: menu.c プロジェクト: ricardocerq/FEUP-LCOM
void initialize_lobby_buttons()
{
	lobby_buttons[0] = initialize_button_t(to_coord_t(get_h_res()/2, get_v_res() / 2 - 50), "PLAY", play_button, LOBBY_MENU_BUTTON_SIZE, 0.9);
	lobby_buttons[1] = initialize_button_t(to_coord_t(get_h_res()/2, get_v_res() / 2 +50), "Back", back_button, LOBBY_MENU_BUTTON_SIZE-1, 0.9);
}
コード例 #13
0
ファイル: menu.c プロジェクト: ricardocerq/FEUP-LCOM
int mp_lobby_render()
{
	memcpy(get_program_secondary_buf(),get_background()->color,get_vram_size());
	printgr_shade_centered(get_program_secondary_buf(),"Lobby",get_v_res()/2-200, 0.75,0xFFFF,5,5, .1, 8);
	printgr_shade(get_program_secondary_buf(),get_program_playername(),10, get_v_res()- get_line_space(2), 0.75,0xFFFF,5,5, .1, 2);
	if(*get_date_str_ptr() != NULL)
		printgr_shade_centered(get_program_secondary_buf(),*get_date_str_ptr(),0, 0.75,0xFFFF,5,5, .1, 1);
	if(get_role() == SEARCHING)
	{
		if(get_ticks() % 120 < 30)
			printgr_shade_centered(get_program_secondary_buf(),"Searching",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7);
		else if(get_ticks() % 120 < 60)
			printgr_shade_centered(get_program_secondary_buf(),"Searching.",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7);
		else if(get_ticks() % 120 < 90)
			printgr_shade_centered(get_program_secondary_buf(),"Searching..",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7);
		else
			printgr_shade_centered(get_program_secondary_buf(),"Searching...",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7);
	}
	else if(get_role() == FAILED)
	{
		printgr_shade_centered(get_program_secondary_buf(),"Connection Failed",get_v_res()/2, 0.75,0xFFFF,5,5, .1, 7);
		printgr_shade_centered(get_program_secondary_buf(),"Player Names must not be the same",get_v_res()/2+100, 0.75,0xFFFF,5,5, .1, 7);
	}
	if(get_role() == CLIENT || get_role() == SERVER)
	{
		strcpy(opponentmessage, "Opponent: ");
		strcat(opponentmessage, get_program_playername2());
		printgr_shade_centered(get_program_secondary_buf(),opponentmessage,get_v_res()/2 +200, 0.75,0xFFFF,5,5, .1, 5);
		draw_cursor(get_program_secondary_buf(),get_cursor());
		size_t i;
		if(lobby_state == PLAYER2_READY)
		{
			lobby_buttons[0]->text = "Play";
			lobby_buttons[0]->trans = 0.9;
		}
		else if(lobby_state == PLAYER1_READY)
		{
			lobby_buttons[0]->text = "Unready";
			lobby_buttons[0]->trans = 0.6;
		}
		else if(lobby_state == BOTH_READY)
		{
			lobby_buttons[0]->text = "Launching";
			lobby_buttons[0]->trans = 0.9;
		}
		else {
			lobby_buttons[0]->text = "Ready";
			lobby_buttons[0]->trans = 0.9;
		}
		lobby_buttons[0]->width = get_string_width(lobby_buttons[0]->text, lobby_buttons[0]->size);
		lobby_buttons[0]->pos.x = get_h_res()/2- lobby_buttons[0]->width/2;
		for(i = 0; i < NUM_LOBBY_BUTTONS; i++)
		{
			draw_button_t_centered(lobby_buttons[i]);
		}
		for(i = 0; i < size(im_message_log) && i < 20; ++i)
		{
			if(**(char**)at(im_message_log,size(im_message_log)-i-1) == 'm')
					printgr_shade(get_program_secondary_buf(),*(char**)at(im_message_log, size(im_message_log)-i-1),20,get_v_res()-100-(i+1)*20, .75,RGB(0,63,16),5,5, .1, 2);
			else printgr_shade(get_program_secondary_buf(),*(char**)at(im_message_log, size(im_message_log)-i-1),20,get_v_res()-100-(i+1)*20, .75,0xFFFF,5,5, .1, 2);
		}
		printgr_shade(get_program_secondary_buf(),">",10,get_v_res()-100, 0.75,0xFFFF,5,5, .1, 2);
		printgr_shade(get_program_secondary_buf(),current_im,20,get_v_res()-100, 0.75,0xFFFF,5,5, .1, 2);
	}
	if(darken > 0)
		darken_buf(get_program_secondary_buf(),darken);
	if(darken > 0 && !fade_condition)
	{

		darken-= FADE_RATE;
	}
	if(fade_condition)
	{
		if(darken <= 127)
		{

			darken += FADE_RATE;
		}
		else
		{
			if(lobby_state == BOTH_READY)
			{

				mp_game();
				fade_condition = false;
				lobby_state = NOT_READY;
			}
			else continue_condition = false;
		}
	}
	copy_video_buffer(get_program_video_mem(), get_program_secondary_buf());
	return 0;
}