Collision bug and health change

This commit is contained in:
Asrın Doğan 2019-09-10 11:52:00 +03:00
parent 245f39a672
commit 54dbf0346d
1 changed files with 45 additions and 56 deletions

View File

@ -11,8 +11,9 @@
#include "allegro-5.0.10-mingw-4.7.0\include\allegro5\allegro_image.h" #include "allegro-5.0.10-mingw-4.7.0\include\allegro5\allegro_image.h"
#include "allegro-5.0.10-mingw-4.7.0\include\allegro5\allegro_primitives.h" #include "allegro-5.0.10-mingw-4.7.0\include\allegro5\allegro_primitives.h"
#define playerSpeed 7.5 #define playerSpeed 7.5
#define initialPlayerHealth 4
#define bulletSpeed 25 #define bulletSpeed 25
#define numberSize 5 #define numberImageSize 5
#define scoreDigitLimit 10 #define scoreDigitLimit 10
#define enemyLimiter 8 #define enemyLimiter 8
#define initialEnemyLimit 3 #define initialEnemyLimit 3
@ -95,7 +96,7 @@ 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, int damage); char DealDamage(char *health);
Vector2D NormalizeVector(Vector2D vector); Vector2D NormalizeVector(Vector2D vector);
ALLEGRO_KEYBOARD_STATE keyboardState; ALLEGRO_KEYBOARD_STATE keyboardState;
@ -361,7 +362,7 @@ char InitializeGame()
player.position.y = screenDimensions.y / 2; player.position.y = screenDimensions.y / 2;
player.moveSpeed = playerSpeed; player.moveSpeed = playerSpeed;
player.shootPerSecond = 10; player.shootPerSecond = 10;
player.health = 100; player.health = initialPlayerHealth;
player.playerImage = al_load_bitmap("Images/Player.png"); player.playerImage = al_load_bitmap("Images/Player.png");
bullets.bulletCount = 0; bullets.bulletCount = 0;
bullets.bulletArray = (Bullet *) malloc(sizeof(Bullet) * bullets.bulletCount); bullets.bulletArray = (Bullet *) malloc(sizeof(Bullet) * bullets.bulletCount);
@ -565,8 +566,8 @@ void DrawScore()
while (i > 0) while (i > 0)
{ {
spawnPosition = scorePosition; spawnPosition = scorePosition;
/* numberSize + 1 is because 1 pixel space between digits */ /* numberImageSize + 1 is because 1 pixel space between digits */
spawnPosition.x += sizeMultiplier * (numberSize + 1) * i; spawnPosition.x += sizeMultiplier * (numberImageSize + 1) * i;
digit = processedScore % 10; digit = processedScore % 10;
processedScore = (int)(processedScore / 10); processedScore = (int)(processedScore / 10);
DrawNumber(spawnPosition, digit); DrawNumber(spawnPosition, digit);
@ -605,12 +606,9 @@ void PlayerMovement()
player.position.y += input.y * player.moveSpeed; player.position.y += input.y * player.moveSpeed;
} }
char DealDamage(char *health, int damage) char DealDamage(char *health)
{ {
int healthInt = *health; return --*health <= 0;
*health -= damage;
return healthInt <= 0;
} }
void BulletMovement() void BulletMovement()
@ -708,7 +706,11 @@ void BulletCollisions()
int bulletCounter = 0; int bulletCounter = 0;
int enemyCounter = 0; int enemyCounter = 0;
int i = 0; int i = 0;
byte isCheckPlayerEnemyInteraction = 1; 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++) for (bulletCounter = 0; bulletCounter < bullets.bulletCount; bulletCounter++)
{ {
bullet = (bullets.bulletArray + bulletCounter); bullet = (bullets.bulletArray + bulletCounter);
@ -723,21 +725,11 @@ void BulletCollisions()
RemoveBulletAtIndex(bulletCounter); RemoveBulletAtIndex(bulletCounter);
bulletCounter--; bulletCounter--;
if(DealDamage(&player.health, 25)) if(DealDamage(&player.health))
isGameOver = 1; isGameOver = 1;
break; continue;
} }
printf("Enemy-Bullet\n");
for (enemyCounter = 0; enemyCounter < enemies.enemyCount; enemyCounter++)
{
enemy = (enemies.enemyArray + enemyCounter);
printf("Enemy-Bullet|enemyCounter\n");
printf("Enemy Count = %d\n", enemyCounter);
printf("Enemy Counter = %d\n", enemies.enemyCount);
printf("Bullet Count = %d\n", bulletCounter);
printf("Bullet Counter = %d\n", bullets.bulletCount);
if(bullet -> isEnemyBullet == 0 && CheckCollision( if(bullet -> isEnemyBullet == 0 && CheckCollision(
&bullet -> position, &bullet -> position,
&enemy -> position, &enemy -> position,
@ -753,12 +745,11 @@ void BulletCollisions()
RemoveBulletAtIndex(bulletCounter); RemoveBulletAtIndex(bulletCounter);
bulletCounter--; bulletCounter--;
player.killedEnemyCount++; player.killedEnemyCount++;
break; }
} }
printf("Enemy-Player\n"); printf("Enemy-Player\n");
if( isCheckPlayerEnemyInteraction == 1 && if(CheckCollision(
CheckCollision(
&enemy -> position, &enemy -> position,
&player.position, &player.position,
enemyImage, enemyImage,
@ -768,13 +759,11 @@ void BulletCollisions()
RemoveEnemyAtIndex(enemyCounter); RemoveEnemyAtIndex(enemyCounter);
enemyCounter--; enemyCounter--;
if(DealDamage(&player.health, 25)) if(DealDamage(&player.health))
isGameOver = 1; isGameOver = 1;
}
}
isCheckPlayerEnemyInteraction = 0;
}
}
}
} }
void DestroyGame() void DestroyGame()