| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> c/c++ >> C++ kua ping tai you xi kai fa zhi ClanLibSDK

C++ kua ping tai you xi kai fa zhi ClanLibSDK

2008-06-01 02:08:08 编辑來源:互联网 评论
 
 
 
本文为【C++跨平台游戏开发之ClanLibSDK】的拼音翻译版
  yi 、 jian jie ClanLib shi yi ge zhu yao zhen dui you xi kai fa zhe de kua ping tai C++ kuang jia 。 jin guan API zhu yao wei you xi kai fa she ji , ni zhao yang ke yi qing yi di shi yong ClanLib lai kai fa yi ge ke xue de 3D ke shi hua gong ju huo duo mei ti ying yong cheng xu ( li ru Gecko duo mei ti xi tong )。ClanLib yong you ge zhong API-2D he 3D tu xing , sheng yin , wang luo ,I/O, shu ru ,GUI yi ji zi yuan zhi li 。 ta huan ti gong tou ming de OpenGL zhi chi , yin ci ni ke yi shi yong ben ji OpenGL ming ling er rang ClanLib chu li yi kao yu cao zuo xi tong de chuang kou zhi li he qi ta yi qie shi qing 。ClanLib tong guo DirectX huo jian dan de Direct Media Layer( yi ping tai du li de duo mei ti ku ) sheng cheng 2D tu xing 。ClanLib you xi zhu ye shang lie ju le yue 50 duo ge kai fa fei chang cheng gong de you xi , bao kuo yi 2D he 3D xing shi wan cheng de nan ti 、 ce lue yi ji she shou lei you xi 。 li ru ,Asteroid Arena( jian tu 1) shi yong le ClanLib he OpenGL ji shu , shi xian le sheng ren yi chou de jing dian jie ji you xi 。
C++跨平台游戏开发之ClanLibSDK

  tu 1.Asteroid Arena ping mu kuai zhao
  ClanLib ke yi gong zuo zai Windows,linux he MacOS cao zuo xi tong zhi shang , bing qie ti gong yuan ma ji de zip huo tar wen jian zhi chi 。Windows kai fa zhe ke yi shi yong wei ruan Visual Studio,Borland C++ huo zhe MinGW( xiao xing GNU for Windows) bian yi qi he huan jing 。 di san fang de dui yu Ruby he Perl yu yan de bang ding zhi chi ye shi ke yong de 。 ke xuan de te xiao cheng xu bao kuo yi ge Lua cha jian ( liu xing de xiao jiao ben bian cheng yu yan ) he FreeType( yi ge mian fei de TrueType zi ti ku )。
  er 、 ClanLib te zheng ji
  zai ju ti shi yong API zhi qian , rang wo men kan yi xia ClanLib de zhu yao te zheng :
  · ji ben kua ping tai yun xing shi ke ku (GUI, duo xian cheng , wen jian I/O, deng deng )
  · ji yu mo ban de C++ xin hao / cao ku ( lei xing an quan de hui tiao / dai li )
  · zong he de zi yuan zhi li
  · sheng yin hun he qi zhi chi 。WAV wen jian ,Ogg Vorbis, yi ji you MikMod ku (MOD,S3M,XM, deng deng ) zhi chi de ren he lei xing wen jian
  · wen dang dui xiang mo xing (DOM)xml fen xi qi zhi chi
  · gao ji 2D tu xing API, zhi chi OpenGL,DirectX he SDL zuo wei zhe se mu biao
  · gao xing neng de pi liang zhe se yin qing , dang yong OpenGL zhe se 2D shi
  ·2D peng zhuang jian ce
  ·2D jing ling dong hua zhi chi
  · gao du ke ding zhi de GUI kuang jia
  · cong di ji dao gao ji de wang luo ku jie kou
  san 、 ClanLib ji ben de you xi mo xing
  xian zai , rang wo men zai xi fen xi yi xia ClanLib API mo xing 。 wo fa xian zui hao de jiao cheng shi yi ge wan quan zi jie shi de shi li cheng xu 。 ju ti di , rang wo men fen xi yi xia Luke Worth de he zi you xi , zhe shi yi ge you liang ge wan jia de zhi he qian bi you xi ( jian tu 2)。 zhe ge he zi you xi bao han yi xie ge zi dian , zai ren yi liang dian jian wan jia dou ke yi hua xian 。 shui yong zui hou yi tiao xian hua cheng yi ge feng zhuang de ju xing , shui jiu de yi fen , bing jin ru dao xia yi lun zhong 。
C++跨平台游戏开发之ClanLibSDK

  tu 2. yi ge jin xing zhong de he zi you xi , de fen qing kuang shi lan 8/ hong 3
  wo te yi shi cheng xu de main han shu jin ke neng jian duan , zhe yang wo men ke neng ji zhong zhu chong li yu gao liang chu de " you xi xun huan ":
  1 #include <iostream>
  2 #include <ClanLib/application.h>
  3 #include <ClanLib/core.h>
  4 #include <ClanLib/display.h>
  5 #include <ClanLib/gl.h>
  6 #include <ClanLib/sound.h>
  7 #include <ClanLib/vorbis.h>
  8
  9 const int boardsize = 6, spacing = 50, border = 20;
  
   10 const int numsquares = int(pow(float(boardsize - 1), 2));
  11
  12 enum coloursquare { off, blue, red };
  13 strUCt cursor {
  14 int x, y;
  15 bool vert;
  16 };
  17
  18 class Boxes: public CL_ClanApplication {
  19 bool ver[boardsize][boardsize - 1];
  20 bool hor[boardsize - 1][boardsize];
  21 coloursquare squares[boardsize - 1][boardsize - 1];
  22 bool redturn;
  23 bool fullup;
  24 cursor curs;
  25
  26 void inputHandler(const CL_InputEvent &i);
  27 bool findsquares(void);
  28 inline int numaroundsquare(int x, int y);
  29 void init();
  30 void drawBoard();
  31 void endOfGame();
  32
  33 public:
  34 virtual int Boxes::main(int, char **);
  35 } app;
  36
  37 using namespace std;
  40
  41 int Boxes::main(int, char **)
  42 {
  43 int winsize = spacing * (boardsize - 1) + border * 2;
  44 try {
  45 Boxes::init();
  46 while (!CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) {
  47 Boxes::drawBoard();
  48 if (fullup) break;
  49 CL_System::keep_alive(20);
  50 }
  51 Boxes::endOfGame();
  52
  53 CL_SetupVorbis::deinit();
  54 CL_SetupSound::deinit();
  55 CL_SetupGL::deinit();
  56 CL_SetupDisplay::deinit();
  57 CL_SetupCore::deinit();
  58 }
  59 catch (CL_Error err) {
  60 std::cout << "Exception caught: "<< err.message.c_str() << std::endl;
  61 }
  62
  63 return 0;
  64 }
  guan yu zhe ge ying yong cheng xu , ying zhu chong de di yi shi qing shi main() han shu ( jian xing 41) bing bu shi yi ge zui ding ceng de han shu , er shi qian ru dao yi ge cong CL_ClanApplication pai sheng de dui xiang zhong 。 gai dui xiang feng zhuang le bu shao nan yi bi mian de ping tai yi kao xing - zhe ke neng bao han yi ge chuan tong de ::main() shi xian ( li ru zai Win32 ying yong cheng xu zhong bi xu shi yong WinMain())。
  er qie huan ying zhu chong , shi shi shang suo you de ke zhi xing de dai ma ( xing 43-58) bei feng zhuang zai yi ge try{}/catch{} yi chang chu li qi kuai zhong 。 jia ru xu yao de hua ,ClanLib jiang yin fa yi chang , ni ke yi chong qi yi you xi , deng deng 。 ji ben shang , suo you de you xi luo ji bao han zai init(),drawBoard(),endOfGame() he inputHandler() zhe ji ge fang fa zhong 。 jia ru board bu zai yi dong (fullup==true), ze tui chu you xi xun huan ( xing 48)。CL_System::keep_alive() geng xin suo you de shu ru he xi tong shi jian ( xiang guan bi chuang kou huo zhe yi dong ta )。 zhe zai lao shi de Win16 API ::Yield() huo zhe Linux shang de sleep() zhong jiang hui shi fang CPU zhou qi 。
  66 void Boxes::init()
  67 {
  68 CL_SetupCore::init();
  69 CL_SetupDisplay::init();
  70 CL_SetupGL::init();
  71 CL_SetupSound::init();
  72 CL_SetupVorbis::init();
  73
  74 CL_DisplayWindow window("Boxes", winsize, winsize);
  75 CL_SoundOutput output(44100); // xuan ze 44Khz cai yang
  76
  77 CL_Surface *cursimg = new CL_Surface("cursor.tga");
  78 cursimg->set_alignment(origin_center);
  79 CL_Surface *redpict = new CL_Surface("handtransp.tga");
  80 redpict->set_alignment(origin_center);
  81 redpict->set_scale(float(spacing)/float(redpict->get_width()),
  82 float(spacing)/float(redpict->get_height()));
  83 CL_Surface *bluepict = new CL_Surface("circlehandtransp.tga");
  84 bluepict->set_alignment(origin_center);
  85 bluepict->set_scale(float(spacing) / float(bluepict->get_width()),
  86 float(spacing) / float(bluepict->get_height()));
  87
  zhe li de init() fang fa wan cheng da bu fen de you xi chu shi hua gong zuo 。 dang ran , zai ci xu yao ClanLib zi xi tong yi yong yu chu li tu xing he sheng yin ( xing 68-72), ran hou gou jian yi ge chuang kou yong yu xian shi suo you de tu xing ( xing 75)。
  
  
  CL_Surface( xing 77-87) shi yi ge 2D wei tu lei , yong yu hui zhi guang biao , yong lan se tian chong de fang ge he yong hong se tian chong de fang ge 。
  TGA wen jian shi yi zhong wei tu wen jian ge shi 。ClanLib you yi ge ji cheng de PNG ku , yin ci ta ke yi du xie zui liu xing de wei tu wen jian ge shi hua 。
  xia yi bu , ni bi xu ba ban zi chu shi hua cheng yi ge kong zhuang tai ( xing 87-103) bing zhi xing lei si de qi ta de qing li gong zuo yi shi xian xin de you xi ji shu qi 。
  89
  90 redturn = true;
  91 curs.vert = false;
  92 fullup = false;
  93 curs.x = curs.y = 1;
  94
  95 srand(CL_System::get_time()); // qi dong sui ji shu zi sheng cheng qi
  96
  97 for (int x = 0; x < boardsize - 1; x++) {
  98 for (int y = 0; y < boardsize; y++)
  99 hor[x][y] = ver[y][x] = false;
  100
  101 for (int y = 0; y < boardsize - 1; y++)
  102 squares[x][y] = off;
  103
  104
  ClanLib de yi ge fei fan tu chu de fang mian shi ta bi kai chuan tong xing ying yong yu xu duo kuang jia zhong de hui tiao mo xing , er yin ru le " xin hao he cao " mo xing 。 zhe zhong mo xing guang fan ying yong yu Boost C++ ku zhong , bing zai QT zhong de dao shi xian 。 xin hao dai biao ju you duo ge mu biao de hui tiao han shu , you zai yi xie lei si de xi tong zhong cheng zuo " chu ban zhe " huo zhe " shi jian "。 xin hao bei lian jie dao yi xie cao shang , ta men shi hui tiao han shu jie shou qi ( ye cheng zuo shi jian mu biao huo zhe ding hu ), dang xin hao bei " fa chu " shi ji bei tiao yong 。 xin hao ju you lei xing an quan de you dian , ta men bi kai le zai chuan tong xing de kuang jia zhong de bu ke bi mian de cast cao zuo 。
  xin hao he cao bei tong yi zhi li 。 zai xin hao he cao zhong ( huo zhe geng zhun que xie shuo shi , zuo wei cao de yi bu fen chu xian de dui xiang ) gen zong suo you de lian jie , bing dang ren he qi yi bei po huai shi neng gou zi dong di duan kai xin hao / cao lian jie 。 zhe neng gou shi yong hu jian li xin hao / cao lian jie er bu xu yao hua fei duo da de dai jia lai zhi li na xie lian jie yi ji suo you bao han yu qi zhong de dui xiang de sheng ming zhou qi 。 zai xing 105 zhong , ni zhi yao bu zhuo suo you de jian ji ("down") shi jian bing que bao shi yong le ni zi ji de inputHandler()( jian xing 168-216)。
  105 CL_Slot keyPRess =
  CL_Keyboard::sig_key_down().connect(this,
  &Boxes::inputHandler);
  xian zai , ni jiang kai shi chu shi hua cheng xu de yin le bu fen 。 shou xian , ni yong yi ge .wav ge shi de ("binary") yin le wen jian zhuang zai yi ge CL_SoundBuffer, ran hou yu bei yi ge hui hua ju bing yi wei wan you xi zhi yong 。 xia yi bu , ni ying yong yi ge dan ru dan chu guo lv qi lai yi bu di tiao zheng yin liang - zai wu miao ( xing 108-112) nei ba yin liang cong ling bian hua dao zui da yin liang de bai fen zhi liu shi 。
  106 CL_SoundBuffer *music = new CL_SoundBuffer("linemusic.ogg");
  107 CL_SoundBuffer_session session = music->prepare();
  108 CL_FadeFilter *fade = new CL_FadeFilter(0.0f);
  109 session.add_filter(fade);
  110 session.set_looping(true);
  111 session.play();
  112 fade->fade_to_volume(0.6f, 5000);
  113 }
  drawBoard() fang fa hui zhi xian duan suo zai de dian hua ge zi tu an , ru , mei ge wan jia ying de de hong se de xi hong shi he lan se de shi che ju kuang chu de fang ge , huan you mo ni de guang biao 。 er zui chong yao de dai ma xing shi di 165 xing 。CL_Display::flip() jiao huan qian hou tai huan chong qu 。 hou tai huan chong qu shi zai gai zhen zhong ni hui zhi suo you tu xing de di fang , er qian tai huan chong qu shi xian shi zai ping mu shang de nei rong 。
  115 void Boxes::drawBoard()
  116 {
  117 CL_Display::clear(redturn ? CL_Color::red : CL_Color::blue);
  118 CL_Display::fill_rect(CL_Rect(border/2, border/2,
  119 winsize - border/2, winsize - border/2),CL_Color::black);
  120
  121 // hua fang kuang
  122 for (int x = 0; x < boardsize - 1; x++)
  123 for (int y = 0; y < boardsize - 1; y++) {
  124 if (squares[x][y] == red) {
  125 CL_Display::fill_rect(CL_Rect(x * spacing + border,y * spacing + border, x * spacing + border +
  spacing,
  127 y * spacing + border + spacing),CL_Gradient(CL_Color::red,
  128 CL_Color::red, CL_Color::tomato, CL_Color::tomato));
  129 redpict->draw(x * spacing + border + spacing / 2,
  130 y * spacing + border + spacing / 2);
  131 }
  132 else if (squares[x][y] == blue) {
  133 CL_Display::fill_rect(CL_Rect(x * spacing + border,
  134 y * spacing + border,x * spacing + border +spacing,
  135 y * spacing + border +spacing),CL_Gradient(CL_Color::blue,
  136 CL_Color::blue, CL_Color::cornflowerblue,CL_Color::cornflowerblue));
  137 bluepict->draw(x * spacing + border + spacing / 2,y * spacing + border + spacing / 2);
  139 }
  140 }
  141
  142 // hua xian
  
   143 for (int x = 0; x < boardsize; x++) {
  144 for (int y = 0; y < boardsize - 1; y++) {
  145 if (ver[x][y]) CL_Display::draw_line(x * spacing + border,
  146 y * spacing + border,x * spacing + border,
  147 y * spacing + border+ spacing,CL_Color::yellow);
  148 if (hor[y][x]) CL_Display::draw_line(y * spacing + border,
  149 x * spacing + border,y * spacing + border+ spacing,x * spacing + border,CL_Color::yellow);
  151 }
  152 }
  153
  154 // hua ge zi
  155 for (int x = 0; x < boardsize; x++)
  156 for (int y = 0; y < boardsize; y++)
  157 CL_Display::draw_rect(CL_Rect(x * spacing + border,
  158 y * spacing + border,x * spacing + border + 2,159 y * spacing + border + 2),CL_Color::white);
  160
  161 // hua guang biao
  162 if (curs.vert) cursimg->draw((curs.x - 1) * spacing + border,int((curs.y - 0.5) * spacing + border));
  163 else cursimg->draw(int((curs.x - 0.5) * spacing + border),(curs.y - 1) * spacing + border);
  164
  165 CL_Display::flip();
  166 }
  ni an zhuang de inputHandler() han shu yong yu guan cha zai xing 105 de an jian xin hao 。 zhe ge han shu fu ze chu li xi jie wen ti - ba jian ji bian cheng you xi yun dong , huan you zui chong yao de kong ge huo zhe hui che jian - yong yu zhi shi dang qian wan jia de yi ge xuan ze ( xing 200-210)。 ran hou , ni yao jian cha yi xia shi fou yi wan cheng le yi ge " fang xing " bing ba kong zhi fan hui dao yuan lai de wan jia 。
  168 void Boxes::inputHandler(const CL_InputEvent &i)
  169 {
  170 if (redturn) {
  171 switch(i.id) {
  172 case CL_KEY_LEFT:
  173 case CL_KEY_G:
  174 if (curs.x > 1) curs.x--;
  175 break;
  176 case CL_KEY_RIGHT:
  177 case CL_KEY_J:
  178 if (curs.x < boardsize) curs.x++;
  179 break;
  180 case CL_KEY_UP:
  181 case CL_KEY_Y:
  182 if (!curs.vert && curs.y > 1) {
  183 curs.y--;
  184 curs.vert = !curs.vert;
  185 }
  186 else if (curs.vert) curs.vert = false;
  187 break;
  188 case CL_KEY_DOWN:
  189 case CL_KEY_H:
  190 if (curs.vert && curs.y < boardsize) {
  191 curs.y++;
  192 curs.vert = !curs.vert;
  193 }
  194 else if (!curs.vert) curs.vert = true;
  195 break;
  196 }
  197 if (curs.x == boardsize && !curs.vert) curs.x--;
  198 if (curs.y == boardsize && curs.vert)
  curs.vert = false;
  199
  200 if (i.id == CL_KEY_SPACE i.id == CL_KEY_ENTER) {
  201 if (curs.vert) {
  202 if (!ver[curs.x-1][curs.y-1]) {
  203 ver[curs.x-1][curs.y-1] = true;
  204 if (!findsquares()) redturn = !redturn;
  205 }
  206 }
  207 else {
  208 if (!hor[curs.x-1][curs.y-1]) {
  209 hor[curs.x-1][curs.y-1] = true;
  210 if (!findsquares()) redturn = !redturn;
  211 }
  212 }
  213 }
  214 }
  215 }
  zui hou , you endOfGame() fang fa ji suan zui hou de de fen 。 ji zhu you xi huan mei you jie shu , zhi dao ban zi man le wei zhi ( jian xing 48) huo zhe mou ren tong guo an xia ESC jian ( jian xing 46) tui chu 。 zui hou , ni yong da yue 1 miao de shi jian ba yin liang dan chu dao 0。
  217 void Boxes::endOfGame()
  218 {
  219 // ji shu de fen
  220 int redscore, bluescore;
  221 redscore = bluescore = 0;
  222 for (int x = 0; x < boardsize - 1; x++)
  223 for (int y = 0; y < boardsize - 1; y++) {
  
   224 if (squares[x][y] == red) redscore++;
  225 else if (squares[x][y] == blue) bluescore++;
  226 }
  227
  228 cout << "Red: " << redscore << "\nBlue: " << bluescore << endl;
  229 if (bluescore != redscore)
  230 cout << (bluescore > redscore ? "Blue" : "Red") << " player wins\n";
  231 else cout << "It was a tie\n";
  232
  233 if (fullup) {
  234 fade->fade_to_volume(0.0f, 1000);
  235 CL_System::sleep(1000);
  236 }
  237 }【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
yi 、 jian jie  ClanLib shi yi ge zhu yao zhen dui you xi kai fa zhe de kua ping tai C++ kuang jia 。 jin guan API zhu yao wei you xi kai fa she ji , ni zhao yang ke yi qing yi di shi yong ClanLib lai kai fa yi ge ke xue de 3D ke shi hua gong ju huo duo mei ti ying yong cheng xu ( li ru Gecko duo mei ti xi tong )。 ClanLib yong you ge zhong API-2D he 3D tu xing , sheng yin , wang luo ,I/O, shu ru ,GUI yi ji zi yuan zhi li 。 ta huan ti gong tou ming de OpenGL zhi chi , yin ci ni ke yi shi yong ben ji OpenGL ming ling er rang ClanLib chu li yi kao yu cao zuo xi tong de chuang kou zhi li he qi ta yi qie shi qing 。ClanLib tong guo DirectX huo jian dan de Direct Media Layer( yi ping tai du li de duo mei ti ku ) sheng cheng 2D tu xing 。ClanLib you xi zhu ye shang lie ju le yue 50 duo ge kai fa fei chang cheng gong de you xi , bao kuo yi 2D he 3D xing shi wan cheng de nan ti 、 ce lue yi ji she shou lei you xi 。 li ru ,Asteroid Arena( jian tu 1) shi yong le ClanLib he OpenGL ji shu , shi xian le sheng ren yi chou de jing dian jie ji you xi 。 [url=http://www.wangchao.net.cn/bbs/pydetail_1785417.html][img]http://image.wangchao.net.cn/it/1323423490174.jpg[/img][/url] tu 1.Asteroid Arena ping mu kuai zhao   ClanLib ke yi gong zuo zai Windows,linux he MacOS cao zuo xi tong zhi shang , bing qie ti gong yuan ma ji de zip huo tar wen jian zhi chi 。Windows kai fa zhe ke yi shi yong wei ruan Visual Studio,Borland C++ huo zhe MinGW( xiao xing GNU for Windows) bian yi qi he huan jing 。 di san fang de dui yu Ruby he Perl yu yan de bang ding zhi chi ye shi ke yong de 。 ke xuan de te xiao cheng xu bao kuo yi ge Lua cha jian ( liu xing de xiao jiao ben bian cheng yu yan ) he FreeType( yi ge mian fei de TrueType zi ti ku )。    er 、 ClanLib te zheng ji    zai ju ti shi yong API zhi qian , rang wo men kan yi xia ClanLib de zhu yao te zheng :   · ji ben kua ping tai yun xing shi ke ku (GUI, duo xian cheng , wen jian I/O, deng deng )   · ji yu mo ban de C++ xin hao / cao ku ( lei xing an quan de hui tiao / dai li )   · zong he de zi yuan zhi li   · sheng yin hun he qi zhi chi 。WAV wen jian ,Ogg Vorbis, yi ji you MikMod ku (MOD,S3M,XM, deng deng ) zhi chi de ren he lei xing wen jian   · wen dang dui xiang mo xing (DOM)xml fen xi qi zhi chi   · gao ji 2D tu xing API, zhi chi OpenGL,DirectX he SDL zuo wei zhe se mu biao   · gao xing neng de pi liang zhe se yin qing , dang yong OpenGL zhe se 2D shi   ·2D peng zhuang jian ce   ·2D jing ling dong hua zhi chi   · gao du ke ding zhi de GUI kuang jia   · cong di ji dao gao ji de wang luo ku jie kou    san 、 ClanLib ji ben de you xi mo xing    xian zai , rang wo men zai xi fen xi yi xia ClanLib API mo xing 。 wo fa xian zui hao de jiao cheng shi yi ge wan quan zi jie shi de shi li cheng xu 。 ju ti di , rang wo men fen xi yi xia Luke Worth de he zi you xi , zhe shi yi ge you liang ge wan jia de zhi he qian bi you xi ( jian tu 2)。 zhe ge he zi you xi bao han yi xie ge zi dian , zai ren yi liang dian jian wan jia dou ke yi hua xian 。 shui yong zui hou yi tiao xian hua cheng yi ge feng zhuang de ju xing , shui jiu de yi fen , bing jin ru dao xia yi lun zhong 。 [url=http://www.wangchao.net.cn/bbs/pydetail_1785417.html][img]http://image.wangchao.net.cn/it/1323423490343.jpg[/img][/url] tu 2. yi ge jin xing zhong de he zi you xi , de fen qing kuang shi lan 8/ hong 3    wo te yi shi cheng xu de main han shu jin ke neng jian duan , zhe yang wo men ke neng ji zhong zhu chong li yu gao liang chu de " you xi xun huan ": 1 #include <iostream> 2 #include <ClanLib/application.h> 3 #include <ClanLib/core.h> 4 #include <ClanLib/display.h> 5 #include <ClanLib/gl.h> 6 #include <ClanLib/sound.h> 7 #include <ClanLib/vorbis.h> 8 9 const int boardsize = 6, spacing = 50, border = 20; 10 const int numsquares = int(pow(float(boardsize - 1), 2)); 11 12 enum coloursquare { off, blue, red }; 13 strUCt cursor { 14  int x, y; 15  bool vert; 16 }; 17 18 class Boxes: public CL_ClanApplication { 19  bool ver[boardsize][boardsize - 1]; 20  bool hor[boardsize - 1][boardsize]; 21  coloursquare squares[boardsize - 1][boardsize - 1]; 22  bool redturn; 23  bool fullup; 24  cursor curs; 25 26  void inputHandler(const CL_InputEvent &i); 27  bool findsquares(void); 28  inline int numaroundsquare(int x, int y); 29  void init(); 30  void drawBoard(); 31  void endOfGame(); 32 33 public: 34  virtual int Boxes::main(int, char **); 35 } app; 36 37 using namespace std; 40 41 int Boxes::main(int, char **) 42 { 43  int winsize = spacing * (boardsize - 1) + border * 2; 44  try { 45   Boxes::init(); 46   while (!CL_Keyboard::get_keycode(CL_KEY_ESCAPE)) { 47    Boxes::drawBoard(); 48    if (fullup) break; 49     CL_System::keep_alive(20); 50   } 51   Boxes::endOfGame(); 52 53   CL_SetupVorbis::deinit(); 54   CL_SetupSound::deinit(); 55   CL_SetupGL::deinit(); 56   CL_SetupDisplay::deinit(); 57   CL_SetupCore::deinit(); 58  } 59  catch (CL_Error err) { 60   std::cout << "Exception caught: "<< err.message.c_str() << std::endl; 61  } 62 63  return 0; 64 }    guan yu zhe ge ying yong cheng xu , ying zhu chong de di yi shi qing shi main() han shu ( jian xing 41) bing bu shi yi ge zui ding ceng de han shu , er shi qian ru dao yi ge cong CL_ClanApplication pai sheng de dui xiang zhong 。 gai dui xiang feng zhuang le bu shao nan yi bi mian de ping tai yi kao xing - zhe ke neng bao han yi ge chuan tong de ::main() shi xian ( li ru zai Win32 ying yong cheng xu zhong bi xu shi yong WinMain())。    er qie huan ying zhu chong , shi shi shang suo you de ke zhi xing de dai ma ( xing 43-58) bei feng zhuang zai yi ge try{}/catch{} yi chang chu li qi kuai zhong 。 jia ru xu yao de hua ,ClanLib jiang yin fa yi chang , ni ke yi chong qi yi you xi , deng deng 。 ji ben shang , suo you de you xi luo ji bao han zai init(),drawBoard(),endOfGame() he inputHandler() zhe ji ge fang fa zhong 。 jia ru board bu zai yi dong (fullup==true), ze tui chu you xi xun huan ( xing 48)。CL_System::keep_alive() geng xin suo you de shu ru he xi tong shi jian ( xiang guan bi chuang kou huo zhe yi dong ta )。 zhe zai lao shi de Win16 API ::Yield() huo zhe Linux shang de sleep() zhong jiang hui shi fang CPU zhou qi 。 66 void Boxes::init() 67 { 68  CL_SetupCore::init(); 69  CL_SetupDisplay::init(); 70  CL_SetupGL::init(); 71  CL_SetupSound::init(); 72  CL_SetupVorbis::init(); 73 74  CL_DisplayWindow window("Boxes", winsize, winsize); 75  CL_SoundOutput output(44100); // xuan ze 44Khz cai yang 76 77  CL_Surface *cursimg = new CL_Surface("cursor.tga"); 78  cursimg->set_alignment(origin_center); 79  CL_Surface *redpict = new CL_Surface("handtransp.tga"); 80  redpict->set_alignment(origin_center); 81  redpict->set_scale(float(spacing)/float(redpict->get_width()), 82  float(spacing)/float(redpict->get_height())); 83  CL_Surface *bluepict = new CL_Surface("circlehandtransp.tga"); 84  bluepict->set_alignment(origin_center); 85  bluepict->set_scale(float(spacing) / float(bluepict->get_width()), 86  float(spacing) / float(bluepict->get_height())); 87    zhe li de init() fang fa wan cheng da bu fen de you xi chu shi hua gong zuo 。 dang ran , zai ci xu yao ClanLib zi xi tong yi yong yu chu li tu xing he sheng yin ( xing 68-72), ran hou gou jian yi ge chuang kou yong yu xian shi suo you de tu xing ( xing 75)。   CL_Surface( xing 77-87) shi yi ge 2D wei tu lei , yong yu hui zhi guang biao , yong lan se tian chong de fang ge he yong hong se tian chong de fang ge 。   TGA wen jian shi yi zhong wei tu wen jian ge shi 。ClanLib you yi ge ji cheng de PNG ku , yin ci ta ke yi du xie zui liu xing de wei tu wen jian ge shi hua 。    xia yi bu , ni bi xu ba ban zi chu shi hua cheng yi ge kong zhuang tai ( xing 87-103) bing zhi xing lei si de qi ta de qing li gong zuo yi shi xian xin de you xi ji shu qi 。 89 90 redturn = true; 91 curs.vert = false; 92 fullup = false; 93 curs.x = curs.y = 1; 94 95 srand(CL_System::get_time()); // qi dong sui ji shu zi sheng cheng qi 96 97 for (int x = 0; x < boardsize - 1; x++) { 98  for (int y = 0; y < boardsize; y++) 99  hor[x][y] = ver[y][x] = false; 100 101  for (int y = 0; y < boardsize - 1; y++) 102   squares[x][y] = off; 103 104   ClanLib de yi ge fei fan tu chu de fang mian shi ta bi kai chuan tong xing ying yong yu xu duo kuang jia zhong de hui tiao mo xing , er yin ru le " xin hao he cao " mo xing 。 zhe zhong mo xing guang fan ying yong yu Boost C++ ku zhong , bing zai QT zhong de dao shi xian 。 xin hao dai biao ju you duo ge mu biao de hui tiao han shu , you zai yi xie lei si de xi tong zhong cheng zuo " chu ban zhe " huo zhe " shi jian "。 xin hao bei lian jie dao yi xie cao shang , ta men shi hui tiao han shu jie shou qi ( ye cheng zuo shi jian mu biao huo zhe ding hu ), dang xin hao bei " fa chu " shi ji bei tiao yong 。 xin hao ju you lei xing an quan de you dian , ta men bi kai le zai chuan tong xing de kuang jia zhong de bu ke bi mian de cast cao zuo 。    xin hao he cao bei tong yi zhi li 。 zai xin hao he cao zhong ( huo zhe geng zhun que xie shuo shi , zuo wei cao de yi bu fen chu xian de dui xiang ) gen zong suo you de lian jie , bing dang ren he qi yi bei po huai shi neng gou zi dong di duan kai xin hao / cao lian jie 。 zhe neng gou shi yong hu jian li xin hao / cao lian jie er bu xu yao hua fei duo da de dai jia lai zhi li na xie lian jie yi ji suo you bao han yu qi zhong de dui xiang de sheng ming zhou qi 。 zai xing 105 zhong , ni zhi yao bu zhuo suo you de jian ji ("down") shi jian bing que bao shi yong le ni zi ji de inputHandler()( jian xing 168-216)。 105 CL_Slot keyPRess = CL_Keyboard::sig_key_down().connect(this, &Boxes::inputHandler);    xian zai , ni jiang kai shi chu shi hua cheng xu de yin le bu fen 。 shou xian , ni yong yi ge .wav ge shi de ("binary") yin le wen jian zhuang zai yi ge CL_SoundBuffer, ran hou yu bei yi ge hui hua ju bing yi wei wan you xi zhi yong 。 xia yi bu , ni ying yong yi ge dan ru dan chu guo lv qi lai yi bu di tiao zheng yin liang - zai wu miao ( xing 108-112) nei ba yin liang cong ling bian hua dao zui da yin liang de bai fen zhi liu shi 。 106 CL_SoundBuffer *music = new CL_SoundBuffer("linemusic.ogg"); 107 CL_SoundBuffer_session session = music->prepare(); 108 CL_FadeFilter *fade = new CL_FadeFilter(0.0f); 109 session.add_filter(fade); 110 session.set_looping(true); 111 session.play(); 112 fade->fade_to_volume(0.6f, 5000); 113 }   drawBoard() fang fa hui zhi xian duan suo zai de dian hua ge zi tu an , ru , mei ge wan jia ying de de hong se de xi hong shi he lan se de shi che ju kuang chu de fang ge , huan you mo ni de guang biao 。 er zui chong yao de dai ma xing shi di 165 xing 。CL_Display::flip() jiao huan qian hou tai huan chong qu 。 hou tai huan chong qu shi zai gai zhen zhong ni hui zhi suo you tu xing de di fang , er qian tai huan chong qu shi xian shi zai ping mu shang de nei rong 。 115 void Boxes::drawBoard() 116 { 117  CL_Display::clear(redturn ? CL_Color::red : CL_Color::blue); 118  CL_Display::fill_rect(CL_Rect(border/2, border/2, 119    winsize - border/2, winsize - border/2),CL_Color::black); 120 121  // hua fang kuang 122  for (int x = 0; x < boardsize - 1; x++) 123   for (int y = 0; y < boardsize - 1; y++) { 124    if (squares[x][y] == red) { 125     CL_Display::fill_rect(CL_Rect(x * spacing + border,y * spacing + border, x * spacing + border +         spacing, 127       y * spacing + border + spacing),CL_Gradient(CL_Color::red, 128       CL_Color::red, CL_Color::tomato, CL_Color::tomato)); 129     redpict->draw(x * spacing + border + spacing / 2, 130        y * spacing + border + spacing / 2); 131    } 132    else if (squares[x][y] == blue) { 133      CL_Display::fill_rect(CL_Rect(x * spacing + border, 134      y * spacing + border,x * spacing + border +spacing, 135        y * spacing + border +spacing),CL_Gradient(CL_Color::blue, 136        CL_Color::blue, CL_Color::cornflowerblue,CL_Color::cornflowerblue)); 137      bluepict->draw(x * spacing + border + spacing / 2,y * spacing + border + spacing / 2); 139    } 140   } 141 142   // hua xian 143   for (int x = 0; x < boardsize; x++) { 144    for (int y = 0; y < boardsize - 1; y++) { 145     if (ver[x][y]) CL_Display::draw_line(x * spacing + border, 146       y * spacing + border,x * spacing + border, 147       y * spacing + border+ spacing,CL_Color::yellow); 148     if (hor[y][x]) CL_Display::draw_line(y * spacing + border, 149       x * spacing + border,y * spacing + border+ spacing,x * spacing + border,CL_Color::yellow); 151     } 152   } 153 154   // hua ge zi 155   for (int x = 0; x < boardsize; x++) 156    for (int y = 0; y < boardsize; y++) 157     CL_Display::draw_rect(CL_Rect(x * spacing + border, 158       y * spacing + border,x * spacing + border + 2,159 y * spacing + border + 2),CL_Color::white); 160 161     // hua guang biao 162     if (curs.vert) cursimg->draw((curs.x - 1) * spacing + border,int((curs.y - 0.5) * spacing + border)); 163     else cursimg->draw(int((curs.x - 0.5) * spacing + border),(curs.y - 1) * spacing + border); 164 165      CL_Display::flip(); 166    }    ni an zhuang de inputHandler() han shu yong yu guan cha zai xing 105 de an jian xin hao 。 zhe ge han shu fu ze chu li xi jie wen ti - ba jian ji bian cheng you xi yun dong , huan you zui chong yao de kong ge huo zhe hui che jian - yong yu zhi shi dang qian wan jia de yi ge xuan ze ( xing 200-210)。 ran hou , ni yao jian cha yi xia shi fou yi wan cheng le yi ge " fang xing " bing ba kong zhi fan hui dao yuan lai de wan jia 。 168 void Boxes::inputHandler(const CL_InputEvent &i) 169 { 170  if (redturn) { 171   switch(i.id) { 172    case CL_KEY_LEFT: 173    case CL_KEY_G: 174     if (curs.x > 1) curs.x--; 175     break; 176    case CL_KEY_RIGHT: 177    case CL_KEY_J: 178     if (curs.x < boardsize) curs.x++; 179     break; 180    case CL_KEY_UP: 181    case CL_KEY_Y: 182     if (!curs.vert && curs.y > 1) { 183      curs.y--; 184      curs.vert = !curs.vert; 185     } 186     else if (curs.vert) curs.vert = false; 187     break; 188    case CL_KEY_DOWN: 189    case CL_KEY_H: 190     if (curs.vert && curs.y < boardsize) { 191      curs.y++; 192      curs.vert = !curs.vert; 193     } 194     else if (!curs.vert) curs.vert = true; 195     break; 196    } 197    if (curs.x == boardsize && !curs.vert) curs.x--; 198    if (curs.y == boardsize && curs.vert)       curs.vert = false; 199 200    if (i.id == CL_KEY_SPACE i.id == CL_KEY_ENTER) { 201     if (curs.vert) { 202      if (!ver[curs.x-1][curs.y-1]) { 203       ver[curs.x-1][curs.y-1] = true; 204       if (!findsquares()) redturn = !redturn; 205      } 206    } 207    else { 208     if (!hor[curs.x-1][curs.y-1]) { 209      hor[curs.x-1][curs.y-1] = true; 210      if (!findsquares()) redturn = !redturn; 211     } 212    } 213   } 214  } 215 }    zui hou , you endOfGame() fang fa ji suan zui hou de de fen 。 ji zhu you xi huan mei you jie shu , zhi dao ban zi man le wei zhi ( jian xing 48) huo zhe mou ren tong guo an xia ESC jian ( jian xing 46) tui chu 。 zui hou , ni yong da yue 1 miao de shi jian ba yin liang dan chu dao 0。 217 void Boxes::endOfGame() 218 { 219  // ji shu de fen 220  int redscore, bluescore; 221  redscore = bluescore = 0; 222  for (int x = 0; x < boardsize - 1; x++) 223   for (int y = 0; y < boardsize - 1; y++) { 224    if (squares[x][y] == red) redscore++; 225    else if (squares[x][y] == blue) bluescore++; 226   } 227 228  cout << "Red: " << redscore << "\nBlue: " << bluescore << endl; 229  if (bluescore != redscore) 230   cout << (bluescore > redscore ? "Blue" : "Red") << " player wins\n"; 231  else cout << "It was a tie\n"; 232 233  if (fullup) { 234   fade->fade_to_volume(0.0f, 1000); 235   CL_System::sleep(1000); 236  } 237 }
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
时尚秀气模特裴裴(8)
时尚秀气模特裴裴(7)
时尚秀气模特裴裴(6)
时尚秀气模特裴裴(5)
白墙黑瓦
广州东郊[原创]
八美至丹巴的东谷天然盆景
不一样的
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有