opengl实现推箱子游戏讲述.docxVIP

  • 4
  • 0
  • 约1.33万字
  • 约 19页
  • 2017-05-04 发布于湖北
  • 举报
共分为4个.h文件和5个.cpp文件 keyListener.h,keyListener.cpp map.h,map.cpp texture.h,texture.cpp textview.h,textview.cpp Main.cpp Main.cpp #include GL/glut.h #include GL/glu.h #include GL/gl.h #include string.h #include stdio.h #include map.h #include Texture.h #include keyListener.h #include textview.h #pragma comment(linker,/subsystem:\Windows\ /entry:\mainCRTStartup\) Texture texture; // 文理加载类 Map map; // 地图加载类 KeyListener keylistener; //键盘监听事件类 TextView textview; int* image; int **mp; int window; //窗口 int is_pass = 0; // 是否过关标志 int *pass = is_pass; int level = 1; // 关卡 int *lv = level; int pre_lv = 1; //颜色的RGB值 int black[3] = {0 , 0 , 0}; int white[3] = {255 , 255 , 255}; int orange[3] = {255, 128, 0}; //窗口大小变化时调用的函数 void ChangeSize(GLsizei w, GLsizei h) { if(h == 0) { h = 1; } glViewport(0, 0, w, h); //定义视口大小,宽高一致 int width = 550; int height = 550; glMatrixMode(GL_PROJECTION); //重置坐标系统,使投影变换复位 glLoadIdentity(); //将当前的用户坐标系的原点移到了屏幕中心 GLfloat aspect; if(w = h) { aspect = (GLfloat) h / w; glOrtho(0, width, 0, height * aspect, 0, height); } else if(w h) { aspect = (GLfloat) w / h; glOrtho(0, width * aspect, 0, height, 0, width); } } void display_text() { glColor3ub(orange[0],orange[1],orange[2]); glRasterPos2i(250, 570); //起始位置 textview.drawString(推箱子); //输出的字符串 glRasterPos2i(400, 570); char c[10] = 第; char d[5] ; sprintf(d, %d关, level); strcat(c, d); textview.drawString(c); glRasterPos2i(120, 80); textview.drawString(1、ESC键退出游戏); glRasterPos2i(120, 60); textview.drawString(2、BackSpace后退); glRasterPos2i(120, 40); textview.drawString(3、PageUp、PageDown切换关卡); glRasterPos2i(120, 20); textview.drawString(4、键盘上、下、左、右键控制方向); } //画长方形 void draw_rect(int leftX, int leftY) { glBegin(GL_POLYGON); glColor3ub(black[0],black[1],black[2]); glVertex2d(leftX,leftY);

文档评论(0)

1亿VIP精品文档

相关文档