天地之灵学习小组
我们学习小组的OpenGL学习笔记 大家一定要互相折磨呀~~
posts - 150,  comments - 156,  trackbacks - 0
  1 #include <GL/glut.h>
  2 #include <ctime>
  3 
  4 #define MULTIPLIER 0x015a4e35L 
  5 #define INCREMENT 1 
  6 
  7 static const unsigned char CD_UP = 24;
  8 static const unsigned char CD_DOWN = 25;
  9 static const unsigned char CD_RIGHT = 26;
 10 static const unsigned char CD_LEFT = 27;
 11 
 12 static const int WindowWidth = 640;
 13 static const int WindowHeight = 480;
 14 
 15 static Bottle* bottle = NULL;
 16 static Capsule* capsule = NULL;
 17 
 18 enum Connect
 19 {
 20     LEFT, RIGHT, UP, DOWN, NOT_CONNECTED
 21 };
 22 
 23 enum Color
 24 {
 25     YELLOW, BLUE, RED, BLACK
 26 };
 27 
 28 enum GridType
 29 {
 30     CAPSULE, WORM, NOTHING
 31 };
 32 
 33 class Bottle
 34 {
 35 private:
 36     GridType b_grid_type[16][8];
 37     Color b_color[16][8];
 38     int b_x,b_y;
 39     int b_seed;
 40 public:
 41     Bottle( int seed, int level, int xx, int yy )
 42     {
 43         b_seed = seed;
 44         b_x = xx;
 45         b_y = yy;
 46         for ( int i = 0; i < 16++i )
 47         {
 48             for ( int j = 0; j < 8++j )
 49             {
 50                 b_grid_type[i][j] = NOTHING;
 51                 b_color[16][8= BLACK;
 52             }
 53         }
 54         for ( int i = 0; i < level*4++i )
 55         {
 56             int x = myRand()%8;
 57             int y = myRand()%16;
 58             Color color = myRand()%3;
 59             if ( ok( x, y, color, level ) )
 60             {
 61                 b_grid_type[y][x] = WORM;
 62                 b_color[y][x] = color;
 63             }
 64             else
 65                 --i;
 66         }
 67     }
 68     int myRand( void )
 69     {
 70         seed = MULTIPLIER*seed + INCREMENT; 
 71         return ((int)(seed>>16& 0x7fff); 
 72     }
 73     bool ok( int x, int y, Color color, int level )
 74     {
 75         if ( level < 15 && y <= 6 ) return false;
 76         if ( ((level+1)>>1)+3+< 16 ) return false;
 77         if ( x-2 >= 0 && b_grid_type[x-1][y] == WORM && b_color[x-1][y] == color 
 78             && b_grid_type[x-2][y] == WORM && b_color[x-2][y] == color ) return false;
 79         if ( x+2 < 8 && b_grid_type[x+1][y] == WORM && b_color[x+1][y] == color 
 80             && b_grid_type[x+2][y] == WORM && b_color[x+2][y] == color ) return false;
 81         if ( y+2 < 16 && b_grid_type[x][y+1== WORM && b_color[x][y+1== color 
 82             && b_grid_type[x][y+2== WORM && b_color[x][y+2== color ) return false;
 83         if ( b_grid_type[x][y-1== WORM && b_color[x][y-1== color 
 84             && b_grid_type[x][y-2== WORM && b_color[x][y-2== color ) return false;
 85         return true;
 86     }
 87 };
 88 
 89 class Capsule
 90 {
 91 private:
 92     int c_x,c_y;
 93     Connect c_connect;
 94     Color C_color;
 95 public:
 96     Capsule( int xx, int yy, Connect con, int color)
 97     {
 98         c_x = xx; c_y = yy; c_connect = con; c_color = color;
 99     }
100 };
101 
102 void draw( void )
103 {
104     bottle->display();
105 }
106 
107 void display( void )
108 {
109     glClear( GL_COLOR_BUFFER_BIT );
110     draw();
111     glutSwapBuffers();
112 }
113 
114 void key( unsigned char key_char, int not_use, int not_use_1 )
115 {
116     capsule->setDirect( key_char );
117 }
118 
119 int main( int argc, char * argv[] )
120 {
121     glutInit( &argc, argv );
122     glutInitDisplayMode( GLUT_RGBA|GLUT_DOUBLE );
123     glutInitWindowPosition( 5050 );
124     glutInitWindowSize( WindowWidth, WindowHeight );
125     glutCreateWindow( "Dr Mario By PureMilk" );
126     glutDisplayFunc( display );
127     glutKeyboardFunc( key );
128     glutTimerFunc( 250, timer, 0 );
129     gluOrtho2D( 0, WindowWidth, WindowHeight, 0 );
130     glutMainLoop();
131     
132     return 0;
133 }
我是C++盲……

FeedBack:
# re: 10月15日_拍板砖吧_By PureMilk
2008-10-15 17:08 | 筱筱殿下
注解注解~~  回复  更多评论
  
# re: 10月15日_拍板砖吧_By PureMilk
2008-10-15 17:32 | risky
都开始写了,俄们还停留在。。  回复  更多评论
  
# re: 10月15日_拍板砖吧_By PureMilk[未登录]
2008-10-15 19:10 | missdeer
何必自己写随机值函数,而且就算要写,放在这个类里也不合适  回复  更多评论
  
# re: 10月15日_拍板砖吧_By PureMilk
2008-10-16 19:27 | 肖赫_王婷婷_王冠_郑燚
@missdeer
对,您教训的是,俺C++盲,要仔细地研究下。  回复  更多评论
  
# re: 10月15日_拍板砖吧_By PureMilk
2008-10-17 01:43 | 陈梓瀚(vczh)
类的职责要单一、要正交、要小。  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



<2008年10月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(6)

随笔分类(149)

随笔档案(150)

同道中人

搜索

  •  

积分与排名

  • 积分 - 43689
  • 排名 - 487

最新随笔

最新评论

阅读排行榜

评论排行榜