Commit 529b2296 authored by Lila NICKLER's avatar Lila NICKLER

Declaration + affichage des items

parent cab222d0
...@@ -26,11 +26,13 @@ ...@@ -26,11 +26,13 @@
#define SECOND_WAVE 10 #define SECOND_WAVE 10
#define THIRD_WAVE 20 #define THIRD_WAVE 20
#define FOURTH_WAVE 20 #define FOURTH_WAVE 20
#define ItemNumber 2
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Types and Structures Definition // Types and Structures Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
typedef enum { FIRST = 0, SECOND, THIRD, FOURTH } EnemyWave; typedef enum { FIRST = 0, SECOND, THIRD, FOURTH } EnemyWave;
typedef enum {Life=0,Speed,SpeedShot,SizeShoot} ItemEffect;
typedef struct Player{ typedef struct Player{
Rectangle rec; Rectangle rec;
...@@ -55,6 +57,15 @@ typedef struct Shoot{ ...@@ -55,6 +57,15 @@ typedef struct Shoot{
Color color; Color color;
} Shoot; } Shoot;
typedef struct Item{
Rectangle rec;
Vector2 speed;
ItemEffect effect;
Color color;
bool active;
} Item;
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
...@@ -72,7 +83,7 @@ static Player player = { 0 }; ...@@ -72,7 +83,7 @@ static Player player = { 0 };
static Enemy enemy[NUM_MAX_ENEMIES] = { 0 }; static Enemy enemy[NUM_MAX_ENEMIES] = { 0 };
static Shoot shoot[NUM_SHOOTS] = { 0 }; static Shoot shoot[NUM_SHOOTS] = { 0 };
static EnemyWave wave = { 0 }; static EnemyWave wave = { 0 };
static Item item[ItemNumber] = {0};
static int shootRate = 0; static int shootRate = 0;
static float alpha = 0.0f; static float alpha = 0.0f;
...@@ -153,7 +164,7 @@ void InitGame(void) ...@@ -153,7 +164,7 @@ void InitGame(void)
player.speed.x = 5; player.speed.x = 5;
player.speed.y = 5; player.speed.y = 5;
player.color = BLACK; player.color = BLACK;
player.life = 3; player.life =10;
// Initialize enemies // Initialize enemies
for (int i = 0; i < NUM_MAX_ENEMIES; i++) for (int i = 0; i < NUM_MAX_ENEMIES; i++)
...@@ -183,6 +194,22 @@ void InitGame(void) ...@@ -183,6 +194,22 @@ void InitGame(void)
shoot[i].active = false; shoot[i].active = false;
shoot[i].color = MAROON; shoot[i].color = MAROON;
} }
// Initialize Item
for (int i =0; i<ItemNumber;i++)
{
item[i].rec.x = 5;
item[i].rec.y = 5;
item[i].rec.width = 20;
item[i].rec.height= 20;
item[i].speed.x = 5;
item[i].speed.y = 5;
item[i].effect = Life;
item[i].color = GOLD;
item[i].active = true;
}
} }
// Update game (one frame) // Update game (one frame)
...@@ -281,7 +308,7 @@ void UpdateGame(void) ...@@ -281,7 +308,7 @@ void UpdateGame(void)
enemy[0].speed.x = 1; enemy[0].speed.x = 1;
enemy[0].speed.y = 1; enemy[0].speed.y = 1;
enemy[0].active = true; enemy[0].active = true;
enemy[0].color = MAROON; enemy[0].color = DARKPURPLE;
enemy[0].boss = true; enemy[0].boss = true;
enemy[0].life = 100; enemy[0].life = 100;
...@@ -338,7 +365,7 @@ void UpdateGame(void) ...@@ -338,7 +365,7 @@ void UpdateGame(void)
{ {
if (CheckCollisionRecs(player.rec, enemy[i].rec)) if (CheckCollisionRecs(player.rec, enemy[i].rec))
{ {
if (player.life == 1) if (player.life == 1 || enemy[i].boss == true)
{ {
gameOver = true; gameOver = true;
} else } else
...@@ -433,6 +460,21 @@ void UpdateGame(void) ...@@ -433,6 +460,21 @@ void UpdateGame(void)
} }
} }
} }
//item behaviour
for (int i = 0; i < ItemNumber; i++)
{
if (item[i].active)
{
item[i].rec.x -= item[i].speed.x;
if (item[i].rec.x < 0)
{
item[i].rec.x = GetRandomValue(screenWidth, screenWidth + 1000);
item[i].rec.y = GetRandomValue(0, screenHeight - item[i].rec.height);
}
}
}
} }
} }
else else
...@@ -462,7 +504,7 @@ void DrawGame(void) ...@@ -462,7 +504,7 @@ void DrawGame(void)
else if (wave == FOURTH) else if (wave == FOURTH)
{ {
DrawText("FOURTH WAVE:", screenWidth/2 - MeasureText("FOURTH WAVE", 40)/2, screenHeight/2 - 40, 40, Fade(BLACK, alpha)); DrawText("FOURTH WAVE:", screenWidth/2 - MeasureText("FOURTH WAVE", 40)/2, screenHeight/2 - 40, 40, Fade(BLACK, alpha));
DrawText("BOSS IN COMMING", screenWidth/2 - MeasureText("BOSS IN COMMING", 40)/2, 2*screenHeight/3 - 40, 40, Fade(MAROON, alpha)); DrawText("BOSS IN COMMING", screenWidth/2 - MeasureText("BOSS IN COMMING", 40)/2, 2*screenHeight/3 - 40, 40, Fade(DARKPURPLE, alpha));
} }
...@@ -475,7 +517,12 @@ void DrawGame(void) ...@@ -475,7 +517,12 @@ void DrawGame(void)
{ {
if (shoot[i].active) DrawRectangleRec(shoot[i].rec, shoot[i].color); if (shoot[i].active) DrawRectangleRec(shoot[i].rec, shoot[i].color);
} }
for (int i = 0; i < ItemNumber; i++)
{
if (item[i].active) DrawRectangleRec(item[i].rec, item[i].color);
}
// Display of score and player life
DrawText("Score:",20,10,30, GRAY); DrawText("Score:",20,10,30, GRAY);
DrawText(TextFormat("%04i", score), 120, 10, 30, GRAY); DrawText(TextFormat("%04i", score), 120, 10, 30, GRAY);
DrawText("Life:",20,40,30, GRAY); DrawText("Life:",20,40,30, GRAY);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment