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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
#include <ctype.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define TERASGN(a, b, c, d) (a) ? (b = d) : (c = d)
enum {THM, AABB};
int colltype = -1;
int postype = -1;
int verbose = 0;
const char *opts = "c:v:h";
struct pos {
int x;
int y;
int z;
double fx;
double fy;
double fz;
};
struct colis {
int w;
int h;
double xvel;
double yvel;
struct pos pos;
int a1;
int a2;
int b1;
int b2;
double c1;
double c2;
double d1;
double d2;
uint8_t *heightmap;
unsigned int clx : 1;
unsigned int cly : 1;
unsigned int gnded : 1;
unsigned int flp : 1;
};
static int usage() {
printf(
"clld Version MFIYA.\n"
"Usage: clld [options]\n"
"Options:\n"
" -c[type] Force the collision type to be\n"
" the specified type (THM=0, AABB=1).\n"
" -v[level] Sets the verbosity level (0-3).\n"
" -h What do you fucking think it does.\n"
" Anyways, it brings up this cool help\n"
" message.\n"
);
return 0;
}
int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
int newy = 0;
if (!flt) {
cursor.clx = (cursor.a2 > floor.a1-(int)cursor.xvel-1 && cursor.b2 > floor.b1) && (cursor.a1 < (floor.a2-cursor.w)-(int)cursor.xvel+1 && cursor.b1 < floor.b2);
cursor.cly = (cursor.b2 >= floor.b1-(int)cursor.yvel && cursor.a2 >= floor.a1) && (cursor.b1 <= floor.b2-(int)cursor.yvel && cursor.a1 <= floor.a2);
uint8_t l;
uint8_t r;
uint8_t t;
uint8_t b;
if (!floor.flp) {
l = (cursor.a2 > floor.a1-(int)cursor.xvel-1 && floor.b2-cursor.b2 < (int)floor.heightmap[0] && cursor.xvel > 0);
r = (cursor.a1 < (floor.a2-cursor.w)-(int)cursor.xvel+1 && floor.b2-cursor.b2 < (int)floor.heightmap[floor.w-1] && cursor.xvel < 0);
t = (cursor.b2 > (floor.b2-hmpeak)-(int)cursor.yvel && floor.b2-cursor.b2 >= 0);
b = (cursor.b1 < floor.b2-(int)cursor.yvel+1 && floor.b2-cursor.b1 <= 0);
} else {
l = (cursor.a2 > floor.a1-(int)cursor.xvel-1 && floor.b1-cursor.b1 > -(int)floor.heightmap[0] && cursor.xvel > 0);
r = (cursor.a1 < (floor.a2-cursor.w)-(int)cursor.xvel+1 && floor.b1-cursor.b1 > -(int)floor.heightmap[floor.w-1] && cursor.xvel < 0);
t = (cursor.b2 > floor.b1-(int)cursor.yvel-1 && floor.b1-cursor.b2 >= 0 && cursor.yvel > 0);
b = (cursor.b1 < (floor.b1+hmpeak)-(int)cursor.yvel && cursor.b1-floor.b1 >= 0);
}
if (cursor.clx) {
if (cursor.a2-floor.a1 < 0 || cursor.a2-floor.a1 > floor.w) {
if (l)
cursor.pos.x = (floor.pos.x-(int)cursor.xvel)-cursor.w-1;
else if (r)
cursor.pos.x = (floor.a2-cursor.w)-(int)cursor.xvel+1;
cursor.xvel = 0;
}
}
if (cursor.cly) {
if (cursor.a2-floor.a1 < floor.w) {
newy = (int)floor.heightmap[cursor.a2-floor.a1];
if (t)
(!floor.flp) ? (cursor.pos.y = ((floor.b2-cursor.h)-newy)-(int)cursor.yvel) : (cursor.pos.y = (floor.pos.y-cursor.h)-(int)cursor.yvel);
else if (b)
(!floor.flp) ? (cursor.pos.y = (floor.pos.y+floor.h)-(int)cursor.yvel+1) : (cursor.pos.y = (floor.pos.y+newy)-(int)cursor.yvel);
cursor.yvel = 0;
}
}
cursor.gnded = (cursor.pos.y == ((floor.b2-cursor.h)-newy)-(int)cursor.yvel) ? 1 : 0;
printf("%u, %u\n%u\n%i\n%i, %i\n%07.06f, %07.06f\n", cursor.clx, cursor.cly, cursor.gnded, newy, cursor.pos.x, cursor.pos.y, cursor.xvel, cursor.yvel);
} else {
cursor.clx = (cursor.c2 > floor.c1-cursor.xvel-1 && cursor.d2 > floor.d1) && (cursor.c1 < (floor.c2-cursor.w)-cursor.xvel+1 && cursor.d1 < floor.d2);
cursor.cly = (cursor.d2 >= floor.d1-cursor.yvel && cursor.c2 >= floor.c1) && (cursor.d1 <= floor.d2-cursor.yvel && cursor.c1 <= floor.c2);
uint8_t l;
uint8_t r;
uint8_t t;
uint8_t b;
if (!floor.flp) {
l = (cursor.c2 > floor.c1-cursor.xvel-1 && floor.d2-cursor.d2 < (int)floor.heightmap[0] && cursor.xvel > 0);
r = (cursor.c1 < (floor.c2-cursor.w)-cursor.xvel+1 && floor.d2-cursor.d2 < (int)floor.heightmap[floor.w-1] && cursor.xvel < 0);
t = (cursor.d2 > (floor.d2-hmpeak)-cursor.yvel && floor.d2-cursor.d2 >= 0);
b = (cursor.d1 < floor.d2-cursor.yvel+1 && floor.d2-cursor.d1 <= 0);
} else {
l = (cursor.c2 > floor.c1-cursor.xvel-1 && floor.d1-cursor.d1 > -(int)floor.heightmap[0] && cursor.xvel > 0);
r = (cursor.c1 < (floor.c2-cursor.w)-cursor.xvel+1 && floor.d1-cursor.d1 > -(int)floor.heightmap[floor.w-1] && cursor.xvel < 0);
t = (cursor.d2 > floor.d1-cursor.yvel-1 && floor.d1-cursor.d2 >= 0 && cursor.yvel > 0);
b = (cursor.c1 < (floor.d1+hmpeak)-cursor.yvel && cursor.d1-floor.d1 >= 0);
}
if (cursor.clx) {
if (cursor.c2-floor.c1 < -1 || cursor.c2-floor.c1 > floor.w) {
if (l)
cursor.pos.fx = (floor.pos.fx-cursor.xvel)-cursor.w-1;
else if (r)
cursor.pos.fx = (floor.c2-cursor.w)-cursor.xvel+1;
cursor.xvel = 0;
}
}
if (cursor.cly) {
if (cursor.c2-floor.c1 < floor.w) {
newy = (int)floor.heightmap[(int)cursor.c2-(int)floor.c1];
if (t)
(!floor.flp) ? (cursor.pos.fy = ((floor.d2-cursor.h)-newy)-cursor.yvel) : (cursor.pos.fy = (floor.pos.fy-cursor.h)-cursor.yvel);
else if (b)
(!floor.flp) ? (cursor.pos.fy = (floor.pos.fy+floor.h)-cursor.yvel) : (cursor.pos.fy = (floor.pos.fy+newy)-cursor.yvel);
cursor.yvel = 0;
}
}
cursor.gnded = (cursor.pos.fy == ((floor.d2-cursor.h)-newy)-cursor.yvel) ? 1 : 0;
printf("%u, %u\n%u\n%i\n%07.06f, %07.06f\n%07.06f, %07.06f\n", cursor.clx, cursor.cly, cursor.gnded, newy, cursor.pos.fx, cursor.pos.fy, cursor.xvel, cursor.yvel);
}
return 0;
}
int aabb(uint8_t flt, struct colis cursor, struct colis floor) {
uint8_t l = (!flt) ? (cursor.a2 > floor.a1-(int)cursor.xvel-1 && cursor.b2 > floor.b1) : (cursor.c2 > floor.c1-cursor.xvel-1 && cursor.d2 > floor.d1);
uint8_t r = (!flt) ? (cursor.a1 < floor.a2-(int)cursor.xvel+1 && cursor.b1 < floor.b2) : (cursor.c1 < floor.c2-cursor.xvel+1 && cursor.d1 < floor.d2);
uint8_t t = (!flt) ? (cursor.b2 > floor.b1-(int)cursor.yvel-1 && cursor.a2 > floor.a1) : (cursor.d2 > floor.d1-cursor.yvel-1 && cursor.c2 > floor.c1);
uint8_t b = (!flt) ? (cursor.b1 < floor.b2-(int)cursor.yvel+1 && cursor.a1 < floor.a2) : (cursor.d1 < floor.d2-cursor.yvel+1 && cursor.c1 < floor.c2);
cursor.clx = l && r;
cursor.cly = t && b;
cursor.gnded = (cursor.b2 == floor.b1-(int)cursor.yvel-1) ? 1 : 0;
if (l && cursor.xvel > 0)
(!flt) ? (cursor.pos.x = (floor.pos.x-(int)cursor.xvel)-cursor.w-1) : (cursor.pos.fx = (floor.pos.fx-cursor.xvel)-(double)cursor.w-1);
else if (r && cursor.xvel < 0)
(!flt) ? (cursor.pos.x = (floor.pos.x+floor.w)-(int)cursor.xvel+1) : (cursor.pos.fx = (floor.pos.fx+(double)floor.w)-cursor.xvel+1);
cursor.xvel = 0;
if (t && cursor.yvel > 0)
(!flt) ? (cursor.pos.y = (floor.pos.y-(int)cursor.yvel)-cursor.h-1) : (cursor.pos.fy = (floor.pos.fy-cursor.yvel)-(double)cursor.h-1);
else if (b && cursor.yvel < 0)
(!flt) ? (cursor.pos.y = (floor.pos.y+floor.h)-(int)cursor.yvel+1) : (cursor.pos.fy = (floor.pos.fy+(double)floor.h)-cursor.yvel+1);
cursor.yvel = 0;
if (!flt)
printf("%u, %u\n%u\n%i, %i\n%07.06f, %07.06f\n", cursor.clx, cursor.cly, cursor.gnded, cursor.pos.x, cursor.pos.y, cursor.xvel, cursor.yvel);
else
printf("%u, %u\n%u\n%07.06f, %07.06f\n%07.06f, %07.06f\n", cursor.clx, cursor.cly, cursor.gnded, cursor.pos.fx, cursor.pos.fy, cursor.xvel, cursor.yvel);
return 0;
}
int main(int argc, char **argv) {
int c;
opterr = 0;
while ((c = getopt(argc, argv, opts)) != -1) {
switch(c) {
case 'c':
colltype = atoi(optarg);
break;
case 'v':
verbose = atoi(optarg);
break;
case 'h':
usage();
return 2;
case '?':
if (isprint(optopt)) {
if (optopt == 'c') {
fprintf(stderr, "Setting colltype to default.\n");
colltype = -1;
break;
} else if (optopt == 'v') {
fprintf(stderr, "Enabling single level verbosity.\n");
verbose = 1;
break;
} else {
fprintf(stderr
, "The option that you have typed in, which in this case\n"
"is -%c, does not exist.\n"
"Try looking at the help message, or RTFM, next time.\n"
, optopt);
}
} else {
fprintf(stderr
, "What the fuck are you trying to type in, a binary blob?\n"
"Because of this, clld will exit, so, stop acting like a\n"
"jackass.\n");
}
return -1;
default: ;
}
}
struct colis cursor;
struct colis floor;
colltype = AABB;
cursor.h = 16;
cursor.w = 16;
cursor.pos.x = 17;
cursor.pos.y = 24;
cursor.xvel = 1;
cursor.yvel = 0;
floor.w = 16;
floor.h = 16;
floor.flp = 0;
int hmpeak;
if (colltype == THM) {
floor.heightmap = malloc(sizeof(uint8_t *)*floor.w);
for (int i = 0; i <floor.w; i++)
floor.heightmap[i] = i+1;
hmpeak = floor.heightmap[floor.w-1];
}
uint8_t flt = 0;
floor.pos.x = 32;
floor.pos.y = 32;
(!flt) ? (cursor.a1 = cursor.pos.x) : (cursor.c1 = cursor.pos.fx);
(!flt) ? (cursor.a2 = cursor.pos.x+cursor.w) : (cursor.c2 = cursor.pos.fx+cursor.w);
(!flt) ? (cursor.b1 = cursor.pos.y) : (cursor.d1 = cursor.pos.fy);
(!flt) ? (cursor.b2 = cursor.pos.y+cursor.h) : (cursor.d2 = cursor.pos.fy+cursor.h);
(!flt) ? (floor.a1 = floor.pos.x) : (floor.c1 = floor.pos.fx);
(!flt) ? (floor.a2 = floor.pos.x+floor.w) : (floor.c2 = floor.pos.fx+floor.w);
(!flt) ? (floor.b1 = floor.pos.y) : (floor.d1 = floor.pos.fy);
(!flt) ? (floor.b2 = floor.pos.y+floor.h) : (floor.d2 = floor.pos.fy+floor.h);
if (colltype == THM)
thm(flt, hmpeak, cursor, floor);
if (colltype == AABB)
aabb(flt, cursor, floor);
if(colltype == THM) {
free(floor.heightmap);
}
fflush(stdout);
return 0;
}
|