Compare commits

...

15 Commits
1.0 ... master

Author SHA1 Message Date
df79395421 Author information updated 2023-01-28 21:19:30 +00:00
Asrın Doğan
5a82e45de7 Replaced some int values with char 2019-09-29 23:18:44 +03:00
Asrın Doğan
5a37718718 Replaced bytes with ints 2019-09-29 23:16:51 +03:00
Asrın Doğan
acfcade62e Script Organization 2019-09-26 23:44:57 +03:00
Asrın Doğan
a87b248a1c Update SynGame.c 2019-09-26 23:20:37 +03:00
Asrın Doğan
8e1dedc421 Update .gitignore for a missing .a file 2019-09-26 22:00:33 +03:00
Asrın Doğan
f9e795e5e4 Added The Missing NULL Checks 2019-09-26 21:58:03 +03:00
Asrın Doğan
5596b53c02 Script Optimization and Organization 2019-09-26 21:49:53 +03:00
Asrın Doğan
f1620e54a0 Added a new Struct for Images 2019-09-26 21:10:50 +03:00
Asrın Doğan
049612b1c8 Changed External Paths to Variables 2019-09-26 20:20:13 +03:00
Asrın Doğan
0738d7f9a7 Spawn Bug Fix, Script Organization and BGM Speed Up 2019-09-26 20:12:04 +03:00
Asrın Doğan
477b4ddb40 Changed TimerDraw Function Slightly for Readability 2019-09-13 21:02:16 +03:00
Asrın Doğan
23a49fa855 Update README.md 2019-09-13 20:33:20 +03:00
Asrın Doğan
0938c7b364 Update README.md 2019-09-13 20:32:26 +03:00
Asrın Doğan
7886dbd994 Readme Update and BGM update 2019-09-13 20:31:08 +03:00
5 changed files with 897 additions and 795 deletions

4
.gitignore vendored
View File

@ -4,13 +4,13 @@
*.a
*.dll
*.syn
!allegro_acodec-5.0.10-md.dll
!allegro_audio-5.0.10-md.dll
!allegro_acodec-5.0.10-md.dll
!allegro_image-5.0.10-md.dll
!allegro_primitives-5.0.10-md.dll
!allegro-5.0.10-md.dll
!liballegro_audio-5.0.10-md.a
!liballegro_acodec-5.0.10-md.a
!liballegro_image-5.0.10-md.a
!liballegro_dialog-5.0.10-md.a
!liballegro_primitives-5.0.10-md.a
!liballegro-5.0.10-md.a

View File

@ -1,26 +1,24 @@
# SynGame
Simple Shoot 'Em Up game.
Simple Shoot 'Em Up game for Windows.
Keys:
Move Up - Up Arrow
Move Right - Right Arrow
Move Down - Down Arrow
Move Left - Left Arrow
Shoot - Space
Restart - R
Keys:\
Move Up - Up Arrow\
Move Right - Right Arrow\
Move Down - Down Arrow\
Move Left - Left Arrow\
Shoot - Space\
Restart - R\
Exit - Escape(ESC)
Settings.syn can be opened with a text editor.
Format:
First line: Screen Mode, 1 is Fullscreen, 0 is Windowed (Default Value = 1)
Second line: Screen Width, Windowed Mode Only (Default Value = 1600)
Third line: Screen Height, Windowed Mode Only (Default Value = 900)
Settings.syn can be opened with a text editor.\
Settings Format:\
First line: Screen Mode, 1 is Fullscreen, 0 is Windowed (Default Value = 1)\
Second line: Screen Width, Windowed Mode Only (Default Value = 1600)\
Third line: Screen Height, Windowed Mode Only (Default Value = 900)\
Fourth line: Enemy Count Limiter, there will be no more enemies than this number on the screen (Default Value = 12)
Exe without console window
Exe without console window\
gcc SynGame.c -o SynGame.exe "allegro\lib\liballegro-5.0.10-md.a" "allegro\lib\liballegro_audio-5.0.10-md.a" "allegro\lib\liballegro_acodec-5.0.10-md.a" "allegro\lib\liballegro_image-5.0.10-md.a" "allegro\lib\liballegro_dialog-5.0.10-md.a" "allegro\lib\liballegro_primitives-5.0.10-md.a" --machine-windows
Exe with console window
Exe with console window\
gcc SynGame.c -o SynGame.exe "allegro\lib\liballegro-5.0.10-md.a" "allegro\lib\liballegro_audio-5.0.10-md.a" "allegro\lib\liballegro_acodec-5.0.10-md.a" "allegro\lib\liballegro_image-5.0.10-md.a" "allegro\lib\liballegro_primitives-5.0.10-md.a"

Binary file not shown.

456
SynGame.c
View File

@ -1,8 +1,6 @@
/*
Author: Asrın "Syntriax" Doğan
Date: 10.09.2019
Mail: asrindogan99@gmail.com
Author: Syntriax <Syntriax@gmail.com>
Start: 05.09.2019
Simple Shoot 'Em Up game.
Keys:
@ -23,6 +21,7 @@
#include "allegro\include\allegro5\allegro_acodec.h"
#include "allegro\include\allegro5\allegro_image.h"
#include "allegro\include\allegro5\allegro_primitives.h"
#define playerSpeed 0.75
#define enemySpeed 0.1
#define initialPlayerHealth 4
@ -41,6 +40,13 @@ typedef struct
float y;
} Vector2D;
typedef struct
{
Vector2D originalSize;
Vector2D size;
ALLEGRO_BITMAP *bitmap;
} Image;
typedef struct
{
Vector2D position;
@ -75,25 +81,33 @@ struct
Vector2D position;
char health;
float moveSpeed;
byte lookDirection;
char lookDirection;
int shootPerSecond;
float shootCooldown;
unsigned int killedEnemyCount;
unsigned int score;
ALLEGRO_BITMAP *playerImage;
Image image;
} player;
char InitializeGameWindow();
char InitializeGame();
char InitializeEnemies();
char DealDamage(char *health);
char isVectorExceedingLimits(Vector2D vector, Vector2D limits);
char CheckCollision(Vector2D *firstPos, Vector2D *secondPos, Image *firstMap, Image *secondMap);
void Update();
void SpawnEnemies();
void CheckBullets();
void RemoveBulletAtIndex(int index);
void RemoveEnemyAtIndex(int index);
void CheckEnemies();
void MoveEnemies();
void InitializeEnemies();
void DestroyGame();
void DrawObject(Vector2D position, ALLEGRO_BITMAP *image, int flag);
void DrawSizedObject(Vector2D position, ALLEGRO_BITMAP *image, int flag, float objectscreenSizeMultiplier);
void LimitEnemies();
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 DrawScreen();
void DrawScore();
void DrawHighScore();
@ -101,70 +115,92 @@ void DrawTimer();
void CheckHighScore();
void GetHighScore();
void GetSettings();
void DrawNumber(Vector2D position, int number);
void CalculateScore();
void Inputs();
void PlayerMovement();
void ClampPlayerPositionToScreenDimensions();
void BulletMovement();
void ShootSoundEffect();
void DieSoundEffect();
void PlayerShootCheck();
void PlayerShoot();
void EnemyShoot();
void BulletMovement();
void BulletCollisions();
void Update();
void DestroyGame();
void DestroyGameWindow();
float VectorMagnitude(Vector2D vector);
float VectorDistanceBetween(Vector2D vectorFirst, Vector2D vectorSecond);
byte isVectorExceedingLimits(Vector2D vector, Vector2D limits);
byte CheckCollision(Vector2D *firstPos, Vector2D *secondPos, ALLEGRO_BITMAP *firstMap, ALLEGRO_BITMAP *secondMap);
char InitializeGameWindow();
char InitializeGame();
char DealDamage(char *health);
Vector2D NormalizeVector(Vector2D vector);
Image InitImage(const char *path);
ALLEGRO_KEYBOARD_STATE keyboardState;
ALLEGRO_DISPLAY_MODE disp_data;
ALLEGRO_COLOR backgroundColor;
ALLEGRO_DISPLAY *display = NULL;
ALLEGRO_EVENT_QUEUE *event_queue = NULL;
ALLEGRO_TIMER *timer = NULL;
ALLEGRO_BITMAP *gameOverImage = NULL;
Image gameOverImage;
ALLEGRO_SAMPLE *BGM = NULL;
ALLEGRO_SAMPLE *shootSound = NULL;
ALLEGRO_SAMPLE_ID shootSoundID;
ALLEGRO_BITMAP *enemyImage = NULL;
ALLEGRO_BITMAP *enemyBulletImage = NULL;
Image enemyImage;
Image enemyBulletImage;
ALLEGRO_SAMPLE *enemyDieSound = NULL;
ALLEGRO_SAMPLE_ID enemyDieSoundID;
ALLEGRO_BITMAP *numberTable = NULL;
Image numberTable;
const char *playerImagePath = "Images/Player.png";
const char *enemyImagePath = "Images/Enemy.png";
const char *bulletImagePath = "Images/Bullet.png";
const char *gameOverImagePath = "Images/GameOver.png";
const char *numbersImagePath = "Images/Numbers.png";
const char *dieSoundPath = "Sounds/Die.wav";
const char *bgmSoundPath = "Sounds/Background.wav";
const char *shootSoundPath = "Sounds/Shoot.wav";
const char *displayName = "Syn Game";
const char *savePath = "Save.syn";
const char *settingsPath = "Settings.syn";
const char *settingsFormat = "%d\n%d\n%d";
int isFullscreen = 1;
int settingsWidth = 1600;
int settingsHeight = 900;
const Vector2D referenceScreenDimensions = {160, 90};
Vector2D screenDimensions = {0, 0};
Vector2D scorePosition = {0, 0};
Vector2D highScorePosition = {0, 0};
Vector2D timerPosition = {0, 0};
float screenSizeMultiplier;
float timeSinceStart;
const float FPS = 60;
double deltaTime;
unsigned int enemyRespawnCounter = 0;
unsigned int highScore = 0;
int enemyLimiter = 12;
Vector2D input;
byte isRestart = 0;
byte isRunning = 1;
byte isGameOver = 0;
char isRestart = 0;
char isRunning = 1;
char isGameOver = 0;
void Update()
{
@ -189,28 +225,16 @@ void Update()
printf("BulletCollisions();\n");
BulletCollisions();
if(player.shootCooldown < 0.0f)
{
if(al_key_down(&keyboardState, ALLEGRO_KEY_SPACE))
{
printf("PlayerShoot();\n");
PlayerShoot();
}
}
else
player.shootCooldown -= deltaTime;
printf("PlayerShootCheck();\n");
PlayerShootCheck();
printf("LimitEnemies();\n");
LimitEnemies();
timeSinceStart += deltaTime;
player.score = (int)(timeSinceStart * timeSinceStart) * (player.killedEnemyCount + 1);
/* To limit the enemies on the screen */
if(enemies.enemyLimit != enemyLimiter)
{
enemies.enemyLimit = initialEnemyLimit + (int)(timeSinceStart / 10);
if(enemies.enemyCount > enemyLimiter)
enemies.enemyLimit = enemyLimiter;
}
printf("CalculateScore();\n");
CalculateScore();
}
else if(al_key_down(&keyboardState, ALLEGRO_KEY_R))
isRestart = 1;
@ -231,7 +255,6 @@ void Update()
printf("DrawScreen();\n");
DrawScreen();
al_flip_display();
}
@ -267,7 +290,8 @@ int main(int argc, char **argv)
}
DestroyGame();
} while (isRestart);
}
while (isRestart);
DestroyGameWindow();
@ -275,10 +299,26 @@ int main(int argc, char **argv)
return 0;
}
Image InitImage(const char *path)
{
Image result;
result.bitmap = al_load_bitmap(path);
result.originalSize.x = al_get_bitmap_width(result.bitmap);
result.originalSize.y = al_get_bitmap_height(result.bitmap);
result.size.x = result.originalSize.x * screenSizeMultiplier;
result.size.y = result.originalSize.y * screenSizeMultiplier;
return result;
}
Vector2D NormalizeVector(Vector2D vector)
{
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)
return vector;
@ -302,33 +342,32 @@ float VectorDistanceBetween(Vector2D vectorFirst, Vector2D vectorSecond)
return VectorMagnitude(difference);
}
byte isVectorExceedingLimits(Vector2D vector, Vector2D limits)
char isVectorExceedingLimits(Vector2D vector, Vector2D limits)
{
byte result = vector.x > limits.x || vector.x < 0 || vector.y > limits.y || vector.y < 0;
char result = vector.x > limits.x || vector.x < 0 || vector.y > limits.y || vector.y < 0;
return result;
}
/*
Gets the shortest dimensions of both images, sums these dimension and divides by 2 to get minimum accepted distance.
And compares the distance between those objects to the minimum distancce to check if they're colliding.
It's the most optimized way I can think of for a game like this.
It's the most simple and optimized way I can think of for a game like this.
*/
byte CheckCollision(Vector2D *firstPos, Vector2D *secondPos, ALLEGRO_BITMAP *firstMap, ALLEGRO_BITMAP *secondMap)
char CheckCollision(Vector2D *firstPos, Vector2D *secondPos, Image *firstMap, Image *secondMap)
{
Vector2D firstImageSize;
Vector2D secondImageSize;
byte result;
char result;
float minDistance;
float distance;
firstImageSize.x = (float)al_get_bitmap_width(firstMap);
firstImageSize.y = (float)al_get_bitmap_height(firstMap);
secondImageSize.x = (float)al_get_bitmap_width(secondMap);
secondImageSize.y = (float)al_get_bitmap_height(secondMap);
minDistance = firstImageSize.x > firstImageSize.y ? firstImageSize.y : firstImageSize.x;
minDistance += secondImageSize.x > secondImageSize.y ? secondImageSize.y : secondImageSize.x;
minDistance = firstMap -> size.x > firstMap -> size.y ?
firstMap -> size.y :
firstMap -> size.x;
minDistance *= screenSizeMultiplier * 0.5f;
minDistance += secondMap -> size.x > secondMap -> size.y ?
secondMap -> size.y :
secondMap -> size.x;
minDistance *= 0.5f;
distance = VectorDistanceBetween(*firstPos, *secondPos);
@ -338,8 +377,10 @@ byte CheckCollision(Vector2D *firstPos, Vector2D *secondPos, ALLEGRO_BITMAP *fir
char InitializeGameWindow()
{
float x = 0.0f;
float y = 0.0f;
float x;
float y;
x = 0.0f;
y = 0.0f;
if(!al_init() ||
!al_init_primitives_addon() ||
@ -366,9 +407,10 @@ char InitializeGameWindow()
}
screenDimensions = (Vector2D){x, y};
scorePosition = (Vector2D){x * (float)0.05, y * (float)0.05};
highScorePosition = (Vector2D){x * (float)0.95, y * (float)0.05};
timerPosition = (Vector2D){x * (float)0.5 , y * (float)0.95};
scorePosition = (Vector2D){x * (float)0.05, y * (float)0.05}; /* Upper Left Position */
highScorePosition = (Vector2D){x * (float)0.95, y * (float)0.05}; /* Upper Right Position */
timerPosition = (Vector2D){x * (float)0.5 , y * (float)0.95}; /* Bottom Center Position */
screenSizeMultiplier = screenDimensions.x / referenceScreenDimensions.x;
display = al_create_display(screenDimensions.x, screenDimensions.y);
@ -399,21 +441,30 @@ char InitializeGameWindow()
al_set_window_title(display, displayName);
backgroundColor.a = 1;
backgroundColor.a = 0;
backgroundColor.a = 0;
backgroundColor.a = 0;
backgroundColor.r = .1;
backgroundColor.g = .1;
backgroundColor.b = .1;
/* 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(bgmSoundPath);
if(BGM == NULL)
return 0;
al_play_sample(BGM, 1.0, 0.0, 1.0, ALLEGRO_PLAYMODE_LOOP, NULL);
return 1;
}
char InitializeGame()
{
shootSound = al_load_sample("Sounds/Shoot.wav");
enemyDieSound = al_load_sample("Sounds/Die.wav");
shootSound = al_load_sample(shootSoundPath);
enemyDieSound = al_load_sample(dieSoundPath);
InitializeEnemies();
if(shootSound == NULL || enemyDieSound == NULL)
return 0;
if(!InitializeEnemies())
return 0;
GetHighScore();
/* Player Initialization */
@ -422,9 +473,9 @@ char InitializeGame()
player.moveSpeed = playerSpeed * screenSizeMultiplier;
player.shootPerSecond = 10;
player.health = initialPlayerHealth;
player.playerImage = al_load_bitmap("Images/Player.png");
player.image = InitImage(playerImagePath);
if(player.playerImage == NULL ||
if(player.image.bitmap == NULL ||
shootSound == NULL ||
enemyDieSound == NULL)
return 0;
@ -442,16 +493,30 @@ char InitializeGame()
return 1;
}
void InitializeEnemies()
char InitializeEnemies()
{
enemies.enemyLimit = initialEnemyLimit;
enemies.enemyCount = 0;
enemies.enemyArray = (Enemy *) malloc(sizeof(Enemy) * enemies.enemyCount);
enemyImage = al_load_bitmap("Images/Enemy.png");
numberTable = al_load_bitmap("Images/Numbers.png");
enemyBulletImage = al_load_bitmap("Images/Bullet.png");
gameOverImage = al_load_bitmap("Images/GameOver.png");
enemyImage = InitImage(enemyImagePath);
numberTable = InitImage(numbersImagePath);
enemyBulletImage = InitImage(bulletImagePath);
gameOverImage = InitImage(gameOverImagePath);
if( enemyImage.bitmap == NULL ||
numberTable.bitmap == NULL ||
enemyBulletImage.bitmap == NULL ||
gameOverImage.bitmap == NULL )
return 0;
SpawnEnemies();
return 1;
}
char DealDamage(char *health)
{
return --*health <= 0;
}
void SpawnEnemies()
@ -469,7 +534,7 @@ void SpawnEnemies()
{
/* enemyRespawnCounter is just for making the value of rand() more randomized */
srand(time(0) + enemyRespawnCounter);
randomNumber = rand() * enemies.enemyCount;
randomNumber = rand();
enemies.enemyCount++;
enemies.enemyArray = (Enemy *) realloc(enemies.enemyArray, sizeof(Enemy) * enemies.enemyCount);
@ -488,7 +553,7 @@ void SpawnEnemies()
enemySpawnVector.y = enemyVelocity.y > 0 ? 0 : screenDimensions.y;
enemy -> position = enemySpawnVector;
enemy -> fireCooldown = 01.0 / (rand() % 5) + 2.0;
enemy -> fireCooldown = 1.0 / (rand() % 5) + 2.0;
enemyRespawnCounter++;
}
@ -496,11 +561,10 @@ void SpawnEnemies()
void CheckBullets()
{
int i = 0;
int j = 0;
int i;
int j;
for (; i < bullets.bulletCount; i++)
{
for (i = 0; i < bullets.bulletCount; i++)
if(isVectorExceedingLimits((bullets.bulletArray + i) -> position, screenDimensions))
{
for (j = i; j < bullets.bulletCount - 1; j++)
@ -510,7 +574,6 @@ void CheckBullets()
bullets.bulletArray = (Bullet *) realloc(bullets.bulletArray, sizeof(Bullet) * bullets.bulletCount);
}
}
}
void RemoveBulletAtIndex(int index)
{
@ -536,9 +599,9 @@ void RemoveEnemyAtIndex(int index)
void CheckEnemies()
{
int i = 0;
int i;
for (; i < enemies.enemyCount; i++)
for (i = 0; i < enemies.enemyCount; i++)
if(isVectorExceedingLimits((enemies.enemyArray + i) -> position, screenDimensions))
RemoveEnemyAtIndex(i);
@ -547,11 +610,11 @@ void CheckEnemies()
void MoveEnemies()
{
int i = 0;
Vector2D velocity;
float speed;
int i;
for (; i < enemies.enemyCount; i++)
for (i = 0; i < enemies.enemyCount; i++)
{
speed = (enemies.enemyArray + i) -> moveSpeed;
velocity = (enemies.enemyArray + i) -> velocity;
@ -559,38 +622,60 @@ void MoveEnemies()
(enemies.enemyArray + i) -> position.y += velocity.y * speed;
}
}
void DrawObject(Vector2D position, ALLEGRO_BITMAP *image, int flag)
{
Vector2D InstantiateSize;
InstantiateSize.x = (float)al_get_bitmap_width(image);
InstantiateSize.y = (float)al_get_bitmap_height(image);
al_draw_scaled_bitmap(image,
0, 0, InstantiateSize.x, InstantiateSize.y,
position.x - InstantiateSize.x / 2 * screenSizeMultiplier, position.y - InstantiateSize.y / 2 * screenSizeMultiplier,
InstantiateSize.x * screenSizeMultiplier, InstantiateSize.y * screenSizeMultiplier, flag);
void LimitEnemies()
{
if(enemies.enemyLimit != enemyLimiter)
{
enemies.enemyLimit = initialEnemyLimit + (int)(timeSinceStart / 10);
if(enemies.enemyCount > enemyLimiter)
enemies.enemyLimit = enemyLimiter;
}
}
void DrawObject(Vector2D position, Image *image, int flag)
{
Vector2D InstantiateSize;
Vector2D originalSize;
InstantiateSize = image -> size;
originalSize = image -> originalSize;
al_draw_scaled_bitmap(image -> bitmap,
0, 0, originalSize.x, originalSize.y,
position.x - InstantiateSize.x / 2, position.y - InstantiateSize.y / 2,
InstantiateSize.x, InstantiateSize.y, flag);
}
/*
Allegra Fonts is not working so I use this for displaying numbers
Special Characters:
10 = :
*/
void DrawNumber(Vector2D position, int number)
{
Vector2D InstantiateSize;
InstantiateSize.x = (float)al_get_bitmap_width(numberTable);
InstantiateSize.y = (float)al_get_bitmap_height(numberTable);
Vector2D originalSize;
al_draw_scaled_bitmap(numberTable,
numberImageSize * number, 0, numberImageSize, InstantiateSize.y,
position.x - numberImageSize / 2 * screenSizeMultiplier, position.y - InstantiateSize.y / 2 * screenSizeMultiplier,
numberImageSize * screenSizeMultiplier, InstantiateSize.y * screenSizeMultiplier, 0);
InstantiateSize = numberTable.size;
originalSize = numberTable.originalSize;
al_draw_scaled_bitmap(numberTable.bitmap,
numberImageSize * number, 0, numberImageSize, originalSize.y,
position.x - numberImageSize / 2 * screenSizeMultiplier, position.y - InstantiateSize.y / 2,
numberImageSize * screenSizeMultiplier, InstantiateSize.y, 0);
}
void DrawSizedObject(Vector2D position, ALLEGRO_BITMAP *image, int flag, float objectscreenSizeMultiplier)
void DrawSizedObject(Vector2D position, Image *image, int flag, float objectscreenSizeMultiplier)
{
Vector2D InstantiateSize;
float sizeFactor = screenSizeMultiplier * objectscreenSizeMultiplier;
InstantiateSize.x = (float)al_get_bitmap_width(image);
InstantiateSize.y = (float)al_get_bitmap_height(image);
float sizeFactor;
al_draw_scaled_bitmap(image,
sizeFactor = screenSizeMultiplier * objectscreenSizeMultiplier;
InstantiateSize = image -> size;
al_draw_scaled_bitmap(image -> bitmap,
0, 0, InstantiateSize.x, InstantiateSize.y,
position.x - InstantiateSize.x / 2 * sizeFactor, position.y - InstantiateSize.y / 2 * sizeFactor,
InstantiateSize.x * sizeFactor, InstantiateSize.y * sizeFactor, flag);
@ -598,22 +683,23 @@ void DrawSizedObject(Vector2D position, ALLEGRO_BITMAP *image, int flag, float o
void DrawScreen()
{
int i = 0;
Vector2D halfScreen = {screenDimensions.x / 2, screenDimensions.y / 2};
int i;
Vector2D halfScreen;
halfScreen = (Vector2D){screenDimensions.x / 2, screenDimensions.y / 2};
/* Enemy Draw */
for (i = 0; i < enemies.enemyCount; i++)
DrawObject((enemies.enemyArray + i) -> position, enemyImage, (enemies.enemyArray + i) -> velocity.x > 0 ? ALLEGRO_FLIP_HORIZONTAL : 0 );
DrawObject((enemies.enemyArray + i) -> position, &enemyImage, (enemies.enemyArray + i) -> velocity.x > 0 ? ALLEGRO_FLIP_HORIZONTAL : 0 );
/* Bullet Draw */
for (i = 0; i < bullets.bulletCount; i++)
DrawObject((bullets.bulletArray + i) -> position, enemyBulletImage, 0);
DrawObject((bullets.bulletArray + i) -> position, &enemyBulletImage, 0);
/* Player Draw */
if(!isGameOver)
DrawObject(player.position, player.playerImage, player.lookDirection == 1 ? ALLEGRO_FLIP_HORIZONTAL : 0);
DrawObject(player.position, &player.image, player.lookDirection == 1 ? ALLEGRO_FLIP_HORIZONTAL : 0);
else
DrawObject(halfScreen, gameOverImage, 0);
DrawObject(halfScreen, &gameOverImage, 0);
DrawScore();
DrawHighScore();
@ -622,13 +708,14 @@ void DrawScreen()
void DrawScore()
{
unsigned int processedScore = player.score;
unsigned int processedScore;
char digit;
Vector2D spawnPosition;
int i = scoreDigitLimit - 1;
int i;
/* while (processedScore >= 1 && i > 0) */
while (i >= 0)
processedScore = player.score;
for(i = scoreDigitLimit - 1; i >= 0; i--)
{
spawnPosition = scorePosition;
/* numberImageSize + 1 is because 1 pixel space between digits */
@ -636,19 +723,19 @@ void DrawScore()
digit = processedScore % 10;
processedScore = (int)(processedScore / 10);
DrawNumber(spawnPosition, digit);
i--;
}
}
void DrawHighScore()
{
unsigned int processedScore = highScore;
unsigned int processedScore;
char digit;
Vector2D spawnPosition;
int i = 0;
int i;
/* while (processedScore >= 1 && i > 0) */
while (i < scoreDigitLimit)
processedScore = highScore;
for(i = 0; i < scoreDigitLimit; i++)
{
spawnPosition = highScorePosition;
/* numberImageSize + 1 is because 1 pixel space between digits */
@ -656,25 +743,26 @@ void DrawHighScore()
digit = processedScore % 10;
processedScore = (int)(processedScore / 10);
DrawNumber(spawnPosition, digit);
i++;
}
}
void DrawTimer()
{
int seconds = (int)timeSinceStart % 60;
int minutes = (timeSinceStart - seconds) / 60;
int seconds;
int minutes;
char digit;
Vector2D spawnPosition;
int i = -timerDigitLimit / 2;
int i;
seconds = (int)timeSinceStart % 60;
minutes = (timeSinceStart - seconds) / 60;
spawnPosition = timerPosition;
i = -timerDigitLimit / 2;
/* while (processedScore >= 1 && i > 0) */
while (i < 0)
{
spawnPosition = timerPosition;
/* numberImageSize + 1 is because 1 pixel space between digits */
spawnPosition.x -= screenSizeMultiplier * (numberImageSize + 1) * i;
spawnPosition.x = timerPosition.x - screenSizeMultiplier * (numberImageSize + 1) * i;
digit = seconds % 10;
seconds = (int)(seconds / 10);
@ -682,18 +770,15 @@ void DrawTimer()
i++;
}
spawnPosition = timerPosition;
/* numberImageSize + 1 is because 1 pixel space between digits */
spawnPosition.x -= screenSizeMultiplier * (numberImageSize + 1) * i;
spawnPosition.x = timerPosition.x - screenSizeMultiplier * (numberImageSize + 1) * i;
DrawNumber(spawnPosition, colon);
i++;
while (i < (timerDigitLimit / 2) + 1)
{
spawnPosition = timerPosition;
/* numberImageSize + 1 is because 1 pixel space between digits */
spawnPosition.x -= screenSizeMultiplier * (numberImageSize + 1) * i;
spawnPosition.x = timerPosition.x - screenSizeMultiplier * (numberImageSize + 1) * i;
if(i == 0)
{
@ -731,8 +816,8 @@ void CheckHighScore()
void GetHighScore()
{
printf("Getting Highscore\n");
FILE *saveFile = fopen(savePath, "rb");
printf("Getting Highscore\n");
if(saveFile == NULL)
{
printf("!!!!Error Reading Highscore!!!!\n");
@ -746,8 +831,8 @@ void GetHighScore()
void GetSettings()
{
printf("Getting Settings\n");
FILE *settingsFile = fopen(settingsPath, "r");
printf("Getting Settings\n");
if(settingsFile == NULL)
{
printf("!!!!Error Reading Settings!!!!\n");
@ -766,6 +851,11 @@ void GetSettings()
fclose(settingsFile);
}
void CalculateScore()
{
player.score = (int)(timeSinceStart * timeSinceStart) * (player.killedEnemyCount + 1);
}
void Inputs()
{
input.x = 0;
@ -787,7 +877,6 @@ void Inputs()
player.lookDirection = input.x;
}
input = NormalizeVector(input);
}
@ -812,23 +901,6 @@ void ClampPlayerPositionToScreenDimensions()
player.position.y = screenDimensions.y;
}
char DealDamage(char *health)
{
return --*health <= 0;
}
void BulletMovement()
{
Bullet *bullet;
int i = 0;
for (; i < bullets.bulletCount; i++)
{
bullet = (bullets.bulletArray + i);
bullet -> position.x += bullet -> velocity.x;
bullet -> position.y += bullet -> velocity.y;
}
}
void ShootSoundEffect()
{
printf("ShootSoundEffect();\n");
@ -843,11 +915,27 @@ void DieSoundEffect()
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()
{
Vector2D shootDir;
Bullet *newBullet;
float offset = (al_get_bitmap_width(player.playerImage) + al_get_bitmap_width(enemyBulletImage) * 2.0 * screenSizeMultiplier);
float offset;
offset = (player.image.size.x + enemyBulletImage.size.x * 2.0);
if(player.lookDirection != 1)
offset = -offset;
@ -857,8 +945,10 @@ void PlayerShoot()
shootDir.y = 0;
player.shootCooldown = 1 / (float)player.shootPerSecond;
bullets.bulletCount++;
bullets.bulletArray = (Bullet *) realloc(bullets.bulletArray, sizeof(Bullet) * bullets.bulletCount);
newBullet = (bullets.bulletArray + bullets.bulletCount - 1);
newBullet -> position = player.position;
newBullet -> position.x += offset;
@ -875,12 +965,15 @@ void EnemyShoot()
Enemy *enemy;
Bullet *bullet;
int i;
float offset = (al_get_bitmap_width(player.playerImage) + al_get_bitmap_width(enemyBulletImage) * 2.0 * screenSizeMultiplier);
float offset;
offset = (player.image.size.x + enemyBulletImage.size.x * 2.0);
for (i = 0; i < enemies.enemyCount; i++)
{
srand(time(0) + enemyRespawnCounter++);
enemy = (enemies.enemyArray + i);
if(enemy -> fireCooldown > 0.0)
enemy -> fireCooldown -= deltaTime;
else
@ -903,21 +996,21 @@ void EnemyShoot()
ShootSoundEffect();
}
}
}
void BulletCollisions()
{
Bullet *bullet;
Enemy *enemy;
int bulletCounter = 0;
int enemyCounter = 0;
int i = 0;
int bulletCounter;
int enemyCounter;
printf("Enemy-Bullet\n");
for (enemyCounter = 0; enemyCounter < enemies.enemyCount; enemyCounter++)
{
printf("Enemy-Bullet|enemyCounter\n");
enemy = (enemies.enemyArray + enemyCounter);
for (bulletCounter = 0; bulletCounter < bullets.bulletCount; bulletCounter++)
{
bullet = (bullets.bulletArray + bulletCounter);
@ -925,8 +1018,8 @@ void BulletCollisions()
if(bullet -> isEnemyBullet == 1 && CheckCollision(
&bullet -> position,
&player.position,
enemyBulletImage,
player.playerImage
&enemyBulletImage,
&player.image
))
{
RemoveBulletAtIndex(bulletCounter);
@ -940,8 +1033,8 @@ void BulletCollisions()
if(bullet -> isEnemyBullet == 0 && CheckCollision(
&bullet -> position,
&enemy -> position,
enemyBulletImage,
enemyImage
&enemyBulletImage,
&enemyImage
))
{
printf("Enemy-Bullet|EnemyRemove\n");
@ -959,8 +1052,8 @@ void BulletCollisions()
if(CheckCollision(
&enemy -> position,
&player.position,
enemyImage,
player.playerImage
&enemyImage,
&player.image
))
{
RemoveEnemyAtIndex(enemyCounter);
@ -970,19 +1063,30 @@ void BulletCollisions()
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()
{
CheckHighScore();
al_destroy_bitmap(enemyImage);
al_destroy_bitmap(enemyBulletImage);
al_destroy_bitmap(gameOverImage);
al_destroy_bitmap(numberTable);
al_destroy_bitmap(enemyImage.bitmap);
al_destroy_bitmap(enemyBulletImage.bitmap);
al_destroy_bitmap(gameOverImage.bitmap);
al_destroy_bitmap(numberTable.bitmap);
al_destroy_bitmap(player.image.bitmap);
al_destroy_sample(shootSound);
al_destroy_sample(enemyDieSound);
al_destroy_bitmap(player.playerImage);
free(enemies.enemyArray);
}

Binary file not shown.