Commit faf99d87 authored by Lila NICKLER's avatar Lila NICKLER

3 types d'Item, +1vie, +speed, +taille tire

parent f3634285
......@@ -26,13 +26,13 @@
#define SECOND_WAVE 10
#define THIRD_WAVE 20
#define FOURTH_WAVE 20
#define ItemNumber 2
#define ItemNumber 3
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
typedef enum { FIRST = 0, SECOND, THIRD, FOURTH } EnemyWave;
typedef enum {Life=0,Speed,SpeedShot,SizeShoot} ItemEffect;
typedef enum {Life=0,Speed,SizeShoot} ItemEffect;
typedef struct Player{
Rectangle rec;
......@@ -55,6 +55,7 @@ typedef struct Shoot{
Vector2 speed;
bool active;
Color color;
bool bonus;
} Shoot;
typedef struct Item{
......@@ -193,6 +194,7 @@ void InitGame(void)
shoot[i].speed.y = 0;
shoot[i].active = false;
shoot[i].color = MAROON;
shoot[i].bonus = false;
}
// Initialize Item
......@@ -204,9 +206,23 @@ void InitGame(void)
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;
item[i].effect = i;
switch (item[i].effect)
{
case 0:
item[i].color=RED;
break;
case 1:
item[i].color = GOLD;
break;
case 2:
item[i].color = PINK;
break;
default:
item[i].color = GRAY;
break;
}
item[i].active = false;
}
......@@ -225,11 +241,16 @@ void UpdateGame(void)
{
case FIRST:
{
item[0].active=true;
if (!smooth)
{
alpha += 0.02f;
if (alpha >= 1.0f) smooth = true;
for (int i = 0; i < ItemNumber; i++)
{
item[i].effect= GetRandomValue(0,2);
}
}
if (smooth) alpha -= 0.02f;
......@@ -243,6 +264,10 @@ void UpdateGame(void)
if (!enemy[i].active) enemy[i].active = true;
}
for (int i = 0; i < ItemNumber; i++)
{
item[i].effect= GetRandomValue(0,2);
}
activeEnemies = SECOND_WAVE;
wave = SECOND;
smooth = false;
......@@ -266,17 +291,21 @@ void UpdateGame(void)
for (int i = 0; i < activeEnemies; i++)
{
enemy[i].active= true;
enemy[i].rec.width =50;
enemy[i].rec.height = 50;
enemy[i].rec.x = screenWidth/2;
enemy[i].rec.y = 200;
enemy[i].speed.x = 5;
enemy[i].speed.y = 5;
enemy[i].active = true;
enemy[i].color = GRAY;
enemy[i].boss = false;
enemy[i].life = 10;
enemy[i].active= true;
enemy[i].rec.width =25;
enemy[i].rec.height = 25;
enemy[i].rec.x = screenWidth/2;
enemy[i].rec.y = 200;
enemy[i].speed.x = 5;
enemy[i].speed.y = 5;
enemy[i].active = true;
enemy[i].color = GRAY;
enemy[i].boss = false;
enemy[i].life = 10;
}
for (int i = 0; i < ItemNumber; i++)
{
item[i].effect= GetRandomValue(0,2);
}
activeEnemies = THIRD_WAVE;
......@@ -331,6 +360,11 @@ void UpdateGame(void)
if (!enemy[i].active) enemy[i].active = true;
}
for (int i = 0; i < ItemNumber; i++)
{
item[i].effect= GetRandomValue(0,2);
}
activeEnemies = FOURTH_WAVE;
wave = FOURTH;
smooth = false;
......@@ -376,6 +410,44 @@ void UpdateGame(void)
}
}
}
// Player get item
for (int i = 0; i < ItemNumber; i++)
{
if (CheckCollisionRecs(player.rec, item[i].rec))
{
item[i].active = false;
if ( i == ItemNumber -1)
{
item[0].active = true;
}else {
item[i+1].active = true;
}
item[i].rec.x = GetRandomValue(screenWidth, screenWidth + 1000);
item[i].rec.y = GetRandomValue(0, screenHeight - item[i].rec.height);
switch (item[i].effect)
{
case Life:
player.life ++;
break;
case Speed:
player.speed.x += 2;
player.speed.y += 2;
break;
case SizeShoot:
for (int i; i<NUM_SHOOTS;i++)
{
shoot[i].bonus = true;
}
break;
default:
break;
}
}
}
// Enemy behaviour
for (int i = 0; i < activeEnemies; i++)
......@@ -411,9 +483,16 @@ void UpdateGame(void)
{
if (!shoot[i].active && shootRate%20 == 0)
{
shoot[i].rec.x = player.rec.x;
shoot[i].rec.y = player.rec.y + player.rec.height/4;
shoot[i].active = true;
if (shoot[i].bonus)
{
shoot[i].rec.x = player.rec.x +2;
shoot[i].rec.y = player.rec.y + player.rec.height/4 + 2;
shoot[i].active = true;
}else {
shoot[i].rec.x = player.rec.x;
shoot[i].rec.y = player.rec.y + player.rec.height/4;
shoot[i].active = true;
}
break;
}
}
......@@ -467,6 +546,7 @@ void UpdateGame(void)
if (item[i].active)
{
item[i].rec.x -= item[i].speed.x;
item[i].effect = GetRandomValue(0,2);
if (item[i].rec.x < 0)
{
......@@ -522,6 +602,7 @@ void DrawGame(void)
if (item[i].active) DrawRectangleRec(item[i].rec, item[i].color);
}
// Display of score and player life
DrawText("Score:",20,10,30, GRAY);
DrawText(TextFormat("%04i", score), 120, 10, 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