Added The Missing NULL Checks

This commit is contained in:
Asrın Doğan 2019-09-26 21:58:03 +03:00
parent 5596b53c02
commit f9e795e5e4
1 changed files with 26 additions and 10 deletions

View File

@ -95,7 +95,6 @@ void SpawnEnemies();
void CheckBullets(); void CheckBullets();
void RemoveBulletAtIndex(int index); void RemoveBulletAtIndex(int index);
void RemoveEnemyAtIndex(int index); void RemoveEnemyAtIndex(int index);
void InitializeEnemies();
void CheckEnemies(); void CheckEnemies();
void MoveEnemies(); void MoveEnemies();
void LimitEnemies(); void LimitEnemies();
@ -130,6 +129,7 @@ float VectorDistanceBetween(Vector2D vectorFirst, Vector2D vectorSecond);
byte isVectorExceedingLimits(Vector2D vector, Vector2D limits); byte isVectorExceedingLimits(Vector2D vector, Vector2D limits);
byte CheckCollision(Vector2D *firstPos, Vector2D *secondPos, Image *firstMap, Image *secondMap); byte CheckCollision(Vector2D *firstPos, Vector2D *secondPos, Image *firstMap, Image *secondMap);
char InitializeEnemies();
char InitializeGameWindow(); char InitializeGameWindow();
char InitializeGame(); char InitializeGame();
char DealDamage(char *health); char DealDamage(char *health);
@ -443,15 +443,24 @@ char InitializeGameWindow()
/* BGM is an exception since I don't want to it to restart itself every restart */ /* BGM is an exception since I don't want to it to restart itself every restart */
BGM = al_load_sample(bgmSoundPath); BGM = al_load_sample(bgmSoundPath);
if(BGM == NULL)
return 0;
al_play_sample(BGM, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL); al_play_sample(BGM, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);
return 1;
} }
char InitializeGame() char InitializeGame()
{ {
shootSound = al_load_sample(shootSoundPath); shootSound = al_load_sample(shootSoundPath);
enemyDieSound = al_load_sample(dieSoundPath); enemyDieSound = al_load_sample(dieSoundPath);
if(shootSound == NULL || enemyDieSound == NULL)
return 0;
InitializeEnemies(); if(!InitializeEnemies())
return 0;
GetHighScore(); GetHighScore();
/* Player Initialization */ /* Player Initialization */
@ -480,7 +489,7 @@ char InitializeGame()
return 1; return 1;
} }
void InitializeEnemies() char InitializeEnemies()
{ {
enemies.enemyLimit = initialEnemyLimit; enemies.enemyLimit = initialEnemyLimit;
enemies.enemyCount = 0; enemies.enemyCount = 0;
@ -490,8 +499,15 @@ void InitializeEnemies()
numberTable = InitImage(numbersImagePath); numberTable = InitImage(numbersImagePath);
enemyBulletImage = InitImage(bulletImagePath); enemyBulletImage = InitImage(bulletImagePath);
gameOverImage = InitImage(gameOverImagePath); gameOverImage = InitImage(gameOverImagePath);
if( enemyImage.bitmap == NULL ||
numberTable.bitmap == NULL ||
enemyBulletImage.bitmap == NULL ||
gameOverImage.bitmap == NULL )
return 0;
SpawnEnemies(); SpawnEnemies();
return 1;
} }
void SpawnEnemies() void SpawnEnemies()
@ -898,15 +914,15 @@ void DieSoundEffect()
void PlayerShootCheck() void PlayerShootCheck()
{ {
if(player.shootCooldown < 0.0f) if(player.shootCooldown < 0.0f)
{
if(al_key_down(&keyboardState, ALLEGRO_KEY_SPACE))
{ {
if(al_key_down(&keyboardState, ALLEGRO_KEY_SPACE)) printf("PlayerShoot();\n");
{ PlayerShoot();
printf("PlayerShoot();\n");
PlayerShoot();
}
} }
else }
player.shootCooldown -= deltaTime; else
player.shootCooldown -= deltaTime;
} }
void PlayerShoot() void PlayerShoot()