summaryrefslogtreecommitdiff
path: root/clld.c
diff options
context:
space:
mode:
Diffstat (limited to 'clld.c')
-rw-r--r--clld.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/clld.c b/clld.c
index 6cef7b5..73043a5 100644
--- a/clld.c
+++ b/clld.c
@@ -14,8 +14,6 @@
#include <string.h>
#include <unistd.h>
#define TERASGN(a, b, c, d) (a) ? (b = d) : (c = d)
-#define max(a, b) (abs(a-b)+(a+b))/2
-#define min(a, b) -max(-a, -b)
enum {THM, AABB};
@@ -95,6 +93,18 @@ 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 b = (!flt) ? (c.b2 > f.b1-yvel-1 && c.a2 > f.a1) : (c.d2 > f.d1-c.yvel-1 && c.c2 > f.c1);
+ int t = (!flt) ? (c.b1 < f.b2-yvel+1 && c.a1 < f.a2) : (c.d1 < f.d2-c.yvel+1 && c.c1 < f.c2);
+ return b && t;
+}
+
/* Tile Heightmap Collision. */
int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
int newy = 0;
@@ -144,18 +154,6 @@ int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
}
}
cursor.gnded = (cursor.pos.y == ((floor.b2-cursor.h)-newy)-(int)cursor.yvel) ? 1 : 0;
- if (verbose >= 1) {
- printf(
- "cursor.a1-(floor.a2-(floor.w/2)): %i\n"
- "cursor.a2-(floor.a2-(floor.w/2)): %i\n"
- "(cursor.a2-(cursor.w/2))-(floor.a2-(floor.w/2)): %i\n"
- "(cursor.a2-(cursor.w/2)): %i\n"
- , cursor.a1-(floor.a2-(floor.w/2))
- , cursor.a2-(floor.a2-(floor.w/2))
- , (cursor.a2-(cursor.w/2))-(floor.a2-(floor.w/2))
- , (cursor.a2-(cursor.w/2)));
- }
- printf("cursor.w: %i, cursor.h: %i\n", cursor.w, cursor.h);
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.c1 = cursor.pos.fx;
@@ -203,7 +201,6 @@ int thm(uint8_t flt, int hmpeak, struct colis cursor, struct colis floor) {
}
}
cursor.gnded = (cursor.pos.fy == ((floor.d2-cursor.h)-newy)-cursor.yvel) ? 1 : 0;
- printf("cursor.c2-floor.c1: %07.06f\n", cursor.c2-floor.c1);
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;
@@ -224,8 +221,8 @@ int aabb(uint8_t flt, struct colis cursor, struct colis floor) {
cursor.gnded = (cursor.b2 == floor.b1-(int)cursor.yvel-1) ? 1 : 0;
/* Check for collisions, on both axies. */
- cursor.clx = ((cursor.a2 > floor.a1-(int)cursor.xvel-1 && cursor.b2 > floor.b1) && (cursor.a1 < floor.a2-(int)cursor.xvel+1 && cursor.b1 < floor.b2)) ? 1 : 0;
- cursor.cly = ((cursor.b2 > floor.b1-(int)cursor.yvel-1 && cursor.a2 > floor.a1) && (cursor.b1 < floor.b2-(int)cursor.yvel+1 && cursor.a1 < floor.a2)) ? 1 : 0;
+ 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? */
@@ -265,8 +262,8 @@ int aabb(uint8_t flt, struct colis cursor, struct colis floor) {
floor.d2 = floor.pos.fy+floor.h;
cursor.gnded = (cursor.d2 == floor.d1-cursor.yvel-1) ? 1 : 0;
- cursor.clx = ((cursor.c2 > floor.c1-cursor.xvel-1 && cursor.d2 > floor.d1) && (cursor.c1 < floor.c2-cursor.xvel+1 && cursor.d1 < floor.d2)) ? 1 : 0;
- cursor.cly = ((cursor.d2 > floor.d1-cursor.yvel-1 && cursor.c2 > floor.c1) && (cursor.d1 < floor.d2-cursor.yvel+1 && cursor.c1 < floor.c2)) ? 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)