diff --git a/src/background.h b/src/background.h index 087411f..ef7e5a7 100644 --- a/src/background.h +++ b/src/background.h @@ -2,9 +2,7 @@ #define FADE_TOP_I BG_I + 64 #define FADE_BOTTOM_I FADE_TOP_I + 64 -#define BG_COUNT 27 #define BG_OFF 112 -s16 bgScrolls[BG_COUNT]; void loadBackground(){ VDP_loadTileSet(sky.tileset, BG_I, DMA); diff --git a/src/bullets.h b/src/bullets.h index 482ecc3..bd38561 100644 --- a/src/bullets.h +++ b/src/bullets.h @@ -63,16 +63,9 @@ void spawnBullet(struct bulletSpawner spawner, void(*updater)){ bullets[i].active = TRUE; bullets[i].pos.x = spawner.x; bullets[i].pos.y = spawner.y; - bullets[i].speed = spawner.speed; bullets[i].angle = spawner.angle; bullets[i].player = spawner.player; - bullets[i].explosion = FALSE; bullets[i].clock = 0; - for(u8 j = 0; j < COUNT_INT; j++){ - bullets[i].bools[j] = spawner.bools[j]; - bullets[i].ints[j] = spawner.ints[j]; - bullets[i].fixes[j] = spawner.fixes[j]; - } if(spawner.vel.x || spawner.vel.y){ bullets[i].vel.x = spawner.vel.x; bullets[i].vel.y = spawner.vel.y; @@ -146,6 +139,19 @@ static void updateBullet(u8 i){ bullets[i].pos.x += GAME_WRAP; } + // Cull bullets that go off-screen + // Horizontal: use wrapped distance to handle world wrap correctly + fix32 dx = getWrappedDelta(bullets[i].pos.x, player.pos.x); + bool offScreenX = (dx < FIX32(-256) || dx > FIX32(256)); + + // Vertical: simple linear check (no Y wrapping) + bool offScreenY = (bullets[i].pos.y < FIX32(-16) || bullets[i].pos.y > GAME_H_F + FIX32(16)); + + if(offScreenX || offScreenY){ + killBullet(i); + return; // Skip rest of update for culled bullet + } + if(bullets[i].clock > 0) bullets[i].updater(i); if(bullets[i].player) collideWithEnemy(i); else collideWithPlayer(i); diff --git a/src/enemies.h b/src/enemies.h index 59c0183..51e49d6 100644 --- a/src/enemies.h +++ b/src/enemies.h @@ -1,9 +1,9 @@ void spawnEnemy(u8 type){ + (void)type; // Unused parameter, kept for API compatibility s16 i = -1; for(s16 j = 0; j < ENEMY_COUNT; j++) if(!enemies[j].active && i == -1) i = j; if(i > -1){ enemies[i].active = TRUE; - enemies[i].type = type; enemies[i].pos.x = FIX32(64); enemies[i].pos.y = FIX32(64); enemies[i].off = 16; @@ -52,11 +52,11 @@ void updateEnemies(){ } void spawnEnemyAt(u8 type, fix32 x, fix32 y){ + (void)type; // Unused parameter, kept for API compatibility s16 i = -1; for(s16 j = 0; j < ENEMY_COUNT; j++) if(!enemies[j].active && i == -1) i = j; if(i > -1){ enemies[i].active = TRUE; - enemies[i].type = type; enemies[i].pos.x = x; enemies[i].pos.y = y; enemies[i].off = 16; diff --git a/src/global.h b/src/global.h index f56143b..a264710 100644 --- a/src/global.h +++ b/src/global.h @@ -1,6 +1,5 @@ u32 clock; #define CLOCK_LIMIT 32000 -#define COUNT_INT 4 #define GAME_H_F FIX32(224) @@ -9,24 +8,15 @@ u32 clock; #define SECTION_COUNT 4 // Number of sections (N = 2, 4, 8, etc.) #define GAME_WRAP (SECTION_SIZE * SECTION_COUNT) // Total world width -u32 score, highScore; +u32 score; #define SCORE_LENGTH 8 #define FIRST_ROTATING_BULLET 3 -#define CAMERA_Y_MOD FIX32(112) - -// Screen bounds for visibility (screen is 320x224) -// VDP wraps sprites every 512px, so we must hide sprites outside screen -#define VISIBLE_X_MIN 0 -#define VISIBLE_X_MAX 512 -#define VISIBLE_Y_MIN -32 -#define VISIBLE_Y_MAX 256 char debugStr[8]; -s16 emptyI; -void EMPTY(s16 i){emptyI = i;} +void EMPTY(s16 i){(void)i;} -bool gameOver, paused, started; +bool gameOver; s16 enemyCount; // controls @@ -35,7 +25,7 @@ struct controls { }; struct controls ctrl; void updateControls(u16 joy, u16 changed, u16 state){ - if(changed){} + (void)changed; // Unused parameter if(joy == JOY_1){ ctrl.left = (state & BUTTON_LEFT); ctrl.right = (state & BUTTON_RIGHT); @@ -51,7 +41,7 @@ void updateControls(u16 joy, u16 changed, u16 state){ // player struct playerStruct { - Vect2D_f32 pos, vel, last; + Vect2D_f32 pos, vel; s16 shotAngle; u8 lives; fix32 camera; @@ -68,21 +58,14 @@ struct bulletSpawner { Vect2D_f32 vel; s16 angle, anim; bool top, player; - bool bools[COUNT_INT]; - s16 ints[COUNT_INT]; - fix32 fixes[COUNT_INT]; }; struct bullet { - bool active, player, explosion, top, vFlip, hFlip; - fix32 speed; + bool active, player, vFlip, hFlip; Vect2D_f32 pos, vel; Sprite* image; s16 clock, angle, anim, frame; s16 dist; void (*updater)(s16); - bool bools[COUNT_INT]; - s16 ints[COUNT_INT]; - fix32 fixes[COUNT_INT]; }; struct bullet bullets[BULLET_COUNT]; @@ -92,16 +75,11 @@ struct bullet bullets[BULLET_COUNT]; struct enemy { bool active; - s16 clock, angle, anim, frame, off; - fix32 speed; u8 type; + s16 angle, off; + fix32 speed; Vect2D_f32 vel, pos; - s16 dist; Sprite* image; - void (*updater)(s16); - bool bools[COUNT_INT]; - s16 ints[COUNT_INT]; - fix32 fixes[COUNT_INT]; }; struct enemy enemies[ENEMY_COUNT]; diff --git a/src/main.c b/src/main.c index 3c2c606..9d33b31 100644 --- a/src/main.c +++ b/src/main.c @@ -8,7 +8,6 @@ #include "player.h" #include "stage.h" #include "chrome.h" -#include "start.h" static void loadInternals(){ JOY_init(); diff --git a/src/player.h b/src/player.h index a0c40cd..0d57a16 100644 --- a/src/player.h +++ b/src/player.h @@ -1,8 +1,6 @@ #define PLAYER_SPEED FIX32(5) -#define PLAYER_SPEED_NORM fix32Mul(PLAYER_SPEED, FIX32(0.707)) #define PLAYER_SPEED_FOCUS FIX32(3) -#define PLAYER_SPEED_FOCUS_NORM fix32Mul(PLAYER_SPEED_FOCUS, FIX32(0.707)) #define PLAYER_ACCEL PLAYER_SPEED >> 3 #define PLAYER_ACCEL_FOCUS PLAYER_SPEED_FOCUS >> 3 @@ -19,7 +17,7 @@ s16 shotClock; fix32 screenX; -fix32 playerSpeed, playerSpeedNorm; +fix32 playerSpeed; fix32 playerVelX; // Track actual X velocity for momentum static void movePlayer(){ @@ -31,12 +29,9 @@ static void movePlayer(){ if(ctrl.left || ctrl.right || ctrl.up || ctrl.down){ if(ctrl.b){ playerSpeed = PLAYER_SPEED_FOCUS; - playerSpeedNorm = PLAYER_SPEED_FOCUS_NORM; } else { playerSpeed = PLAYER_SPEED; - playerSpeedNorm = PLAYER_SPEED_NORM; } - player.last.x = player.pos.x; if(ctrl.left || ctrl.right){ if(!ctrl.a) player.shotAngle = ctrl.left ? 512 : 0; targetVelX = ctrl.left ? -playerSpeed : playerSpeed; @@ -116,10 +111,7 @@ static void shootPlayer(){ .angle = player.shotAngle, .player = TRUE }; - void updater(u8 i){ - if(bullets[i].clock >= 16) killBullet(i); - } - spawnBullet(spawner, updater); + spawnBullet(spawner, EMPTY); shotClock = SHOT_INTERVAL; } else if(shotClock > 0) shotClock--; }