Presentation is loading. Please wait.

Presentation is loading. Please wait.

C언어 개요 게임프로그래밍.

Similar presentations


Presentation on theme: "C언어 개요 게임프로그래밍."— Presentation transcript:

1 C언어 개요 게임프로그래밍

2 C언어 개요 C/C++ LANGUAGE 게임프로그래밍

3 소프트웨어 준비 Visual Studio 설치 DirectX SDK 설치 별도 설치 버전:
최신버전 권장 (“2015”), C/C++ DirectX SDK 설치 Windows 8부터 DirectX SDK는 Windows SDK에 포함되어 배포됨 별도 설치 필요 없음 관련 주소: 별도 설치 버전: Windows 7 이전 환경 또는 예전 버전 호환이 필요한 경우 마지막 별도 설치 버전: “June 2010” 관련 주소: Documentation “DirectX Documentation for C++”를 참조 Windows DirectX Graphics Documentation Direct3D, DXGI, HLSL, Direct2D 게임프로그래밍

4 기타 준비 Direct2D Library Direct3D Library 기타 Library d2d1.lib
Related: dwrite.lib, windowscodecs.lib Direct3D Library d3d10.lib (기본) d3dx10.lib (확장) 유용한 함수들이 많이 포함되어 있으므로 편리함 Related: dxgi.lib 기타 Library winmm.lib : Window Multimedia 타이머 함수 등의 사용을 위해 필요함 게임프로그래밍

5 간단한 프로젝트 생성 가장 간단한 형식의 프로젝트 생성 프로젝트 속성 소스 코딩
메뉴 “파일(File)”→“새로 만들기(New)”→“프로젝트(Project)” 선택 템플릿 “Visual C++” → “Win32” 클릭 “Win32 Console Application” 또는 “Win32 Project” 중에서 선택 프로젝트 속성 메뉴 “프로젝트(Project)”→”속성(Properties)” “링커(Linker)”→“입력(Input)” : “추가 종속성(Additional Dependencies)” 필요한 라이브러리 파일을 추가 파일명 구분은 “;”로 참고: 헤더파일에 다음과 같이 컴파일러를 위한 #pragma 지시어(directive)를 사용하면 프로젝트 속성에 명시하지 않아도 됨 소스 코딩 “hello.cpp”를 편집 #pragma comment(lib, "Winmm.lib") 게임프로그래밍

6 연습 – 빈 프로젝트 만들기 빈 프로젝트를 만들어 보세요 폴더 내 파일들 살펴보기 실행 파일→새로만들기→프로젝트
01.HelloEmpty 빈 프로젝트를 만들어 보세요 파일→새로만들기→프로젝트 Visual C++/Win32→Win32 콘솔 응용 프로그램 이름 : hello, 위치 : C:\Home\Work 선택사항 “Create directory for solution”은 체크해제 프로젝트 생성 위치 : C:\Home\Work\hello 기타 사항들을 모두 디폴트로 마침 폴더 내 파일들 살펴보기 생성된 폴더를 살펴 보세요 C:\Home\Work\hello 폴더 “빌드→솔루션 빌드” 후 다시 살펴 보세요 실행 “디버그→디버깅 시작” (F5) “디버그→디버깅 하지 않고 시작” (Ctrl+F5) 게임프로그래밍

7 연습 – 소스코드 수정하기 “Hello World!” 를 출력해 보세요 02.HelloSimple
#include "stdafx.h“ int _tmain(int argc, _TCHAR* argv[]) { printf("Hello World!\n"); return 0; } 게임프로그래밍

8 연습 – 함수 사용하기 sin(45º)의 값을 출력해 보세요 03.HelloSine #include "stdafx.h“
#define _USE_MATH_DEFINES #include <math.h> int _tmain(int argc, _TCHAR* argv[]) { printf("sin(%d) = %f\n", 45, sin(M_PI/4)); return 0; } 게임프로그래밍

9 정렬 – 랜덤 숫자 생성 10개의 random 숫자를 출력하세요. 04.SortPrint #include "stdafx.h"
#include <time.h> static void print(const int* list, int n) { printf("<"); for (int i=0; i<n; i++) printf("%d%s", list[i], (i<n-1) ? ", " : ">\n" ); } int _tmain(int argc, _TCHAR* argv[]) { int n = 10; int* list; srand( (unsigned)time( NULL ) ); list = (int *)malloc(sizeof(int)*n); list[i] = rand(); print(list, n); free(list); return 0; 게임프로그래밍

10 정렬 – 사용자 정의 함수에 의한 퀵소트 정수 배열을 오름차순으로 정렬하세요. 05.SortUser
#include "stdafx.h" #include <time.h> static void print(const int* list, int n); int _tmain(int argc, _TCHAR* argv[]) { int* list int n=10; srand( (unsigned)time( NULL ) ); list=(int *)malloc(sizeof(int)*n); for (int i=0; i<n; i++) list[i] = rand(); print(list, n); quicksort(list, 0, n-1); free(list); return 0; } void quicksort(int * list, int ilo, int ihi) { int pivot, ulo, uhi, ieq, tempEntry; if (ilo >= ihi) return; pivot = list[(ilo + ihi)/2]; ieq = ulo = ilo; uhi = ihi; while (ulo <= uhi) { if (list[uhi] > pivot) { uhi--; } else { tempEntry = list[ulo]; list[ulo] = list[uhi]; list[uhi] = tempEntry; if (list[ulo] < pivot) { tempEntry = list[ieq]; list[ieq] = list[ulo]; list[ulo] = tempEntry; ieq++; } ulo++; }} quicksort(list, ilo, ieq - 1); quicksort(list, uhi + 1, ihi); 게임프로그래밍

11 정렬 – 시스템 정의 함수에 의한 퀵소트 Library 함수인 qsort를 사용해 보세요. 06.SortSystem
#include "stdafx.h“ #include <stdlib.h> #include <time.h> static void print(const int* list, int n); static int compare(const void* p, const void* q) { const int* ip = (const int*) p; const int* iq = (const int*) q; return *ip - *iq; } int _tmain(int argc, _TCHAR* argv[]) { int* list; int n=10; srand( (unsigned)time( NULL ) ); list = (int *)malloc(sizeof(int)*n); for (int i=0; i<n; i++) list[i] = rand(); print(list, n); qsort(list, n, sizeof(list[0]), compare); free(list); return 0; 게임프로그래밍

12 정렬 – 시스템 정의 함수에 의한 구조체 퀵소트 구조체를 정렬해 보세요. 07.SortStruct
#include "stdafx.h" #include <stdlib.h> #include <time.h> typedef struct { int id; float score; } stu; static void print(const stu* list, int n) { printf("<"); for (int i=0; i<n; i++, list++) { printf("[%d,%d]%s", list->id, (int)list->score, (i<n-1) ? ", " : ">\n" ); } int compare(const void *p, const void *q) { const stu * ip = (const stu *)p; const stu * iq = (const stu *)q; if (ip->score > iq->score) return 1; else if (ip->score < iq->score) return -1; else return 0; int _tmain(int argc, _TCHAR* argv[]) { stu * students; int n = 10; srand( (unsigned)time( NULL ) ); list = (stu *)malloc(sizeof(stu)*n); for (int i=0; i<n; i++) { list[i].id = i; list[i].score = (float)(rand() % 100); } print(list, n); qsort( list, n, sizeof(stu), compare ); free(list); return 0; 게임프로그래밍


Download ppt "C언어 개요 게임프로그래밍."

Similar presentations


Ads by Google