Esempio n. 1
0
int main(int argc, char **argv)
{

	/* Pas d'argument */
	if (argc == 1)
		usage(argv[0]);

    /* Initialisation */
	int c;
	char *nom = NULL;
	int de = open("lena.bmp", O_RDONLY);
	entete_bmp entete;
	unsigned char *pixels;

	if (de < 0){
		printf("erreur fichier entree\n");
		exit(EXIT_FAILURE);
	}else{
    /* Lecture du fichier source */
		lire_entete(de, &entete);
		pixels = allouer_pixels(&entete);
		lire_pixels(de, &entete, pixels);
	}

	while ((c = getopt(argc, argv, "rnbmia")) != -1) {
		switch (c) {
			case 'r':
			rouge(&entete, pixels);
			break;
			case 'n':
			negatif(&entete, pixels);
			break;
			case 'b':
			noir_et_blanc(&entete, pixels);
			break;
			case 'm':
			moitie(&entete, pixels, 1);
			break;
			case 'i':
			moitie(&entete, pixels, 0);
			break;
			case 'a':
			sepia(&entete, pixels);
			break;
			default :
			tuto(argv[0]);
			break;
		}
	}

	/* Lecture de l'option facultative (nom fichier) */
	int index;
	for (index = optind; index < argc; index++) {
		if (nom == NULL)
			nom = argv[index];
		else
			printf ("L'option %s a été ignoré.\n", argv[index]);
	}

    /* On écrit dans le fichier de destination */
	int vers;
	if (nom == NULL)
		vers = open("lena_out.bmp", O_WRONLY | O_CREAT, 0644);
	else 
		vers = open(nom, O_WRONLY | O_CREAT, 0644);

	if (vers < 0){
		printf("erreur fichier sortie\n");
		exit(EXIT_FAILURE);
	}else{
    /* Écriture du fichier destination */
		ecrire_entete(vers, &entete);
		ecrire_pixels(vers, &entete, pixels);
	}
    /* On libère les pixels */
	free(pixels);

	return EXIT_SUCCESS;
}
Esempio n. 2
0
//
// 함수: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// 목적: 주 창의 메시지를 처리합니다.
//
// WM_COMMAND	- 응용 프로그램 메뉴를 처리합니다.
// WM_PAINT	- 주 창을 그립니다.
// WM_DESTROY	- 종료 메시지를 게시하고 반환합니다.
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static int ac=0,j_flag=0,j_not=0;
	static float j_count1=0;
	static Player player[2]; //player[0]는 현재위치 player[1]은 전위치
	PAINTSTRUCT ps;
	static HANDLE hTimer;
	static char map[HEIGHT][WIDTH]={};
	static int stage[1]={MENU}, trapKey[10];
	static TRAP trap[10];
	static MapBox mapbox[HEIGHT][WIDTH] = {0};
	int save[3] = {0};	 //save[0] = ac, save[1] = j_count1, save[2] = j_not
	HDC hdc, hBitDC, mapDC, backDC, charDC, BulletDC;
	HBITMAP hBit, mapbit, Bulletbit;
	HBITMAP backbitmap;	 //기존에 dc에 저장된 BitMap을 다른곳에 보관 해주면서 새 BitMap을 dc에 저장한다.
	RECT rt={0,0,900,700};
	static int player_bullet_direction;
	static Bullet player_bullet[P_BULLET_MAX];
	static int player_bullet_count[1] = {0};
	static int enemy_count[1] = {0};
	static int reset=0;
	static int menu_select = 0;
	char B[7] = "bullet";
	static int menu_arrow[1] = {1}; //1 = 처음하기, 2 = 이어하기, 3 = 끝내기
	static int die_check = 0;
	SetTimer(hWnd, MOVE_TIMER_ID, 10, NULL);
	SetTimer(hWnd, BULLET_TIMER_ID, 200, NULL); //총알 타이머

	save[0] = ac;
	save[1] = j_count1;
	save[2] = j_not;


	switch(stage[0])
	{
		case MENU:
			menu(menu_arrow, player, reset, stage, menu_select);
			break;
		if(die_check == 1){
			die_check = 0;
			menu_arrow[0] = 1;
			menu_select = 0;
			stage[0] = MENU;
		}
		case TUTORIAL1:
			tuto(player, save, map,trap,stage, mapbox,&reset);
			break;
		case TUTORIAL2:
			tuto2(player,save,map,trap, stage, mapbox, &reset);
			break;
		case STAGE1_1:
			stage1(player,save,map,trap, stage, mapbox, &reset);
			break;
	}
	

	ac = save[0];
	j_count1 = save[1];
	j_not = save[2];


	switch (message)
	{

		case WM_CREATE :
			hTimer=(HANDLE)SetTimer(hWnd,AC_TIMER_ID,50,NULL);
			return 0;


		case WM_KEYDOWN:
			switch(wParam)
			{
				if(stage[0] == MENU){
					case VK_LEFT:
						if(menu_arrow[0] > 1){
							menu_arrow[0]--;
						}
						return FALSE;
					case VK_RIGHT:
						if(menu_arrow[0] < 3){
							menu_arrow[0]++;
						}
						return FALSE;
					case VK_RETURN:
						menu_select = menu_arrow[0];
						return FALSE;
				}
				case 'z': //위누르면 점프 2단까지 허용
				case 'Z':
					if(player[0].life==1 && j_count1<2 && j_not<1.1)
					{
						SetTimer(hWnd,JUMP_TIMER_ID,50,NULL);
						j_not++;
						ac=0;
						j_flag=0;
						j_count1+=1;
					//	InvalidateRect(hWnd,NULL,false);
						return false;
					}
			}

			if(stage[0] != MENU){
				case WM_TIMER:
					switch(wParam)
					{
					case AC_TIMER_ID: //중력처리
						if(ac<17)
							ac+=2;
						player[1].top = player[0].top;
						player[0].top+=ac;
						player[1].bottom = player[0].bottom;
						player[0].bottom+=ac;
						InvalidateRect(hWnd,NULL,FALSE);
						return false;

					case JUMP_TIMER_ID:
						player[1].top = player[0].top;
						player[0].top-=(20-j_flag*3); //점프 올라갈수록 느려짐
						player[1].bottom = player[0].bottom;
						player[0].bottom-=(20-j_flag*3);
						j_flag++;
						if(j_flag==4)
							KillTimer(hWnd,2); 
						return false;
					case MOVE_TIMER_ID:
						if(player[0].life!=0)
						{
							if(GetAsyncKeyState(VK_LEFT) < 0) //왼쪽ㄱㄱ
							{
								if(LR_Crash(map, player, mapbox, LEFT)) // if 문 추가로 입력
								{
									player_bullet_direction = WW;
									player[1].left = player[0].left;
									player[0].left -= 3;
									player[1].right = player[0].right;
									player[0].right -= 3;
								}
							}
							if(GetAsyncKeyState(VK_RIGHT) < 0) //오른쪽 ㄱㄱ
							{
								if(LR_Crash(map, player, mapbox, RIGHT))//if 문 추가로 입력 (이동 불가하게 만듬)
								{
									player_bullet_direction = EE;
									player[1].left = player[0].left;
									player[0].left += 3;
									player[1].right = player[0].right;
									player[0].right += 3;
								}
							}
						}
						return false;
					case BULLET_TIMER_ID:
						if(GetAsyncKeyState(0x58) < 0) // X = Bullet
						{
							player_bullet[player_bullet_count[0]].direction = player_bullet_direction;
							if(player_bullet[player_bullet_count[0]].direction == WW){
								player_bullet[player_bullet_count[0]].right = player[0].left;
								player_bullet[player_bullet_count[0]].left = player_bullet[player_bullet_count[0]].right - P_BULLETSIZE;
							}
							else if(player_bullet[player_bullet_count[0]].direction == EE){
								player_bullet[player_bullet_count[0]].left = player[0].right;
								player_bullet[player_bullet_count[0]].right = player_bullet[player_bullet_count[0]].left + P_BULLETSIZE;
							}
							player_bullet[player_bullet_count[0]].top = player[0].top + 11;
							player_bullet[player_bullet_count[0]].bottom = player_bullet[player_bullet_count[0]].top + P_BULLETSIZE;
							player_bullet_count[0]++;
						}
						for(int i=0; i<player_bullet_count[0]; i++){
							if(player_bullet[i].direction == WW){
								player_bullet[i].right -= 10;
								player_bullet[i].left = player_bullet[i].right - P_BULLETSIZE;
							}
							else if(player_bullet[i].direction == EE){
								player_bullet[i].left += 10;
								player_bullet[i].right = player_bullet[i].left + P_BULLETSIZE;
							}
						}
						return false;
					}
			}


		case WM_PAINT:

			hdc = BeginPaint(hWnd, &ps);
			backDC=CreateCompatibleDC(hdc);
			backbitmap = CreateCompatibleBitmap(hdc,rt.right,rt.bottom);
			hBitDC = CreateCompatibleDC(hdc);
			mapDC = CreateCompatibleDC(hdc);
			charDC = CreateCompatibleDC(hdc);
			BulletDC = CreateCompatibleDC(hdc);
			if(player[0].life==1)
				mapbit=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP1));
			else{
				mapbit=LoadBitmap(hInst,MAKEINTRESOURCE(IDB_BITMAP3));
				die_check = 1;
			}
			if(stage[0]/10==TUTO)
				hBit = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP2));
			else if(stage[0]/10==STAGE1)
				hBit = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP7));
			Bulletbit = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP15));
			SelectObject(backDC, backbitmap);
			SelectObject(mapDC,hBit);
			SelectObject(charDC,mapbit);
			SelectObject(BulletDC, Bulletbit);
			SelectObject(backDC,hBit);
			FillRect(backDC, &rt, (HBRUSH)GetStockObject(WHITE_BRUSH));
			switch(stage[0]/10)
			{
				case MENU:
					DrawMenu(hdc, backDC, hInst, menu_arrow);
					break;
				case TUTO:
					DrawBlockTuto(hdc,backDC,mapDC,trap,stage,hInst,map);
					break;
				case STAGE1:
					DrawBlockStage1(hdc,backDC,mapDC,trap,stage,hInst,map);
					break;
			}
			for(int i=0; i<player_bullet_count[0]; i++){
				//BitBlt(backDC, player_bullet[i].left, player_bullet[i].top, P_BULLETSIZE, P_BULLETSIZE, BulletDC , 0, 0, SRCCOPY);
				TextOut(backDC, player_bullet[i].left, player_bullet[i].top, B, strlen(B)); 
			}
		TransparentBlt(backDC, player[0].left-BOXSIZE, player[0].top-BOXSIZE, PLAYERSIZE, PLAYERSIZE, charDC, 0, 0,PLAYERSIZE,PLAYERSIZE, RGB(255,255,255));
		BitBlt(hdc,0,0,rt.right,rt.bottom,backDC,0,0,SRCCOPY);

// TODO: 여기에 그리기 코드를 추가합니다.
// SelectObject(hBitDC, hOldBit); 
// SelectObject(mapDC, holdmap); 
		DeleteObject(backbitmap);
		DeleteObject(hBit);
		DeleteObject(Bulletbit);
		DeleteObject(mapbit);
		DeleteDC(hBitDC);
		DeleteDC(backDC);
		DeleteDC(BulletDC);
		DeleteDC(hdc);
		DeleteDC(mapDC);
		DeleteDC(charDC);

		EndPaint(hWnd, &ps);
		return FALSE;
	case WM_DESTROY:
		KillTimer(hWnd, AC_TIMER_ID);
		KillTimer(hWnd, MOVE_TIMER_ID);
		KillTimer(hWnd, BULLET_TIMER_ID);
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}