Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include "glut.h"
- #include "CGameHandler.h"
- #include "CModel.h"
- #include "CCube.h"
- #include "CPolygon.h"
- //defintion of the global variables:
- CCube cube;
- int jumpincrease;//משתנה עזר הבודק אם עברו 200 פריימים
- double ro, cubespeedx;//ro- cube rotation speed, cubespeed - the amount of distance the cube makes in a single frame.
- bool r, cs, csy, csyf;//csy/csyf making sure that the cube goes up and down, r/cs making sure the cube will/not rotate/move.
- extern void renderBitmapString(float x, float y, void *font, char *string);
- extern void renderVerticalBitmapString(float x, float y, int bitmapHeight, void *font, char *string);
- void CGameHandler::StartOfGame()
- {
- //variables for game handling
- font = def_font = (int)GLUT_BITMAP_HELVETICA_18;
- ChangeBackgroundColors(0.5, 0.75, 0.25);
- //settings of the objects:
- cube.MoveModel(-0.5, -3, -10);
- r = true;
- cs = true;
- csy = false;
- csyf = false;
- ro = 0.5;
- cubespeedx = 0;
- jumpincrease = 0;
- }
- //on each frame:
- void CGameHandler::DrawScene()
- {
- cube.DrawModel();
- }
- void CGameHandler::LogicPart()
- {
- //שליטה על סיבוב הקובייה
- if (r)
- cube.RotateSelfModel(Y_AXIS, ro);
- //שליטה על תזוזת הקובייה
- if (cs)
- cube.MoveModel(cubespeedx, 0, 0);
- //תנאים לקוביה היוצאת מן המסך
- if (cube.GetModelCenter().GetCoordinate(X_AXIS) >= 6.5)
- cube.MoveModel(-13 , 0, 0);
- if (cube.GetModelCenter().GetCoordinate(X_AXIS) <= -6.5)
- cube.MoveModel(13, 0, 0);
- //הזזת הקובייה מעלה 200 פריימים
- if (csy && jumpincrease < 201)
- {
- jumpincrease++;
- cube.MoveModel(0, 0.004, 0);
- if (jumpincrease > 199)
- {
- csy = false;
- csyf = true;
- }
- }
- //הוזזת הקובייה מטה 200 פריימים
- if (csyf && jumpincrease < 202)
- {
- jumpincrease--;
- cube.MoveModel(0, -0.004, 0);
- if (jumpincrease < 1)
- csyf = false;
- }
- }
- void CGameHandler::WriteText()
- {
- font = (int)GLUT_BITMAP_TIMES_ROMAN_24; // font type and size
- glColor3f(0, 255, 100); // yellow color
- int x_pos = glutGet(GLUT_SCREEN_WIDTH) / 2 - 100; // to be at the center of the screen
- int y_pos = 30;
- if (r)
- renderBitmapString(x_pos, 80, (void *)font, "The cube is rotating");
- else
- renderBitmapString(x_pos, 80, (void *)font, "The cube is not rotating");
- if (cs)
- renderBitmapString(x_pos, 120, (void *)font, "The cube can move");
- else
- renderBitmapString(x_pos, 120, (void *)font, "The cube can't move");
- if (cubespeedx == 0)
- renderBitmapString(x_pos, 100, (void *)font, "The Cube is stationary");
- else if (cubespeedx < 0)
- renderBitmapString(x_pos, 100, (void *)font, "The Cube is going left");
- else
- renderBitmapString(x_pos, 100, (void *)font, "The Cube is going right");
- }
- //keys:
- void CGameHandler::KeyPressed(char key)
- {
- switch (key)
- {
- case ' '://spacebar
- r = !r;
- break;
- case 13: //Enter
- cs = !cs;
- break;
- case 27://Esc
- break;
- case '1':
- ro = 0.2;
- break;
- case '2':
- ro = 0.4;
- break;
- case '3':
- ro = 0.6;
- break;
- case '4':
- ro = 0.8;
- break;
- case '5':
- ro = 1.0;
- break;
- case 'r':
- StartOfGame();
- break;
- default:
- break;
- }
- }
- void CGameHandler::SpecialKeyPressed(char key)
- {
- switch (key)
- {
- case GLUT_KEY_LEFT:
- cubespeedx -= 0.001;
- break;
- case GLUT_KEY_RIGHT:
- cubespeedx += 0.001;
- break;
- case GLUT_KEY_UP:
- if(jumpincrease == 0)
- csy = true;
- break;
- default:
- break;
- }
- }
- //getting backgroundColor
- float CGameHandler::GetBeckgroundColorR()
- {
- return BGColor_R;
- }
- float CGameHandler::GetBeckgroundColorG()
- {
- return BGColor_G;
- }
- float CGameHandler::GetBeckgroundColorB()
- {
- return BGColor_B;
- }
- //internal procedures:
- void CGameHandler::ChangeBackgroundColors(float R, float G, float B)
- {
- BGColor_R = R;
- BGColor_G = G;
- BGColor_B = B;
- }
Add Comment
Please, Sign In to add comment