• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 96  文章 - 255  trackbacks - 0
            <2008年4月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            E-mail:zbln426@163.com QQ:85132383 長期尋找對戰(zhàn)略游戲感興趣的合作伙伴。

            常用鏈接

            留言簿(21)

            隨筆分類

            隨筆檔案

            SDL相關(guān)網(wǎng)站

            我的個人網(wǎng)頁

            我的小游戲

            資源下載

            搜索

            •  

            積分與排名

            • 積分 - 492164
            • 排名 - 38

            最新評論

            閱讀排行榜

            評論排行榜

            作者:龍飛

            3.1:一些小的修改

                    我覺得寫C++的程序,一是看起來確實比較C++一點,二是相對于C的“精煉”,C++要的是“健壯”。所以,其實我不太滿意用C風(fēng)格字符串作為ScreenSurface的成員數(shù)據(jù),所以做了修改。這也是為了在程序中構(gòu)建ScreenSurface對象的時候可以使用string。
            class ScreenSurface
            {
            private:
                
            //
                std::string windowName;
            public:
                
            //
                ScreenSurface(int w, int h, const std::string& window_name = "NULL"int b = 0, Uint32 f = 0);
            };
            相應(yīng)的,我們修改了2個構(gòu)造函數(shù)。
            ScreenSurface::ScreenSurface():
            width(
            640), height(480), bpp(32), flags(0), windowName("NULL")
            {
                
            if ( screenNum > 0 )
                    
            throw ErrorInfo("DONOT create more than ONE screen!");
                
            if ( SDL_Init(SDL_INIT_VIDEO < 0 ) )
                    
            throw ErrorInfo(SDL_GetError());
                pScreen 
            = SDL_SetVideoMode(width, height, bpp, flags);
                screenNum
            ++;
            }

            ScreenSurface::ScreenSurface(
            int w, int h, const std::string& window_name, int b, Uint32 f):
            width(w), height(h), bpp(b), flags(f)
            {
                
            if ( screenNum > 0 )
                    
            throw ErrorInfo("DONOT create more than ONE screen!");
                
            if ( SDL_Init(SDL_INIT_VIDEO < 0 ) )
                    
            throw ErrorInfo(SDL_GetError());
                pScreen 
            = SDL_SetVideoMode(width, height, bpp, flags);
                screenNum
            ++;
                
            if ( window_name != "NULL" ) {
                    windowName 
            = window_name;
                    SDL_WM_SetCaption(windowName.c_str(), 
            0);
                }
                
            else
                    windowName 
            = "NULL";
            }

                    第二個地方,我修改了TextSurface構(gòu)造函數(shù)的參數(shù)順序,并且將默認(rèn)的字體改為Windows都自帶的“新羅馬時代”字體times.ttf。我將字體參數(shù)放在最后,將字體大小參數(shù)提前了,這樣更符合習(xí)慣上的使用規(guī)律。

            class TextSurface: public DisplaySurface
            {
            public:
                TextSurface(
            const std::string& msg_name, const std::string& message, const ScreenSurface& screen,
                                Uint8 r 
            = 0xFF, Uint8 g = 0xFF, Uint8 b = 0xFF
                                
            int ttf_size = 28const std::string& ttf_fileName = "times.ttf");
                
            ~TextSurface();
            };

            (在DisplaySurface里相應(yīng)的構(gòu)造函數(shù)也做類似的修改,略)

            3.2:回顧SDL事件輪詢

                    SDL_PollEvent()的作用,是事件一旦被觸發(fā),就會響應(yīng)一次,注意它的響應(yīng)并不是連續(xù)不斷的。比如你按下某個鍵,即觸發(fā)了一次事件。即使你按著不松開,也僅僅是觸發(fā)了一次,所以SDL_PollEvent()也只響應(yīng)一次。
                    下面的程序,演示鍵盤事件中,方向鍵被按下后的反饋信息。

            3.3:演示程序

            //UVi Soft (2008)
            //Long Fei (lf426), E-mail: zbln426@163.com

            #include 
            "SurfaceClass.h"

            int game(int argc, char* argv[]);
            int main(int argc ,char* argv[])
            {
                
            int mainRtn = 0;
                
            try {
                    mainRtn 
            = game(argc, argv);
                }
                
            catch ( const ErrorInfo& info ) {
                    info.show();
                    
            return -1;
                }
                
                
            return mainRtn;
            }

            int game(int argc ,char* argv[])
            {
                
            //Create a SDL screen.
                const int SCREEN_WIDTH = 640;
                
            const int SCREEN_HEIGHT = 480;
                
            const std::string WINDOW_NAME = "Key Presses";
                ScreenSurface screen(SCREEN_WIDTH, SCREEN_HEIGHT, WINDOW_NAME);
                
            //Fill background.(default is black)
                screen.fillColor();
                screen.flip();

                
            //Load a textSurface
                TextSurface upMessage("upMsg""Up was pressed.", screen);
                TextSurface downMessage(
            "downMsg""Down was pressed.", screen, 0xFF00);
                TextSurface leftMessage(
            "leftMsg""Left was pressed.", screen, 00xFF0);
                TextSurface rightMessage(
            "rightMsg""Right was pressed.", screen, 000xFF);
                TextSurface otherMessage(
            "otherMsg""Other key was pressed.", screen, 10010010035);
                
                
            //Main loop.Press ESC or click X to quit.
                bool gameOver = false;
                SDL_Event gameEvent;
                
            int x = 200;
                
            int y = 200;
                
            while( gameOver == false ){
                    
            while ( SDL_PollEvent(&gameEvent) != 0 ){
                        
            if ( gameEvent.type == SDL_KEYDOWN ){
                            screen.fillColor();
                            
            switch ( gameEvent.key.keysym.sym ){
                                
            case SDLK_UP:
                                    upMessage.blit(x, y
            --);
                                    
            break;
                                
            case SDLK_DOWN:
                                    downMessage.blit(x, y
            ++);
                                    
            break;
                                
            case SDLK_LEFT:
                                    leftMessage.blit(x
            --, y);
                                    
            break;
                                
            case SDLK_RIGHT:
                                    rightMessage.blit(x
            ++, y);
                                    
            break;
                                
            default:
                                    otherMessage.blit(x, y);
                            }
                            screen.flip();
                        }
                        
            if ( gameEvent.type == SDL_QUIT ){
                            gameOver 
            = true;
                        }
                        
            if ( gameEvent.type == SDL_KEYUP ){
                            
            if ( gameEvent.key.keysym.sym == SDLK_ESCAPE ){
                                gameOver 
            = true;
                            }
                        }
                    }
                }

                
            return 0;
            }
            posted on 2008-03-25 11:56 lf426 閱讀(1846) 評論(0)  編輯 收藏 引用 所屬分類: SDL入門教程
            夜夜亚洲天天久久| 久久久精品人妻一区二区三区蜜桃| 无码乱码观看精品久久| 久久九九亚洲精品| 996久久国产精品线观看| 久久亚洲精品成人av无码网站| 亚洲精品乱码久久久久66| 香蕉久久久久久狠狠色| 久久无码AV一区二区三区| 久久久久久久久66精品片| 欧美黑人激情性久久| 99久久成人国产精品免费| 久久亚洲国产欧洲精品一| 久久精品嫩草影院| 久久国产精品波多野结衣AV| 伊人 久久 精品| 人妻精品久久无码区| 日本一区精品久久久久影院| 久久久久亚洲AV综合波多野结衣| 性做久久久久久久久久久| 久久精品一本到99热免费| 久久香综合精品久久伊人| 亚洲国产精品婷婷久久| 婷婷久久精品国产| 久久综合久久自在自线精品自| 国产综合久久久久| 久久se精品一区二区| 亚洲а∨天堂久久精品| 久久亚洲欧美国产精品| a级毛片无码兔费真人久久| 久久无码高潮喷水| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 99久久人妻无码精品系列| 久久久久久国产精品美女| 久久综合噜噜激激的五月天| 国产亚洲成人久久| 2021精品国产综合久久| 欧美亚洲国产精品久久| 久久久久国产日韩精品网站| 看久久久久久a级毛片| 2021国内精品久久久久久影院|