This commit is contained in:
t. boddy 2026-02-14 21:31:14 -05:00
parent 30734885e4
commit b2c0eaf30b
3 changed files with 6 additions and 34 deletions

View file

@ -3,10 +3,9 @@ u32 clock;
#define GAME_H_F FIX32(224)
// Section-based world size
#define SECTION_SIZE FIX32(512) // Size of one section (512px)
#define SECTION_COUNT 4 // Number of sections (N = 2, 4, 8, etc.)
#define GAME_WRAP (SECTION_SIZE * SECTION_COUNT) // Total world width
#define SECTION_SIZE FIX32(512)
#define SECTION_COUNT 4
#define GAME_WRAP (SECTION_SIZE * SECTION_COUNT)
u32 score;
#define SCORE_LENGTH 8
@ -94,11 +93,8 @@ void killEnemy(u8 i){
SPR_releaseSprite(enemies[i].image);
}
// Calculate shortest X distance accounting for world wrap
// Returns distance in the range [-GAME_WRAP/2, GAME_WRAP/2]
static fix32 getWrappedDelta(fix32 a, fix32 b) {
fix32 delta = a - b;
// If distance is more than half the world, go the other way
if (delta > GAME_WRAP / 2) {
delta -= GAME_WRAP;
} else if (delta < -GAME_WRAP / 2) {
@ -107,11 +103,8 @@ static fix32 getWrappedDelta(fix32 a, fix32 b) {
return delta;
}
// Safe screen X calculation handling wrap edge cases
// Returns screen coordinate for an entity, accounting for entities that just wrapped
static s16 getScreenX(fix32 worldX, fix32 camera) {
fix32 screenX = worldX - camera;
// Handle entity that just wrapped (temporarily far off-screen)
if (screenX < FIX32(-256)) {
screenX += GAME_WRAP;
} else if (screenX > FIX32(256)) {