-
Notifications
You must be signed in to change notification settings - Fork 0
/
visuals.c
190 lines (165 loc) · 7.05 KB
/
visuals.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "definitions.h" //All structure definitions, #defines, #includes, and ENUMs
#include "globals.h" //Includes all global variables declared as "extern"
void drawGrid (); //Draws map and people
void drawHistogram(int x, int y);
void drawPerson(PERSON *thePerson);
void drawHUD();
int placeOnGridX(int x, int y); //Converts a grid coordinate to pixels
int placeOnGridY(int x, int y); //Converts a grid coordinate to pixels
int placementToButton(); //Converts the int "placement" to button number
extern int getGridX(int x, int y); //Converts a pixel location to grid coordinate
extern int getGridY(int x, int y); //Converts a pixel location to grid coordinate
extern int buildingIDtoResource(int theNumber); //Converts a building index to resource index (0-12)
/* gameVisuals()
Draws the map, people, HUD, and mouse, in that order.
*/
void gameVisuals()
{
drawGrid (); //Draws map and people
if (mouseGridX >= 0 && mouseGridY >= 0)
{
//Draw the map highlighter
draw_sprite(screenBuffer, selector, placeOnGridX(mouseGridX, mouseGridY),placeOnGridY(mouseGridX, mouseGridY));
}
drawHUD();
draw_sprite(screenBuffer, mousePic, mouseX, mouseY);
blit(screenBuffer, screen, 0,0,0,0,1024,768); //Blit the buffer
clear_bitmap(screenBuffer);
}
/* drawGrid()
Draws the map, and people.
*/
void drawGrid ()
{
PERSON *thePerson = personHeader;
int y;
int x;
int i;
for (y = 0; y < mapWidth; y++)
{
for (x = 0; x < mapWidth; x++)
{
//Draw the squares
draw_sprite(screenBuffer, aMapSquare[x][y].picture, placeOnGridX(x, y), placeOnGridY(x, y) - anObject[aMapSquare[x][y].objectType].printOffset);
drawHistogram(x,y);
/* Drawing people
Because people are always moving, ther can be no fixed order for printing them.
Instead, they are constantly sorted, and once sorted, this loop prints them.
They are sorted by gridX and gridY, in the same order as the squares.
Thus, while stepping though the squares, you can step through the list of people
and print all of them until you reach the next square
*/
while (thePerson != NULL && thePerson->gridY == y && thePerson->gridX == x)
{
drawPerson(thePerson);
thePerson = thePerson->next;
}
}
}
if(showPersonInfo)
{
for(i = 0; i < NUMRESOURCES; i++)
{
if (selectionX != -1 && selectionY != -1){
if (aMapSquare[selectionX][selectionY].walker[i] != NULL)
{
thePerson = aMapSquare[selectionX][selectionY].walker[i];
line(screenBuffer, thePerson->x + cameraX, thePerson->y + cameraY - 15, placeOnGridX(selectionX, selectionY) + squareWidth/2, placeOnGridY(selectionX, selectionY) + squareWidth/4, resourceColour[i]);
}
}
}
}
}
/*Converts a grid coordinate to pixels*/
int placeOnGridX(int x, int y)
{
return (int)(0.5*squareWidth*(x-y) + cameraX);
}
/*Converts a grid coordinate to pixels*/
int placeOnGridY(int x, int y)
{
return (int)(0.25*squareWidth*(x+y) + cameraY);
}
void drawHistogram(int x, int y)
{
//Make sure an actual resource building is selected
if (buildingIDtoResource(placement) >= 0)
{
//make sure you are printing a house
if (aMapSquare[x][y].objectType >= TENT && showBuildingInfo)
{
//If the house has a decent amount of the resource
if (aMapSquare[x][y].currentSupply[buildingIDtoResource(placement)] > 250)
{
//Draw the bar graph
rectfill(screenBuffer, placeOnGridX(x, y) + squareWidth/2 - 5 + aMapSquare[x][y].supplyBarOffset, placeOnGridY(x, y) - 5, placeOnGridX(x, y) - 5 + squareWidth/2 + 10 + aMapSquare[x][y].supplyBarOffset, placeOnGridY(x, y) - 5 - 50, 0);
rectfill(screenBuffer, placeOnGridX(x, y) + squareWidth/2 + 2 - 5 + aMapSquare[x][y].supplyBarOffset, placeOnGridY(x, y) - 5 - 2, placeOnGridX(x, y) - 5 + squareWidth/2 + 10 -2 + aMapSquare[x][y].supplyBarOffset, placeOnGridY(x, y) - 5 - (aMapSquare[x][y].percentageFull[buildingIDtoResource(placement)]/2) + 2, resourceColour[buildingIDtoResource(placement)]);
}
}
//If you are printing a producer
else if (aMapSquare[x][y].objectType >= FARM && showBuildingInfo && anObject[aMapSquare[x][y].objectType].productionRate[buildingIDtoResource(placement)] > 0)
{
//Draw a white bar graph
rectfill(screenBuffer, placeOnGridX(x, y) + squareWidth/2 - 5 + aMapSquare[x][y].supplyBarOffset, placeOnGridY(x, y) - 5, placeOnGridX(x, y) - 5 + squareWidth/2 + 10 + aMapSquare[x][y].supplyBarOffset, placeOnGridY(x, y) - 5 - 50, makecol(255, 255, 255));
rectfill(screenBuffer, placeOnGridX(x, y) + squareWidth/2 - 4 + aMapSquare[x][y].supplyBarOffset, placeOnGridY(x, y) - 6, placeOnGridX(x, y) - 6 + squareWidth/2 + 10 + aMapSquare[x][y].supplyBarOffset, placeOnGridY(x, y) - 4 - 50, 0);
if ((aMapSquare[x][y].percentageFull[buildingIDtoResource(placement)]/2) > 2)
{
//Draw the graph
rectfill(screenBuffer, placeOnGridX(x, y) + squareWidth/2 + 2 - 5 + aMapSquare[x][y].supplyBarOffset, placeOnGridY(x, y) - 5 - 2, placeOnGridX(x, y) - 5 + squareWidth/2 + 10 -2 + aMapSquare[x][y].supplyBarOffset, placeOnGridY(x, y) - 5 - (aMapSquare[x][y].percentageFull[buildingIDtoResource(placement)]/2) + 2, resourceColour[buildingIDtoResource(placement)]);
}
}
}
}
/* drawPerson(PERSON *thePerson)
Draws a single person, given a pointer to the person.
*/
void drawPerson(PERSON *thePerson)
{
//Draw the person
draw_sprite(screenBuffer, thePerson->picture[thePerson->animationCounter], thePerson->x - 12 + cameraX, thePerson->y - 28 + cameraY);
//If showPersonInfo is true, write the person's cargo info
if (showPersonInfo && buildingIDtoResource(placement) >= 0)
{
//If the person is carrying the selected resource
if (thePerson->cargoIndex == buildingIDtoResource(placement))
{
draw_sprite(screenBuffer, resourceIcon[buildingIDtoResource(placement)], thePerson->x + cameraX, thePerson->y - 38 + cameraY);
textprintf_centre_ex(screenBuffer, font, thePerson->x + cameraX, thePerson->y - 20 + cameraY, makecol(255, 255, 255), -1, "%d", thePerson->cargo);
}
}
}
/* drawHUD()
Draws the entire HUD
*/
void drawHUD()
{
//HUD picture
draw_sprite(screenBuffer, HUD, 0, 0);
/*PRINT TEXT INFO*/
//Population
textprintf_ex(screenBuffer, font15, 530, 14, makecol(255, 255, 255), 0, "%d", population);
//Money
textprintf_ex(screenBuffer, font15, 130, 14, makecol(255, 255, 255), 0, "%d", money);
//Employees / Employees Needed
textprintf_centre_ex(screenBuffer, font15, 890, 14, makecol(255, 255, 255), 0, "%d/%d", employees, employeesNeeded );
//Highlight the selected resource button
draw_sprite(screenBuffer, placmentOutline, resourceButton[placementToButton()].left - 4, resourceButton[placementToButton()].top - 4);
}
/* placementToButton()
Converts an OBJECT index to a HUD-BUTTON index
*/
int placementToButton()
{
if (placement > EMPTY)
{
if (placement == TENT)
{
return 1;
}
else
{
return (placement - 2);
}
}
return EMPTY;
}