• <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++博客 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
              21 Posts :: 3 Stories :: 31 Comments :: 0 Trackbacks

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

            #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 大熊貓 閱讀(1822) 評(píng)論(3)  編輯 收藏 引用

            Feedback

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

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

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


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


            久久久无码精品亚洲日韩按摩| 国内精品久久国产| 亚洲国产精品18久久久久久| 日韩欧美亚洲国产精品字幕久久久 | 亚洲精品无码久久久久| 伊人色综合久久天天人守人婷 | 久久亚洲日韩看片无码| 欧美久久亚洲精品| 久久人人添人人爽添人人片牛牛| 香蕉99久久国产综合精品宅男自 | 热99re久久国超精品首页| 久久精品国产精品青草app| 色综合久久精品中文字幕首页| 一本大道久久a久久精品综合| 99久久婷婷国产综合精品草原| 国产精品欧美久久久久无广告| 久久国产成人午夜aⅴ影院| 亚洲?V乱码久久精品蜜桃| 亚洲AV无码一区东京热久久| 99久久人妻无码精品系列| 777久久精品一区二区三区无码 | 久久九九久精品国产免费直播| 人妻丰满AV无码久久不卡| 国产精品VIDEOSSEX久久发布| 无码精品久久一区二区三区| 久久国产精品无码HDAV| 精品久久人人爽天天玩人人妻| 亚洲人AV永久一区二区三区久久| 午夜精品久久久久久毛片| 国产69精品久久久久99| 一97日本道伊人久久综合影院| 99久久婷婷免费国产综合精品| 久久无码AV中文出轨人妻| 日产精品久久久一区二区| 久久这里只有精品视频99| 久久超碰97人人做人人爱| 一级a性色生活片久久无少妇一级婬片免费放 | 久久久久人妻一区精品性色av| 国内精品久久久久久久影视麻豆| 亚洲AV成人无码久久精品老人| 久久电影网|