Taking a break from hitboxes

This commit is contained in:
2025-06-20 10:06:17 -05:00
parent 2a8183e9a3
commit 6af88cc394
7 changed files with 110 additions and 11 deletions

View File

@ -1,5 +1,5 @@
{
"activeFile": "overworld.tsx",
"activeFile": "map.tmj",
"expandedProjectPaths": [
"templates",
"."
@ -16,8 +16,8 @@
"scale": 4,
"selectedLayer": 2,
"viewCenter": {
"x": 6625.125,
"y": 6667.875
"x": 6599.375,
"y": 6795.125
}
},
"overworld.tsx": {
@ -35,8 +35,8 @@
"project": "map project.tiled-project",
"property.type": "int",
"recentFiles": [
"map.tmj",
"overworld.tsx",
"map.tmj",
"entities.tsx"
],
"tileset.lastUsedFilter": "Tiled tileset files (*.tsx *.xml)",

View File

@ -40,9 +40,9 @@
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 18, 19, 20, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 34, 35, 36, 1, 1],
"height":16,
"width":16,
"x":400,
@ -270,7 +270,6 @@
}],
"height":32,
"id":1,
"locked":true,
"name":"Base Layer",
"opacity":1,
"startx":384,
@ -426,8 +425,8 @@
"type":"player_spawn",
"visible":true,
"width":16,
"x":6591.33333333333,
"y":6787
"x":6607.58333333333,
"y":6944.25
},
{
"id":7,

View File

@ -90,6 +90,11 @@ void entityUpdate(entity_t *entity) {
uint8_t chunkTileX = tileX % CHUNK_WIDTH;
uint8_t chunkTileY = tileY % CHUNK_HEIGHT;
tile_t tile = chunk->tilesBase[chunkTileY * CHUNK_WIDTH + chunkTileX];
fixed248_t lx = fx248Mulfx248(x, FIXED248(TILE_WIDTH_HEIGHT, 0));
fixed248_t ty = fx248Mulfx248(y, FIXED248(TILE_WIDTH_HEIGHT, 0));
fixed248_t rx = fx248Addfx248(lx, FIXED248(TILE_WIDTH_HEIGHT, 0));
fixed248_t by = fx248Addfx248(ty, FIXED248(TILE_WIDTH_HEIGHT, 0));
// Determine tile collision type
collisionresult_t collision;
@ -104,6 +109,47 @@ void entityUpdate(entity_t *entity) {
);
break;
case TILE_SOLID_TRIANGLE_TOP_RIGHT:
collision = physicsCheckCircleTriangle(
newX, newY, selfCircR,
lx, ty,
rx, ty,
rx, by
);
break;
// case TILE_SOLID_TRIANGLE_TOP_LEFT:
// collision = physicsCheckCircleTriangle(
// newX, newY, selfCircR,
// lx, ty,
// rx, ty,
// lx, by
// );
// break;
// case TILE_SOLID_TRIANGLE_BOTTOM_RIGHT:
// collision = physicsCheckCircleTriangle(
// newX, newY, selfCircR,
// fx248Mulfx248(x, FIXED248(TILE_WIDTH_HEIGHT, 0)),
// fx248Addfx248(fx248Mulfx248(y, FIXED248(TILE_WIDTH_HEIGHT, 0)), FIXED248(TILE_WIDTH_HEIGHT, 0)),
// fx248Addfx248(fx248Mulfx248(x, FIXED248(TILE_WIDTH_HEIGHT, 0)), FIXED248(TILE_WIDTH_HEIGHT, 0)),
// fx248Addfx248(fx248Mulfx248(y, FIXED248(TILE_WIDTH_HEIGHT, 0)), FIXED248(TILE_WIDTH_HEIGHT, 0)),
// fx248Mulfx248(x, FIXED248(TILE_WIDTH_HEIGHT, 0)),
// fx248Mulfx248(y, FIXED248(TILE_WIDTH_HEIGHT, 0))
// );
// break;
// case TILE_SOLID_TRIANGLE_BOTTOM_LEFT:
// collision = physicsCheckCircleTriangle(
// newX, newY, selfCircR,
// fx248Mulfx248(x, FIXED248(TILE_WIDTH_HEIGHT, 0)),
// fx248Addfx248(fx248Mulfx248(y, FIXED248(TILE_WIDTH_HEIGHT, 0)), FIXED248(TILE_WIDTH_HEIGHT, 0)),
// fx248Addfx248(fx248Mulfx248(x, FIXED248(TILE_WIDTH_HEIGHT, 0)), FIXED248(TILE_WIDTH_HEIGHT, 0)),
// fx248Addfx248(fx248Mulfx248(y, FIXED248(TILE_WIDTH_HEIGHT, 0)), FIXED248(TILE_WIDTH_HEIGHT, 0)),
// fx248Addfx248(fx248Mulfx248(x, FIXED248(TILE_WIDTH_HEIGHT, 0)), FIXED248(TILE_WIDTH_HEIGHT, 0)),
// fx248Mulfx248(y, FIXED248(TILE_WIDTH_HEIGHT, 0))
// );
// break;
default:
continue;
}

View File

@ -97,4 +97,15 @@ collisionresult_t physicsCheckCircleAABB(
result.hit = true;
return result;
}
collisionresult_t physicsCheckCircleTriangle(
fixed248_t circleX, fixed248_t circleY, fixed248_t circleR,
fixed248_t triX0, fixed248_t triY0,
fixed248_t triX1, fixed248_t triY1,
fixed248_t triX2, fixed248_t triY2
) {
collisionresult_t result;
result.hit = false;
return result;
}

View File

@ -46,4 +46,25 @@ collisionresult_t physicsCheckCircleAABB(
fixed248_t circleX, fixed248_t circleY, fixed248_t circleR,
fixed248_t aabb, fixed248_t aabbY,
fixed248_t aabbWidth, fixed248_t aabbHeight
);
/**
* Check for collision between a circle and a triangle.
*
* @param circleX X coordinate of the circle's center.
* @param circleY Y coordinate of the circle's center.
* @param circleR Radius of the circle.
* @param triX0 X coordinate of the first vertex of the triangle.
* @param triY0 Y coordinate of the first vertex of the triangle.
* @param triX1 X coordinate of the second vertex of the triangle.
* @param triY1 Y coordinate of the second vertex of the triangle.
* @param triX2 X coordinate of the third vertex of the triangle.
* @param triY2 Y coordinate of the third vertex of the triangle.
* @return A collisionresult_t structure containing collision information.
*/
collisionresult_t physicsCheckCircleTriangle(
fixed248_t circleX, fixed248_t circleY, fixed248_t circleR,
fixed248_t triX0, fixed248_t triY0,
fixed248_t triX1, fixed248_t triY1,
fixed248_t triX2, fixed248_t triY2
);

View File

@ -190,4 +190,12 @@ fixed248_t fx248Max(const fixed248_t a, const fixed248_t b) {
fixed248_t fx248Min(const fixed248_t a, const fixed248_t b) {
return (a < b) ? a : b;
}
fixed248_t fx248Clamp(
const fixed248_t a,
const fixed248_t min,
const fixed248_t max
) {
return (a < min) ? min : (a > max) ? max : a;
}

View File

@ -335,4 +335,18 @@ fixed248_t fx248Max(const fixed248_t a, const fixed248_t b);
* @param b Second fixed248_t value.
* @return The minimum of the two values.
*/
fixed248_t fx248Min(const fixed248_t a, const fixed248_t b);
fixed248_t fx248Min(const fixed248_t a, const fixed248_t b);
/**
* Clamp a fixed248_t value between a minimum and maximum value.
*
* @param a The fixed248_t value to clamp.
* @param min The minimum value to clamp to.
* @param max The maximum value to clamp to.
* @return The clamped fixed248_t value.
*/
fixed248_t fx248Clamp(
const fixed248_t a,
const fixed248_t min,
const fixed248_t max
);