-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.c
105 lines (98 loc) · 2.61 KB
/
score.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include "main.h"
#define SCORE_BOARD_HEIGHT 36
#define SCORE_BOARD_WIDTH 220
#define SCORE_BOARD_PADDING 150
GLdouble width, height; /* window width and height */
int wd; /* GLUT window handle */
long long int curr_score=-108;//this is the score that is printed on screen
void draw_score(long long int score)
{
long long int tempsc = score;
char str[15];
sprintf(str,"%lld",tempsc);
glutStrokeString(GLUT_STROKE_ROMAN,"SCORE : ");
glutStrokeString(GLUT_STROKE_ROMAN,str);
}
void draw_score_board(long long int score)
{
curr_score=score;
glPushMatrix();
glTranslatef(SCORE_BOARD_PADDING, height - SCORE_BOARD_HEIGHT - 20, 0);
glColor3f(0.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(0, 0);
glVertex2f(SCORE_BOARD_WIDTH, 0);
glVertex2f(SCORE_BOARD_WIDTH, SCORE_BOARD_HEIGHT);
glVertex2f(0, SCORE_BOARD_HEIGHT);
glEnd();
glLineWidth(5);
glColor3f(0,0,1);
glBegin(GL_LINE_STRIP);
glVertex2f(0, 0);
glVertex2f(SCORE_BOARD_WIDTH, 0);
glVertex2f(SCORE_BOARD_WIDTH, SCORE_BOARD_HEIGHT);
glVertex2f(0, SCORE_BOARD_HEIGHT);
glVertex2f(0,0);
glEnd();
glLineWidth(1);
glColor3f(1,0.98,0);
glPushMatrix();
glTranslatef(8,8,0);
glScalef(0.2,0.2,1);
draw_score(curr_score);
glPopMatrix();
glPopMatrix();
}
//code for showing the timer
void draw_time(int time)
{
int tempt = time;
tempt/=1000;
int tmin=tempt/60;
int tsec=tempt%60;
char str1[15],str2[15];
sprintf(str1,"%d",tmin);
sprintf(str2,"%d",tsec);
glutStrokeString(GLUT_STROKE_ROMAN,"Time ");
glutStrokeString(GLUT_STROKE_ROMAN,str1);
glutStrokeString(GLUT_STROKE_ROMAN,":");
if(tsec/10==0)
{
glutStrokeString(GLUT_STROKE_ROMAN,"0");
glutStrokeString(GLUT_STROKE_ROMAN,str2);
}
else
glutStrokeString(GLUT_STROKE_ROMAN,str2);
}
void draw_time_board()
{
glPushMatrix();
glTranslatef(1000, 770 - 36 - 20, 0);
glColor3f(0.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(0, 0);
glVertex2f(150, 0);
glVertex2f(150, 36);
glVertex2f(0, 36);
glEnd();
glLineWidth(5);
glColor3f(0,0,1);
glBegin(GL_LINE_STRIP);
glVertex2f(0, 0);
glVertex2f(150, 0);
glVertex2f(150,36);
glVertex2f(0, 36);
glVertex2f(0,0);
glEnd();
glLineWidth(1);
glColor3f(1,0.98,0);
glPushMatrix();
glTranslatef(8,8,0);
glScalef(0.2,0.2,1);
draw_time(count*50);
glPopMatrix();
glPopMatrix();
}