Script Organization
This commit is contained in:
parent
a87b248a1c
commit
acfcade62e
123
SynGame.c
123
SynGame.c
|
@ -23,6 +23,7 @@
|
||||||
#include "allegro\include\allegro5\allegro_acodec.h"
|
#include "allegro\include\allegro5\allegro_acodec.h"
|
||||||
#include "allegro\include\allegro5\allegro_image.h"
|
#include "allegro\include\allegro5\allegro_image.h"
|
||||||
#include "allegro\include\allegro5\allegro_primitives.h"
|
#include "allegro\include\allegro5\allegro_primitives.h"
|
||||||
|
|
||||||
#define playerSpeed 0.75
|
#define playerSpeed 0.75
|
||||||
#define enemySpeed 0.1
|
#define enemySpeed 0.1
|
||||||
#define initialPlayerHealth 4
|
#define initialPlayerHealth 4
|
||||||
|
@ -91,6 +92,12 @@ struct
|
||||||
Image image;
|
Image image;
|
||||||
} player;
|
} player;
|
||||||
|
|
||||||
|
char InitializeGameWindow();
|
||||||
|
char InitializeGame();
|
||||||
|
char InitializeEnemies();
|
||||||
|
char DealDamage(char *health);
|
||||||
|
|
||||||
|
void Update();
|
||||||
void SpawnEnemies();
|
void SpawnEnemies();
|
||||||
void CheckBullets();
|
void CheckBullets();
|
||||||
void RemoveBulletAtIndex(int index);
|
void RemoveBulletAtIndex(int index);
|
||||||
|
@ -98,8 +105,8 @@ void RemoveEnemyAtIndex(int index);
|
||||||
void CheckEnemies();
|
void CheckEnemies();
|
||||||
void MoveEnemies();
|
void MoveEnemies();
|
||||||
void LimitEnemies();
|
void LimitEnemies();
|
||||||
void DestroyGame();
|
|
||||||
void DrawObject(Vector2D position, Image *image, int flag);
|
void DrawObject(Vector2D position, Image *image, int flag);
|
||||||
|
void DrawNumber(Vector2D position, int number);
|
||||||
void DrawSizedObject(Vector2D position, Image *image, int flag, float objectscreenSizeMultiplier);
|
void DrawSizedObject(Vector2D position, Image *image, int flag, float objectscreenSizeMultiplier);
|
||||||
void DrawScreen();
|
void DrawScreen();
|
||||||
void DrawScore();
|
void DrawScore();
|
||||||
|
@ -109,38 +116,33 @@ void CheckHighScore();
|
||||||
void GetHighScore();
|
void GetHighScore();
|
||||||
void GetSettings();
|
void GetSettings();
|
||||||
void CalculateScore();
|
void CalculateScore();
|
||||||
void DrawNumber(Vector2D position, int number);
|
|
||||||
void Inputs();
|
void Inputs();
|
||||||
void PlayerMovement();
|
void PlayerMovement();
|
||||||
void ClampPlayerPositionToScreenDimensions();
|
void ClampPlayerPositionToScreenDimensions();
|
||||||
void BulletMovement();
|
|
||||||
void ShootSoundEffect();
|
void ShootSoundEffect();
|
||||||
void DieSoundEffect();
|
void DieSoundEffect();
|
||||||
|
void PlayerShootCheck();
|
||||||
void PlayerShoot();
|
void PlayerShoot();
|
||||||
void EnemyShoot();
|
void EnemyShoot();
|
||||||
|
void BulletMovement();
|
||||||
void BulletCollisions();
|
void BulletCollisions();
|
||||||
void PlayerShootCheck();
|
void DestroyGame();
|
||||||
void Update();
|
|
||||||
void DestroyGameWindow();
|
void DestroyGameWindow();
|
||||||
|
|
||||||
float VectorMagnitude(Vector2D vector);
|
|
||||||
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();
|
float VectorMagnitude(Vector2D vector);
|
||||||
char InitializeGameWindow();
|
float VectorDistanceBetween(Vector2D vectorFirst, Vector2D vectorSecond);
|
||||||
char InitializeGame();
|
|
||||||
char DealDamage(char *health);
|
|
||||||
|
|
||||||
Image InitImage(const char *path);
|
|
||||||
|
|
||||||
Vector2D NormalizeVector(Vector2D vector);
|
Vector2D NormalizeVector(Vector2D vector);
|
||||||
|
|
||||||
|
Image InitImage(const char *path);
|
||||||
|
|
||||||
ALLEGRO_KEYBOARD_STATE keyboardState;
|
ALLEGRO_KEYBOARD_STATE keyboardState;
|
||||||
ALLEGRO_DISPLAY_MODE disp_data;
|
ALLEGRO_DISPLAY_MODE disp_data;
|
||||||
ALLEGRO_COLOR backgroundColor;
|
ALLEGRO_COLOR backgroundColor;
|
||||||
|
|
||||||
ALLEGRO_DISPLAY *display = NULL;
|
ALLEGRO_DISPLAY *display = NULL;
|
||||||
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
|
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
|
||||||
ALLEGRO_TIMER *timer = NULL;
|
ALLEGRO_TIMER *timer = NULL;
|
||||||
|
@ -316,7 +318,9 @@ Image InitImage(const char *path)
|
||||||
Vector2D NormalizeVector(Vector2D vector)
|
Vector2D NormalizeVector(Vector2D vector)
|
||||||
{
|
{
|
||||||
Vector2D normalizedVector;
|
Vector2D normalizedVector;
|
||||||
float magnitude = sqrt(vector.x * vector.x + vector.y * vector.y);
|
float magnitude;
|
||||||
|
|
||||||
|
magnitude = sqrt(vector.x * vector.x + vector.y * vector.y);
|
||||||
|
|
||||||
if(vector.x == 0.0 && vector.y == 0.0)
|
if(vector.x == 0.0 && vector.y == 0.0)
|
||||||
return vector;
|
return vector;
|
||||||
|
@ -375,8 +379,10 @@ byte CheckCollision(Vector2D *firstPos, Vector2D *secondPos, Image *firstMap, Im
|
||||||
|
|
||||||
char InitializeGameWindow()
|
char InitializeGameWindow()
|
||||||
{
|
{
|
||||||
float x = 0.0f;
|
float x;
|
||||||
float y = 0.0f;
|
float y;
|
||||||
|
x = 0.0f;
|
||||||
|
y = 0.0f;
|
||||||
|
|
||||||
if(!al_init() ||
|
if(!al_init() ||
|
||||||
!al_init_primitives_addon() ||
|
!al_init_primitives_addon() ||
|
||||||
|
@ -510,6 +516,11 @@ char InitializeEnemies()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char DealDamage(char *health)
|
||||||
|
{
|
||||||
|
return --*health <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
void SpawnEnemies()
|
void SpawnEnemies()
|
||||||
{
|
{
|
||||||
Vector2D enemySpawnVector;
|
Vector2D enemySpawnVector;
|
||||||
|
@ -629,6 +640,7 @@ void DrawObject(Vector2D position, Image *image, int flag)
|
||||||
{
|
{
|
||||||
Vector2D InstantiateSize;
|
Vector2D InstantiateSize;
|
||||||
Vector2D originalSize;
|
Vector2D originalSize;
|
||||||
|
|
||||||
InstantiateSize = image -> size;
|
InstantiateSize = image -> size;
|
||||||
originalSize = image -> originalSize;
|
originalSize = image -> originalSize;
|
||||||
|
|
||||||
|
@ -647,6 +659,7 @@ void DrawNumber(Vector2D position, int number)
|
||||||
{
|
{
|
||||||
Vector2D InstantiateSize;
|
Vector2D InstantiateSize;
|
||||||
Vector2D originalSize;
|
Vector2D originalSize;
|
||||||
|
|
||||||
InstantiateSize = numberTable.size;
|
InstantiateSize = numberTable.size;
|
||||||
originalSize = numberTable.originalSize;
|
originalSize = numberTable.originalSize;
|
||||||
|
|
||||||
|
@ -659,7 +672,9 @@ void DrawNumber(Vector2D position, int number)
|
||||||
void DrawSizedObject(Vector2D position, Image *image, int flag, float objectscreenSizeMultiplier)
|
void DrawSizedObject(Vector2D position, Image *image, int flag, float objectscreenSizeMultiplier)
|
||||||
{
|
{
|
||||||
Vector2D InstantiateSize;
|
Vector2D InstantiateSize;
|
||||||
float sizeFactor = screenSizeMultiplier * objectscreenSizeMultiplier;
|
float sizeFactor;
|
||||||
|
|
||||||
|
sizeFactor = screenSizeMultiplier * objectscreenSizeMultiplier;
|
||||||
InstantiateSize = image -> size;
|
InstantiateSize = image -> size;
|
||||||
|
|
||||||
al_draw_scaled_bitmap(image -> bitmap,
|
al_draw_scaled_bitmap(image -> bitmap,
|
||||||
|
@ -670,8 +685,9 @@ void DrawSizedObject(Vector2D position, Image *image, int flag, float objectscre
|
||||||
|
|
||||||
void DrawScreen()
|
void DrawScreen()
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i;
|
||||||
Vector2D halfScreen = {screenDimensions.x / 2, screenDimensions.y / 2};
|
Vector2D halfScreen;
|
||||||
|
halfScreen = (Vector2D){screenDimensions.x / 2, screenDimensions.y / 2};
|
||||||
|
|
||||||
/* Enemy Draw */
|
/* Enemy Draw */
|
||||||
for (i = 0; i < enemies.enemyCount; i++)
|
for (i = 0; i < enemies.enemyCount; i++)
|
||||||
|
@ -694,11 +710,13 @@ void DrawScreen()
|
||||||
|
|
||||||
void DrawScore()
|
void DrawScore()
|
||||||
{
|
{
|
||||||
unsigned int processedScore = player.score;
|
unsigned int processedScore;
|
||||||
char digit;
|
char digit;
|
||||||
Vector2D spawnPosition;
|
Vector2D spawnPosition;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
processedScore = player.score;
|
||||||
|
|
||||||
for(i = scoreDigitLimit - 1; i >= 0; i--)
|
for(i = scoreDigitLimit - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
spawnPosition = scorePosition;
|
spawnPosition = scorePosition;
|
||||||
|
@ -712,11 +730,13 @@ void DrawScore()
|
||||||
|
|
||||||
void DrawHighScore()
|
void DrawHighScore()
|
||||||
{
|
{
|
||||||
unsigned int processedScore = highScore;
|
unsigned int processedScore;
|
||||||
char digit;
|
char digit;
|
||||||
Vector2D spawnPosition;
|
Vector2D spawnPosition;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
processedScore = highScore;
|
||||||
|
|
||||||
for(i = 0; i < scoreDigitLimit; i++)
|
for(i = 0; i < scoreDigitLimit; i++)
|
||||||
{
|
{
|
||||||
spawnPosition = highScorePosition;
|
spawnPosition = highScorePosition;
|
||||||
|
@ -730,12 +750,16 @@ void DrawHighScore()
|
||||||
|
|
||||||
void DrawTimer()
|
void DrawTimer()
|
||||||
{
|
{
|
||||||
int seconds = (int)timeSinceStart % 60;
|
int seconds;
|
||||||
int minutes = (timeSinceStart - seconds) / 60;
|
int minutes;
|
||||||
char digit;
|
char digit;
|
||||||
Vector2D spawnPosition;
|
Vector2D spawnPosition;
|
||||||
int i = -timerDigitLimit / 2;
|
int i;
|
||||||
|
|
||||||
|
seconds = (int)timeSinceStart % 60;
|
||||||
|
minutes = (timeSinceStart - seconds) / 60;
|
||||||
spawnPosition = timerPosition;
|
spawnPosition = timerPosition;
|
||||||
|
i = -timerDigitLimit / 2;
|
||||||
|
|
||||||
while (i < 0)
|
while (i < 0)
|
||||||
{
|
{
|
||||||
|
@ -794,8 +818,8 @@ void CheckHighScore()
|
||||||
|
|
||||||
void GetHighScore()
|
void GetHighScore()
|
||||||
{
|
{
|
||||||
printf("Getting Highscore\n");
|
|
||||||
FILE *saveFile = fopen(savePath, "rb");
|
FILE *saveFile = fopen(savePath, "rb");
|
||||||
|
printf("Getting Highscore\n");
|
||||||
if(saveFile == NULL)
|
if(saveFile == NULL)
|
||||||
{
|
{
|
||||||
printf("!!!!Error Reading Highscore!!!!\n");
|
printf("!!!!Error Reading Highscore!!!!\n");
|
||||||
|
@ -809,8 +833,8 @@ void GetHighScore()
|
||||||
|
|
||||||
void GetSettings()
|
void GetSettings()
|
||||||
{
|
{
|
||||||
printf("Getting Settings\n");
|
|
||||||
FILE *settingsFile = fopen(settingsPath, "r");
|
FILE *settingsFile = fopen(settingsPath, "r");
|
||||||
|
printf("Getting Settings\n");
|
||||||
if(settingsFile == NULL)
|
if(settingsFile == NULL)
|
||||||
{
|
{
|
||||||
printf("!!!!Error Reading Settings!!!!\n");
|
printf("!!!!Error Reading Settings!!!!\n");
|
||||||
|
@ -855,7 +879,6 @@ void Inputs()
|
||||||
player.lookDirection = input.x;
|
player.lookDirection = input.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
input = NormalizeVector(input);
|
input = NormalizeVector(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -880,23 +903,6 @@ void ClampPlayerPositionToScreenDimensions()
|
||||||
player.position.y = screenDimensions.y;
|
player.position.y = screenDimensions.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
char DealDamage(char *health)
|
|
||||||
{
|
|
||||||
return --*health <= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BulletMovement()
|
|
||||||
{
|
|
||||||
Bullet *bullet;
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < bullets.bulletCount; i++)
|
|
||||||
{
|
|
||||||
bullet = (bullets.bulletArray + i);
|
|
||||||
bullet -> position.x += bullet -> velocity.x;
|
|
||||||
bullet -> position.y += bullet -> velocity.y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ShootSoundEffect()
|
void ShootSoundEffect()
|
||||||
{
|
{
|
||||||
printf("ShootSoundEffect();\n");
|
printf("ShootSoundEffect();\n");
|
||||||
|
@ -929,7 +935,9 @@ void PlayerShoot()
|
||||||
{
|
{
|
||||||
Vector2D shootDir;
|
Vector2D shootDir;
|
||||||
Bullet *newBullet;
|
Bullet *newBullet;
|
||||||
float offset = (player.image.size.x + enemyBulletImage.size.x * 2.0);
|
float offset;
|
||||||
|
|
||||||
|
offset = (player.image.size.x + enemyBulletImage.size.x * 2.0);
|
||||||
|
|
||||||
if(player.lookDirection != 1)
|
if(player.lookDirection != 1)
|
||||||
offset = -offset;
|
offset = -offset;
|
||||||
|
@ -959,7 +967,9 @@ void EnemyShoot()
|
||||||
Enemy *enemy;
|
Enemy *enemy;
|
||||||
Bullet *bullet;
|
Bullet *bullet;
|
||||||
int i;
|
int i;
|
||||||
float offset = (player.image.size.x + enemyBulletImage.size.x * 2.0);
|
float offset;
|
||||||
|
|
||||||
|
offset = (player.image.size.x + enemyBulletImage.size.x * 2.0);
|
||||||
|
|
||||||
for (i = 0; i < enemies.enemyCount; i++)
|
for (i = 0; i < enemies.enemyCount; i++)
|
||||||
{
|
{
|
||||||
|
@ -988,21 +998,21 @@ void EnemyShoot()
|
||||||
ShootSoundEffect();
|
ShootSoundEffect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BulletCollisions()
|
void BulletCollisions()
|
||||||
{
|
{
|
||||||
Bullet *bullet;
|
Bullet *bullet;
|
||||||
Enemy *enemy;
|
Enemy *enemy;
|
||||||
int bulletCounter = 0;
|
int bulletCounter;
|
||||||
int enemyCounter = 0;
|
int enemyCounter;
|
||||||
int i = 0;
|
|
||||||
printf("Enemy-Bullet\n");
|
printf("Enemy-Bullet\n");
|
||||||
for (enemyCounter = 0; enemyCounter < enemies.enemyCount; enemyCounter++)
|
for (enemyCounter = 0; enemyCounter < enemies.enemyCount; enemyCounter++)
|
||||||
{
|
{
|
||||||
printf("Enemy-Bullet|enemyCounter\n");
|
printf("Enemy-Bullet|enemyCounter\n");
|
||||||
enemy = (enemies.enemyArray + enemyCounter);
|
enemy = (enemies.enemyArray + enemyCounter);
|
||||||
|
|
||||||
for (bulletCounter = 0; bulletCounter < bullets.bulletCount; bulletCounter++)
|
for (bulletCounter = 0; bulletCounter < bullets.bulletCount; bulletCounter++)
|
||||||
{
|
{
|
||||||
bullet = (bullets.bulletArray + bulletCounter);
|
bullet = (bullets.bulletArray + bulletCounter);
|
||||||
|
@ -1055,7 +1065,18 @@ void BulletCollisions()
|
||||||
isGameOver = 1;
|
isGameOver = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BulletMovement()
|
||||||
|
{
|
||||||
|
Bullet *bullet;
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < bullets.bulletCount; i++)
|
||||||
|
{
|
||||||
|
bullet = (bullets.bulletArray + i);
|
||||||
|
bullet -> position.x += bullet -> velocity.x;
|
||||||
|
bullet -> position.y += bullet -> velocity.y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DestroyGame()
|
void DestroyGame()
|
||||||
|
|
Loading…
Reference in New Issue