DX라이브러리2014. 12. 22. 16:40

1.9 게임 프로그램 골격의 완성


#include <DxLib.h>


int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){

        ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK ); //윈도우모두, DX라이브러리 초기화, 백그라운드 처리


        int x = 0;

        int Handle;

        Handle = LoadGraph( "image/character_01.png" );


        // while(이미지 반영, 메세지 처리, 화면 클리어)

        while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 ){


                DrawGraph( x, 100, Handle, TRUE );

                x = x + 2;


        }

        

        DxLib_End();

        return 0;


프로그램은 while문의 내부에서 루프하고 있다. 즉, 게임에서 프레임이 필요한 처리는 붉은색 표시부분만 추가하면 된다는 말이다. 그럼 다음과 같이 표시될 좌표를 세개로 나누어보자.


#include <DxLib.h>


int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){

        ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK );


        int x = 0;

        int Handle;

        Handle = LoadGraph( "image/character_01.png" );


        while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 ){


                DrawGraph( x,   100, Handle, TRUE ); //이미지 처리

                DrawGraph( x/2, 200, Handle, TRUE ); //이미지 처리

                DrawGraph( x/4, 300, Handle, TRUE ); //이미지 처리

                x = x + 2;


        }

        

        DxLib_End();

        return 0;


실행결과




3개의 이미지가 동시에 다른 속도로 움직이는 것을 확인 가능하다. 이처럼 while문 내부에 코딩하는 것으로 게임을 만들어가게 된다. 즉, 필요 최소한의 코드는 다음과 같다.


#include <DxLib.h>


int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){

        ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK );


        while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 ){


                //이곳에 필요한 코딩을 하게된다.


        }

        

        DxLib_End();

        return 0;

}



Posted by 캡슐리어