collision work

This commit is contained in:
t. boddy 2022-08-16 23:13:05 -04:00
parent 9102b190c8
commit cf71ad715a
2 changed files with 5 additions and 1 deletions

View File

@ -6,6 +6,9 @@
#define BULLET_DIST FIX32(4) #define BULLET_DIST FIX32(4)
#define BULLET_DIST_BIG FIX32(8) #define BULLET_DIST_BIG FIX32(8)
// lifecycle
void spawnBullet(struct bulletSpawner spawner, void(*updater)){ void spawnBullet(struct bulletSpawner spawner, void(*updater)){
s16 i = -1; s16 i = -1;
for(s16 j = 0; j < BULLET_COUNT; j++) if(!bullets[j].active && i == -1) i = j; for(s16 j = 0; j < BULLET_COUNT; j++) if(!bullets[j].active && i == -1) i = j;

View File

@ -45,10 +45,11 @@ void collideObstacleWithPlayer(s16 i){
fix16Add(obstacles[i].pos.x, obstacles[i].size.x) > fix16Sub(player.pos.x, PLAYER_OFF) && fix16Add(obstacles[i].pos.x, obstacles[i].size.x) > fix16Sub(player.pos.x, PLAYER_OFF) &&
obstacles[i].pos.y < fix16Add(player.pos.y, PLAYER_OFF) && obstacles[i].pos.y < fix16Add(player.pos.y, PLAYER_OFF) &&
fix16Add(obstacles[i].pos.y, obstacles[i].size.y) > fix16Sub(player.pos.y, PLAYER_OFF) fix16Add(obstacles[i].pos.y, obstacles[i].size.y) > fix16Sub(player.pos.y, PLAYER_OFF)
){ ){
if(obstacles[i].pos.x > player.pos.x) player.pos.x = fix16Sub(fix16Sub(obstacles[i].pos.x, FG_SPEED), PLAYER_OFF); if(obstacles[i].pos.x > player.pos.x) player.pos.x = fix16Sub(fix16Sub(obstacles[i].pos.x, FG_SPEED), PLAYER_OFF);
// else if(fix16Add(obstacles[i].pos.x, obstacles[i].size.x) > fix16Sub(player.pos.x, PLAYER_OFF)) player.pos.x = fix16Add(fix16Add(obstacles[i].pos.x, obstacles[i].size.x), PLAYER_OFF);
else if(obstacles[i].pos.y > player.pos.y) player.pos.y = fix16Sub(obstacles[i].pos.y, PLAYER_OFF); else if(obstacles[i].pos.y > player.pos.y) player.pos.y = fix16Sub(obstacles[i].pos.y, PLAYER_OFF);
else if(fix16Add(obstacles[i].pos.y, obstacles[i].size.y) > fix16Sub(player.pos.y, PLAYER_OFF)) player.pos.y = fix16Add(fix16Add(obstacles[i].pos.y, obstacles[i].size.y), PLAYER_OFF);
checkPlayerBounds(); checkPlayerBounds();
} }
} }