• <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>

            VC++ C++ C# Algorithm

            C++博客 首頁 新隨筆 聯(lián)系 聚合 管理
              21 Posts :: 3 Stories :: 31 Comments :: 0 Trackbacks

            很多游戲都是用鼠標(biāo)控制的,所以說處理鼠標(biāo)事件也是非常重要的,鼠標(biāo)事件和鍵盤事件處理方式差的不太多,所以我就直接給出了一個小程序,該程序把窗口一分為二,當(dāng)在左半部分移動時,左面部分就變綠色,右面部分變黑色,在右半部分移動時,該部分就變藍色,左半部分就變成了黑色,當(dāng)鼠標(biāo)左擊時,對應(yīng)的部分將會變紅色。

            #include? " SDL.h "
            #include?
            " SDL_ttf.h "
            SDL_Surface?
            * screen = NULL;

            TTF_Font?
            * font =
            NULL;
            // screen?to?show?on?window

            const ? int ?SCREEN_BPP = 32 ;



            int ?main(? int ?argc,? char *
            ?args[]?)
            {
            ????
            // Start?SDL

            ???? bool ?quit = false ;
            ????SDL_Rect?rectLeft;
            ????SDL_Rect?rectRight;
            ????rectLeft.x
            = 0
            ;
            ????rectLeft.y
            = 0
            ;
            ????rectLeft.w
            = 320
            ;
            ????rectLeft.h
            = 480
            ;
            ????rectRight.x
            = 320
            ;
            ????rectRight.y
            = 0
            ;
            ????rectRight.w
            = 640
            ;
            ????rectRight.h
            = 480
            ;
            ????SDL_Init(?SDL_INIT_EVERYTHING?);
            ????
            if (TTF_Init() ==- 1
            )
            ????????
            return ? false
            ;
            ????
            ????screen?
            = ?SDL_SetVideoMode(? 600 ,? 480
            ,?SCREEN_BPP,?SDL_SWSURFACE?);
            ????
            if (screen ==
            NULL)
            ????????
            return ? false
            ;

            ????Uint32?colorBlue
            = SDL_MapRGB(screen -> format, 0 , 0 , 255
            );
            ????Uint32?colorGreen
            = SDL_MapRGB(screen -> format, 0 , 255 , 0
            );
            ????Uint32?colorRed
            = SDL_MapRGB(screen -> format, 255 , 0 , 0
            );
            ????Uint32?colorBlack
            = SDL_MapRGB(screen -> format, 0 , 0 , 0
            );
            ????SDL_Event?
            event
            ;
            ????
            while ( !
            quit)
            ????
            {
            ????????
            if (SDL_PollEvent( & event
            ))
            ????????
            {
            ????????????
            if ( event .type? ==
            ?SDL_MOUSEMOTION)
            ????????????
            {
            ????????????????Uint16?x
            = event
            .motion.x;
            ????????????????Uint16?y
            = event
            .motion.y;


            ????????????????
            if (x > 0 ? && ?x < 320 ? && ?y > 0 ? && ?y < 480
            ?)
            ????????????????
            {
            ????????????????????SDL_FillRect(screen,
            &
            rectLeft,colorBlue);
            ????????????????????SDL_FillRect(screen,
            &
            rectRight,colorBlack);
            ????????????????}

            ????????????????
            if (x > 320 ? && ?x < 640 ? && ?y > 0 ? && ?y < 480 ?)
            ????????????????
            {
            ????????????????????SDL_FillRect(screen,
            &
            rectRight,colorGreen);
            ????????????????????SDL_FillRect(screen,
            &
            rectLeft,colorBlack);
            ????????????????}

            ????????????}

            ????????????
            if ( event .type? == SDL_MOUSEBUTTONDOWN)
            ????????????
            {
            ????????????????Uint16?x
            = event
            .motion.x;
            ????????????????Uint16?y
            = event
            .motion.y;
            ????????????????
            if ( event .button.button? ==
            ?SDL_BUTTON_LEFT)
            ????????????????
            {
            ????????????????????
            if (x > 0 ? && ?x < 320 ? && ?y > 0 ? && ?y < 480
            ?)
            ????????????????????
            {
            ????????????????????????SDL_FillRect(screen,
            &
            rectLeft,colorRed);
            ????????????????????}

            ????????????????????
            if (x > 320 ? && ?x < 640 ? && ?y > 0 ? && ?y < 480 ?)
            ????????????????????
            {
            ????????????????????????SDL_FillRect(screen,
            &
            rectRight,colorRed);
            ????????????????????}

            ????????????????}

            ????????????}

            ????????????
            if ( event .type? == ?SDL_QUIT)
            ????????????????quit
            = true
            ;
            ????????}

            ????????
            if (SDL_Flip(screen)? == ? - 1 )
            ????????
            {
            ????????????
            return ? false
            ;
            ????????}

            ????}

            ????SDL_FreeSurface(screen);
            ????SDL_Quit();

            ????
            return ? 0 ;????
            }

            mousedown.jpg
            posted on 2007-03-12 20:10 大熊貓 閱讀(1790) 評論(3)  編輯 收藏 引用

            Feedback

            # re: SDL游戲編程(8)鼠標(biāo)事件 2007-04-17 17:48 brick
            Orz...
            正在學(xué)習(xí)SDL,受益。。。  回復(fù)  更多評論
              

            # re: SDL游戲編程(8)鼠標(biāo)事件 2007-07-12 12:34 溺水的魚
            有個問題,一般情況下我們用的都是主surface(即程序啟動時由SDL_SetVideoMode創(chuàng)建的surface),此時往這個surface上用SDL_BlitSurface來blit一個虛擬surface(即由SDL_CreateRGBSurface創(chuàng)建的surface)時是可以的,但是如果把一個虛擬surface用SDL_BlitSurface來blit另一個虛擬surface上時為什么顯示不出來  回復(fù)  更多評論
              

            # re: SDL游戲編程(8)鼠標(biāo)事件 2007-12-23 21:42 秦歌
            頂  回復(fù)  更多評論
              


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            日本久久久久亚洲中字幕| 久久久青草久久久青草| 久久久艹| 久久亚洲sm情趣捆绑调教 | 午夜精品久久久久久99热| 国产成人精品综合久久久久 | 精品久久久久久国产三级| 亚洲午夜精品久久久久久浪潮| 亚洲精品乱码久久久久久按摩 | 一本大道加勒比久久综合| 一级做a爰片久久毛片看看| 精品无码久久久久国产| 久久免费国产精品| 久久99国产精品99久久| 91麻豆国产精品91久久久| 97精品国产97久久久久久免费| 亚洲中文字幕伊人久久无码| 久久青青草原精品影院| 熟妇人妻久久中文字幕| 狠狠色丁香久久婷婷综合蜜芽五月 | 99久久人妻无码精品系列| 久久无码一区二区三区少妇| 国产精品久久精品| 久久丫忘忧草产品| 一级女性全黄久久生活片免费 | 久久婷婷色香五月综合激情| 亚洲中文字幕久久精品无码APP| 久久综合久久久| 人妻久久久一区二区三区| 久久天天躁狠狠躁夜夜不卡| 久久国产成人| 精品一久久香蕉国产线看播放| 久久青草国产手机看片福利盒子| 国产情侣久久久久aⅴ免费| 婷婷久久香蕉五月综合加勒比| 精品一二三区久久aaa片| 亚洲欧美国产精品专区久久| 漂亮人妻被中出中文字幕久久| 亚洲国产高清精品线久久 | 久久av高潮av无码av喷吹| 亚洲狠狠综合久久|