• <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)事件和鍵盤事件處理方式差的不太多,所以我就直接給出了一個(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 大熊貓 閱讀(1807) 評(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è)問題,一般情況下我們用的都是主surface(即程序啟動(dòng)時(shí)由SDL_SetVideoMode創(chuàng)建的surface),此時(shí)往這個(gè)surface上用SDL_BlitSurface來blit一個(gè)虛擬surface(即由SDL_CreateRGBSurface創(chuàng)建的surface)時(shí)是可以的,但是如果把一個(gè)虛擬surface用SDL_BlitSurface來blit另一個(gè)虛擬surface上時(shí)為什么顯示不出來  回復(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   博問   Chat2DB   管理


            久久99国产精品99久久| 亚洲七七久久精品中文国产| 久久人人爽人人人人爽AV| 超级碰碰碰碰97久久久久| 亚洲精品乱码久久久久久| 久久99国产精一区二区三区| 91精品国产综合久久香蕉 | 久久久久亚洲AV片无码下载蜜桃| 久久久精品国产免大香伊| 97久久精品无码一区二区| 久久国产V一级毛多内射| 久久精品国产99国产精品亚洲| 国产成人久久激情91| 久久亚洲国产最新网站| 久久夜色精品国产亚洲| 偷偷做久久久久网站| 26uuu久久五月天| 亚洲中文精品久久久久久不卡| 99久久精品免费| 精品久久久久香蕉网| yy6080久久| 久久亚洲电影| 精品久久人人爽天天玩人人妻| 蜜臀av性久久久久蜜臀aⅴ麻豆 | 热久久最新网站获取| 国产精品一久久香蕉国产线看 | www.久久99| 亚洲AV日韩AV天堂久久| 污污内射久久一区二区欧美日韩| AA级片免费看视频久久| 久久er99热精品一区二区| 亚洲va久久久噜噜噜久久| 伊人久久大香线蕉综合网站| 久久精品无码一区二区日韩AV| 国产成人无码精品久久久久免费 | 中文国产成人精品久久亚洲精品AⅤ无码精品| 久久久久久亚洲Av无码精品专口| 狠狠色综合网站久久久久久久高清 | 久久午夜无码鲁丝片| 色欲久久久天天天综合网 | 国产成人精品白浆久久69|