-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLVCREATE.C
206 lines (192 loc) · 6.97 KB
/
LVCREATE.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
/*
Map maker
load map from txt file and put in lvl file with map data and objects
*/
char fileName[50] = "AREA4";
#include "MZRUN/INCLUDES/GLOBALS.H"
struct Creator {
struct Level data;
struct Tile map[MaxY][MaxX];
int cmap[MaxY][MaxX];
struct coord pos;
char paths[50][50];
struct coord player_pos[4];
bool end;
int totFiles;
};
char src[50], trg[50];
void Creator_init(struct Creator *this) {
int i, j;
for(i = 0; i < fullmap.y; i++) {
for(j = 0; j < fullmap.x; j++) {
Tile_init(&this->data.map[i][j], false, false, false, true);
}
}
this->pos.x = this->pos.y = 1; this->end = false; this->totFiles = 0;
}
/*void Creator_draw(struct Creator *this) {
}
void Creator_create_object(struct Creator *this, char c) {
}
void Creator_make_map(struct Creator *this) {
}
void Creator_input(struct Creator *this) {
}
bool Creator_move(struct Creator *this, int PosX, int PosY) {
}*/
int Creator_getPaths(struct Creator *this) {
struct dirent *de;
int i, cnt=0, s;
char ext[] = ".TXT", tmp[50];
DIR *dr = opendir("MZRUN/files/TXTFILES");
if(dr == NULL) return 0;
while((de = readdir(dr)) != NULL) {
s = strlen(de->d_name);
for(i = s-4; i < s; i++) {
if(de->d_name[i] != ext[i-(s-4)]) break;
}
if(i==s) {
for(i = 0; i<s-4; i++) {
tmp[i] = de->d_name[i];
}
tmp[i] = '\0';
strcpy(this->paths[cnt++], tmp);
//printf("\n%s", paths[cnt-1]);
}
}
closedir(dr);
return cnt;
}
void Creator_create_lvl(struct Creator *this) {
int i = 0, j = 0, cnt = 0;
char ch;
struct Object temp;
int p_cnt = 0;
FILE *file;
char fileName[50] = "MZRUN/files/TXTFILES/";
coord_init(&fullmap, 90, 30);
//Create Map file
strcpy(fileName, src);
file = fopen(fileName, "r");
//file = fopen("MZRUN/files/TXTFILES/area4.txt", "r");
if( file == NULL) {
clrscr(); printf("\n! ERROR: %s missing !", fileName); getch(); exit(0);
}
/*while(!feof(file)) {
fscanf(file, "%s", &this->cmap[i++]);
}*/
while((ch = fgetc(file)) != EOF ) {
if(ch == '\n') { i = 0; j++; continue; }
this->cmap[j][i] = ch;
i++;
}
fclose(file);
totalEntities = 1;
/*gotoxy(1, 1);
for(i = 0; i<20; i++) {
for(j = 0; j<60; j++) {
printf("%c", this->cmap[i][j]);
}
printf("\n");
}
getch(); exit(0);*/
for(i = 0; i<fullmap.y; i++) {
for(j = 0; j<fullmap.x; j++) {
Tile_init(&this->data.map[i][j], false, false, false, true);
if(this->cmap[i][j]=='@') {
Object_init(&temp, j, i, RIGHT, '@', "player", "player", GREEN, BLACK, 0, 0, 1);
this->cmap[i][j] = '.'; entityObjects[0] = temp;
if(p_cnt < 4) {
coord_init(&(this->data.player_pos[p_cnt++]), j, i);
}
} else if(this->cmap[i][j] == '1') {
Object_init(&temp, j, i, STOP, '*', "monster", "normal", RED, BLACK, 5, 5, 1);
this->cmap[i][j] = '.'; entityObjects[totalEntities++] = temp;
this->data.map[i][j].playerOnly = true;
} else if(this->cmap[i][j] == '2') {
Object_init(&temp, j, i, STOP, '*', "monster", "ranger", RED, BLACK, 7, 9, 1);
this->cmap[i][j] = '.'; entityObjects[totalEntities++] = temp;
this->data.map[i][j].playerOnly = true;
} else if(this->cmap[i][j] == '3') {
Object_init(&temp, j, i, STOP, '*', "monster", "sprinter", RED, BLACK, 9, 7, 1);
this->cmap[i][j] = '.'; entityObjects[totalEntities++] = temp;
this->data.map[i][j].playerOnly = true;
} else if(this->cmap[i][j] == '4') {
Object_init(&temp, j, i, STOP, '*', "monster", "reaper", BROWN, BLACK, 15, fullmap.x, 1);
this->cmap[i][j] = '.'; entityObjects[totalEntities++] = temp;
this->data.map[i][j].playerOnly = true;
} else if(this->cmap[i][j] == '5') {
Object_init(&temp, j, i, STOP, '*', "monster", "vampire", CYAN, BLACK, 11, 11, 1);
this->cmap[i][j] = '.'; entityObjects[totalEntities++] = temp;
this->data.map[i][j].playerOnly = true;
} else if(this->cmap[i][j] == '6') {
Object_init(&temp, j, i, STOP, '*', "monster", "elite", YELLOW, BLACK, 9, 9, 1);
this->cmap[i][j] = '.'; entityObjects[totalEntities++] = temp;
this->data.map[i][j].playerOnly = true;
} else if(this->cmap[i][j] == '7') {
Object_init(&temp, j, i, STOP, '*', "monster", "ghost", WHITE, BLACK, 9, 9, 1);
this->cmap[i][j] = '.'; entityObjects[totalEntities++] = temp;
} else if(this->cmap[i][j] == '#') {
Tile_block(&this->data.map[i][j]); Tile_blockSight(&this->data.map[i][j]);
} else if(this->cmap[i][j] == 'g') {
Object_init(&temp, j, i, STOP, 'g', "goal", "goal1", CYAN, CYAN, 0, 0, 0);
entityObjects[totalEntities++] = temp;
this->cmap[i][j] = '.'; this->data.map[i][j].playerOnly = true;
} else if(this->cmap[i][j] == 's') {
Object_init(&temp, j, i, STOP, 4, "effect", "slow1", LIGHTBLUE, BLACK, 0, 0, 0);
entityObjects[totalEntities++] = temp;
this->cmap[i][j] = '.'; //this->data.map[i][j].playerOnly = true;
} else if(this->cmap[i][j] == 'f') {
Object_init(&temp, j, i, STOP, 4, "effect", "fast1", LIGHTBLUE, BLACK, 0, 0, 0);
entityObjects[totalEntities++] = temp;
this->cmap[i][j] = '.'; //this->data.map[i][j].playerOnly = true;
} else if(this->cmap[i][j] == 'x') {
Object_init(&temp, j, i, STOP, 4, "effect", "breaker1", LIGHTBLUE, BLACK, 0, 0, 0);
entityObjects[totalEntities++] = temp;
this->cmap[i][j] = '.'; //this->data.map[i][j].playerOnly = true;
} else if(this->cmap[i][j] == 'r') {
Object_init(&temp, j, i, STOP, 4, "effect", "repel1", LIGHTBLUE, BLACK, 0, 0, 0);
entityObjects[totalEntities++] = temp;
this->cmap[i][j] = '.'; //this->data.map[i][j].playerOnly = true;
} else if(this->cmap[i][j] == 'a') {
Object_init(&temp, j, i, STOP, 4, "effect", "attract1", LIGHTBLUE, BLACK, 0, 0, 0);
entityObjects[totalEntities++] = temp;
this->cmap[i][j] = '.'; //this->data.map[i][j].playerOnly = true;
} else if(this->cmap[i][j] == 'v') {
Object_init(&temp, j, i, STOP, 4, "effect", "fullvision1", LIGHTBLUE, BLACK, 0, 0, 0);
entityObjects[totalEntities++] = temp;
this->cmap[i][j] = '.'; //this->data.map[i][j].playerOnly = true;
} else if(this->cmap[i][j] == ' ') {
this->cmap[i][j] = '.'; Tile_close(&this->data.map[i][j]); this->data.map[i][j].playerOnly = true;
} else {
}
}
}
while(p_cnt < 4) {
coord_cpy(&(this->data.player_pos[p_cnt]), this->data.player_pos[p_cnt-1]);
p_cnt++;
}
/*for(i=0; i<4; i++)
printf("\n%d, %d", this->data.player_pos[i].x, this->data.player_pos[i].y);*/
strcpy(fileName, trg);
Level_Export(&(this->data), fileName);
cnt++;
}
void main() {
struct Creator creator;
int i, j;
clrscr();
textcolor(WHITE);
/*printf("Enter File Name: ");
scanf("%s", &fileName);*/
creator.totFiles = Creator_getPaths(&creator);
for(i = 0; i<creator.totFiles; i++) {
strcpy(fileName, creator.paths[i]);
//sprintf(src, "MZRUN/files/TXTFILES/%s.TXT", fileName);
sprintf(src, "MZRUN/files/TXTFILES/%s.TXT", fileName);
sprintf(trg, "MZRUN/files/LEVELS/%s.LVL", fileName);
printf("\nCreating: %s.LVL ...", fileName);
Creator_create_lvl(&creator);
}
printf("\n\nDone"); getch();
}