메뉴 건너뛰기

자유롭게 이야기를 적는 공간

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개 선언할 것 없이
일사천리로 할 수 있었을텐데, 왜 그랬지.

원하시면 각 변수나 배열이 무슨 역할인지 설명해드리죠.
조회 수 :
554
등록일 :
2004.06.20
21:23:54 (*.108.)
엮인글 :
게시글 주소 :
https://hondoom.com/zbxe/index.php?mid=free&document_srl=74363

우성호

2008.03.19
09:34:35
(*.117.113.197)
main.cpp 전체 공개하랬지 일부 공개하랬소? 맨 아랫 부분하고 윗 부분 어디갔소? 내 게임 오류의 근원을 찾으려면 main.cpp 전체가 있어야 하거늘!!!

우성호

2008.03.19
09:34:35
(*.117.113.197)
새 사냥 폴더 안에 필요 파일 싸그리 넣고 main.cpp에 이 내용 넣으면 에러 93개 납니다.

철없는 아이

2008.03.19
09:34:35
(*.81.198.146)
뭐예요?

행방불명

2008.03.19
09:34:35
(*.213.29.126)
그러게 말입니다.
List of Articles
공지 (대피소) 혼돈과 어둠의 디스코드
노루발
343   2023-09-05 2023-09-05 16:05
공지 글 작성을 위해서는 회원 가입이 필요합니다.
노루발
4929   2016-02-22 2021-07-06 09:43