Herugan
Herugan
Herugan
h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#define TIMER_PERIOD 25
#define SCALE_SPEED 1.020 //the scale amount applied to the hexagons in every frame
#define COLOR_CHANGE true //true for repeatedly color change, false for no color change
typedef struct {
float r, g, b;
} color_t;
typedef struct {
int missingPart; //the empty part of the hexagon so that player can pass through
} hexagon_t;
typedef struct {
animate;
} game_control_t;
typedef struct {
int current,
max = -1;
} score_t;
game_control_t game;
hexagon_t hexagons[4];
int input = 0; //the screen is splitted into 6 parts and as players uses arrow keys, the value of this
variable changes accordingly
float maxScale; //after this scale, the scale of the hexagons will be initialized to initialScale
float initialScale; //
float rotation; //rotation of all objects, hexagons and players, which changes in time
float scale; //scale of the whole screen, used in the initial animation and in game in general
void initializeGlobals()
input = 0;
scale = 1;
score.current = 0;
game.isStarted = false;
game.pause = false;
game.animate = false;
rotateSpeed = (rand() % 100) / 50.0 + 1;
rotation = 0;
float hexagonScales[4];
hexagonScales[3] = 0.2;
initialScale = hexagonScales[2];
hexagons[i].scale = hexagonScales[i];
hexagons[i].missingPart = rand() % 6;
background = { rand() % 100 / 300.0f, rand() % 100 / 300.0f ,rand() % 100 / 300.0f };
//
// radius r
//
#define PI 3.1415
float angle;
glBegin(GL_POLYGON);
glEnd();
glPushMatrix();
while (*string)
glutStrokeCharacter(GLUT_STROKE_ROMAN, *string++);
glPopMatrix();
void displayBackground()
glColor4f(0, 0, 0, 0.1);
glPushMatrix();
glBegin(GL_TRIANGLES);
glVertex2f(0, 0);
glEnd();
glPopMatrix();
void displayHexagons()
if (j == hexagons[i].missingPart)
continue;
glPushMatrix();
glPopMatrix();
void displayPlayer()
glPushMatrix();
glColor3f(1, 1, 1);
glPopMatrix();
void displayUI()
glPushMatrix();
if (!game.isStarted)
glColor4f(0, 0, 0, 0.7);
glColor3f(1, 1, 1);
glTranslatef(-100, 0, 0);
drawString("F1 to Start");
if (score.max != -1)
char str[100];
drawString(str);
drawString(str);
}
}
else
if (!game.pause)
drawString("F2 to Pause");
else
drawString("F2 to Continue");
char str[100];
glPopMatrix();
glPushMatrix();
drawString(str);
glPopMatrix();
glPushMatrix();
drawString("F1 to reset");
glPopMatrix();
//
void display()
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
if (game.animate)
glRotatef(rotation, 0, 0, 1);
displayBackground();
displayHexagons();
displayPlayer();
displayUI();
glutSwapBuffers();
//
//
if (key == 27)
exit(0);
//
// Special Key like F1, F2, F3, Arrow Keys, Page UP, ...
//
switch (key) {
case GLUT_KEY_LEFT:
input = (input + 5) % 6;
break;
case GLUT_KEY_RIGHT:
input = (input + 1) % 6;
break;
if (key == GLUT_KEY_F1)
initializeGlobals();
game.animate = true;
scale = 9;
game.pause = !game.pause;
}
//
//
}
//
//
width = w;
height = h;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
void onTimer(int v) {
if (game.animate)
timerCount++;
scale -= 0.1;
rotation += 9;
if (scale <= 1)
{
scale = 1;
rotation = 0;
game.animate = false;
game.isStarted = true;
timerCount++;
rotation += rotateSpeed;
if (input != hexagons[i].missingPart)
game.isStarted = false;
score.max = score.current;
else
score.current++;
hexagons[i].scale *= SCALE_SPEED;
hexagons[i].scale = initialScale;
else if (timerCount % 50 == 0)
if (rnd == 0)
rnd = 180;
rotation += rnd;
timerCount = 0;
glutPostRedisplay();
initializeGlobals();
srand(time(NULL));
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
glutCreateWindow("Template");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
//
// keyboard registration
//
glutKeyboardFunc(ASCIIKeyDown);
glutKeyboardUpFunc(ASCIIKeyUp);
glutSpecialFunc(SpecialKeyDown);
glutSpecialUpFunc(SpecialKeyUp);
//
// mouse registration
//
glutMouseFunc(MouseClick);
glutPassiveMotionFunc(MouseMove);
glutMotionFunc(MouseDownMove);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glutMainLoop();