cleanup
This commit is contained in:
parent
30734885e4
commit
b2c0eaf30b
3 changed files with 6 additions and 34 deletions
|
|
@ -94,14 +94,11 @@ s32 bulletDist;
|
|||
static void collideWithEnemy(u8 i){
|
||||
for(s16 j = 0; j < ENEMY_COUNT; j++) {
|
||||
if(enemies[j].active){
|
||||
// Calculate wrapped distances
|
||||
fix32 deltaX = getWrappedDelta(bullets[i].pos.x, enemies[j].pos.x);
|
||||
fix32 deltaY = bullets[i].pos.y - enemies[j].pos.y;
|
||||
|
||||
// Quick bounding box check using wrapped distance
|
||||
if(deltaY >= -BULLET_CHECK && deltaY <= BULLET_CHECK &&
|
||||
deltaX >= -BULLET_CHECK && deltaX <= BULLET_CHECK){
|
||||
// Precise distance check
|
||||
bulletDist = getApproximatedDistance(
|
||||
fix32ToInt(deltaX),
|
||||
fix32ToInt(deltaY));
|
||||
|
|
@ -122,7 +119,7 @@ static void collideWithPlayer(u8 i){
|
|||
s32 dist = getApproximatedDistance(
|
||||
fix32ToInt(deltaX),
|
||||
fix32ToInt(deltaY));
|
||||
if(dist <= 4){ // Player hit radius
|
||||
if(dist <= 4){
|
||||
killBullet(i);
|
||||
// player.lives--;
|
||||
// if(player.lives <= 0) gameOver = TRUE;
|
||||
|
|
@ -134,7 +131,6 @@ static void updateBullet(u8 i){
|
|||
bullets[i].pos.x += bullets[i].vel.x;
|
||||
bullets[i].pos.y += bullets[i].vel.y;
|
||||
|
||||
// Wrap bullet position
|
||||
if(bullets[i].pos.x >= GAME_WRAP){
|
||||
bullets[i].pos.x -= GAME_WRAP;
|
||||
}
|
||||
|
|
@ -142,19 +138,15 @@ 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
|
||||
return;
|
||||
}
|
||||
|
||||
if(bullets[i].clock > 0) bullets[i].updater(i);
|
||||
if(bullets[i].player) collideWithEnemy(i);
|
||||
else collideWithPlayer(i);
|
||||
|
|
@ -162,12 +154,6 @@ static void updateBullet(u8 i){
|
|||
s16 sx = getScreenX(bullets[i].pos.x, player.camera);
|
||||
s16 sy = fix32ToInt(bullets[i].pos.y);
|
||||
u8 off = bullets[i].player ? P_BULLET_OFF : BULLET_OFF;
|
||||
|
||||
// Set visibility to prevent VDP 512px wrap ghosting
|
||||
// bool onScreen = (sx >= VISIBLE_X_MIN && sx <= VISIBLE_X_MAX &&
|
||||
// sy >= VISIBLE_Y_MIN && sy <= VISIBLE_Y_MAX);
|
||||
// SPR_setVisibility(bullets[i].image, onScreen ? VISIBLE : HIDDEN);
|
||||
|
||||
SPR_setPosition(bullets[i].image, sx - off, sy - off);
|
||||
bullets[i].clock++;
|
||||
}
|
||||
|
|
|
|||
13
src/global.h
13
src/global.h
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -18,13 +18,11 @@ s16 shotClock;
|
|||
fix32 screenX;
|
||||
|
||||
fix32 playerSpeed;
|
||||
fix32 playerVelX; // Track actual X velocity for momentum
|
||||
fix32 playerVelX;
|
||||
|
||||
static void movePlayer(){
|
||||
// Y-axis stays instant
|
||||
player.vel.y = 0;
|
||||
|
||||
// Determine target X speed based on input
|
||||
fix32 targetVelX = 0;
|
||||
if(ctrl.left || ctrl.right || ctrl.up || ctrl.down){
|
||||
if(ctrl.b){
|
||||
|
|
@ -37,12 +35,10 @@ static void movePlayer(){
|
|||
targetVelX = ctrl.left ? -playerSpeed : playerSpeed;
|
||||
}
|
||||
|
||||
// Y velocity (instant)
|
||||
if(ctrl.up) player.vel.y = -playerSpeed;
|
||||
else if(ctrl.down) player.vel.y = playerSpeed;
|
||||
}
|
||||
|
||||
// Apply acceleration toward target X velocity
|
||||
if(playerVelX < targetVelX){
|
||||
playerVelX += ctrl.b ? PLAYER_ACCEL_FOCUS : PLAYER_ACCEL;
|
||||
if(playerVelX > targetVelX) playerVelX = targetVelX;
|
||||
|
|
@ -53,17 +49,14 @@ static void movePlayer(){
|
|||
|
||||
player.vel.x = playerVelX;
|
||||
|
||||
// Normalize if diagonal
|
||||
if(player.vel.x != 0 && player.vel.y != 0){
|
||||
player.vel.x = fix32Mul(player.vel.x, FIX32(0.707));
|
||||
player.vel.y = fix32Mul(player.vel.y, FIX32(0.707));
|
||||
}
|
||||
|
||||
// Apply movement (always, for momentum to work during deceleration)
|
||||
player.pos.x += player.vel.x;
|
||||
player.pos.y += player.vel.y;
|
||||
|
||||
// Update facing direction when moving horizontally
|
||||
if(ctrl.a){
|
||||
SPR_setHFlip(player.image, player.shotAngle != 0);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue