summaryrefslogtreecommitdiff
path: root/clld.c
diff options
context:
space:
mode:
Diffstat (limited to 'clld.c')
-rw-r--r--clld.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/clld.c b/clld.c
index 81954a6..07f3c8b 100644
--- a/clld.c
+++ b/clld.c
@@ -97,6 +97,7 @@ int main(int argc, char **argv) {
* the process of getting collision data, to one for loop.
*/
struct colis tmp;
+ int hmpeak;
/* Get collision type. */
char *buf = NULL;
size_t size;
@@ -161,6 +162,7 @@ int main(int argc, char **argv) {
char *tmptok = strtok((i == 0) ? buf : NULL,",");
tmptok = (tmptok == NULL) ? strtok(NULL,"\n") : tmptok;
tmp.bitmask[i] = (uint8_t *)((atoi(tmptok) <= tmp.h) ? atoi(tmptok) : tmp.h);
+ hmpeak = (atoi(tmptok)+1 >= hmpeak) ? atoi(tmptok)+1 : hmpeak;
}
}
@@ -249,24 +251,43 @@ int main(int argc, char **argv) {
floor.b1 = floor.pos.y;
floor.b2 = floor.pos.y+floor.h;
+ 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)) ? 1 : 0;
/* Check for a collision, on the y axis. */
- cursor.cly = ((cursor.b2 >= floor.b1-(int)cursor.yvel && cursor.a2 >= floor.a1) && (cursor.b1 <= floor.b2-(int)cursor.yvel && cursor.a1 <= floor.a2)) ? 1 : 0;
+ cursor.cly = ((cursor.b2 >= (floor.b1-hmpeak-1)-(int)cursor.yvel && cursor.a2 >= floor.a1) && (cursor.b1 <= (floor.b2+hmpeak+1)-(int)cursor.yvel && cursor.a1 <= floor.a2)) ? 1 : 0;
int newy = 0;
if (cursor.cly) {
if (cursor.a2-floor.a1 < floor.h) {
+ cursor.yvel = 0;
newy = (int)floor.bitmask[cursor.a2-floor.a1];
/* Is the Floor, really a floor? */
- if (cursor.b2 > floor.b1-(int)cursor.yvel-1 && !floor.flp)
- cursor.pos.y = floor.pos.y-(cursor.h-newy)-(int)cursor.yvel;
+ if (cursor.b2 > (floor.b2-hmpeak-1)-(int)cursor.yvel && floor.b2-cursor.b2 >= 0 && !floor.flp)
+ cursor.pos.y = (floor.b2-newy-1)-(int)cursor.yvel;
+ else if (cursor.b1 < floor.b2-(int)cursor.yvel && floor.b2-cursor.b2 < 0 && !floor.flp)
+ cursor.pos.y = (floor.pos.y+floor.h)-(int)cursor.yvel;
/* Is the Floor, actually a ceiling? */
- else if (cursor.b1 < floor.b2-(int)cursor.yvel+1 && floor.flp)
- cursor.pos.y = (floor.pos.y+newy)-(int)cursor.yvel;
+ if (cursor.b1 < (floor.b1+hmpeak+1)-(int)cursor.yvel && floor.b1-cursor.b1 >= 0 && floor.flp)
+ cursor.pos.y = (floor.pos.y+newy+1)-(int)cursor.yvel;
+ else if (cursor.b2 > floor.b1-(int)cursor.yvel-1 && floor.b1-cursor.b1 < 0 && cursor.yvel > 0 && floor.flp)
+ cursor.pos.y = (floor.pos.y-(int)cursor.yvel-1)-cursor.h;
}
}
+ if (cursor.clx) {
+ /* Is the Cursor coming from the left? */
+ if (cursor.a2 > floor.a1-(int)cursor.xvel-1 && floor.b2-cursor.b2 < 0 && !floor.flp && cursor.xvel > 0)
+ cursor.pos.x = (floor.pos.x-(int)cursor.xvel)-cursor.w-1;
+ else if (cursor.a1 < (floor.a2-cursor.w)-(int)cursor.xvel+1 && floor.b2-cursor.b2 < 0 && !floor.flp && cursor.xvel < 0)
+ cursor.pos.x = (floor.a2-cursor.w)-(int)cursor.xvel+1;
+ /* Is the Cursor coming from the right? */
+ if (cursor.a1 < (floor.a2-cursor.w)-(int)cursor.xvel+1 && floor.b1-cursor.b1 < 0 && floor.flp && cursor.xvel < 0)
+ cursor.pos.x = (floor.a2-cursor.w)-(int)cursor.xvel+1;
+ else if (cursor.a2 > floor.a1-(int)cursor.xvel-1 && floor.b1-cursor.b1 < 0 && floor.flp && cursor.xvel > 0)
+ cursor.pos.x = (floor.pos.x-(int)cursor.xvel)-cursor.w-1;
+ cursor.xvel = 0;
+ }
cursor.gnded = (cursor.pos.y == floor.pos.y-(cursor.h-newy)) ? 1 : 0;
- printf("%u\n%u\n%i\n%i, %i\n%07.06f, %07.06f\n", cursor.cly, cursor.gnded, newy, cursor.pos.x, cursor.pos.y, cursor.xvel, cursor.yvel);
+ printf("%u\n%u\n%i\nfloor.b2-cursor.b2: %i, floor.b1-cursor.b1: %i\n%i, %i\n%07.06f, %07.06f\n", cursor.cly, cursor.gnded, newy, floor.b2-cursor.b2, floor.b1-cursor.b1, cursor.pos.x, cursor.pos.y, cursor.xvel, cursor.yvel);
} else {
cursor.c1 = cursor.pos.fx;
cursor.c2 = cursor.pos.fx+cursor.w;
@@ -341,7 +362,7 @@ int main(int argc, char **argv) {
printf("floor.x: %i, floor.y: %i\n", floor.pos.x, floor.pos.y);
printf ("r: %i\n", (floor.pos.x+floor.w)-(int)cursor.xvel+1);
}
- 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);
+ printf("%u, %u\n%u\n%i, %i\n%07.06f, %07.06f\n\0", cursor.clx, cursor.cly, cursor.gnded, cursor.pos.x, cursor.pos.y, cursor.xvel, cursor.yvel);
} else {
cursor.c1 = cursor.pos.fx;
cursor.c2 = cursor.pos.fx+cursor.w;
@@ -375,7 +396,7 @@ int main(int argc, char **argv) {
printf("fx: %07.06f, fy: %07.06f\n", cursor.pos.fx, cursor.pos.fy);
printf("floor.fx: %07.06f, floor.fy: %07.06f\n", floor.pos.fx, floor.pos.fy);
}
- 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);
+ printf("%u, %u\n%u\n%07.06f, %07.06f\n%07.06f, %07.06f\n\0", cursor.clx, cursor.cly, cursor.gnded, cursor.pos.fx, cursor.pos.fy, cursor.xvel, cursor.yvel);
}
}
}