-
Notifications
You must be signed in to change notification settings - Fork 0
/
grafic.c
127 lines (109 loc) · 3.12 KB
/
grafic.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
122
123
124
125
126
127
#include "grafic.h"
void drawStat(BITMAP *dest,int x,int y)
{
int color = makecol(230, 100, 50);
textprintf_ex(dest, font, x, y, color,
-1, "Score: %d", score);
textprintf_ex(dest, font, x, y+25, color,
-1, "Level: %d", level);
textprintf_ex(dest, font, x, y+50, color,
-1, "Lines: %d", lines);
}
void drawNextBlock(BITMAP *dest,int offsetX,int offsetY)
{
const int colors[BLOCKS+1] =
{
makecol(0,0,0),
makecol(255,0,0),
makecol(0,255,0),
makecol(0,0,255),
makecol(255,255,0),
makecol(0,255,255),
makecol(255,0,255),
makecol(0,255,133)
};
int x,y;
int w = 20;
int h = 20;
int border = 2;
for(x=0;x<BLOCK_WIDTH;x++)
for(y=0;y<BLOCK_HEIGHT;y++)
{
rectfill(dest,x*w+offsetX,y*h+offsetY,x*w+offsetX+w,y*h+offsetY+h,makecol(20,20,20));
rectfill(dest,x*w+offsetX+border,y*h+offsetY+border,x*w+offsetX+w-border,y*h+offsetY+h-border,colors[block[nextBlock][y*BLOCK_WIDTH+x]]);
}
}
void drawField(BITMAP* dest,int offsetX,int offsetY)
{
const int colors[BLOCKS+1] =
{
makecol(100,100,130),
makecol(255,0,0),
makecol(0,255,0),
makecol(0,0,255),
makecol(255,255,0),
makecol(0,255,255),
makecol(255,0,255),
makecol(0,255,133)
};
const int w = 20;
const int h = 20;
int x,y,i;
int border = 1;
for(y=0;y<FIELD_HEIGHT;y++)
{
for(x=0;x<FIELD_WIDTH;x++)
{
i = *(field+y*FIELD_WIDTH+x);
rectfill(dest,x*w+offsetX,y*h+offsetY,x*w+offsetX+w,y*h+offsetY+h,makecol(10,20,20));
//rectfill(dest,x*w+offsetX,y*h+offsetY,x*w+offsetX+w,y*h+offsetY+h,colors[i]);
rectfill(dest,x*w+offsetX+border,y*h+offsetY+border,x*w+offsetX+w-border,y*h+offsetY+h-border,colors[i]);
}
}
}
void welcomeScreen(BITMAP *dest)
{
textprintf_ex(dest, font, 300, 100, makecol(200,20,20),
-1, "Tetris");
readkey();
}
void gameOverScreen(BITMAP *dest,int offsetX,int offsetY)
{
const int colors[BLOCKS+1] =
{
makecol(100,34,130),
makecol(34,100,0),
makecol(200,0,0),
makecol(200,250,20),
makecol(0,30,0),
makecol(100,255,20),
makecol(50,0,255),
makecol(0,0,133)
};
const int w = 20;
const int h = 20;
int x,y,i;
int border = 1;
int restTime = 30;
for(y=FIELD_HEIGHT-1;y>=0;y--)
{
for(x=0;x<FIELD_WIDTH;x++)
{
i = *(field+y*FIELD_WIDTH+x);
rectfill(dest,x*w+offsetX,y*h+offsetY,x*w+offsetX+w,y*h+offsetY+h,makecol(10,20,20));
rectfill(dest,x*w+offsetX+border,y*h+offsetY+border,x*w+offsetX+w-border,y*h+offsetY+h-border,colors[i]);
rest(restTime);
if(key[KEY_ESC]) restTime = 0;
}
}
}
void drawFooter(BITMAP *dest,int x,int y)
{
textprintf_ex(dest, font, x, y, makecol(200,20,20),
-1, "developed by Maurer C.");
}
void drawHeader(BITMAP *dest,int x,int y)
{
textprintf_ex(dest, font, x, y, makecol(200,20,20),
-1, "Tetris %s",T_VERSION);
}