Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
df79395421 | |||
|
5a82e45de7 | ||
|
5a37718718 | ||
|
acfcade62e | ||
|
a87b248a1c | ||
|
8e1dedc421 | ||
|
f9e795e5e4 | ||
|
5596b53c02 | ||
|
f1620e54a0 | ||
|
049612b1c8 | ||
|
0738d7f9a7 | ||
|
477b4ddb40 | ||
|
23a49fa855 | ||
|
0938c7b364 | ||
|
7886dbd994 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -4,13 +4,13 @@
|
|||||||
*.a
|
*.a
|
||||||
*.dll
|
*.dll
|
||||||
*.syn
|
*.syn
|
||||||
!allegro_acodec-5.0.10-md.dll
|
|
||||||
!allegro_audio-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_image-5.0.10-md.dll
|
||||||
!allegro_primitives-5.0.10-md.dll
|
!allegro_primitives-5.0.10-md.dll
|
||||||
!allegro-5.0.10-md.dll
|
!allegro-5.0.10-md.dll
|
||||||
!liballegro_audio-5.0.10-md.a
|
!liballegro_audio-5.0.10-md.a
|
||||||
!liballegro_acodec-5.0.10-md.a
|
!liballegro_acodec-5.0.10-md.a
|
||||||
!liballegro_image-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_primitives-5.0.10-md.a
|
||||||
|
!liballegro-5.0.10-md.a
|
32
README.md
32
README.md
@ -1,26 +1,24 @@
|
|||||||
# SynGame
|
# SynGame
|
||||||
Simple Shoot 'Em Up game.
|
Simple Shoot 'Em Up game for Windows.
|
||||||
|
|
||||||
Keys:
|
Keys:\
|
||||||
Move Up - Up Arrow
|
Move Up - Up Arrow\
|
||||||
Move Right - Right Arrow
|
Move Right - Right Arrow\
|
||||||
Move Down - Down Arrow
|
Move Down - Down Arrow\
|
||||||
Move Left - Left Arrow
|
Move Left - Left Arrow\
|
||||||
Shoot - Space
|
Shoot - Space\
|
||||||
Restart - R
|
Restart - R\
|
||||||
Exit - Escape(ESC)
|
Exit - Escape(ESC)
|
||||||
|
|
||||||
Settings.syn can be opened with a text editor.
|
Settings.syn can be opened with a text editor.\
|
||||||
Format:
|
Settings Format:\
|
||||||
First line: Screen Mode, 1 is Fullscreen, 0 is Windowed (Default Value = 1)
|
First line: Screen Mode, 1 is Fullscreen, 0 is Windowed (Default Value = 1)\
|
||||||
Second line: Screen Width, Windowed Mode Only (Default Value = 1600)
|
Second line: Screen Width, Windowed Mode Only (Default Value = 1600)\
|
||||||
Third line: Screen Height, Windowed Mode Only (Default Value = 900)
|
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)
|
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
|
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"
|
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.
458
SynGame.c
458
SynGame.c
@ -1,8 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Author: Asrın "Syntriax" Doğan
|
Author: Syntriax <Syntriax@gmail.com>
|
||||||
Date: 10.09.2019
|
Start: 05.09.2019
|
||||||
Mail: asrindogan99@gmail.com
|
|
||||||
|
|
||||||
Simple Shoot 'Em Up game.
|
Simple Shoot 'Em Up game.
|
||||||
|
|
||||||
Keys:
|
Keys:
|
||||||
@ -23,6 +21,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
|
||||||
@ -41,6 +40,13 @@ typedef struct
|
|||||||
float y;
|
float y;
|
||||||
} Vector2D;
|
} Vector2D;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
Vector2D originalSize;
|
||||||
|
Vector2D size;
|
||||||
|
ALLEGRO_BITMAP *bitmap;
|
||||||
|
} Image;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Vector2D position;
|
Vector2D position;
|
||||||
@ -75,25 +81,33 @@ struct
|
|||||||
Vector2D position;
|
Vector2D position;
|
||||||
char health;
|
char health;
|
||||||
float moveSpeed;
|
float moveSpeed;
|
||||||
byte lookDirection;
|
char lookDirection;
|
||||||
int shootPerSecond;
|
int shootPerSecond;
|
||||||
float shootCooldown;
|
float shootCooldown;
|
||||||
unsigned int killedEnemyCount;
|
unsigned int killedEnemyCount;
|
||||||
unsigned int score;
|
unsigned int score;
|
||||||
|
|
||||||
ALLEGRO_BITMAP *playerImage;
|
Image image;
|
||||||
} player;
|
} 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 SpawnEnemies();
|
||||||
void CheckBullets();
|
void CheckBullets();
|
||||||
void RemoveBulletAtIndex(int index);
|
void RemoveBulletAtIndex(int index);
|
||||||
void RemoveEnemyAtIndex(int index);
|
void RemoveEnemyAtIndex(int index);
|
||||||
void CheckEnemies();
|
void CheckEnemies();
|
||||||
void MoveEnemies();
|
void MoveEnemies();
|
||||||
void InitializeEnemies();
|
void LimitEnemies();
|
||||||
void DestroyGame();
|
void DrawObject(Vector2D position, Image *image, int flag);
|
||||||
void DrawObject(Vector2D position, ALLEGRO_BITMAP *image, int flag);
|
void DrawNumber(Vector2D position, int number);
|
||||||
void DrawSizedObject(Vector2D position, ALLEGRO_BITMAP *image, int flag, float objectscreenSizeMultiplier);
|
void DrawSizedObject(Vector2D position, Image *image, int flag, float objectscreenSizeMultiplier);
|
||||||
void DrawScreen();
|
void DrawScreen();
|
||||||
void DrawScore();
|
void DrawScore();
|
||||||
void DrawHighScore();
|
void DrawHighScore();
|
||||||
@ -101,70 +115,92 @@ void DrawTimer();
|
|||||||
void CheckHighScore();
|
void CheckHighScore();
|
||||||
void GetHighScore();
|
void GetHighScore();
|
||||||
void GetSettings();
|
void GetSettings();
|
||||||
void DrawNumber(Vector2D position, int number);
|
void CalculateScore();
|
||||||
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 Update();
|
void DestroyGame();
|
||||||
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 CheckCollision(Vector2D *firstPos, Vector2D *secondPos, ALLEGRO_BITMAP *firstMap, ALLEGRO_BITMAP *secondMap);
|
|
||||||
char InitializeGameWindow();
|
|
||||||
char InitializeGame();
|
|
||||||
char DealDamage(char *health);
|
|
||||||
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;
|
||||||
ALLEGRO_BITMAP *gameOverImage = NULL;
|
|
||||||
|
Image gameOverImage;
|
||||||
|
|
||||||
ALLEGRO_SAMPLE *BGM = NULL;
|
ALLEGRO_SAMPLE *BGM = NULL;
|
||||||
|
|
||||||
ALLEGRO_SAMPLE *shootSound = NULL;
|
ALLEGRO_SAMPLE *shootSound = NULL;
|
||||||
ALLEGRO_SAMPLE_ID shootSoundID;
|
ALLEGRO_SAMPLE_ID shootSoundID;
|
||||||
|
|
||||||
ALLEGRO_BITMAP *enemyImage = NULL;
|
Image enemyImage;
|
||||||
ALLEGRO_BITMAP *enemyBulletImage = NULL;
|
Image enemyBulletImage;
|
||||||
ALLEGRO_SAMPLE *enemyDieSound = NULL;
|
ALLEGRO_SAMPLE *enemyDieSound = NULL;
|
||||||
ALLEGRO_SAMPLE_ID enemyDieSoundID;
|
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 *displayName = "Syn Game";
|
||||||
const char *savePath = "Save.syn";
|
const char *savePath = "Save.syn";
|
||||||
const char *settingsPath = "Settings.syn";
|
const char *settingsPath = "Settings.syn";
|
||||||
const char *settingsFormat = "%d\n%d\n%d";
|
const char *settingsFormat = "%d\n%d\n%d";
|
||||||
|
|
||||||
int isFullscreen = 1;
|
int isFullscreen = 1;
|
||||||
int settingsWidth = 1600;
|
int settingsWidth = 1600;
|
||||||
int settingsHeight = 900;
|
int settingsHeight = 900;
|
||||||
|
|
||||||
const Vector2D referenceScreenDimensions = {160, 90};
|
const Vector2D referenceScreenDimensions = {160, 90};
|
||||||
Vector2D screenDimensions = {0, 0};
|
Vector2D screenDimensions = {0, 0};
|
||||||
Vector2D scorePosition = {0, 0};
|
Vector2D scorePosition = {0, 0};
|
||||||
Vector2D highScorePosition = {0, 0};
|
Vector2D highScorePosition = {0, 0};
|
||||||
Vector2D timerPosition = {0, 0};
|
Vector2D timerPosition = {0, 0};
|
||||||
|
|
||||||
float screenSizeMultiplier;
|
float screenSizeMultiplier;
|
||||||
float timeSinceStart;
|
float timeSinceStart;
|
||||||
|
|
||||||
const float FPS = 60;
|
const float FPS = 60;
|
||||||
|
|
||||||
double deltaTime;
|
double deltaTime;
|
||||||
|
|
||||||
unsigned int enemyRespawnCounter = 0;
|
unsigned int enemyRespawnCounter = 0;
|
||||||
unsigned int highScore = 0;
|
unsigned int highScore = 0;
|
||||||
|
|
||||||
int enemyLimiter = 12;
|
int enemyLimiter = 12;
|
||||||
|
|
||||||
Vector2D input;
|
Vector2D input;
|
||||||
byte isRestart = 0;
|
|
||||||
byte isRunning = 1;
|
char isRestart = 0;
|
||||||
byte isGameOver = 0;
|
char isRunning = 1;
|
||||||
|
char isGameOver = 0;
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
@ -189,28 +225,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 +255,6 @@ void Update()
|
|||||||
printf("DrawScreen();\n");
|
printf("DrawScreen();\n");
|
||||||
DrawScreen();
|
DrawScreen();
|
||||||
|
|
||||||
|
|
||||||
al_flip_display();
|
al_flip_display();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +290,8 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DestroyGame();
|
DestroyGame();
|
||||||
} while (isRestart);
|
}
|
||||||
|
while (isRestart);
|
||||||
|
|
||||||
DestroyGameWindow();
|
DestroyGameWindow();
|
||||||
|
|
||||||
@ -275,10 +299,26 @@ int main(int argc, char **argv)
|
|||||||
return 0;
|
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 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;
|
||||||
@ -302,33 +342,32 @@ float VectorDistanceBetween(Vector2D vectorFirst, Vector2D vectorSecond)
|
|||||||
return VectorMagnitude(difference);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Gets the shortest dimensions of both images, sums these dimension and divides by 2 to get minimum accepted distance.
|
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.
|
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;
|
char result;
|
||||||
Vector2D secondImageSize;
|
|
||||||
byte result;
|
|
||||||
float minDistance;
|
float minDistance;
|
||||||
float distance;
|
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 = firstMap -> size.x > firstMap -> size.y ?
|
||||||
minDistance += secondImageSize.x > secondImageSize.y ? secondImageSize.y : secondImageSize.x;
|
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);
|
distance = VectorDistanceBetween(*firstPos, *secondPos);
|
||||||
|
|
||||||
@ -338,8 +377,10 @@ byte CheckCollision(Vector2D *firstPos, Vector2D *secondPos, ALLEGRO_BITMAP *fir
|
|||||||
|
|
||||||
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() ||
|
||||||
@ -366,9 +407,10 @@ char InitializeGameWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
screenDimensions = (Vector2D){x, y};
|
screenDimensions = (Vector2D){x, y};
|
||||||
scorePosition = (Vector2D){x * (float)0.05, y * (float)0.05};
|
|
||||||
highScorePosition = (Vector2D){x * (float)0.95, y * (float)0.05};
|
scorePosition = (Vector2D){x * (float)0.05, y * (float)0.05}; /* Upper Left Position */
|
||||||
timerPosition = (Vector2D){x * (float)0.5 , y * (float)0.95};
|
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;
|
screenSizeMultiplier = screenDimensions.x / referenceScreenDimensions.x;
|
||||||
display = al_create_display(screenDimensions.x, screenDimensions.y);
|
display = al_create_display(screenDimensions.x, screenDimensions.y);
|
||||||
@ -399,21 +441,30 @@ 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(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("Sounds/Shoot.wav");
|
shootSound = al_load_sample(shootSoundPath);
|
||||||
enemyDieSound = al_load_sample("Sounds/Die.wav");
|
enemyDieSound = al_load_sample(dieSoundPath);
|
||||||
|
|
||||||
InitializeEnemies();
|
if(shootSound == NULL || enemyDieSound == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if(!InitializeEnemies())
|
||||||
|
return 0;
|
||||||
GetHighScore();
|
GetHighScore();
|
||||||
|
|
||||||
/* Player Initialization */
|
/* Player Initialization */
|
||||||
@ -422,9 +473,9 @@ char InitializeGame()
|
|||||||
player.moveSpeed = playerSpeed * screenSizeMultiplier;
|
player.moveSpeed = playerSpeed * screenSizeMultiplier;
|
||||||
player.shootPerSecond = 10;
|
player.shootPerSecond = 10;
|
||||||
player.health = initialPlayerHealth;
|
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 ||
|
shootSound == NULL ||
|
||||||
enemyDieSound == NULL)
|
enemyDieSound == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
@ -442,16 +493,30 @@ char InitializeGame()
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitializeEnemies()
|
char InitializeEnemies()
|
||||||
{
|
{
|
||||||
enemies.enemyLimit = initialEnemyLimit;
|
enemies.enemyLimit = initialEnemyLimit;
|
||||||
enemies.enemyCount = 0;
|
enemies.enemyCount = 0;
|
||||||
enemies.enemyArray = (Enemy *) malloc(sizeof(Enemy) * enemies.enemyCount);
|
enemies.enemyArray = (Enemy *) malloc(sizeof(Enemy) * enemies.enemyCount);
|
||||||
enemyImage = al_load_bitmap("Images/Enemy.png");
|
|
||||||
numberTable = al_load_bitmap("Images/Numbers.png");
|
enemyImage = InitImage(enemyImagePath);
|
||||||
enemyBulletImage = al_load_bitmap("Images/Bullet.png");
|
numberTable = InitImage(numbersImagePath);
|
||||||
gameOverImage = al_load_bitmap("Images/GameOver.png");
|
enemyBulletImage = InitImage(bulletImagePath);
|
||||||
|
gameOverImage = InitImage(gameOverImagePath);
|
||||||
|
|
||||||
|
if( enemyImage.bitmap == NULL ||
|
||||||
|
numberTable.bitmap == NULL ||
|
||||||
|
enemyBulletImage.bitmap == NULL ||
|
||||||
|
gameOverImage.bitmap == NULL )
|
||||||
|
return 0;
|
||||||
|
|
||||||
SpawnEnemies();
|
SpawnEnemies();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char DealDamage(char *health)
|
||||||
|
{
|
||||||
|
return --*health <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpawnEnemies()
|
void SpawnEnemies()
|
||||||
@ -469,7 +534,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 +553,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++;
|
||||||
}
|
}
|
||||||
@ -496,11 +561,10 @@ void SpawnEnemies()
|
|||||||
|
|
||||||
void CheckBullets()
|
void CheckBullets()
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i;
|
||||||
int j = 0;
|
int j;
|
||||||
|
|
||||||
for (; i < bullets.bulletCount; i++)
|
for (i = 0; i < bullets.bulletCount; i++)
|
||||||
{
|
|
||||||
if(isVectorExceedingLimits((bullets.bulletArray + i) -> position, screenDimensions))
|
if(isVectorExceedingLimits((bullets.bulletArray + i) -> position, screenDimensions))
|
||||||
{
|
{
|
||||||
for (j = i; j < bullets.bulletCount - 1; j++)
|
for (j = i; j < bullets.bulletCount - 1; j++)
|
||||||
@ -509,7 +573,6 @@ void CheckBullets()
|
|||||||
bullets.bulletCount--;
|
bullets.bulletCount--;
|
||||||
bullets.bulletArray = (Bullet *) realloc(bullets.bulletArray, sizeof(Bullet) * bullets.bulletCount);
|
bullets.bulletArray = (Bullet *) realloc(bullets.bulletArray, sizeof(Bullet) * bullets.bulletCount);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveBulletAtIndex(int index)
|
void RemoveBulletAtIndex(int index)
|
||||||
@ -536,9 +599,9 @@ void RemoveEnemyAtIndex(int index)
|
|||||||
|
|
||||||
void CheckEnemies()
|
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))
|
if(isVectorExceedingLimits((enemies.enemyArray + i) -> position, screenDimensions))
|
||||||
RemoveEnemyAtIndex(i);
|
RemoveEnemyAtIndex(i);
|
||||||
|
|
||||||
@ -547,11 +610,11 @@ void CheckEnemies()
|
|||||||
|
|
||||||
void MoveEnemies()
|
void MoveEnemies()
|
||||||
{
|
{
|
||||||
int i = 0;
|
|
||||||
Vector2D velocity;
|
Vector2D velocity;
|
||||||
float speed;
|
float speed;
|
||||||
|
int i;
|
||||||
|
|
||||||
for (; i < enemies.enemyCount; i++)
|
for (i = 0; i < enemies.enemyCount; i++)
|
||||||
{
|
{
|
||||||
speed = (enemies.enemyArray + i) -> moveSpeed;
|
speed = (enemies.enemyArray + i) -> moveSpeed;
|
||||||
velocity = (enemies.enemyArray + i) -> velocity;
|
velocity = (enemies.enemyArray + i) -> velocity;
|
||||||
@ -559,38 +622,60 @@ void MoveEnemies()
|
|||||||
(enemies.enemyArray + i) -> position.y += velocity.y * speed;
|
(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,
|
void LimitEnemies()
|
||||||
0, 0, InstantiateSize.x, InstantiateSize.y,
|
{
|
||||||
position.x - InstantiateSize.x / 2 * screenSizeMultiplier, position.y - InstantiateSize.y / 2 * screenSizeMultiplier,
|
if(enemies.enemyLimit != enemyLimiter)
|
||||||
InstantiateSize.x * screenSizeMultiplier, InstantiateSize.y * screenSizeMultiplier, flag);
|
{
|
||||||
|
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)
|
void DrawNumber(Vector2D position, int number)
|
||||||
{
|
{
|
||||||
Vector2D InstantiateSize;
|
Vector2D InstantiateSize;
|
||||||
InstantiateSize.x = (float)al_get_bitmap_width(numberTable);
|
Vector2D originalSize;
|
||||||
InstantiateSize.y = (float)al_get_bitmap_height(numberTable);
|
|
||||||
|
|
||||||
al_draw_scaled_bitmap(numberTable,
|
InstantiateSize = numberTable.size;
|
||||||
numberImageSize * number, 0, numberImageSize, InstantiateSize.y,
|
originalSize = numberTable.originalSize;
|
||||||
position.x - numberImageSize / 2 * screenSizeMultiplier, position.y - InstantiateSize.y / 2 * screenSizeMultiplier,
|
|
||||||
numberImageSize * screenSizeMultiplier, InstantiateSize.y * screenSizeMultiplier, 0);
|
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;
|
Vector2D InstantiateSize;
|
||||||
float sizeFactor = screenSizeMultiplier * objectscreenSizeMultiplier;
|
float sizeFactor;
|
||||||
InstantiateSize.x = (float)al_get_bitmap_width(image);
|
|
||||||
InstantiateSize.y = (float)al_get_bitmap_height(image);
|
|
||||||
|
|
||||||
al_draw_scaled_bitmap(image,
|
sizeFactor = screenSizeMultiplier * objectscreenSizeMultiplier;
|
||||||
|
InstantiateSize = image -> size;
|
||||||
|
|
||||||
|
al_draw_scaled_bitmap(image -> bitmap,
|
||||||
0, 0, InstantiateSize.x, InstantiateSize.y,
|
0, 0, InstantiateSize.x, InstantiateSize.y,
|
||||||
position.x - InstantiateSize.x / 2 * sizeFactor, position.y - InstantiateSize.y / 2 * sizeFactor,
|
position.x - InstantiateSize.x / 2 * sizeFactor, position.y - InstantiateSize.y / 2 * sizeFactor,
|
||||||
InstantiateSize.x * sizeFactor, InstantiateSize.y * sizeFactor, flag);
|
InstantiateSize.x * sizeFactor, InstantiateSize.y * sizeFactor, flag);
|
||||||
@ -598,22 +683,23 @@ void DrawSizedObject(Vector2D position, ALLEGRO_BITMAP *image, int flag, float o
|
|||||||
|
|
||||||
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++)
|
||||||
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 */
|
/* Bullet Draw */
|
||||||
for (i = 0; i < bullets.bulletCount; i++)
|
for (i = 0; i < bullets.bulletCount; i++)
|
||||||
DrawObject((bullets.bulletArray + i) -> position, enemyBulletImage, 0);
|
DrawObject((bullets.bulletArray + i) -> position, &enemyBulletImage, 0);
|
||||||
|
|
||||||
/* Player Draw */
|
/* Player Draw */
|
||||||
if(!isGameOver)
|
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
|
else
|
||||||
DrawObject(halfScreen, gameOverImage, 0);
|
DrawObject(halfScreen, &gameOverImage, 0);
|
||||||
|
|
||||||
DrawScore();
|
DrawScore();
|
||||||
DrawHighScore();
|
DrawHighScore();
|
||||||
@ -622,13 +708,14 @@ void DrawScreen()
|
|||||||
|
|
||||||
void DrawScore()
|
void DrawScore()
|
||||||
{
|
{
|
||||||
unsigned int processedScore = player.score;
|
unsigned int processedScore;
|
||||||
char digit;
|
char digit;
|
||||||
Vector2D spawnPosition;
|
Vector2D spawnPosition;
|
||||||
int i = scoreDigitLimit - 1;
|
int i;
|
||||||
|
|
||||||
/* while (processedScore >= 1 && i > 0) */
|
processedScore = player.score;
|
||||||
while (i >= 0)
|
|
||||||
|
for(i = scoreDigitLimit - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
spawnPosition = scorePosition;
|
spawnPosition = scorePosition;
|
||||||
/* numberImageSize + 1 is because 1 pixel space between digits */
|
/* numberImageSize + 1 is because 1 pixel space between digits */
|
||||||
@ -636,19 +723,19 @@ void DrawScore()
|
|||||||
digit = processedScore % 10;
|
digit = processedScore % 10;
|
||||||
processedScore = (int)(processedScore / 10);
|
processedScore = (int)(processedScore / 10);
|
||||||
DrawNumber(spawnPosition, digit);
|
DrawNumber(spawnPosition, digit);
|
||||||
i--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawHighScore()
|
void DrawHighScore()
|
||||||
{
|
{
|
||||||
unsigned int processedScore = highScore;
|
unsigned int processedScore;
|
||||||
char digit;
|
char digit;
|
||||||
Vector2D spawnPosition;
|
Vector2D spawnPosition;
|
||||||
int i = 0;
|
int i;
|
||||||
|
|
||||||
/* while (processedScore >= 1 && i > 0) */
|
processedScore = highScore;
|
||||||
while (i < scoreDigitLimit)
|
|
||||||
|
for(i = 0; i < scoreDigitLimit; i++)
|
||||||
{
|
{
|
||||||
spawnPosition = highScorePosition;
|
spawnPosition = highScorePosition;
|
||||||
/* numberImageSize + 1 is because 1 pixel space between digits */
|
/* numberImageSize + 1 is because 1 pixel space between digits */
|
||||||
@ -656,25 +743,26 @@ void DrawHighScore()
|
|||||||
digit = processedScore % 10;
|
digit = processedScore % 10;
|
||||||
processedScore = (int)(processedScore / 10);
|
processedScore = (int)(processedScore / 10);
|
||||||
DrawNumber(spawnPosition, digit);
|
DrawNumber(spawnPosition, digit);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
i = -timerDigitLimit / 2;
|
||||||
|
|
||||||
/* while (processedScore >= 1 && i > 0) */
|
|
||||||
while (i < 0)
|
while (i < 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
spawnPosition = timerPosition;
|
|
||||||
/* numberImageSize + 1 is because 1 pixel space between digits */
|
/* 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;
|
digit = seconds % 10;
|
||||||
seconds = (int)(seconds / 10);
|
seconds = (int)(seconds / 10);
|
||||||
@ -682,18 +770,15 @@ void DrawTimer()
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
spawnPosition = timerPosition;
|
|
||||||
/* numberImageSize + 1 is because 1 pixel space between digits */
|
/* 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);
|
DrawNumber(spawnPosition, colon);
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
while (i < (timerDigitLimit / 2) + 1)
|
while (i < (timerDigitLimit / 2) + 1)
|
||||||
{
|
{
|
||||||
|
|
||||||
spawnPosition = timerPosition;
|
|
||||||
/* numberImageSize + 1 is because 1 pixel space between digits */
|
/* 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)
|
if(i == 0)
|
||||||
{
|
{
|
||||||
@ -731,8 +816,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");
|
||||||
@ -746,8 +831,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");
|
||||||
@ -766,6 +851,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;
|
||||||
@ -787,7 +877,6 @@ void Inputs()
|
|||||||
player.lookDirection = input.x;
|
player.lookDirection = input.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
input = NormalizeVector(input);
|
input = NormalizeVector(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -812,23 +901,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 = 0;
|
|
||||||
for (; 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");
|
||||||
@ -843,11 +915,27 @@ 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;
|
||||||
Bullet *newBullet;
|
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)
|
if(player.lookDirection != 1)
|
||||||
offset = -offset;
|
offset = -offset;
|
||||||
@ -857,8 +945,10 @@ void PlayerShoot()
|
|||||||
shootDir.y = 0;
|
shootDir.y = 0;
|
||||||
|
|
||||||
player.shootCooldown = 1 / (float)player.shootPerSecond;
|
player.shootCooldown = 1 / (float)player.shootPerSecond;
|
||||||
|
|
||||||
bullets.bulletCount++;
|
bullets.bulletCount++;
|
||||||
bullets.bulletArray = (Bullet *) realloc(bullets.bulletArray, sizeof(Bullet) * bullets.bulletCount);
|
bullets.bulletArray = (Bullet *) realloc(bullets.bulletArray, sizeof(Bullet) * bullets.bulletCount);
|
||||||
|
|
||||||
newBullet = (bullets.bulletArray + bullets.bulletCount - 1);
|
newBullet = (bullets.bulletArray + bullets.bulletCount - 1);
|
||||||
newBullet -> position = player.position;
|
newBullet -> position = player.position;
|
||||||
newBullet -> position.x += offset;
|
newBullet -> position.x += offset;
|
||||||
@ -875,12 +965,15 @@ void EnemyShoot()
|
|||||||
Enemy *enemy;
|
Enemy *enemy;
|
||||||
Bullet *bullet;
|
Bullet *bullet;
|
||||||
int i;
|
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++)
|
for (i = 0; i < enemies.enemyCount; i++)
|
||||||
{
|
{
|
||||||
srand(time(0) + enemyRespawnCounter++);
|
srand(time(0) + enemyRespawnCounter++);
|
||||||
enemy = (enemies.enemyArray + i);
|
enemy = (enemies.enemyArray + i);
|
||||||
|
|
||||||
if(enemy -> fireCooldown > 0.0)
|
if(enemy -> fireCooldown > 0.0)
|
||||||
enemy -> fireCooldown -= deltaTime;
|
enemy -> fireCooldown -= deltaTime;
|
||||||
else
|
else
|
||||||
@ -903,21 +996,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);
|
||||||
@ -925,8 +1018,8 @@ void BulletCollisions()
|
|||||||
if(bullet -> isEnemyBullet == 1 && CheckCollision(
|
if(bullet -> isEnemyBullet == 1 && CheckCollision(
|
||||||
&bullet -> position,
|
&bullet -> position,
|
||||||
&player.position,
|
&player.position,
|
||||||
enemyBulletImage,
|
&enemyBulletImage,
|
||||||
player.playerImage
|
&player.image
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
RemoveBulletAtIndex(bulletCounter);
|
RemoveBulletAtIndex(bulletCounter);
|
||||||
@ -940,8 +1033,8 @@ void BulletCollisions()
|
|||||||
if(bullet -> isEnemyBullet == 0 && CheckCollision(
|
if(bullet -> isEnemyBullet == 0 && CheckCollision(
|
||||||
&bullet -> position,
|
&bullet -> position,
|
||||||
&enemy -> position,
|
&enemy -> position,
|
||||||
enemyBulletImage,
|
&enemyBulletImage,
|
||||||
enemyImage
|
&enemyImage
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
printf("Enemy-Bullet|EnemyRemove\n");
|
printf("Enemy-Bullet|EnemyRemove\n");
|
||||||
@ -959,8 +1052,8 @@ void BulletCollisions()
|
|||||||
if(CheckCollision(
|
if(CheckCollision(
|
||||||
&enemy -> position,
|
&enemy -> position,
|
||||||
&player.position,
|
&player.position,
|
||||||
enemyImage,
|
&enemyImage,
|
||||||
player.playerImage
|
&player.image
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
RemoveEnemyAtIndex(enemyCounter);
|
RemoveEnemyAtIndex(enemyCounter);
|
||||||
@ -970,19 +1063,30 @@ 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()
|
||||||
{
|
{
|
||||||
CheckHighScore();
|
CheckHighScore();
|
||||||
al_destroy_bitmap(enemyImage);
|
al_destroy_bitmap(enemyImage.bitmap);
|
||||||
al_destroy_bitmap(enemyBulletImage);
|
al_destroy_bitmap(enemyBulletImage.bitmap);
|
||||||
al_destroy_bitmap(gameOverImage);
|
al_destroy_bitmap(gameOverImage.bitmap);
|
||||||
al_destroy_bitmap(numberTable);
|
al_destroy_bitmap(numberTable.bitmap);
|
||||||
|
al_destroy_bitmap(player.image.bitmap);
|
||||||
al_destroy_sample(shootSound);
|
al_destroy_sample(shootSound);
|
||||||
al_destroy_sample(enemyDieSound);
|
al_destroy_sample(enemyDieSound);
|
||||||
al_destroy_bitmap(player.playerImage);
|
|
||||||
free(enemies.enemyArray);
|
free(enemies.enemyArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
allegro/lib/liballegro-5.0.10-md.a
Normal file
BIN
allegro/lib/liballegro-5.0.10-md.a
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user