Guest User

Untitled

a guest
Dec 15th, 2016
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <string>
  5. #include <sstream>
  6. #include <math.h>
  7. #include <GL/glew.h>
  8. #include <GL/freeglut.h>
  9. #include <GL/gl.h>
  10. #include "Player.h"
  11. #include "Bullet.h"
  12. #include "DrawBresenhamLine.h"
  13. #include "MainConst.h"
  14.  
  15. using namespace std;
  16.  
  17. Player playerObj(50, 50, 0);
  18. Bullet bulletObj(playerObj.x, playerObj.y, playerObj.angle);
  19.  
  20. string buff;
  21. char array[100];
  22.  
  23. void KeyboardMove(int key, int _x, int _y){
  24.     switch (key){
  25.         case GLUT_KEY_LEFT:
  26.             //playerObj.x--;
  27.             playerObj.angle += 5;
  28.             break;
  29.         case GLUT_KEY_RIGHT:
  30.             //playerObj.x++;
  31.             playerObj.angle -= 5;
  32.             break;
  33.         case GLUT_KEY_DOWN:
  34.             playerObj.x = playerObj.x + 2 * sin(playerObj.angle * M_PI / 180);
  35.             playerObj.y = playerObj.y - 2 * cos(playerObj.angle * M_PI / 180);
  36.             break;
  37.         case GLUT_KEY_UP:
  38.             playerObj.x = playerObj.x - 2 * sin(playerObj.angle * M_PI / 180);
  39.             playerObj.y = playerObj.y + 2 * cos(playerObj.angle * M_PI / 180);
  40.             break;
  41.         case GLUT_KEY_INSERT:
  42.             bulletObj.drawBullet(playerObj.x, playerObj.y);
  43.             break;
  44.     }
  45. }
  46.  
  47. void output(GLfloat x, GLfloat y, string text){
  48.     glPushMatrix();
  49.     glTranslatef(x, y, 0);
  50.     glScalef(0.1, 0.1, 0);
  51.     for(int i = 0; i < text.length(); i++){
  52.         glutStrokeCharacter(GLUT_STROKE_ROMAN, text[i]);
  53.     }
  54.     glPopMatrix();
  55. }
  56.  
  57. string LDToStr(double one){
  58.     std::stringstream ss;
  59.     ss << one;
  60.     return ss.str();
  61. }
  62.  
  63. void Display() {
  64.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  65.  
  66.     playerObj.drawPlayer(playerObj.x, playerObj.y, playerObj.angle);
  67.  
  68.     buff = "x: " + LDToStr(playerObj.x) + "; y: " + LDToStr(playerObj.y) + "; a: " + LDToStr((double)playerObj.angle);
  69.     buff += " sin: " + LDToStr((double)sin(playerObj.angle * 3.14 / 180)) + " cos: " + LDToStr((double)cos(playerObj.angle * 3.14 / 180));
  70.     output(15, WIDTH_D-15, buff);
  71.  
  72.     glutSwapBuffers();
  73. }
  74.  
  75. void Update(void) {
  76.     glutPostRedisplay();
  77. }
  78.  
  79. void Initialize() {
  80.     glClearColor(0, 0, 0, 1.0);
  81.     glMatrixMode(GL_PROJECTION);
  82.     glLoadIdentity();
  83.     glOrtho(0.0, WIDTH_D, 0.0, HEIGHT_D, -5.0, 5.0);
  84.     glutIdleFunc(Update);
  85. }
  86.  
  87. int main(int argc, char** argv) {
  88.     glutInit(&argc, argv);
  89.     glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
  90.     glutInitWindowSize(400, 400);
  91.     glutCreateWindow("Window");
  92.     Initialize();
  93.     glutDisplayFunc(Display);
  94.     glutSpecialFunc(KeyboardMove);
  95.     glutMainLoop();
  96.  
  97.     getch();
  98.  
  99.     return 0;
  100. }
Add Comment
Please, Sign In to add comment