-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_over.c
121 lines (115 loc) · 2.44 KB
/
game_over.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "helpers.h"
#define GAMEOVER_X 38.0f
int UNDERSCORE_POS = UNDERSCORE_DEFAULT;
typedef struct _underscore
{
UBYTE line[5];
UBYTE y;
} Underscore;
Underscore underscore = {{0x01, 0x01, 0x01, 0x01, 0x01}, LETTER_HEIGHT*4+2};
char name[6] = {'A', ' ', 'A', ' ', 'A', '\0'};
/**
* Draws the underscore under every letter when picking name.
*/
void draw_underscore()
{
int i, j;
for (i = 0; i < LETTER_WIDTH; i++)
{
UBYTE col = underscore.line[i];
for (j = 0; j < LETTER_HEIGHT; j++)
{
if (col & 1)
pixon(UNDERSCORE_POS + i, underscore.y + j);
else
pixoff(UNDERSCORE_POS + i, underscore.y + j);
col = col >> 1;
}
}
}
/**
* A white noise transitioning screen between game and game over.
*/
void death_transition()
{
UBYTE pix;
int i, j;
for(i = 0; i < OLED_BUF_SIZE; i++)
{
for(j = 0; j < 8; j++)
{
pix |= ((UFRAND > 0.5 ? 0x1 : 0x0) << j);
}
display_buffer[i] = pix;
pix = 0;
}
}
/**
* Displays the game over screen.
*/
void display_game_over()
{
v2 pos = {GAMEOVER_X, 0.0};
prints("GAME OVER", pos);
pos._1 = 0.0;
pos._2 = LETTER_HEIGHT+3;
printsn("SCORE", points, pos);
pos._2 += LETTER_HEIGHT+3;
pos = prints("YOUR NAME ", pos);
prints(name, pos);
draw_underscore();
}
/**
* Increments or decrements the char depending on sign, which changes the letter accordingly.
*
* @param sign amount of steps you want to change the letter
*/
void next_letter(int sign)
{
if(UNDERSCORE_POS == UNDERSCORE_DEFAULT)
{
name[0] += sign;
if(name[0] > 'Z')
{
name[0] = 'A';
}
else if (name[0] <= 'A')
{
name[0] = 'Z';
}
}
else if(UNDERSCORE_POS == UNDERSCORE_DEFAULT+UNDERSCORE_STEP)
{
name[2] += sign;
if(name[2] > 'Z')
{
name[2] = 'A';
}
else if (name[2] <= 'A')
{
name[2] = 'Z';
}
}
else
{
name[4] += sign;
if(name[4] > 'Z')
{
name[4] = 'A';
}
else if (name[4] <= 'A')
{
name[4] = 'Z';
}
}
}
void reset_game_variables()
{
int i;
for(i = 0; i < 3; i++) {
name[i*2] = 'A';
}
distance_traveled = 0.0;
points = 0.0f;
OVERFLOW = 0x0;
}