/*******************************************************************************************
*
*   raylib [core] example - Basic window
*
*   Welcome to raylib!
*
*   To test examples in Notepad++, provided with default raylib installer package, 
*   just press F6 and run [raylib_compile_execute] script, it will compile and execute.
*   Note that compiled executable is placed in the same folder as .c file
*
*   You can find all basic examples on [C:\raylib\raylib\examples] directory and
*   raylib official webpage: [www.raylib.com]
* gcc -W -Wall -Wextra -Wno-unused-parameter -std=c99 core_basic_window.c -o core_basic_window
* Enjoy using raylib. :)
*
*   This example has been created using raylib 1.0 (www.raylib.com)
*   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
*   Copyright (c) 2013-2020 Ramon Santamaria (@raysan5
*
********************************************************************************************/
#include "raylib.h"
#include "air_defense.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>


//----------------------------------------------------------------------------------
// Some Defines
//--------------------------------------------------------------------------------


#define NUMBER_MAX_OF_PARATROOPERS  100
#define NUMBER_MAX_OF_AIRCRAFTS 50 
#define NUMBER_OF_BULLETS  25
#define NUMBER_OF_BOMBSHELLS 25
#define TROOPERS_PER_PLANE 3


//------------------------------------------------------------------------------------
// Global Variables Declaration
//------------------------------------------------------------------------------------

const int screenWidth = 1200;
const int screenHeight = 550;
double shoot_rate;

static bool gameOver = false;
static bool pause =  false;
int score ;
int life ;
int NUMBER_OF_AIRCRAFTS ;

const float bulletSpeed = 10;
const float bombshellSpeed = 6;
float hypothenuse1;
float hypothenuse2;
int framesCounter = 0;

double shoot_rate;
double tempsAAC;
double tempsAPC;

AntiParaCanon antiParaCanon;
AntiAircraftCanon antiAircraftCanon;
Paratrooper paraInitial;
Bombshell bombshellInit;
Bullet bulletInit;
Viewfinder viewfinder;
int jalon;


Aircraft aircraft[NUMBER_MAX_OF_AIRCRAFTS] ;
Bullet bullet[NUMBER_OF_BULLETS] ;
Bombshell bombshells[NUMBER_OF_BOMBSHELLS] ;
Paratrooper paratrooper[NUMBER_MAX_OF_PARATROOPERS] ;

//--------------------------------------------------------------------------------------
// Music and sound
//--------------------------------------------------------------------------------------

const char* crystals = "Musiques/moon-crystals-hotline-miami-soundtrack.mp3";
const char* beams = "Musiques/Beams.mp3";
const char* Dust = "Musiques/MOON - Dust Synthwave.mp3";
Music gameMusic;
Music gameOverMusic;
Music gamePauseMusic;

const char* explosion = "Musiques/explosion.wav";
const char* alert =  "Musiques/Alerte.wav";
const char* bombshellC = "Musiques/Missile.wav";
const char* bulletC = "Musiques/APC.wav";
Wave wave;
Sound soundExplosion; 
Sound soundAlert; 
Sound soundBombshell ;
Sound soundBullet; 

//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------

int main(void)
{
    // Initialization
    //--------------------------------------------------------------------------------------


    InitWindow(screenWidth, screenHeight, "Air defense");
    
    InitGame();
    HideCursor();

    InitAudioDevice();

    LoadAudio();

    
    SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------
    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        if (!gameOver && !pause)
        {
            PlayMusicStream(gameMusic);
            UpdateMusicStream(gameMusic);
        }
        else if (gameOver)
        {
            PlayMusicStream(gameOverMusic);
            UpdateMusicStream(gameOverMusic);
        }
        else if (pause)
        {
            PlayMusicStream(gamePauseMusic);
            UpdateMusicStream(gamePauseMusic);
        }
        
        
      
  // Update
        //----------------------------------------------------------------------------------
        // TODO: Update your variables here
        

        UpdateGame(); 
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        DrawGame();
        //----------------------------------------------------------------------------------
    }
    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadAudio();

    CloseAudioDevice();

    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    //return 0;
}

//-----------------------------------------------------------------------------------------
// Module Functions Definition
//-----------------------------------------------------------------------------------------

void InitGame(void)
{
    score = 0;
    life = 5;
    gameOver = false;
    pause = false;
    jalon = 1000;
    NUMBER_OF_AIRCRAFTS = 5;

    //Initialize paratroopers
    for (int k=0; k < NUMBER_MAX_OF_PARATROOPERS; k++)
    {
        paratrooper[k] = InitializeParatrooper();
    }

    //Initialize aircrafts  
    for (int i = 0; i < NUMBER_MAX_OF_AIRCRAFTS; i++)
    {
        aircraft[i] = InitializeAircraft();
    }

    //Initialize bombshells and bullets
    for (int j =0; j< NUMBER_OF_BOMBSHELLS;j++)
    {
        bombshells[j] = InitializeBombshell();
    }

    for (int j =0; j< NUMBER_OF_BULLETS; j++)
    {
        bullet[j] = InitializeBullet();
    }

    //Initialize canons
    antiParaCanon = InitializeAntiParaCanon();

    antiAircraftCanon = InitializeAntiAircraftCanon();

    //Initialize viewfinder
    viewfinder = InitializeViewfinder(0.);

}

void UpdateGame(void)
{
    if (!gameOver)
    {
        if (IsKeyPressed('P')) 
        {
            pause = !pause;
        }
        if (!pause)
        {
            framesCounter++;
            if((score > jalon) && (NUMBER_OF_AIRCRAFTS< NUMBER_MAX_OF_AIRCRAFTS)){
                NUMBER_OF_AIRCRAFTS+=5;
                jalon+=1000;
                life +=1 ;
            }

            //Moves
            //Paratroopers
            for(int i = 0; i<NUMBER_MAX_OF_PARATROOPERS; i++ )
            {
                if(paratrooper[i].droped)
                {
                    paratrooper[i] =  MoveParatrooper(paratrooper[i]);  
                }
                if (IsRectangleOut(paratrooper[i].hitbox) && paratrooper[i].droped)
                {
                    paratrooper[i] = InitializeParatrooper();
                    life--;
                    gameOver = (life <= 0);
                }
            }

            //Planes
            for(int j = 0; j<NUMBER_OF_AIRCRAFTS; j++)
            {
                aircraft[j] = MoveAircrafts(aircraft[j]);
                if (IsRectangleOut(aircraft[j].hitbox))
                {
                    if (aircraft[j].speed.x>0 && aircraft[j].hitbox.x>screenWidth)
                    {
                        aircraft[j] = InitializeAircraft();
                    }
                    else if(aircraft[j].speed.x<0 && aircraft[j].hitbox.x<0)
                    {
                        aircraft[j] = InitializeAircraft();
                    }
                }
            }

            //Bullets
            for(int k = 0; k<NUMBER_OF_BULLETS; k++)
            {
                if (bullet[k].ammoShot)
                {
                    bullet[k] = MoveBullet(bullet[k]);
                }
                if(IsCircleOut(bullet[k].position,bullet[k].radius))
                {
                    bullet[k] = InitializeBullet();
                }
            }

            //Bombshells
            for(int k = 0; k<NUMBER_OF_BOMBSHELLS; k++)
            {
                if (bombshells[k].ammoShot)
                {
                    bombshells[k] = MoveBombshell(bombshells[k]);
                }
                if (IsCircleOut(bombshells[k].position,bombshells[k].radius))
                {
                    bombshells[k] = InitializeBombshell();
                }
            }

            //Defining where the canons are shooting
            hypothenuse1 = sqrt(powf(GetMousePosition().x - antiAircraftCanon.position.x,2) + powf(GetMousePosition().y - antiAircraftCanon.position.y,2));
            hypothenuse2 = sqrt(powf(GetMousePosition().x - antiParaCanon.position.x,2) + powf(GetMousePosition().y - antiParaCanon.position.y,2));
            
            antiParaCanon.aimingPosition = GetMousePosition();
            antiParaCanon.sin = (antiParaCanon.aimingPosition.y - antiParaCanon.position.y)/hypothenuse2;
            antiParaCanon.cos = (antiParaCanon.aimingPosition.x - antiParaCanon.position.x)/hypothenuse2;

            antiAircraftCanon.aimingPosition = GetMousePosition();
            antiAircraftCanon.sin = (antiAircraftCanon.aimingPosition.y - antiAircraftCanon.position.y)/hypothenuse1;
            antiAircraftCanon.cos = (antiAircraftCanon.aimingPosition.x - antiAircraftCanon.position.x)/hypothenuse1;    
            
            //Shooting
            //anti-aircrafts canon ((double) tempsAAC/CLOCKS_PER_SEC))<(shoot_rate)
            if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON))
            {
                for (int i = 0; i<NUMBER_OF_BOMBSHELLS; i++)
                {
                    if (!bombshells[i].ammoShot)
                    {
                        bombshells[i] = ShootBombshell(bombshells[i]);
                        break;
                    }
                }
            }
            // anti-Paratroopers canon
            if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) )
            {
                for (int i = 0; i<NUMBER_OF_BULLETS; i++)
                {
                    if (!bullet[i].ammoShot)
                    {
                        bullet[i] = ShootBullet(bullet[i]);
                        break;
                    }
                }
            }
            //Destructions
            //Paratroopers
            for (int i = 0; i<NUMBER_MAX_OF_PARATROOPERS; i++)
            {
               if(paratrooper[i].droped)
               {
                    for (int j = 0; j<NUMBER_OF_BULLETS; j++)
                    {
                        if(CheckCollisionCircleRec(bullet[j].position, bullet[j].radius, paratrooper[i].hitbox))
                        {
                            DrawCircleLines(bullet[j].position.x,bullet[j].position.y, bullet[j].radius+20, WHITE);
                            DrawCircleLines(bullet[j].position.x+4,bullet[j].position.y, 10, YELLOW);
                            DrawCircleLines(bullet[j].position.x+8,bullet[j].position.y, 5, RED);
                            paratrooper[i].life--;
                            Vector2 vbullet = bullet[j].position;
                            float rbullet = bullet[j].radius;
                            bullet[j] = InitializeBullet();
                            //Kill paras
                            if(paratrooper[i].life == 0)
                            {
                                paratrooper[i] = InitializeParatrooper();
                            }
                                //explosive ammo
                            for (int s = 0; s<NUMBER_MAX_OF_PARATROOPERS; s++)
                            {
                                if(paratrooper[s].droped)
                                {
                                    if(CheckCollisionCircleRec(vbullet, rbullet+20, paratrooper[s].hitbox))
                                    {
                                        paratrooper[s].life--;
                                        //Kill paras
                                        if(paratrooper[s].life == 0)
                                        {
                                            paratrooper[s] = InitializeParatrooper();
                                        }
                                    }
                                }            
                            }       
                        }
                    }
                } 
            }
            //Planes
            for (int i = 0; i<NUMBER_OF_AIRCRAFTS; i++)
            {
               if((aircraft[i].hitbox.x > 0) && (aircraft[i].hitbox.x < screenWidth))
               {
                    for (int j = 0; j<NUMBER_OF_BOMBSHELLS; j++)
                    {
                        if(CheckCollisionCircleRec(bombshells[j].position, bombshells[j].radius, aircraft[i].hitbox))
                        {
                            DrawCircle(bombshells[j].position.x,bombshells[j].position.y, 15, RED);
                            DrawCircle(bombshells[j].position.x+4,bombshells[j].position.y, 10, YELLOW);
                            aircraft[i].life = aircraft[i].life - 1;
                            PlaySound(soundExplosion);
                            bombshells[j] = InitializeBombshell();
                            //Kill aircrafts
                            if(aircraft[i].life == 0)
                            {
                                score+=50;                               
                                DrawCircle(aircraft[i].hitbox.x,aircraft[i].hitbox.y, 15, WHITE);
                                DrawCircle(aircraft[i].hitbox.x+4,aircraft[i].hitbox.y, 10, YELLOW);
                                DrawCircle(aircraft[i].hitbox.x+8,aircraft[i].hitbox.y, 5, RED);
                                aircraft[i] = InitializeAircraft();
                            }
                        }
                    }
                    //Dropping paratroopers
                    if (GoDropParatrooper(aircraft[i]))
                   {
                        for(int j = 0; j<NUMBER_MAX_OF_PARATROOPERS; j++)
                        {
                            if ((!paratrooper[j].droped) && (fabs(aircraft[i].hitbox.x - aircraft[i].xFirstToJump) > 20) && (aircraft[i].numberOfParatroopers > -1))
                            {
                                paratrooper[j] = DropParatrooperFromAircraft(paratrooper[j],aircraft[i]);
                                aircraft[i].numberOfParatroopers--;
                                aircraft[i].xFirstToJump = aircraft[i].hitbox.x;
                            }
                        }
                    }
                }   
            }
        }
        else
        {
            StopMusicStream(gameMusic);   
        }
    }
    else
    {
        StopMusicStream(gameMusic);
        
        if (IsKeyPressed(KEY_ENTER))
        {
            InitGame();
            gameOver = false;
            
        }
    }
}

void DrawGame(void)
{
  BeginDrawing();

        ClearBackground(BLACK);
        
        if (!gameOver)
        {
            //Draw planes
            for (int i = 0; i<NUMBER_OF_AIRCRAFTS; i++)
            {
                DrawRectangleRec(aircraft[i].hitbox, aircraft[i].color);
            
            }
            //Draw paratroopers
            for (int i = 0; i<NUMBER_MAX_OF_PARATROOPERS; i++)
            {
                if (paratrooper[i].droped)
                {
                    DrawRectangleRec(paratrooper[i].hitbox, paratrooper[i].color);
                    if (framesCounter % 32 < 16) 
                    {
                        DrawRectangleRec(paratrooper[i].hitbox, ORANGE);;
                    }
                }
                //Draw drag
            }
            //Draw bullets
            for (int i = 0; i<NUMBER_OF_BULLETS; i++)
            {
                if (bullet[i].ammoShot)
                {
                    DrawCircleV(bullet[i].position, bullet[i].radius, bullet[i].color);

                }
            }
            //Draw bombshells
            for (int i = 0; i<NUMBER_OF_BOMBSHELLS; i++)
            {
                if (bombshells[i].ammoShot)
                {
                    DrawCircleV(bombshells[i].position, bombshells[i].radius-10,bombshells[i].color);
                    if (framesCounter % 32 < 16)
                    {
                        DrawText( "< >", bombshells[i].position.x -4 ,bombshells[i].position.y -2, 15, GREEN);
                    }
                }
            }
            if (pause){ DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GREEN);}
        }
        else
        {
            DrawText("Press ENTER to play again", 450, 250, 20, GREEN);
        }

        //ATH

        //Beware of paras
        for (int i = 0; i<NUMBER_MAX_OF_PARATROOPERS; i++)
        {
            if (paratrooper[i].droped)
            {
                if (paratrooper[i].hitbox.y>350) 
                {
                    if (framesCounter % 16 < 8) 
                    {
                        DrawText("ALERT -- Invaders close to contact --", 0, 500, 20, GREEN);
                        DrawText(">> <<", paratrooper[i].hitbox.x-12, paratrooper[i].hitbox.y-4, 20, GREEN);
                        PlaySound(soundAlert);
                    }
                }
            }
        }

        //Draw viewfinder
        if((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) || (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)))
        {
            viewfinder = InitializeViewfinder(10);            
        }
        else
        {
            viewfinder = InitializeViewfinder(15);
        }
        DrawRectangleRec(viewfinder.up,viewfinder.color);
        DrawRectangleRec(viewfinder.down,viewfinder.color);
        DrawRectangleRec(viewfinder.right,viewfinder.color);
        DrawRectangleRec(viewfinder.left,viewfinder.color);


        //Score
        DrawText("\\>>>|", 500, 500, 20, GREEN);
        DrawText(TextFormat("%04i",score), 550, 500, 20, GREEN);
        DrawText("|<<</", 600, 500, 20, GREEN);
        DrawText(TextFormat("LIVES = %04i",life), 510, 520, 20, GREEN);



    EndDrawing();  
}
void LoadAudio(void)
{
    //Musics
    gameMusic = LoadMusicStream(crystals); 
    gameOverMusic = LoadMusicStream(beams);
    gamePauseMusic = LoadMusicStream(Dust);
    //Sounds

    soundExplosion = LoadSound(explosion);
    soundBullet =  LoadSound(bulletC);
    soundBombshell = LoadSound(bombshellC);
    soundAlert = LoadSound(alert);
}

void UnloadAudio()
{
    UnloadMusicStream(gameMusic);
    UnloadMusicStream(gameOverMusic);
    UnloadMusicStream(gamePauseMusic);
    UnloadSound(soundAlert);
    UnloadSound(soundBombshell);
    UnloadSound(soundBullet);
    UnloadSound(soundExplosion);
}


//------------------------------------------------------------------------------------
// Other Functions
//------------------------------------------------------------------------------------

//Initialization functions------------------------------------------------------------
Aircraft InitializeAircraft(void)
{
    Aircraft aircraft;
    aircraft.life = 1;
    aircraft.hitbox.width = GetRandomValue(30,50);
    aircraft.hitbox.height = 5;
    aircraft.numberOfParatroopers = GetRandomValue(0,TROOPERS_PER_PLANE);
    if (aircraft.hitbox.width<41)
    {
        aircraft.hitbox.width = 30;
    }
    else
    {
        aircraft.hitbox.width = 50;
    }
    aircraft.hitbox.y = GetRandomValue(0 + aircraft.hitbox.height, screenHeight/2);
    aircraft.height = aircraft.hitbox.y;
    if (GetRandomValue(0,1)==0)
    {
        aircraft.hitbox.x = -GetRandomValue(0,300);
        aircraft.speed.x = 0.5+ 0.5*((float) GetRandomValue(0,1));
        aircraft.xFirstToJump = GetRandomValue(90,screenWidth/2);
    }
    else
    {
        aircraft.speed.x = -(0.5+ 0.5*((float) GetRandomValue(0,1)));
        aircraft.hitbox.x = GetRandomValue(screenWidth,screenWidth+300);
        aircraft.xFirstToJump = GetRandomValue(screenWidth/2,screenWidth-90);
    }
    aircraft.speed.y = 0;
    aircraft.color = GRAY;
    return aircraft;
}

AntiAircraftCanon InitializeAntiAircraftCanon(void)
{
    AntiAircraftCanon antiAircraftCanon;
    antiAircraftCanon.sin = 0.;
    antiAircraftCanon.cos = 0.;
    antiAircraftCanon.position.x = screenWidth*(0.75);
    antiAircraftCanon.position.y = screenHeight;
    antiAircraftCanon.aimingPosition.x = 0.;
    antiAircraftCanon.aimingPosition.y = 0.;
    return antiAircraftCanon;
}

AntiParaCanon InitializeAntiParaCanon(void)
{
    AntiParaCanon antiParaCanon;
    antiParaCanon.sin = 0.;
    antiParaCanon.cos = 0.;
    antiParaCanon.position.x = screenWidth/4;
    antiParaCanon.position.y = screenHeight;
    antiParaCanon.aimingPosition.x = 0.;
    antiParaCanon.aimingPosition.y = 0.;
    return antiParaCanon;
}

Bombshell InitializeBombshell(void)
{
    Bombshell bombshellInit;
    bombshellInit.radius = 15;
    bombshellInit.sin = 0;
    bombshellInit.cos = 0;
    bombshellInit.ammoShot = false;
    bombshellInit.position.x = screenHeight;
    bombshellInit.position.y = 0;
    bombshellInit.speed.x = 0;
    bombshellInit.speed.y = 0;
    bombshellInit.color = DARKPURPLE;
    return bombshellInit; 
}

Bullet InitializeBullet(void)
{
    Bullet bulletInit;
    bulletInit.radius = 3;
    bulletInit.sin = 0;
    bulletInit.cos = 0;
    bulletInit.ammoShot = false;
    bulletInit.position.x = 0;
    bulletInit.position.y = screenWidth;
    bulletInit.speed.x = 0;
    bulletInit.speed.y = 0;
    bulletInit.color = RED;
    return bulletInit;
}

Paratrooper InitializeParatrooper(void)
{
    Paratrooper paraInitial;
    paraInitial.hitbox.x = 0;
    paraInitial.hitbox.y = 0;
    paraInitial.xDrop = 0.;
    paraInitial.yDrop = 0.;
    paraInitial.speed.y = 0.3;
    paraInitial.speed.x = 0;
    paraInitial.color = RED;
    paraInitial.life = 1;
    paraInitial.hitbox.width = 10;
    paraInitial.hitbox.height = 10;
    paraInitial.droped = false;
    paraInitial.whichWay = true;
    return paraInitial;
}

Viewfinder InitializeViewfinder(float decalage)
{
    Viewfinder v;
    v.color = GREEN;
    float d1 = 13;
    float d2 = 2; 
    v.center = GetMousePosition();
    v.up.width = d2;
    v.up.height = d1;
    v.up.y = v.center.y + decalage - d1/2 ;
    v.up.x = v.center.x -d2/2 ;

    v.down.width = d2;
    v.down.height = d1;
    v.down.y = v.center.y - decalage - d1/2;
    v.down.x = v.center.x - d2/2;

    v.right.width = d1;
    v.right.height =d2;
    v.right.x = v.center.x + decalage -d1/2;
    v.right.y = v.center.y - d2/2;

    v.left.width = d1;
    v.left.height = d2;
    v.left.x = v.center.x - decalage - d1/2;
    v.left.y = v.center.y - d2/2;
    

    return v;
}

//Game Functions-------------------------------------------------------------------------
bool IsRectangleOut(Rectangle rec)
{
    if(rec.x<0 || rec.x>screenWidth)
    {
        return true;
    }
    if(rec.y<0 || rec.y>screenHeight)
    {
        return true;
    }
    return false;
}

bool IsCircleOut(Vector2 center, float radius)
{
   if(center.x + radius<0 || center.x - radius >screenWidth)
    {
        return true;
    }
    if(center.y + radius < 0 || center.y - radius>screenHeight)
    {
        return true;
    }
    return false;
}

bool GoDropParatrooper(Aircraft aircraft)
{
    if (aircraft.speed.x>0  && aircraft.hitbox.x > aircraft.xFirstToJump)
    {
        return true;
    }
    if (aircraft.speed.x<0 && aircraft.hitbox.x < aircraft.xFirstToJump)
    {
        return true;
    }
    return false;
}

Aircraft MoveAircrafts(Aircraft aircraft)
{
    aircraft.hitbox.x += aircraft.speed.x;
    aircraft.hitbox.y = aircraft.height + 10*cos(0.01*aircraft.hitbox.x);
    return aircraft;
}

Bullet MoveBullet(Bullet bullet)
{
    bullet.position.x += bullet.speed.x;
    bullet.position.y += bullet.speed.y;
    return bullet;
}

Bullet ShootBullet(Bullet bullet)
{
    bullet.ammoShot = true;
    bullet.position.x = antiParaCanon.position.x;
    bullet.position.y = antiParaCanon.position.y;
    bullet.speed.x = bulletSpeed*antiParaCanon.cos;
    bullet.speed.y = bulletSpeed*antiParaCanon.sin;
    PlaySound(soundBullet);
    return bullet;
}

Bombshell MoveBombshell(Bombshell bombshell)
{
    bombshell.position.x += bombshell.speed.x;
    bombshell.position.y += bombshell.speed.y;
    return bombshell;
}

Bombshell ShootBombshell(Bombshell bombshell)
{
    bombshell.ammoShot = true;
    bombshell.position.x = antiAircraftCanon.position.x;
    bombshell.position.y = antiAircraftCanon.position.y;
    bombshell.speed.x = bombshellSpeed*antiAircraftCanon.cos;
    bombshell.speed.y = bombshellSpeed*antiAircraftCanon.sin;
    PlaySound(soundBombshell);
    return bombshell;
}

Paratrooper DropParatrooperFromAircraft(Paratrooper paratrooper, Aircraft aircraft)
{
    paratrooper.droped = true;
    if (aircraft.speed.x>0)
    {
            paratrooper.whichWay = false;
    }
    else
    {
            paratrooper.whichWay = true;
    }
    paratrooper.hitbox.x = aircraft.hitbox.x;
    paratrooper.hitbox.y = aircraft.hitbox.y;
    paratrooper.xDrop = aircraft.hitbox.x;
    paratrooper.yDrop = aircraft.hitbox.y;
    return paratrooper;
}

Paratrooper MoveParatrooper(Paratrooper paratrooper)
{
    paratrooper.hitbox.y += paratrooper.speed.y;
    if(paratrooper.whichWay)
    {
        paratrooper.hitbox.x = 100*(1-exp(-(paratrooper.hitbox.y-paratrooper.yDrop)/5)) + paratrooper.xDrop;
    }
    else
    {
        paratrooper.hitbox.x = -100*(1-exp(-(paratrooper.hitbox.y-paratrooper.yDrop)/5)) + paratrooper.xDrop;
    }
    return paratrooper;
}

