-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile.c
291 lines (251 loc) · 10.1 KB
/
tile.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*
** Copyright 1998-2008, Pete J. Jensen
** Copyright 1998-2008, Robin McNeil
** All Rights Reserved.
**
** This is UNPUBLISHED PROPRIETARY SOURCE CODE of the authors
** the contents of this file may not be disclosed to third parties, copied or
** duplicated in any form, in whole or in part, without the prior written
** permission of the authors.
**
** RESTRICTED RIGHTS LEGEND:
** Use, duplication or disclosure by the Government is subject to restrictions
** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
** rights reserved under the Copyright Laws of the United States.
**
** ______
** /_____/\
** /_____\\ \ FILE: sounds.h
** /_____\ \\ / AUTHOR: Pete Jensen
** /_____/ \/ / / AUTHOR: Robin McNeil
** /_____/ / \//\ VERSION: 1.0.0
** \_____\//\ / /
** \_____/ / /\ /
** \_____/ \\ \
** \_____\ \\
** \_____\/
**/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
#include "tile.h"
#include "graph.h"
#include "globals.h"
struct {
double percentStars;
double percentBombs;
} tileLevel[TILE_LEVELS];
// Tile level.
int cLevel = 2;
void tile_initializeTileLevels(){
// Initialize the first tile level; where both stars and bombs
// do not occur.
tileLevel[0].percentStars = 0.0;
tileLevel[0].percentBombs = 0.0;
// Initialize the second (1st index) tile level
tileLevel[1].percentStars = 10.0;
tileLevel[1].percentBombs = 0.0;
// Initializes tile level 2.
tileLevel[2].percentStars = 15.0;
tileLevel[2].percentBombs = 0.05;
// Init tile level 3.
tileLevel[3].percentStars = 20.0;
tileLevel[3].percentBombs = 0.02;
}
void tile_generateRandom(TILE* tile, int maxColor){
/* Select a random tile to put here */
tile->type = (int)((float)(maxColor 1) * rand()/(float)(RAND_MAX));
/* Set star based on the percent of stars to be created. */
if ((int)((float)100 * rand()/(float)(RAND_MAX)) <
tileLevel[cLevel].percentStars)
tile->star = 1;
}
void tile_render(int x, int y, TILE *tile) {
register int xIndex;
register int yIndex;
TILE_TEXTURE_PTR tex = 0;
for (xIndex = 0; xIndex < TILE_WIDTH; xIndex ){
for (yIndex = 0; yIndex < TILE_HEIGHT; yIndex ){
tex = 0;
switch (tile->type) {
case TILE_RED:
tex = &TILE_RED_TEXTURE;
break;
case TILE_BLUE:
tex = &TILE_BLUE_TEXTURE;
break;
case TILE_YELLOW:
tex = &TILE_YELLOW_TEXTURE;
break;
case TILE_GREEN:
tex = &TILE_GREEN_TEXTURE;
break;
case TILE_INDIGO:
tex = &TILE_INDIGO_TEXTURE;
break;
case TILE_SUPERSTAR:
tex = &TILE_SUPERSTAR_TEXTURE;
break;
default:
tex = 0;
break;
}
if( tex == 0 )
putPixel(xIndex x, yIndex y, 0);
else
putPixel(xIndex x, yIndex y,
(*tex)[xIndex][yIndex]);
if (tile->star && tile->type != TILE_EMPTY)
if (TILE_STAR_TEXTURE[xIndex][yIndex] != 0x00)
putPixel(xIndex x, yIndex y,
TILE_STAR_TEXTURE[xIndex][yIndex]);
}
}
return;
}
void tile_swap(TILE *a, TILE *b){
TILE temp;
temp.type = a->type;
temp.star = a->star;
a->type = b->type;
a->star = b->star;
b->type = temp.type;
b->star = temp.star;
return;
}
int TILE_GREEN_TEXTURE[TILE_WIDTH][TILE_HEIGHT] =
{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 249},
{0, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249}
};
int TILE_RED_TEXTURE[TILE_WIDTH][TILE_HEIGHT] =
{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 249},
{0, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249}
};
int TILE_BLUE_TEXTURE[TILE_WIDTH][TILE_HEIGHT] =
{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 249},
{0, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249}
};
int TILE_YELLOW_TEXTURE[TILE_WIDTH][TILE_HEIGHT] =
{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 249},
{0, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249}
};
int TILE_INDIGO_TEXTURE[TILE_WIDTH][TILE_HEIGHT] =
{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 249},
{0, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249, 249}
};
int TILE_STAR_TEXTURE[TILE_WIDTH][TILE_HEIGHT] =
{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{30, 25, 0, 0, 0, 0, 29, 0, 0, 0, 0, 0, 30, 0, 0},
{0, 27, 25, 0, 0, 0, 29, 0, 0, 0, 0, 27, 25, 0, 0},
{0, 0, 27, 25, 0, 0, 28, 0, 0, 0, 27, 25, 0, 0, 0},
{0, 0, 0, 27, 25, 0, 28, 0, 0, 27, 25, 0, 0, 0, 0},
{0, 0, 0, 0, 27, 25, 27, 25, 27, 25, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 25, 28, 28, 28, 25, 0, 0, 0, 0, 0, 0},
{30, 29, 28, 28, 27, 29, 29, 29, 27, 28, 28, 29, 30, 0, 0},
{0, 0, 0, 0, 25, 28, 28, 28, 25, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 27, 25, 27, 25, 27, 25, 0, 0, 0, 0, 0},
{0, 0, 0, 27, 25, 0, 28, 0, 0, 27, 25, 0, 0, 0, 0},
{0, 0, 27, 25, 0, 0, 28, 0, 0, 0, 27, 25, 0, 0, 0},
{0, 27, 25, 0, 0, 0, 29, 0, 0, 0, 0, 27, 25, 0, 0},
{30, 25, 0, 0, 0, 0, 29, 0, 0, 0, 0, 0, 30, 25, 0}
};
int TILE_SUPERSTAR_TEXTURE[TILE_WIDTH][TILE_HEIGHT] =
{
{16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16},
{17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 16},
{17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 16},
{17, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 18, 17, 16},
{17, 18, 19, 20, 20, 20, 20, 20, 20, 20, 20, 19, 18, 17, 16},
{17, 18, 19, 20, 21, 21, 21, 21, 21, 21, 20, 19, 18, 17, 16},
{17, 18, 19, 20, 21, 22, 22, 22, 22, 21, 20, 19, 18, 17, 16},
{17, 18, 19, 20, 21, 22, 23, 23, 22, 21, 20, 19, 18, 17, 16},
{17, 18, 19, 20, 21, 22, 24, 24, 22, 21, 20, 19, 18, 17, 16},
{17, 18, 19, 20, 21, 22, 22, 22, 22, 21, 20, 19, 18, 17, 16},
{17, 18, 19, 20, 21, 21, 21, 21, 21, 21, 20, 19, 18, 17, 16},
{17, 18, 19, 20, 20, 20, 20, 20, 20, 20, 20, 19, 18, 17, 16},
{17, 18, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 18, 17, 16},
{17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 17, 16},
{17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 16},
{16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}
};