Skip to content

Commit

Permalink
Implement basic clipping
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Cho committed Jan 1, 2024
1 parent f21412e commit 687d858
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
23 changes: 20 additions & 3 deletions game/levels/02-space.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ void SpaceInit() {


byte SpaceCalculateBkgrndNewXY() {
sword minX = 2 * DynospriteDirectPageGlobalsPtr->Gfx_BkgrndNewX;
sword maxX = minX + 320;
sword minY = DynospriteDirectPageGlobalsPtr->Gfx_BkgrndNewY;
sword maxY = minY + 200;

// Iterate through all active universal objects
DynospriteCOB *obj = DynospriteDirectPageGlobalsPtr->Obj_CurrentTablePtr;
DynospriteCOB *lastObj = obj + DynospriteDirectPageGlobalsPtr->Obj_NumCurrent;
sword xoffset = DynospriteDirectPageGlobalsPtr->Gfx_BkgrndNewX + 79;
sword yoffset = DynospriteDirectPageGlobalsPtr->Gfx_BkgrndNewY + 100;
sword xoffset = 2 * (DynospriteDirectPageGlobalsPtr->Gfx_BkgrndNewX + 79);
sword yoffset = DynospriteDirectPageGlobalsPtr->Gfx_BkgrndNewY + 99;

for(; obj<lastObj; obj++) {
if ((obj->active & OBJECT_ACTIVE) == 0) {
continue;
Expand All @@ -36,8 +42,19 @@ byte SpaceCalculateBkgrndNewXY() {
continue;
}
word depth = uobj->depth - 1;
obj->globalX = uobj->position[0] + ((uobj->position[0] / 2) - xoffset) * depth;
obj->globalX = uobj->position[0] + (uobj->position[0] - xoffset) * depth;
obj->globalY = uobj->position[1] + (uobj->position[1] - yoffset) * depth;

sword globalXMin = obj->globalX + uobj->boundingBox[0];
sword globalYMin = obj->globalY + uobj->boundingBox[1];
sword globalXMax = obj->globalX + uobj->boundingBox[2];
sword globalYMax = obj->globalY + uobj->boundingBox[3];
if ((globalXMin < minX) || (globalYMin < minY) ||
(globalXMax >= maxX) || (globalYMax > maxY)) {
obj->active = obj->active & ~OBJECT_DRAW_ACTIVE;
} else {
obj->active = obj->active | OBJECT_DRAW_ACTIVE;
}
}

return 0;
Expand Down
6 changes: 3 additions & 3 deletions game/levels/02-space.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"Active": 3,
"globalX": 160,
"globalY": 120,
"InitData": [0, 3, 0, 18, 0, 13, 0, 250, 0, 150]
"InitData": [0, 3, 244, 244, 12, 10, 0, 250, 0, 150]
},

{
Expand All @@ -87,7 +87,7 @@
"Active": 3,
"globalX": 20,
"globalY": 100,
"InitData": [0, 2, 0, 9, 0, 9, 0, 245, 0, 150, 0, 0, 0, 0]
"InitData": [0, 2, 248, 248, 8, 8, 0, 245, 0, 150, 0, 0, 0, 0]
},

{
Expand All @@ -97,7 +97,7 @@
"Active": 3,
"globalX": 80,
"globalY": 95,
"InitData": [0, 1, 0, 9, 0, 9, 0, 160, 0, 100]
"InitData": [0, 1, 248, 248, 8, 8, 0, 160, 0, 100]
}
]
}
Expand Down

0 comments on commit 687d858

Please sign in to comment.