昨天没有写笔记,请大家责骂。
原因是,不小心断网了,发送键点出去返回给我一个无情的该页无法显示。中午本想补上,结果greenbrower死掉一次,写了一大片都这样不见了,巨崩溃,懒得写第三遍。直接上代码。
1 #include <GL/glut.h>
2 #include <ctime>
3
4 static const int WindowWidth = 640;
5 static const int WindowHeight = 480;
6
7 int count = 0;
8 int speed = 4;
9
10 enum GridType
11 {
12 NOTHING, CAPSULE, WORM
13 };
14
15 enum Connect
16 {
17 NOT_CONNECTED, LEFT, RIGHT, UP, DOWN
18 };
19
20 enum Color
21 {
22 BLACK, YELLOW, BLUE, RED
23 };
24
25 enum DoctorDirect
26 {
27 DD_NODIRECT, DD_UP, DD_DOWN, DD_LEFT, DD_RIGHT
28 };
29
30
31 class Bottle
32 {
33 private:
34 GridType b_grid_type[8][16];
35 Color b_color[8][16];
36 int b_x,b_y; //bottle的位置
37 Connect b_connect;
38 public:
39 void drawBottle( void )
40 {
41 //画瓶子的外壳
42 //画瓶子的内部,根据b_x,b_y和瓶子的内容物
43 }
44 Bottle( int level )
45 {
46 //生成level*4个虫子
47 }
48 };
49
50 class Doctor
51 {
52 private:
53 int d_x,d_y; //活动药丸(左下角)相对于瓶子的位置
54 bool d_state; //横的0,竖的1
55 Color d_color[2]; //俩药丸的颜色
56 DoctorDirect d_direct;
57 public:
58 void drawDoctor( void )
59 {
60 //画医生的形象
61 //画活动药丸
62 }
63 Doctor( void )
64 {
65 //确定初始位置
66 //随机生成两药丸颜色
67 }
68 void move( void )
69 {
70 //伪码就先不写了,我纸上写了一堆,思路很清晰
71 }
72 void fall( void )
73 {
74 d_direct = DD_DOWN;
75 move();
76 }
77 void setDirect( DoctorDirect direct )
78 {
79 d_direct = direct;
80 }
81 };
82
83 static Bottle* bottle = NULL;
84 static Doctor* doctor = NULL;
85
86 void init( void )
87 {
88 //new两个类
89 }
90
91 void key( unsigned char key_char, int not_use, int not_use_1 )
92 {
93 switch ( key_char )
94 {
95 case 'w':
96 case 'W':
97 doctor->setDirect( DD_UP );
98 break;
99 case 's':
100 case 'S':
101 doctor->setDirect( DD_DOWN );
102 break;
103 case 'a':
104 case 'A':
105 doctor->setDirect( DD_LEFT );
106 break;
107 case 'd':
108 case 'D':
109 doctor->setDirect( DD_RIGHT );
110 break;
111 default:
112 doctor->setDirect( DD_NODIRECT );
113 }
114 }
115
116 void step( void )
117 {
118 if ( dead() ) return ;
119 //还没写完
120 ++count; if ( count == speed ) { count = 0; doctor->fall(); }
121 }
122
123 void timer( int not_use )
124 {
125 step();
126 glutPostRedisplay();
127 if ( !dead() )
128 {
129 glutTimerFunc( 1000/speed, timer, 0 );
130 }
131 }
132
133 void draw()
134 {
135 bottle->drawBottle();
136 doctor->drawDoctor();
137 }
138
139 void display( void )
140 {
141 glClear( GL_COLOR_BUFFER_BIT );
142 draw();
143 glutSwapBuffers();
144 }
145
146 int main( int argc, char * argv[] )
147 {
148 glutInit( &argc, argv );
149 glutInitDisplayMode( GLUT_RGBA|GLUT_DOUBLE );
150 glutInitWindowPosition( 50, 50 );
151 glutInitWindowSize( WindowWidth, WindowHeight );
152 glutCreateWindow( "Dr Mario By PureMilk" );
153 glutDisplayFunc( display );
154 glutKeyboardFunc( key );
155 glutTimerFunc( 1000/speed, timer, 0 );
156 gluOrtho2D( 0, WindowWidth, WindowHeight, 0 );
157 glutMainLoop();
158
159 return 0;
160 }
谢谢vczh的指点,还望多点播点播俺。这次的思路是不是比那个混乱代码要好些了……