summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2019-10-16 13:15:58 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2019-10-16 15:53:32 -0400
commite59a2cc9478a486ce620a63752205da178f2ad04 (patch)
tree0e6f33279e051e1a19e1c45541e3f7663f7c51be
parent940e3be36051694689a292a7433241852e05158f (diff)
Make clld, even less bloat.
-rw-r--r--clld-bench.c122
-rw-r--r--clld.c118
2 files changed, 86 insertions, 154 deletions
diff --git a/clld-bench.c b/clld-bench.c
index 12eb8ec..85d7f22 100644
--- a/clld-bench.c
+++ b/clld-bench.c
@@ -93,24 +93,12 @@ static int usage() {
return 0;
}
-int clx(struct colis c, struct colis f, int xvel, uint8_t flt) {
- int l = (!flt) ? (c.a2 > f.a1-xvel-1 && c.b2 > f.b1) : (c.c2 > f.c1-c.xvel-1 && c.d2 > f.d1);
- int r = (!flt) ? (c.a1 < f.a2-xvel+1 && c.b1 < f.b2) : (c.c1 < f.c2-c.xvel+1 && c.d1 < f.d2);
- return l && r;
-}
-
-int cly(struct colis c, struct colis f, int yvel, uint8_t flt) {
- int t = (!flt) ? (c.b2 > f.b1-yvel-1 && c.a2 > f.a1) : (c.d2 > f.d1-c.yvel-1 && c.c2 > f.c1);
- int b = (!flt) ? (c.b1 < f.b2-yvel+1 && c.a1 < f.a2) : (c.d1 < f.d2-c.yvel+1 && c.c1 < f.c2);
- return t && b;
-}
-
/* Tile Heightmap Collision. */
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-hmpeak)-(int)cursor.yvel && cursor.a2 >= floor.a1) && (cursor.b1 <= (floor.b2+hmpeak)-(int)cursor.yvel && cursor.a1 <= floor.a2);
+ 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;
@@ -121,18 +109,18 @@ int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
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 && cursor.b1-floor.b1 < 0 && cursor.xvel > 0);
- r = (cursor.a1 < (floor.a2-cursor.w)-(int)cursor.xvel+1 && cursor.b1-floor.b1 < 0 && cursor.xvel < 0);
- t = (cursor.b2 > floor.b1-(int)cursor.yvel-1 && cursor.b2-floor.b1 < 0 && cursor.yvel > 0);
+ 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)
- (!floor.flp) ? (cursor.pos.x = (floor.pos.x-(int)cursor.xvel)-cursor.w-1) : (cursor.pos.x = (floor.a2-cursor.w)-(int)cursor.xvel+1);
+ cursor.pos.x = (floor.pos.x-(int)cursor.xvel)-cursor.w-1;
else if (r)
- (!floor.flp) ? (cursor.pos.x = (floor.a2-cursor.w)-(int)cursor.xvel+1) : (cursor.pos.x = (floor.pos.x-(int)cursor.xvel)-cursor.w-1);
+ cursor.pos.x = (floor.a2-cursor.w)-(int)cursor.xvel+1;
cursor.xvel = 0;
}
}
@@ -140,7 +128,7 @@ int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
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+newy)-(int)cursor.yvel);
+ (!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;
@@ -150,7 +138,7 @@ int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
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-hmpeak)-cursor.yvel && cursor.c2 >= floor.c1) && (cursor.d1 <= (floor.d2+hmpeak)-cursor.yvel && cursor.c1 <= floor.c2);
+ 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;
@@ -161,28 +149,28 @@ int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
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 && cursor.d1-floor.d1 < 0 && cursor.xvel > 0);
- r = (cursor.c1 < (floor.c2-cursor.w)-cursor.xvel+1 && cursor.d1-floor.d1 < 0 && cursor.xvel < 0);
- t = (cursor.d2 > floor.d1-cursor.yvel-1 && cursor.d2-floor.d1 < 0 && cursor.yvel > 0);
- b = (cursor.d1 < (floor.d1+hmpeak)-cursor.yvel && cursor.d1-floor.d1 >= 0);
+ 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 < 0 || cursor.c2-floor.c1 > floor.w) {
+ if (cursor.c2-floor.c1 < -1 || cursor.c2-floor.c1 > floor.w) {
if (l)
- (!floor.flp) ? (cursor.pos.fx = (floor.pos.fx-cursor.xvel)-cursor.w-1) : (cursor.pos.fx = (floor.c2-cursor.w)-cursor.xvel+1);
+ cursor.pos.fx = (floor.pos.fx-cursor.xvel)-cursor.w-1;
else if (r)
- (!floor.flp) ? (cursor.pos.fx = (floor.c2-cursor.w)-cursor.xvel+1) : (cursor.pos.fx = (floor.pos.fx-cursor.xvel)-cursor.w-1);
+ cursor.pos.fx = (floor.c2-cursor.w)-cursor.xvel+1;
cursor.xvel = 0;
}
}
if (cursor.cly) {
- if (cursor.a2-floor.a1 < floor.w) {
+ 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+newy)-cursor.yvel);
+ (!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+1) : (cursor.pos.fy = (floor.pos.fy+newy)-cursor.yvel);
+ (!floor.flp) ? (cursor.pos.fy = (floor.pos.fy+floor.h)-cursor.yvel) : (cursor.pos.fy = (floor.pos.fy+newy)-cursor.yvel);
cursor.yvel = 0;
}
}
@@ -194,54 +182,32 @@ int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
/* Axis Aligned Bounding Box Collision. */
int aabb(uint8_t flt, struct colis cursor, struct colis floor) {
- if (!flt) {
- /* Is the Cursor is on the ground? */
- cursor.gnded = (cursor.b2 == floor.b1-(int)cursor.yvel-1) ? 1 : 0;
-
- /* Check for collisions, on both axies. */
- cursor.clx = clx(cursor, floor, (int)cursor.xvel, flt);
- cursor.cly = cly(cursor, floor, (int)cursor.yvel, flt);
-
- if (cursor.clx) {
- /* Is the Cursor coming from the left? */
- if (cursor.a2 > floor.a1-(int)cursor.xvel-1 && cursor.xvel > 0)
- cursor.pos.x = (floor.pos.x-(int)cursor.xvel)-cursor.w-1;
- /* Is the Cursor coming from the right? */
- else if (cursor.a1 < floor.a2-(int)cursor.xvel+1 && cursor.xvel < 0)
- cursor.pos.x = (floor.pos.x+floor.w)-(int)cursor.xvel+1;
- cursor.xvel = 0;
- }
- if (cursor.cly) {
- /* Is the Cursor coming from the top? */
- if (cursor.b2 > floor.b1-(int)cursor.yvel-1 && cursor.yvel > 0)
- cursor.pos.y = (floor.pos.y-(int)cursor.yvel)-cursor.h-1;
- /* Is the Cursor coming from the bottom? */
- else if (cursor.b1 < floor.b2-(int)cursor.yvel+1 && cursor.yvel < 0)
- cursor.pos.y = (floor.pos.y+floor.h)-(int)cursor.yvel+1;
- cursor.yvel = 0;
- }
+ 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;
+ /* Is the Cursor is on the ground? */
+ cursor.gnded = (cursor.b2 == floor.b1-(int)cursor.yvel-1) ? 1 : 0;
+ /* Is the Cursor coming from the left? */
+ 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);
+ /* Is the Cursor coming from the right? */
+ 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;
+ /* Is the Cursor coming from the top? */
+ 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);
+ /* Is the Cursor coming from the bottom? */
+ 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 {
- cursor.gnded = (cursor.d2 == floor.d1-cursor.yvel-1) ? 1 : 0;
- cursor.clx = clx(cursor, floor, 0, flt);
- cursor.cly = cly(cursor, floor, 0, flt);
-
- if (cursor.clx) {
- if (cursor.c2 > floor.c1-cursor.xvel-1 && cursor.xvel > 0)
- cursor.pos.fx = (floor.pos.fx-cursor.xvel)-(double)cursor.w-1;
- else if (cursor.c1 < floor.c2-cursor.xvel+1 && cursor.xvel < 0)
- cursor.pos.fx = (floor.pos.fx+(double)floor.w)-cursor.xvel+1;
- cursor.xvel = 0;
- }
- if (cursor.cly) {
- if (cursor.d2 > floor.d1-cursor.yvel-1 && cursor.yvel > 0)
- cursor.pos.fy = (floor.pos.fy-cursor.yvel)-(double)cursor.h-1;
- else if (cursor.d1 < floor.d2-cursor.yvel+1 && cursor.yvel < 0)
- cursor.pos.fy = (floor.pos.fy+(double)floor.h)-cursor.yvel+1;
- cursor.yvel = 0;
- }
+ 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;
}
@@ -297,8 +263,8 @@ int main(int argc, char **argv) {
cursor.h = 16;
cursor.w = 16;
cursor.pos.x = 17;
- cursor.pos.y = 32;
- cursor.xvel = 0;
+ cursor.pos.y = 24;
+ cursor.xvel = 1;
cursor.yvel = 0;
floor.w = 16;
floor.h = 16;
diff --git a/clld.c b/clld.c
index 4c21090..b08e0de 100644
--- a/clld.c
+++ b/clld.c
@@ -93,24 +93,12 @@ static int usage() {
return 0;
}
-int clx(struct colis c, struct colis f, int xvel, uint8_t flt) {
- int l = (!flt) ? (c.a2 > f.a1-xvel-1 && c.b2 > f.b1) : (c.c2 > f.c1-c.xvel-1 && c.d2 > f.d1);
- int r = (!flt) ? (c.a1 < f.a2-xvel+1 && c.b1 < f.b2) : (c.c1 < f.c2-c.xvel+1 && c.d1 < f.d2);
- return l && r;
-}
-
-int cly(struct colis c, struct colis f, int yvel, uint8_t flt) {
- int t = (!flt) ? (c.b2 > f.b1-yvel-1 && c.a2 > f.a1) : (c.d2 > f.d1-c.yvel-1 && c.c2 > f.c1);
- int b = (!flt) ? (c.b1 < f.b2-yvel+1 && c.a1 < f.a2) : (c.d1 < f.d2-c.yvel+1 && c.c1 < f.c2);
- return t && b;
-}
-
/* Tile Heightmap Collision. */
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-hmpeak)-(int)cursor.yvel && cursor.a2 >= floor.a1) && (cursor.b1 <= (floor.b2+hmpeak)-(int)cursor.yvel && cursor.a1 <= floor.a2);
+ 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;
@@ -121,18 +109,18 @@ int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
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 && cursor.b1-floor.b1 < 0 && cursor.xvel > 0);
- r = (cursor.a1 < (floor.a2-cursor.w)-(int)cursor.xvel+1 && cursor.b1-floor.b1 < 0 && cursor.xvel < 0);
- t = (cursor.b2 > floor.b1-(int)cursor.yvel-1 && cursor.b2-floor.b1 < 0 && cursor.yvel > 0);
+ 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)
- (!floor.flp) ? (cursor.pos.x = (floor.pos.x-(int)cursor.xvel)-cursor.w-1) : (cursor.pos.x = (floor.a2-cursor.w)-(int)cursor.xvel+1);
+ cursor.pos.x = (floor.pos.x-(int)cursor.xvel)-cursor.w-1;
else if (r)
- (!floor.flp) ? (cursor.pos.x = (floor.a2-cursor.w)-(int)cursor.xvel+1) : (cursor.pos.x = (floor.pos.x-(int)cursor.xvel)-cursor.w-1);
+ cursor.pos.x = (floor.a2-cursor.w)-(int)cursor.xvel+1;
cursor.xvel = 0;
}
}
@@ -140,7 +128,7 @@ int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
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+newy)-(int)cursor.yvel);
+ (!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;
@@ -150,7 +138,7 @@ int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
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-hmpeak)-cursor.yvel && cursor.c2 >= floor.c1) && (cursor.d1 <= (floor.d2+hmpeak)-cursor.yvel && cursor.c1 <= floor.c2);
+ 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;
@@ -161,28 +149,28 @@ int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
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 && cursor.d1-floor.d1 < 0 && cursor.xvel > 0);
- r = (cursor.c1 < (floor.c2-cursor.w)-cursor.xvel+1 && cursor.d1-floor.d1 < 0 && cursor.xvel < 0);
- t = (cursor.d2 > floor.d1-cursor.yvel-1 && cursor.d2-floor.d1 < 0 && cursor.yvel > 0);
- b = (cursor.d1 < (floor.d1+hmpeak)-cursor.yvel && cursor.d1-floor.d1 >= 0);
+ 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 < 0 || cursor.c2-floor.c1 > floor.w) {
+ if (cursor.c2-floor.c1 < -1 || cursor.c2-floor.c1 > floor.w) {
if (l)
- (!floor.flp) ? (cursor.pos.fx = (floor.pos.fx-cursor.xvel)-cursor.w-1) : (cursor.pos.fx = (floor.c2-cursor.w)-cursor.xvel+1);
+ cursor.pos.fx = (floor.pos.fx-cursor.xvel)-cursor.w-1;
else if (r)
- (!floor.flp) ? (cursor.pos.fx = (floor.c2-cursor.w)-cursor.xvel+1) : (cursor.pos.fx = (floor.pos.fx-cursor.xvel)-cursor.w-1);
+ cursor.pos.fx = (floor.c2-cursor.w)-cursor.xvel+1;
cursor.xvel = 0;
}
}
if (cursor.cly) {
- if (cursor.a2-floor.a1 < floor.w) {
+ 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+newy)-cursor.yvel);
+ (!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+1) : (cursor.pos.fy = (floor.pos.fy+newy)-cursor.yvel);
+ (!floor.flp) ? (cursor.pos.fy = (floor.pos.fy+floor.h)-cursor.yvel) : (cursor.pos.fy = (floor.pos.fy+newy)-cursor.yvel);
cursor.yvel = 0;
}
}
@@ -194,54 +182,32 @@ int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
/* Axis Aligned Bounding Box Collision. */
int aabb(uint8_t flt, struct colis cursor, struct colis floor) {
- if (!flt) {
- /* Is the Cursor is on the ground? */
- cursor.gnded = (cursor.b2 == floor.b1-(int)cursor.yvel-1) ? 1 : 0;
-
- /* Check for collisions, on both axies. */
- cursor.clx = clx(cursor, floor, (int)cursor.xvel, flt);
- cursor.cly = cly(cursor, floor, (int)cursor.yvel, flt);
-
- if (cursor.clx) {
- /* Is the Cursor coming from the left? */
- if (cursor.a2 > floor.a1-(int)cursor.xvel-1 && cursor.xvel > 0)
- cursor.pos.x = (floor.pos.x-(int)cursor.xvel)-cursor.w-1;
- /* Is the Cursor coming from the right? */
- else if (cursor.a1 < floor.a2-(int)cursor.xvel+1 && cursor.xvel < 0)
- cursor.pos.x = (floor.pos.x+floor.w)-(int)cursor.xvel+1;
- cursor.xvel = 0;
- }
- if (cursor.cly) {
- /* Is the Cursor coming from the top? */
- if (cursor.b2 > floor.b1-(int)cursor.yvel-1 && cursor.yvel > 0)
- cursor.pos.y = (floor.pos.y-(int)cursor.yvel)-cursor.h-1;
- /* Is the Cursor coming from the bottom? */
- else if (cursor.b1 < floor.b2-(int)cursor.yvel+1 && cursor.yvel < 0)
- cursor.pos.y = (floor.pos.y+floor.h)-(int)cursor.yvel+1;
- cursor.yvel = 0;
- }
+ 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;
+ /* Is the Cursor is on the ground? */
+ cursor.gnded = (cursor.b2 == floor.b1-(int)cursor.yvel-1) ? 1 : 0;
+ /* Is the Cursor coming from the left? */
+ 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);
+ /* Is the Cursor coming from the right? */
+ 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;
+ /* Is the Cursor coming from the top? */
+ 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);
+ /* Is the Cursor coming from the bottom? */
+ 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 {
- cursor.gnded = (cursor.d2 == floor.d1-cursor.yvel-1) ? 1 : 0;
- cursor.clx = clx(cursor, floor, 0, flt);
- cursor.cly = cly(cursor, floor, 0, flt);
-
- if (cursor.clx) {
- if (cursor.c2 > floor.c1-cursor.xvel-1 && cursor.xvel > 0)
- cursor.pos.fx = (floor.pos.fx-cursor.xvel)-(double)cursor.w-1;
- else if (cursor.c1 < floor.c2-cursor.xvel+1 && cursor.xvel < 0)
- cursor.pos.fx = (floor.pos.fx+(double)floor.w)-cursor.xvel+1;
- cursor.xvel = 0;
- }
- if (cursor.cly) {
- if (cursor.d2 > floor.d1-cursor.yvel-1 && cursor.yvel > 0)
- cursor.pos.fy = (floor.pos.fy-cursor.yvel)-(double)cursor.h-1;
- else if (cursor.d1 < floor.d2-cursor.yvel+1 && cursor.yvel < 0)
- cursor.pos.fy = (floor.pos.fy+(double)floor.h)-cursor.yvel+1;
- cursor.yvel = 0;
- }
+ 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;
}