Exemplo n.º 1
0
Turtles* newTurtle(int faixa){
	Turtles* t = (Turtles*)malloc(sizeof(Turtles));
	t->faixa = faixa;
	t->vy = 0;
	t->x = rand() % 561 + 120;
	switch(faixa){
	case 1:
		t->width = 0.12375 * get_h_res();
		t->y = 0.35 *get_h_res();
		t->vx = -40/getFPS() * 2;
		break;
	case 4:
		t->width = 0.08125 * get_h_res();
		t->y = 0.20 *get_h_res();
		t->vx = -(40/getFPS())*2;
		break;
	default:
		break;
	}
	int num = rand() % 10;
	t->anim = 0;
	t->desenho = 0;
	if(num >= 8){
		t->anim = 1;
		t->desenho = rand() % 3;
	}
	return t;
}
Exemplo n.º 2
0
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;

}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
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;
	}
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
char* getPath(char * ficheiro){
	char* screenSize;
	if(get_h_res() == 800){
		screenSize = "800x600/";
	}
	else if(get_h_res() == 1024){
		screenSize = "1024x768/";
	}

	unsigned int len1 = strlen(base);
	unsigned int len2 = strlen(screenSize);
	unsigned int len3 = strlen(ficheiro);
	char *result = (char*)malloc(len1+len2+len3+1);
	memcpy(result, base, len1);
	memcpy(result+len1, screenSize, len2);
	memcpy(result+len1+len2, ficheiro, len3+1);//+1 to copy the null-terminator
	return result;
}
Exemplo n.º 7
0
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);
	}
}
Exemplo n.º 8
0
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++;
		}
	}
}
Exemplo n.º 9
0
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;
}
Exemplo n.º 10
0
void updateTurtle(Turtles * t){
	counter++;
	t->x = t->x + t->vx;
	if(t->x >= 0.85*get_h_res()){
		t->x = 0.2*get_h_res() - t->width;
	}
	if(t->x <= 0.15*get_h_res()- t->width){
		t->x = 0.8*get_h_res();
	}
	if(t->anim){
		switch(t->desenho){
		case 0:
			if(getTimer()->counter % 240 == 0){
				t->desenho++;
			}
			break;
		case 1:
			if(getTimer()->counter % 30 == 0){
				t->desenho++;
			}
			break;
		case 2:
			if(getTimer()->counter % 30 == 0){
				t->desenho++;
			}
			break;
		case 3:
			if(getTimer()->counter % 30 == 0){
				t->desenho = 0;
			}
			break;
		default:
			break;
		}
	}
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
0
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;
}
Exemplo n.º 13
0
button_t* initialize_button_t (coord_t pos,char * text, int(*action)(), int size, float trans)
{
	button_t* out = malloc(sizeof(button_t));
	out->text = text;
	out->pos.y = pos.y;
	out->action = action;
	out->height = get_line_space(size);
	size_t i = 0;
	out->width = 0;
	for(; text[i] != '\0'; i++)
	{
		out->width += get_char_width(text[i], size) + get_char_sep(size);
	}
	out->width -= get_char_sep(size);
	out->pos.x = get_h_res()/2 - out->width /2;
	out->size = size;
	out->trans = trans;
	return out;
}
Exemplo n.º 14
0
int search_new_extreme(unsigned char side) {

	unsigned short left = get_h_res();
	unsigned short right = 0;

	alien* new_extreme = NULL; //extreme

	alien* iterator = invaders->head;

	if (side == 1) { //searches rightmost
		do {
			if (iterator->x + iterator->width > right) {
				right = iterator->x + iterator->width;
				new_extreme = iterator;
			}

			iterator = iterator->next;
		} while (iterator != NULL);

		invaders->rightmost = new_extreme;

		return 0;
	}

	else if (side == 2) { //searches leftmost
		do {
			if (iterator->x < left) {
				left = iterator->x;
				new_extreme = iterator;
			}

			iterator = iterator->next;
		} while (iterator != NULL);

		invaders->leftmost = new_extreme;

		return 0;
	}

	return 1;

}
Exemplo n.º 15
0
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;
}
Exemplo n.º 16
0
void start_menu_draw(){
	bitmap_draw(title, get_h_res()/2, 25, ALIGN_CENTER);
	menu_draw(start_menu);
	mouse_draw();
}
Exemplo n.º 17
0
void drawNewRecordMenu(newRecordMenu* menu){
	drawBitmap(menu->fundo, 0, 0,ALIGN_LEFT);
	drawString(menu->nome, 0.45*get_h_res(), 0.35*get_h_res(), RGB888toRGB565(255,255,255));
}
Exemplo n.º 18
0
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);
}
Exemplo n.º 19
0
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;
}