자유롭게 이야기를 적는 공간
글 수 15,207
int x=320,flag=0,flag2=0,flag3=0,missleX,missleY; //움직임 관련 변수
int bird[10]={0,},birdX[10]={0,},birdY[10]={0,},birdS[10]={0,},doa[10]={0,};
void animate_self() // 애니메이션 함수
{
if(flag >= 0 && flag <= 10){jdd->DrawPicture(backbuffer,"s01",x,312,NULL);flag+=2;}
else if(flag >= 10 && flag <= 20){jdd->DrawPicture(backbuffer,"s02",x,312,NULL);flag+=2;}
else if(flag >= 20 && flag <= 30){jdd->DrawPicture(backbuffer,"s01",x,312,NULL);flag+=2;}
else if(flag >= 30 && flag <= 40){jdd->DrawPicture(backbuffer,"s03",x,312,NULL);flag+=2;}
else if(flag >= 40){jdd->DrawPicture(backbuffer,"s03",x,312,NULL);flag = 0;}
}
void missle()
{
if(flag2 == 1){
jdd->DrawPicture(backbuffer,"bull",missleX,missleY,NULL);
missleX-=5;
missleY-=15;
if(missleY <= 10)flag2 = 0;
}
}
void bird_rnd()
{
jds->Play("woo");
for(int i=0;i<10;i++){
birdX[i] = 580;
for(;;){
birdY[i] = rand()%280;
if(birdY[i] > 20)break;
}
for(;;){
birdS[i] = rand()%15;
if(birdS[i] > 5)break;
}
doa[i] = 1;
jdd->DrawPicture(backbuffer,"bird",birdX[i],birdY[i],NULL);
}
}
void bird_move()
{
flag3=0;
for(int i=0;i<10;i++){
if(doa[i]==1){
if(birdX[i]>20)birdX[i]-=birdS[i];
else if(birdX[i]<=20)birdX[i] = 580;
jdd->DrawPicture(backbuffer,"bird",birdX[i],birdY[i],NULL);
flag3 = 1;
}
}
}
void chkcrash()
{
for(int i=0;i<10;i++){
if(birdX[i]<=missleX && birdX[i]+42>=missleX){
if(birdY[i]<=missleY && birdY[i]+22>=missleY && doa[i] == 1){
doa[i]=0;
jds->Play("ark");
}
}
}
}
int main()
{
jdd=CreateDirectDraw();
jds=CreateDirectSound();
jre=CreateDXResourceManager(jdd,jds);
HINSTANCE hInstance=(HINSTANCE)0x00400000;
WNDCLASS wc={0};
wc.hIcon=LoadIcon(hInstance,"PSYCCER.ico");
wc.hCursor=LoadCursor(hInstance,IDC_ARROW);
wc.lpfnWndProc=WndProc;
wc.hInstance=hInstance;
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszClassName="Demo";
RegisterClass(&wc);
HWND hwnd=CreateWindow("Demo","새 사냥",WS_POPUP|WS_VISIBLE,0,0,640,480,NULL,NULL,hInstance,NULL);
ShowCursor( FALSE );
jdd->Initialize(NULL,hwnd,640,480,16,true);
jds->Initialize(0,hwnd);
//초기화
backbuffer=jdd->GetBackBuffer();
JFont font20=jdd->CreateFont("굴림체",20,true,false,false,false,false);
srand( (unsigned)time( NULL ) );
jdd->SetFrameRate(100,true);
jdd->SetVerticalSync(false);
//재료 불러오기
JPictureInfo pi;
pi.SetColorKey(JColor(0,0,255));
jdd->LoadPicture("ground","ground.bmp",&pi); //땅 높이 52
jdd->LoadPicture("s01","char.bmp",&pi); // 총구 x, y-5
jdd->LoadPicture("s02","char2.bmp",&pi);
jdd->LoadPicture("s03","char3.bmp",&pi);
jdd->LoadPicture("bg","sky.jpg");
jdd->LoadPicture("bull","bullet.bmp",&pi);
jdd->LoadPicture("bird","bird.bmp",&pi);
jds->LoadSound("music","bgsound.mid");
jds->LoadSound("shot","shot.wav");
jds->LoadSound("ark","uk.wav");
jds->LoadSound("woo","revolt.wav");
//새게임
jds->Play("music");
for(;;)
{
if(_GetKeyState(VK_LEFT))x-=5;
else if(_GetKeyState(VK_RIGHT))x+=5;
else if(_GetKeyState(VK_ESCAPE))break;
if(_GetKeyPush(VK_SPACE) && flag2 == 0){
jds->Play("shot");
missleX = x;
missleY = 308;
flag2 = 1;
}
jdd->DrawPicture(backbuffer,"bg",0,0,NULL);
jdd->DrawPicture(backbuffer,"ground",0,340,NULL);
missle(); //총알 처리
animate_self(); //슬라임 애니메이션
if(flag3 == 0)bird_rnd();
bird_move();
chkcrash();
jdd->Render();
}
return 0;
}
----------------------------------------------------
거의 감각적으로 프로그램을 짜다보니 효율은 별로임.
그래도 알아보긴 쉬울 겁니다.
지금 생각해보면 2차원 배열로 하면 배열 3개 선언할 것 없이
일사천리로 할 수 있었을텐데, 왜 그랬지.
원하시면 각 변수나 배열이 무슨 역할인지 설명해드리죠.
int bird[10]={0,},birdX[10]={0,},birdY[10]={0,},birdS[10]={0,},doa[10]={0,};
void animate_self() // 애니메이션 함수
{
if(flag >= 0 && flag <= 10){jdd->DrawPicture(backbuffer,"s01",x,312,NULL);flag+=2;}
else if(flag >= 10 && flag <= 20){jdd->DrawPicture(backbuffer,"s02",x,312,NULL);flag+=2;}
else if(flag >= 20 && flag <= 30){jdd->DrawPicture(backbuffer,"s01",x,312,NULL);flag+=2;}
else if(flag >= 30 && flag <= 40){jdd->DrawPicture(backbuffer,"s03",x,312,NULL);flag+=2;}
else if(flag >= 40){jdd->DrawPicture(backbuffer,"s03",x,312,NULL);flag = 0;}
}
void missle()
{
if(flag2 == 1){
jdd->DrawPicture(backbuffer,"bull",missleX,missleY,NULL);
missleX-=5;
missleY-=15;
if(missleY <= 10)flag2 = 0;
}
}
void bird_rnd()
{
jds->Play("woo");
for(int i=0;i<10;i++){
birdX[i] = 580;
for(;;){
birdY[i] = rand()%280;
if(birdY[i] > 20)break;
}
for(;;){
birdS[i] = rand()%15;
if(birdS[i] > 5)break;
}
doa[i] = 1;
jdd->DrawPicture(backbuffer,"bird",birdX[i],birdY[i],NULL);
}
}
void bird_move()
{
flag3=0;
for(int i=0;i<10;i++){
if(doa[i]==1){
if(birdX[i]>20)birdX[i]-=birdS[i];
else if(birdX[i]<=20)birdX[i] = 580;
jdd->DrawPicture(backbuffer,"bird",birdX[i],birdY[i],NULL);
flag3 = 1;
}
}
}
void chkcrash()
{
for(int i=0;i<10;i++){
if(birdX[i]<=missleX && birdX[i]+42>=missleX){
if(birdY[i]<=missleY && birdY[i]+22>=missleY && doa[i] == 1){
doa[i]=0;
jds->Play("ark");
}
}
}
}
int main()
{
jdd=CreateDirectDraw();
jds=CreateDirectSound();
jre=CreateDXResourceManager(jdd,jds);
HINSTANCE hInstance=(HINSTANCE)0x00400000;
WNDCLASS wc={0};
wc.hIcon=LoadIcon(hInstance,"PSYCCER.ico");
wc.hCursor=LoadCursor(hInstance,IDC_ARROW);
wc.lpfnWndProc=WndProc;
wc.hInstance=hInstance;
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszClassName="Demo";
RegisterClass(&wc);
HWND hwnd=CreateWindow("Demo","새 사냥",WS_POPUP|WS_VISIBLE,0,0,640,480,NULL,NULL,hInstance,NULL);
ShowCursor( FALSE );
jdd->Initialize(NULL,hwnd,640,480,16,true);
jds->Initialize(0,hwnd);
//초기화
backbuffer=jdd->GetBackBuffer();
JFont font20=jdd->CreateFont("굴림체",20,true,false,false,false,false);
srand( (unsigned)time( NULL ) );
jdd->SetFrameRate(100,true);
jdd->SetVerticalSync(false);
//재료 불러오기
JPictureInfo pi;
pi.SetColorKey(JColor(0,0,255));
jdd->LoadPicture("ground","ground.bmp",&pi); //땅 높이 52
jdd->LoadPicture("s01","char.bmp",&pi); // 총구 x, y-5
jdd->LoadPicture("s02","char2.bmp",&pi);
jdd->LoadPicture("s03","char3.bmp",&pi);
jdd->LoadPicture("bg","sky.jpg");
jdd->LoadPicture("bull","bullet.bmp",&pi);
jdd->LoadPicture("bird","bird.bmp",&pi);
jds->LoadSound("music","bgsound.mid");
jds->LoadSound("shot","shot.wav");
jds->LoadSound("ark","uk.wav");
jds->LoadSound("woo","revolt.wav");
//새게임
jds->Play("music");
for(;;)
{
if(_GetKeyState(VK_LEFT))x-=5;
else if(_GetKeyState(VK_RIGHT))x+=5;
else if(_GetKeyState(VK_ESCAPE))break;
if(_GetKeyPush(VK_SPACE) && flag2 == 0){
jds->Play("shot");
missleX = x;
missleY = 308;
flag2 = 1;
}
jdd->DrawPicture(backbuffer,"bg",0,0,NULL);
jdd->DrawPicture(backbuffer,"ground",0,340,NULL);
missle(); //총알 처리
animate_self(); //슬라임 애니메이션
if(flag3 == 0)bird_rnd();
bird_move();
chkcrash();
jdd->Render();
}
return 0;
}
----------------------------------------------------
거의 감각적으로 프로그램을 짜다보니 효율은 별로임.
그래도 알아보긴 쉬울 겁니다.
지금 생각해보면 2차원 배열로 하면 배열 3개 선언할 것 없이
일사천리로 할 수 있었을텐데, 왜 그랬지.
원하시면 각 변수나 배열이 무슨 역할인지 설명해드리죠.