//lariolib.h   //contains variables...classes...arrays...universal functions


using namespace std;



class player {
      public:
             int x, y;
             int ty;
             int dir;
             int jump;
             int draw;
             int dead; //for var reset stuff
             long score;  //goes up for kill
             long tscore; //to reset score if dies
             void w1_resp();
             void w2_resp();
             void w3_resp();
             void w4_resp();
             }p;
             
class projectile {
      public:
             int dx, dy;
             int shot;
             int dir;
             int x, y;
             int dis;
             void update_w1();
             void update_w2();
             void update_w3();
             void update_w4();
             }bul;
             
class bot {
      public:
             int x, y;
             int dis;  //for drawing camera
             int dx, dy;  //for drawing code...relative to players loc
             int dead;
             int ds;  //to determine where bot spawns relative to lario
             int dir;  //for drawing animation    <--1 | 2-->
             int type;  //1=g, 2=t
             int attack;  //for movement
             void reset_bot();
             void move_w1();
             void move_w2();
             void move_w3();
             void move_w4();
             void kill();  //makes bot die if too low, prevents crashing
             void check_respawn();  //sets them alive at position relative to lario, spawn in air, gravity makes them fall
             }g1, g2, g3, t1, t2; //t=turtle  g=goomba
             

int mute = 1; //so player can disable sound    1=sound on
int scrnh = 480; //for credits scrolling
int menu = 1; //for the home menu, to do credits/instuctions/quit buttons
int drawmen = 1; //for menu drawing code, so buttons are drawn only once
int caller; //to determine which world called make_save
int world;
int xbuf, ybuf, dirbuf, wbuf, sbuf, mbuf;  //for encryption
int botc; //to keep track of number of bots for rest statements
int hsc1, hsc2, hsc3;  //for high-scores

BITMAP *buffer;
BITMAP *credscrn;
BITMAP *title;
BITMAP *lar1;
BITMAP *lar2;
BITMAP *jump;
BITMAP *gm1;
BITMAP *gm2;
BITMAP *tt1;
BITMAP *tt2;
BITMAP *finzon;
BITMAP *sky;
BITMAP *brick;
BITMAP *grass;
BITMAP *spike;
BITMAP *cloud;
BITMAP *fballi;
BITMAP *fbex;

SAMPLE *ouch;
SAMPLE *bkill;
SAMPLE *die1;
SAMPLE *die2;
SAMPLE *levwin;
SAMPLE *gwin;
SAMPLE *mmus;
SAMPLE *gmus;
SAMPLE *j;
SAMPLE *fballs;
SAMPLE *fbhw;

//*************************************OUTPUT TO USER CODE*******************************\\

void credits(){
     rectfill(credscrn, 0, 0, 640, 700, makecol(0,0,0));
     textout_ex(credscrn, font, "Developed by:", 300, 10, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "ModShop", 330, 30, makecol(255,0,0), makecol(0,0,0));
     
     textout_ex(credscrn, font, "Game Concept:", 300, 70, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "Ben Reid", 330, 90, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "Emily Reid", 330, 110, makecol(255,0,0), makecol(0,0,0));
     
     textout_ex(credscrn, font, "Programming:", 300, 150, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "Ben Reid", 330, 170, makecol(255,0,0), makecol(0,0,0));
     
     textout_ex(credscrn, font, "Graphics:", 300, 200, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "Ben Reid", 330, 220, makecol(255,0,0), makecol(0,0,0));
     
     textout_ex(credscrn, font, "Sound Effects:", 300, 250, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "Creation:", 330, 270, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "Partners in Rhyme", 340, 290, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "Editing:", 330, 310, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "Ben Reid", 340, 330, makecol(255,0,0), makecol(0,0,0));
     
     textout_ex(credscrn, font, "Special Thanks:", 300, 380, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "Mathew Reid", 330, 400, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "Emily Reid", 330, 420, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "Allegro", 330, 440, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "Dev-Cpp", 330, 460, makecol(255,0,0), makecol(0,0,0));
     textout_ex(credscrn, font, "Thanks for Playing!!!", 300, 680, makecol(255,0,0), makecol(0,0,0));
     
     while (scrnh!=-700){
           draw_sprite(screen, credscrn, 0, scrnh);
           scrnh--;
           if (scrnh==-500)
           rest(2500);
           rest(15);}
     scrnh = 480;}
     
void instructions(){
     int a = 1;
     rectfill(screen, 0, 0, 640, 480, makecol(0,0,0));
     draw_sprite(screen, title, 180, 380);
     textout_ex(screen, font, "Instructions:", 300, 20, makecol(255,0,0), makecol(0,0,0));
     
     rect(screen, 0, 0, 210, 120, makecol(0,255,0));
     textout_ex(screen, font, "Controls:", 10, 20, makecol(255,0,0), makecol(0,0,0));
     textout_ex(screen, font, "Left/right- Arrow keys", 30, 40, makecol(255,0,0), makecol(0,0,0));
     textout_ex(screen, font, "Jump- SPACE bar", 30, 60, makecol(255,0,0), makecol(0,0,0));
     textout_ex(screen, font, "Shoot- M key", 30, 80, makecol(255,0,0), makecol(0,0,0));
     textout_ex(screen, font, "Pause- ENTER key", 30, 100, makecol(255,0,0), makecol(0,0,0));
     
     rect(screen, 355, 55, 505, 170, makecol(0,255,0));
     textout_ex(screen, font, "Bots:", 400, 60, makecol(255,0,0), makecol(0,0,0));
     draw_sprite(screen, gm1, 360, 80);
     textout_ex(screen, font, "= 750 points", 405, 100, makecol(255,0,0), makecol(0,0,0));
     draw_sprite(screen, tt1, 360, 125);
     textout_ex(screen, font, "= 1500 points", 400, 145, makecol(255,0,0), makecol(0,0,0));
     
     rect(screen, 15, 195, 480, 325, makecol(0,255,0));
     textout_ex(screen, font, "Concept:", 120, 200, makecol(255,0,0), makecol(0,0,0));
     textout_ex(screen, font, "You are Lario, 3rd brother of Mario", 40, 220, makecol(255,0,0), makecol(0,0,0));
     textout_ex(screen, font, "This game is similar to the retro Mario games", 20, 240, makecol(255,0,0), makecol(0,0,0));
     textout_ex(screen, font, "Try to get through all 3 worlds and get a high score", 20, 260, makecol(255,0,0), makecol(0,0,0));
     textout_ex(screen, font, "Kill the bots for points", 20, 280, makecol(255,0,0), makecol(0,0,0));
     textout_ex(screen, font, "Goodluck! You'll need it", 100, 300, makecol(255,0,0), makecol(0,0,0));
     
     rectfill(screen, 400, 400, 520, 460, makecol(0,255,0));
     textout_ex(screen, font, "Back", 440, 420, makecol(0,0,255), makecol(0,255,0));
     
                         while (a==1){
                               if (mouse_x>=400 && mouse_x<=520 && mouse_y>=400 && mouse_y<=460 && mouse_b&1)
                               return;}
     drawmen = 1;}
     
void winner(){
     credits();
     rectfill(screen, 0, 0, 640, 480, makecol(230,230,40));
     draw_sprite(screen, title, 0, 0);
     draw_sprite(screen, title, 0, 380);
     draw_sprite(screen, title, 440, 0);
     draw_sprite(screen, title, 440, 380);
     textout_ex(screen, font, "Congratulations!!", 220, 150, makecol(255,0,0), makecol(230,230,40));
     textout_ex(screen, font, "You Won!!", 240, 170, makecol(255,0,0), makecol(230,230,40));
     textout_ex(screen, font, "You are the", 220, 220, makecol(255,0,0), makecol(230,230,40));
     textout_ex(screen, font, "Lario Master!!", 220, 240, makecol(255,0,0), makecol(230,230,40));
     textout_ex(screen, font, "Press ESC", 250, 300, makecol(255,0,0), makecol(230,230,40));
     textout_ex(screen, font, "To return", 250, 320, makecol(255,0,0), makecol(230,230,40));
     textout_ex(screen, font, "Score:", 350, 200, makecol(255,0,0), makecol(230,230,40));
     textprintf(screen ,font, 400, 200, makecol(255,0,0), "%i", p.score);
     
                        while (!key[KEY_ESC]){
                              rest(10);}
     stop_sample(gwin);
     drawmen = 1;}

//**************************************GAMESAVES!!!!*****************************************\\

void encrypt(){
     xbuf = p.x * 5 - 20;
     ybuf = p.y * 3 + 37;
     dirbuf = p.dir * 7 - 5;
     wbuf = world * 20 + 1;
     sbuf = p.score * 3 - 5555;}
     
void decrypt(){
     p.x = (xbuf + 20)/ 5;
     p.y = (ybuf - 37)/ 3;
     p.dir = (dirbuf + 5)/ 7;
     world = (wbuf - 1)/ 20;
     p.score = (sbuf + 5555)/ 3;}

void make_save(){
     encrypt();
     ofstream save;
     save.open("Settings/savegame.svg", ios::binary);
     save << wbuf << endl;
     save << xbuf << endl;
     save << ybuf << endl;
     save << dirbuf << endl;
     save << sbuf << endl;
     save << "chjvgfnjbgnjhbfhgjtrnjsxgbnzjrthcgnzjstvcjugvcvjuszg" << endl;
     save << "cxfhnchjbgn cbxzngc nvzgvnhvxndgzvn gn cgbjhnbxjhbcmjb" << endl;
     save << "mhfcxngjhcn chfxb  njchgfjnhbgfjxsdmkxhbcsnxchbsmchbmgchbs" << endl;
     save << "cdhjdnjnhccxcbhcnsjdfnxbjfnckxhbgcmkhjbgmjhbvmhbdxfmjchb" << endl;
     save << "chjvgfnjbgnjhbfhgjt rnjsxgbnzjrthcgnzjstvcjugvcvjuszg" << endl;
     save << "cxfhnchjbgn cbxzngc nvzgvnh vxndgzvn gn cgbjhnbxjhbcmjb" << endl;
     save << "mhfcxngj hcnchfxbnjchgfjnhbgfjxsdmkxhbcsnxchbsmchbmgchbs" << endl;
     save << "cdhjdnjnhccxcbhcnsjdfnxbjfnc kxhbgcmkhjbgmjhbvmhbdxfmjchb" << endl;
     save << "chjvgfnjbgnjhbfhgjtr njsxgbnzjrthcgnzjstvcjugvcvjuszg" << endl;
     save << "cxfhnchjb gncbxzngcnvzgvnhvxndgzv ngncgbjhnbxjhbcmjb" << endl;
     save << "mhfcxngjhcnchfxbnjchgfjnhbgfjxsdmkxhbcsnxchbsmc hbmgchbs" << endl;
     save << "cdhjdnjnhccxcbhcnsj dfnxbjfnckxhbgcmkhjbgmjhbvmhbdxfmjchb" << endl;
     save.close();}

//**************************************UNIVERSAL IN_GAME CODE******************************\\

int pause(){
     int a = 0;
     rectfill(screen, 0, 0, 640, 480, makecol(230,230,40));
     
     if (world==1)
     textout_ex(screen, font, "World 1", 300, 20, makecol(0,0,255), makecol(230,230,40));
     if (world==2)
     textout_ex(screen, font, "World 2", 300, 20, makecol(0,0,255), makecol(230,230,40));
     if (world==3)
     textout_ex(screen, font, "World 3", 300, 20, makecol(0,0,255), makecol(230,230,40));
     if (world==4)
     textout_ex(screen, font, "World 4", 300, 20, makecol(0,0,255), makecol(230,230,40));
     
     draw_sprite(screen, title, 200, 100);
     textout_ex(screen, font, "PAUSED", 280, 305, makecol(255,0,0), makecol(230,230,40));
     textout_ex(screen, font, "Score:", 30, 305, makecol(255,0,0), makecol(230,230,40));
     textprintf(screen ,font, 80, 306, makecol(255,0,0), "%i", p.score);
     textout_ex(screen, font, "Select an Option:", 210, 335, makecol(255,0,0), makecol(230,230,40));
     textout_ex(screen, font, "1. Continue", 220, 375, makecol(255,0,0), makecol(230,230,40));
     textout_ex(screen, font, "2. Save and Quit", 220, 395, makecol(255,0,0), makecol(230,230,40));
     textout_ex(screen, font, "3. Quit w/o Saving", 220, 415, makecol(255,0,0), makecol(230,230,40));
     
                        while (a==0){
                              if (key[KEY_1])
                                 return 0;
                              if (key[KEY_2]){
                                 stop_sample(gmus);
                                 return 10;}
                              if (key[KEY_3]){
                                 stop_sample(gmus);
                                 return -1;}} }
                                 
int retry_screen(){
    stop_sample(gmus);
    if (mute==1){
    play_sample(die1, 255, 128, 1000, 0);
    rest(1000);
    play_sample(die2, 255, 128, 1000, 0);}
    int a = 0;
    p.dead = 1;
    rectfill(screen, 0, 0, 640, 480, makecol(0,0,0));
    if (world==1)
    textout_ex(screen, font, "World 1", 280, 30, makecol(0,200,0), makecol(0,0,0));
    if (world==2)
    textout_ex(screen, font, "World 2", 280, 30, makecol(0,200,0), makecol(0,0,0));
    if (world==3)
    textout_ex(screen, font, "World 3", 280, 30, makecol(0,200,0), makecol(0,0,0));
    if (world==4)
    textout_ex(screen, font, "World 4", 280, 30, makecol(0,200,0), makecol(0,0,0));
    textout_ex(screen, font, "Score:", 200, 150, makecol(0,200,0), makecol(0,0,0));
    textprintf(screen ,font, 250, 150, makecol(255,0,0), "%i", p.score);
    textout_ex(screen, font, "YOU DIED!!", 200, 105, makecol(255,0,0), makecol(0,0,0));
    textout_ex(screen, font, "Select an Option:", 300, 205, makecol(255,0,0), makecol(0,0,0));
    textout_ex(screen, font, "1.Retry", 320, 225, makecol(255,0,0), makecol(0,0,0));
    textout_ex(screen, font, "2.Save and Quit", 320, 245, makecol(255,0,0), makecol(0,0,0));
    textout_ex(screen, font, "3.Quit w/o Saving", 320, 265, makecol(255,0,0), makecol(0,0,0));
    draw_sprite(screen, title, 440, 0);
    
                        while (a==0){
                              if (key[KEY_1])
                              return 0;
                              if (key[KEY_2])
                              return 10;
                              if (key[KEY_3])
                              return -1;} }
                                 
void check_kill(){
     if (bul.shot==1){
     if (bul.y==g1.y && bul.x==g1.x && g1.dead==0){
           if (mute==1){
           play_sample(fbhw, 255, 128, 1000, 0);
           play_sample(bkill, 255, 128, 1000, 0);}
           bul.shot = 0;
           g1.dead = 1;
           p.score+=750;
           draw_sprite(screen, sky, bul.dx * 40, bul.dy * 40);
           if (bul.dir==2)
           draw_sprite(screen, fbex, (bul.dx + 1) * 40, bul.dy * 40);
           else
           draw_sprite(screen, fbex, (bul.dx - 1) * 40, bul.dy * 40);
           rest(50); }
           
        if (bul.y==g2.y && bul.x==g2.x && g2.dead==0){
           if (mute==1){
           play_sample(fbhw, 255, 128, 1000, 0);
           play_sample(bkill, 255, 128, 1000, 0);}
           bul.shot = 0;
           g2.dead = 1;
           p.score+=750;
           draw_sprite(screen, sky, bul.dx * 40, bul.dy * 40);
           if (bul.dir==2)
           draw_sprite(screen, fbex, (bul.dx + 1) * 40, bul.dy * 40);
           else
           draw_sprite(screen, fbex, (bul.dx - 1) * 40, bul.dy * 40);
           rest(50);}
           
        if (bul.y==g3.y && bul.x==g3.x && g3.dead==0){
           if (mute==1){
           play_sample(fbhw, 255, 128, 1000, 0);
           play_sample(bkill, 255, 128, 1000, 0);}
           bul.shot = 0;
           g3.dead = 1;
           p.score+=750;
           draw_sprite(screen, sky, bul.dx * 40, bul.dy * 40);
           if (bul.dir==2)
           draw_sprite(screen, fbex, (bul.dx + 1) * 40, bul.dy * 40);
           else
           draw_sprite(screen, fbex, (bul.dx - 1) * 40, bul.dy * 40);
           rest(50);}
           
        if (bul.y==t1.y && bul.x==t1.x && t1.dead==0){
           if (mute==1){
           play_sample(fbhw, 255, 128, 1000, 0);
           play_sample(bkill, 255, 128, 1000, 0);}
           bul.shot = 0;
           t1.dead = 1;
           p.score+=1500;
           draw_sprite(screen, sky, bul.dx * 40, bul.dy * 40);
           if (bul.dir==2)
           draw_sprite(screen, fbex, (bul.dx + 1) * 40, bul.dy * 40);
           else
           draw_sprite(screen, fbex, (bul.dx - 1) * 40, bul.dy * 40);
           rest(50);}
           
        if (bul.y==t2.y && bul.x==t2.x && t2.dead==0){
           if (mute==1){
           play_sample(fbhw, 255, 128, 1000, 0);
           play_sample(bkill, 255, 128, 1000, 0);}
           bul.shot = 0;
           t2.dead = 1;
           p.score+=1500;
           draw_sprite(screen, sky, bul.dx * 40, bul.dy * 40);
           if (bul.dir==2)
           draw_sprite(screen, fbex, (bul.dx + 1) * 40, bul.dy * 40);
           else
           draw_sprite(screen, fbex, (bul.dx - 1) * 40, bul.dy * 40);
           rest(50);}}
     
     if (p.x==g1.x){
        if (p.y+1==g1.y && g1.dead==0 && p.jump==0){
          if (mute==1)
           play_sample(bkill, 255, 128, 1000, 0);
           g1.dead = 1;
           p.score+=750;
           botc--;}}
           
     if (p.x==g2.x){
        if (p.y+1==g2.y && g2.dead==0 && p.jump==0){
          if (mute==1)
           play_sample(bkill, 255, 128, 1000, 0);
           g2.dead = 1;
           p.score+=750;
           botc--;}}
           
     if (p.x==g3.x){
        if (p.y+1==g3.y && g3.dead==0 && p.jump==0){
          if (mute==1)
           play_sample(bkill, 255, 128, 1000, 0);
           g3.dead = 1;
           p.score+=750;
           botc--;}}
           
     if (p.x==t1.x){
        if (p.y+1==t1.y && t1.dead==0 && p.jump==0){
          if (mute==1)
           play_sample(bkill, 255, 128, 1000, 0);
           t1.dead = 1;
           p.score+=1500;
           botc--;}}
           
     if (p.x==t2.x){
        if (p.y+1==t2.y && t2.dead==0 && p.jump==0){
          if (mute==1)
           play_sample(bkill, 255, 128, 1000, 0);
           t2.dead = 1;
           p.score+=1500;
           botc--;}} }

void bot::reset_bot(){
     dead = 0;
     dir = 1;
     attack = 0;
     botc++;
     if (ds==1){
        x = p.x + 7;
        y = p.y - 8;}
                 
     if (ds==2){
        x = p.x + 12;
        y = p.y - 8;}
                 
     if (ds==3){
        x = p.x + 17;
        y = p.y - 8;}
                 
     if (ds==4){
        x = p.x + 22;
        y = p.y - 8;}
                 
     if (ds==5){
        x = p.x + 25;
        y = p.y - 8;}}
        
//***********************************RESPAWN CODE******************************************\\
        
void bot::check_respawn(){
        if (p.x-x>=17){
           if (world==1 && p.x<=55){
           botc++;            
           dead = 0;
           dir = 1;
           attack = 0;
           
           if (ds==1){
              x = p.x + 8;
              y = p.y - 8;}
                 
           if (ds==2){
              x = p.x + 15;
              y = p.y - 8;}
                 
           if (ds==3){
              x = p.x + 22;
              y = p.y - 8;}
                 
           if (ds==4){
              x = p.x + 30;
              y = p.y - 8;}
                 
           if (ds==5){
              x = p.x + 35;
              y = p.y - 8;}}
              
        if (world==2 && p.x<=95){
           botc++;            
           dead = 0;
           dir = 1;
           attack = 0;
           
           if (ds==1){
              x = p.x + 8;
              y = p.y - 8;}
                 
           if (ds==2){
              x = p.x + 15;
              y = p.y - 8;}
                 
           if (ds==3){
              x = p.x + 22;
              y = p.y - 8;}
                 
           if (ds==4){
              x = p.x + 30;
              y = p.y - 8;}
                 
           if (ds==5){
              x = p.x + 35;
              y = p.y - 8;}}
              
        if (world==3 && p.x<=130){
           botc++;            
           dead = 0;
           dir = 1;
           attack = 0;
           
           if (ds==1){
              x = p.x + 8;
              y = p.y - 8;}
                 
           if (ds==2){
              x = p.x + 15;
              y = p.y - 8;}
                 
           if (ds==3){
              x = p.x + 22;
              y = p.y - 8;}
                 
           if (ds==4){
              x = p.x + 30;
              y = p.y - 8;}
                 
           if (ds==5){
              x = p.x + 35;
              y = p.y - 8;}}}}
              
//*******************************RENDERING CODE************************************************\\ 
              
void draw_bots(){
     if (g1.dead==0){
         if (g1.dir==1){
            draw_sprite(buffer, gm1, g1.dx * 40, g1.dy * 40);}
         else if (g1.dir==2){
              draw_sprite_h_flip(buffer, gm1, g1.dx * 40, g1.dy * 40);}
         g1.dis = 0;}
              
     if (g2.dead==0){
         if (g2.dir==1){
            draw_sprite(buffer, gm1, g2.dx * 40, g2.dy * 40);}
         else if (g2.dir==2){
              draw_sprite_h_flip(buffer, gm1, g2.dx * 40, g2.dy * 40);}
         g2.dis = 0;}
             
      if (g3.dead==0){
         if (g3.dir==1){
            draw_sprite(buffer, gm1, g3.dx * 40, g3.dy * 40);}
         else if (g3.dir==2){
              draw_sprite_h_flip(buffer, gm1, g3.dx * 40, g3.dy * 40);}
         g3.dis = 0;}
              
      if (t1.dead==0){
         if (t1.dir==1){
            draw_sprite(buffer, tt2, t1.dx * 40, t1.dy * 40);}
         else if (t1.dir==2){
              draw_sprite_h_flip(buffer, tt2, t1.dx * 40, t1.dy * 40);}
         t1.dis = 0;}
              
      if (t2.dead==0){
         if (t2.dir==1){
            draw_sprite(buffer, tt2, t2.dx * 40, t2.dy * 40);}
         else if (t2.dir==2){
              draw_sprite_h_flip(buffer, tt2, t2.dx * 40, t2.dy * 40);}
         t2.dis = 0;}
     
     draw_sprite(screen, buffer, 0, 0);
     if (botc>0)
     rest(35);
     
     if (g1.dead==0){
         if (g1.dir==1){
            draw_sprite(buffer, gm2, g1.dx * 40, g1.dy * 40);}
         else if (g1.dir==2){
              draw_sprite_h_flip(buffer, gm2, g1.dx * 40, g1.dy * 40);}
         g1.dis = 0;}
              
     if (g2.dead==0){
         if (g2.dir==1){
            draw_sprite(buffer, gm2, g2.dx * 40, g2.dy * 40);}
         else if (g2.dir==2){
              draw_sprite_h_flip(buffer, gm2, g2.dx * 40, g2.dy * 40);}
         g2.dis = 0;}
             
      if (g3.dead==0){
         if (g3.dir==1){
            draw_sprite(buffer, gm2, g3.dx * 40, g3.dy * 40);}
         else if (g3.dir==2){
              draw_sprite_h_flip(buffer, gm2, g3.dx * 40, g3.dy * 40);}
         g3.dis = 0;}
              
      if (t1.dead==0){
         if (t1.dir==1){
            draw_sprite(buffer, tt1, t1.dx * 40, t1.dy * 40);}
         else if (t1.dir==2){
              draw_sprite_h_flip(buffer, tt1, t1.dx * 40, t1.dy * 40);}
         t1.dis = 0;}
              
      if (t2.dead==0){
         if (t2.dir==1){
            draw_sprite(buffer, tt1, t2.dx * 40, t2.dy * 40);}
         else if (t2.dir==2){
              draw_sprite_h_flip(buffer, tt1, t2.dx * 40, t2.dy * 40);}
         t2.dis = 0;}}
              
void find_bots_on_cam(){
     int x, y;
     int mx, my;
     for (x = p.x-8, mx = 0; x<=p.x+8; x++ && mx++){
         for (y = p.y-6, my = 0; y<=p.y+6; y++ && my++){
             if (y==g1.y && x==g1.x && g1.dead==0){
                g1.dx = mx;
                g1.dy = my;
                g1.dis = 1;}
             else if (g1.dis==0){
                 g1.dx = 30;
                 g1.dy = 30;}
                
             if (y==g2.y && x==g2.x && g2.dead==0){
                g2.dx = mx;
                g2.dy = my;
                g2.dis = 1;}
             else if (g2.dis==0){
                 g2.dx = 30;
                 g2.dy = 30;}
                
             if (y==g3.y && x==g3.x && g3.dead==0){
                g3.dx = mx;
                g3.dy = my;
                g3.dis = 1;}
             else if (g3.dis==0){
                 g3.dx = 30;
                 g3.dy = 30;}
                
             if (y==t1.y && x==t1.x && t1.dead==0){
                t1.dx = mx;
                t1.dy = my;
                t1.dis = 1;}
             else if(t1.dis==0){
                 t1.dx = 30;
                 t1.dy = 30;}
                
             if (y==t2.y && x==t2.x && t2.dead==0){
                t2.dx = mx;
                t2.dy = my;
                t2.dis = 1;}
              else if (t2.dis==0){
                 t2.dx = 30;
                 t2.dy = 30;} } } }
                 
void draw_player(){
     if (p.x<=7){
        if (p.dir==2){
                      
           if (p.draw==1){
                       draw_sprite(screen, lar1, 280, 240);
                       rest(20);
                       draw_sprite(buffer, lar2, 280, 240);
                       rest(20);
                       p.draw = 0;}
                       
           else
               draw_sprite(buffer, lar1, 280, 240);}
           
        else {
             
             if (p.draw==1){
                            draw_sprite_h_flip(screen, lar1, 280, 240);
                            rest(20);
                            draw_sprite_h_flip(buffer, lar2, 280, 240);
                            rest(20);
                            p.draw = 0;}
                            
             else
                 draw_sprite_h_flip(buffer, lar1, 280, 240);}}
            
     else if (p.x>7) {
          if (p.dir==2){
                        
             if (p.draw==1){
                draw_sprite(screen, lar1, 320, 240);
                rest(20);
                draw_sprite(buffer, lar2, 320, 240);
                rest(20);
                p.draw = 0;}
                
             else
                 draw_sprite(buffer, lar1, 320, 240);}
        
     else {
          
          if (p.draw==1){
             draw_sprite_h_flip(screen, lar1, 320, 240);
             rest(20);
             draw_sprite_h_flip(buffer, lar2, 320, 240);
             rest(20);
             p.draw = 0;}
             
          else
              draw_sprite_h_flip(buffer, lar1, 320, 240);}}}
              
void draw_fball(){
     for (int x = p.x-8, mx = 0; x<=p.x+8; x++ && mx++){
         for (int y = p.y-6, my = 0; y<=p.y+6; y++ && my++){
             if (y == bul.y && x==bul.x){
             bul.dx = mx;
             bul.dy = my;
             bul.dis = 1;}
             else if (bul.dis==0){
                  bul.dx = -1;
                  bul.dy = -1;}}}
     
     if (bul.shot==1){
     draw_sprite(buffer, fballi, bul.dx * 40, bul.dy * 40);
     bul.dis = 0;}}

//**************************************ANTI_CRASH CODE*********************************\\

void bot::kill(){
     if (y>45 && dead==0){
     if (mute==1)
     play_sample(bkill, 255, 128, 1000, 0);
     dead = 1;}}
