-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.c
129 lines (100 loc) · 2.76 KB
/
map.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
#include "muon.h"
int Map_init() {
object_array_len = 0;
object_array = malloc(sizeof(Object));
object_array[0].x = 0;
object_array[0].y = 0;
object_array[0].hp = 0;
object_array[0].type = 0;
object_array[0].owner = 0;
return 0;
}
int fileLoad(char *file) {
char tempc, c;
int i = 0, k = 1;
printf("Trying to open file %s...\n", file);
FILE *File;
if ((File = fopen(file, "r")) == NULL) {
printf("Error: fileLoad: Could not load file %s!\n", file);
return -1;
}
while ((tempc = fgetc(File)) != EOF) {
switch (tempc) {
case 'D':
c = getc(File);
map.width = c;
c = getc(File);
map.width = map.width + c * 0x100;
c = getc(File);
map.height = c;
c = getc(File);
map.height = map.height + c * 0x100;
c = getc(File);
break;
case 'C':
i = objectArray_Grow();
object_array[i].x = getc(File);
c = getc(File);
object_array[i].x = object_array[i].x + c * 0x100;
object_array[i].y = getc(File);
c = getc(File);
object_array[i].y = object_array[i].y + c * 0x100;
object_array[i].owner = getc(File);
object_array[i].type = 0x2;
break;
case 'S':
i = objectArray_Grow();
object_array[i].x = getc(File);
c = getc(File);
object_array[i].x = object_array[i].x + c * 0x100;
object_array[i].y = getc(File);
c = getc(File);
object_array[i].y = object_array[i].y + c * 0x100;
object_array[i].type = 0x1;
object_array[i].owner = getc(File);
// if (map.gamemode == 1) {
// objectArray_Add(3, object_array[i].x, object_array[i].y, k);
// }
k++;
break;
case 'G':
i = objectArray_Grow();
object_array[i].x = getc(File);
c = getc(File);
object_array[i].x = object_array[i].x + c * 0x100;
object_array[i].y = getc(File);
c = getc(File);
object_array[i].y = object_array[i].x + c * 0x100;
object_array[i].type = 0x3;
object_array[i].owner = getc(File);
object_array[i].hp = object_template_array[object_array[i].type].max_hp;
object_array[i].shield = object_template_array[object_array[i].type].max_shield;
break;
case 'W':
map.windw = getc(File);
map.windw = map.windw + getc(File) * 0x100;
map.windh = getc(File);
map.windh = map.windh + getc(File) * 0x100;
frame_per_sec = getc(File);
break;
default:
break;
}
}
fclose(File);
return 0;
}
int Map_unload() {
free(object_array);
object_array = NULL;
return 0;
}
int Map_debug() {
int i;
//objectArray_Add(1337, 1000, 500, 3);
//objectArray_Del(0);
for (i=0; object_array[i].type != 0; i++) {
printf("Object type %i at X: %i, Y: %i with owner %i\n", object_array[i].type, object_array[i].x, object_array[i].y, object_array[i].owner);
}
return 0;
}