Spawn Bug Fix, Script Organization and BGM Speed Up
This commit is contained in:
parent
477b4ddb40
commit
0738d7f9a7
Binary file not shown.
87
SynGame.c
87
SynGame.c
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Author: Asrın "Syntriax" Doğan
|
Author: Asrın "Syntriax" Doğan
|
||||||
Date: 10.09.2019
|
Start: 05.09.2019
|
||||||
Mail: asrindogan99@gmail.com
|
Mail: asrindogan99@gmail.com
|
||||||
|
|
||||||
Simple Shoot 'Em Up game.
|
Simple Shoot 'Em Up game.
|
||||||
|
@ -88,9 +88,10 @@ 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 InitializeEnemies();
|
void LimitEnemies();
|
||||||
void DestroyGame();
|
void DestroyGame();
|
||||||
void DrawObject(Vector2D position, ALLEGRO_BITMAP *image, int flag);
|
void DrawObject(Vector2D position, ALLEGRO_BITMAP *image, int flag);
|
||||||
void DrawSizedObject(Vector2D position, ALLEGRO_BITMAP *image, int flag, float objectscreenSizeMultiplier);
|
void DrawSizedObject(Vector2D position, ALLEGRO_BITMAP *image, int flag, float objectscreenSizeMultiplier);
|
||||||
|
@ -101,6 +102,7 @@ void DrawTimer();
|
||||||
void CheckHighScore();
|
void CheckHighScore();
|
||||||
void GetHighScore();
|
void GetHighScore();
|
||||||
void GetSettings();
|
void GetSettings();
|
||||||
|
void CalculateScore();
|
||||||
void DrawNumber(Vector2D position, int number);
|
void DrawNumber(Vector2D position, int number);
|
||||||
void Inputs();
|
void Inputs();
|
||||||
void PlayerMovement();
|
void PlayerMovement();
|
||||||
|
@ -111,15 +113,20 @@ void DieSoundEffect();
|
||||||
void PlayerShoot();
|
void PlayerShoot();
|
||||||
void EnemyShoot();
|
void EnemyShoot();
|
||||||
void BulletCollisions();
|
void BulletCollisions();
|
||||||
|
void PlayerShootCheck();
|
||||||
void Update();
|
void Update();
|
||||||
void DestroyGameWindow();
|
void DestroyGameWindow();
|
||||||
|
|
||||||
float VectorMagnitude(Vector2D vector);
|
float VectorMagnitude(Vector2D vector);
|
||||||
float VectorDistanceBetween(Vector2D vectorFirst, Vector2D vectorSecond);
|
float VectorDistanceBetween(Vector2D vectorFirst, Vector2D vectorSecond);
|
||||||
|
|
||||||
byte isVectorExceedingLimits(Vector2D vector, Vector2D limits);
|
byte isVectorExceedingLimits(Vector2D vector, Vector2D limits);
|
||||||
byte CheckCollision(Vector2D *firstPos, Vector2D *secondPos, ALLEGRO_BITMAP *firstMap, ALLEGRO_BITMAP *secondMap);
|
byte CheckCollision(Vector2D *firstPos, Vector2D *secondPos, ALLEGRO_BITMAP *firstMap, ALLEGRO_BITMAP *secondMap);
|
||||||
|
|
||||||
char InitializeGameWindow();
|
char InitializeGameWindow();
|
||||||
char InitializeGame();
|
char InitializeGame();
|
||||||
char DealDamage(char *health);
|
char DealDamage(char *health);
|
||||||
|
|
||||||
Vector2D NormalizeVector(Vector2D vector);
|
Vector2D NormalizeVector(Vector2D vector);
|
||||||
|
|
||||||
ALLEGRO_KEYBOARD_STATE keyboardState;
|
ALLEGRO_KEYBOARD_STATE keyboardState;
|
||||||
|
@ -189,28 +196,16 @@ void Update()
|
||||||
printf("BulletCollisions();\n");
|
printf("BulletCollisions();\n");
|
||||||
BulletCollisions();
|
BulletCollisions();
|
||||||
|
|
||||||
if(player.shootCooldown < 0.0f)
|
printf("PlayerShootCheck();\n");
|
||||||
{
|
PlayerShootCheck();
|
||||||
if(al_key_down(&keyboardState, ALLEGRO_KEY_SPACE))
|
|
||||||
{
|
printf("LimitEnemies();\n");
|
||||||
printf("PlayerShoot();\n");
|
LimitEnemies();
|
||||||
PlayerShoot();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
player.shootCooldown -= deltaTime;
|
|
||||||
|
|
||||||
timeSinceStart += deltaTime;
|
timeSinceStart += deltaTime;
|
||||||
player.score = (int)(timeSinceStart * timeSinceStart) * (player.killedEnemyCount + 1);
|
|
||||||
|
|
||||||
/* To limit the enemies on the screen */
|
printf("CalculateScore();\n");
|
||||||
if(enemies.enemyLimit != enemyLimiter)
|
CalculateScore();
|
||||||
{
|
|
||||||
enemies.enemyLimit = initialEnemyLimit + (int)(timeSinceStart / 10);
|
|
||||||
|
|
||||||
if(enemies.enemyCount > enemyLimiter)
|
|
||||||
enemies.enemyLimit = enemyLimiter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if(al_key_down(&keyboardState, ALLEGRO_KEY_R))
|
else if(al_key_down(&keyboardState, ALLEGRO_KEY_R))
|
||||||
isRestart = 1;
|
isRestart = 1;
|
||||||
|
@ -231,7 +226,6 @@ void Update()
|
||||||
printf("DrawScreen();\n");
|
printf("DrawScreen();\n");
|
||||||
DrawScreen();
|
DrawScreen();
|
||||||
|
|
||||||
|
|
||||||
al_flip_display();
|
al_flip_display();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +261,8 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
DestroyGame();
|
DestroyGame();
|
||||||
} while (isRestart);
|
}
|
||||||
|
while (isRestart);
|
||||||
|
|
||||||
DestroyGameWindow();
|
DestroyGameWindow();
|
||||||
|
|
||||||
|
@ -399,9 +394,9 @@ char InitializeGameWindow()
|
||||||
al_set_window_title(display, displayName);
|
al_set_window_title(display, displayName);
|
||||||
|
|
||||||
backgroundColor.a = 1;
|
backgroundColor.a = 1;
|
||||||
backgroundColor.a = 0;
|
backgroundColor.r = .1;
|
||||||
backgroundColor.a = 0;
|
backgroundColor.g = .1;
|
||||||
backgroundColor.a = 0;
|
backgroundColor.b = .1;
|
||||||
|
|
||||||
/* 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("Sounds/Background.wav");
|
BGM = al_load_sample("Sounds/Background.wav");
|
||||||
|
@ -469,7 +464,7 @@ void SpawnEnemies()
|
||||||
{
|
{
|
||||||
/* enemyRespawnCounter is just for making the value of rand() more randomized */
|
/* enemyRespawnCounter is just for making the value of rand() more randomized */
|
||||||
srand(time(0) + enemyRespawnCounter);
|
srand(time(0) + enemyRespawnCounter);
|
||||||
randomNumber = rand() * enemies.enemyCount;
|
randomNumber = rand();
|
||||||
enemies.enemyCount++;
|
enemies.enemyCount++;
|
||||||
enemies.enemyArray = (Enemy *) realloc(enemies.enemyArray, sizeof(Enemy) * enemies.enemyCount);
|
enemies.enemyArray = (Enemy *) realloc(enemies.enemyArray, sizeof(Enemy) * enemies.enemyCount);
|
||||||
|
|
||||||
|
@ -488,7 +483,7 @@ void SpawnEnemies()
|
||||||
enemySpawnVector.y = enemyVelocity.y > 0 ? 0 : screenDimensions.y;
|
enemySpawnVector.y = enemyVelocity.y > 0 ? 0 : screenDimensions.y;
|
||||||
|
|
||||||
enemy -> position = enemySpawnVector;
|
enemy -> position = enemySpawnVector;
|
||||||
enemy -> fireCooldown = 01.0 / (rand() % 5) + 2.0;
|
enemy -> fireCooldown = 1.0 / (rand() % 5) + 2.0;
|
||||||
|
|
||||||
enemyRespawnCounter++;
|
enemyRespawnCounter++;
|
||||||
}
|
}
|
||||||
|
@ -559,6 +554,18 @@ void MoveEnemies()
|
||||||
(enemies.enemyArray + i) -> position.y += velocity.y * speed;
|
(enemies.enemyArray + i) -> position.y += velocity.y * speed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LimitEnemies()
|
||||||
|
{
|
||||||
|
if(enemies.enemyLimit != enemyLimiter)
|
||||||
|
{
|
||||||
|
enemies.enemyLimit = initialEnemyLimit + (int)(timeSinceStart / 10);
|
||||||
|
|
||||||
|
if(enemies.enemyCount > enemyLimiter)
|
||||||
|
enemies.enemyLimit = enemyLimiter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DrawObject(Vector2D position, ALLEGRO_BITMAP *image, int flag)
|
void DrawObject(Vector2D position, ALLEGRO_BITMAP *image, int flag)
|
||||||
{
|
{
|
||||||
Vector2D InstantiateSize;
|
Vector2D InstantiateSize;
|
||||||
|
@ -571,6 +578,11 @@ void DrawObject(Vector2D position, ALLEGRO_BITMAP *image, int flag)
|
||||||
InstantiateSize.x * screenSizeMultiplier, InstantiateSize.y * screenSizeMultiplier, flag);
|
InstantiateSize.x * screenSizeMultiplier, InstantiateSize.y * screenSizeMultiplier, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Allegra Fonts is not working so I use this for displaying numbers
|
||||||
|
Special Characters:
|
||||||
|
10 = :
|
||||||
|
*/
|
||||||
void DrawNumber(Vector2D position, int number)
|
void DrawNumber(Vector2D position, int number)
|
||||||
{
|
{
|
||||||
Vector2D InstantiateSize;
|
Vector2D InstantiateSize;
|
||||||
|
@ -761,6 +773,11 @@ void GetSettings()
|
||||||
fclose(settingsFile);
|
fclose(settingsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CalculateScore()
|
||||||
|
{
|
||||||
|
player.score = (int)(timeSinceStart * timeSinceStart) * (player.killedEnemyCount + 1);
|
||||||
|
}
|
||||||
|
|
||||||
void Inputs()
|
void Inputs()
|
||||||
{
|
{
|
||||||
input.x = 0;
|
input.x = 0;
|
||||||
|
@ -838,6 +855,20 @@ void DieSoundEffect()
|
||||||
al_play_sample(enemyDieSound, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, &enemyDieSoundID);
|
al_play_sample(enemyDieSound, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_ONCE, &enemyDieSoundID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlayerShootCheck()
|
||||||
|
{
|
||||||
|
if(player.shootCooldown < 0.0f)
|
||||||
|
{
|
||||||
|
if(al_key_down(&keyboardState, ALLEGRO_KEY_SPACE))
|
||||||
|
{
|
||||||
|
printf("PlayerShoot();\n");
|
||||||
|
PlayerShoot();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
player.shootCooldown -= deltaTime;
|
||||||
|
}
|
||||||
|
|
||||||
void PlayerShoot()
|
void PlayerShoot()
|
||||||
{
|
{
|
||||||
Vector2D shootDir;
|
Vector2D shootDir;
|
||||||
|
|
Loading…
Reference in New Issue