Sign in to follow this  
yurian

Using Allegro and C++, Strange error

Recommended Posts

yurian    182
I don't know why the program is drawing the failx.bmp before I even press any key. The failx is only in warscreen function, but I am still in menu, or should be. But if it is in warscreen, where is valley and player bitmap... I do not understand.
#include <allegro.h>
#include <cstdlib>
#include <time.h>
#define edeadplace 250
#define pdeadplace 70
#define p 100
#define e 540
#define y 240
#define center 320

int attackcount = 0;
int strikecount = 0;
int attacktime = 0;
int striketime = 0;

void attackplus()
{attackcount++;}END_OF_FUNCTION(attackplus);
void strikeplus()
{strikecount++;}END_OF_FUNCTION(strikeplus);

bool gamenotquit = true;

class allthings
{
      int level;
      bool haswon;
      bool failure;
      
      BITMAP*player,*playera,*playerd,*zyars,*zyarsa,*zyarsd,*vandy,*vandya,*vandyd,*mitsu,*mitsua,*mitsud,*ryoku,*ryokua,*ryokud,*drksp,*drkspa,*drkspd;
      BITMAP*champion,*valley,*redraw,*start,*failx;
      SAMPLE*wavplayera,*wavzyarsa,*wavvandya,*wavmitsua,*wavryokua,*wavdrkspa,*wavwind,*attacksignal;
      public:
             allthings();
             ~allthings();
             void declaration();
             void faillevel();
             void attacktie();
             void enemyattack();
             void playerattack();
             void nextlevel();
             void menu();
             void resetlevel();
             void warscreen();
};



allthings::allthings()
{
    
                      level = 1;
                      attackcount = 0;
                      strikecount = 0;
                      attacktime = 0;
                      striketime = 0;
                      haswon = false;
                      failure = false;
      
                      player = load_bitmap("player.bmp",NULL);
                      playera = load_bitmap("playera.bmp",NULL);
                      playerd = load_bitmap("playerd.bmp",NULL);
                      
                      zyars = load_bitmap("zyars.bmp",NULL);
                      zyarsa = load_bitmap("zyarsa.bmp",NULL);
                      zyarsd = load_bitmap("zyarsd.bmp",NULL);
                      
                      vandy = load_bitmap("vandy.bmp",NULL);
                      vandya = load_bitmap("vandya.bmp",NULL);
                      vandyd = load_bitmap("vandya.bmp",NULL);
                      
                      mitsu = load_bitmap("mitsu.bmp",NULL);
                      mitsua = load_bitmap("mitsua.bmp",NULL);
                      mitsud = load_bitmap("mitsud.bmp",NULL);
                      
                      ryoku = load_bitmap("ryoku.bmp",NULL);
                      ryokua = load_bitmap("ryokua.bmp",NULL);
                      ryokud = load_bitmap("ryokud.bmp",NULL);
                      
                      drksp = load_bitmap("drksp.bmp",NULL);
                      drkspa = load_bitmap("drkspa.bmp",NULL);
                      drkspd = load_bitmap("drkspd.bmp",NULL);
                      
                      champion = load_bitmap("champion.bmp",NULL);
                      valley = load_bitmap("valley.bmp",NULL);
                      redraw = load_bitmap("redraw.bmp",NULL);
                      start = load_bitmap("start.bmp",NULL);
                      start = load_bitmap("failx.bmp",NULL);
}
allthings::~allthings()
{
                       destroy_bitmap(player);
                       destroy_bitmap(playera);
                       destroy_bitmap(playerd);
                       
                       destroy_bitmap(zyars);
                       destroy_bitmap(zyarsa);
                       destroy_bitmap(zyarsd);
                       
                       destroy_bitmap(vandy);
                       destroy_bitmap(vandya);
                       destroy_bitmap(vandyd);
                       
                       destroy_bitmap(mitsu);
                       destroy_bitmap(mitsua);
                       destroy_bitmap(mitsud);
                       
                       destroy_bitmap(ryoku);
                       destroy_bitmap(ryokua);
                       destroy_bitmap(ryokud);
                       
                       destroy_bitmap(drksp);
                       destroy_bitmap(drkspa);
                       destroy_bitmap(drkspd);
                       
                       destroy_bitmap(champion);
                       destroy_bitmap(valley);
                       destroy_bitmap(redraw);
                       destroy_bitmap(start);
                       destroy_bitmap(failx);
                       
}


void allthings::declaration()
{
     draw_sprite(screen,champion,0,0);
     readkey();
}

void allthings::nextlevel()
{
     rest(2500);
     if(level < 5)
     {
              level ++;
              warscreen();
     }
     else if(level >= 5)
     {
          rest(1000);
          level = 1;
          declaration();
     }
}

void allthings::resetlevel()
{
     rest(2500);
     warscreen();
}

void allthings::faillevel()
{
     rest(4000);
     level = 1;
     menu();
}    

void allthings::playerattack()
{
     clear_bitmap(screen);
     draw_sprite(screen,valley,0,0);
     draw_sprite(screen,playera,center,y);
     play_sample(wavplayera,255,0,1000,0);
          if(level == 1)
     {draw_sprite(screen,zyarsd,edeadplace,y);}
     else if(level == 2)
     {draw_sprite(screen,vandyd,edeadplace,y);}
     else if(level == 3)
     {draw_sprite(screen,mitsud,edeadplace,y);}
     else if(level == 4)
     {draw_sprite(screen,ryokud,edeadplace,y);}
     else if(level == 5)
     {draw_sprite(screen,drkspd,edeadplace,y);}
     haswon = true;
}

void allthings::attacktie()
{
     clear_bitmap(screen);
     draw_sprite(screen,valley,0,0);
     draw_sprite(screen,playera,edeadplace,y);
     draw_sprite(screen,redraw,center, 100);
     play_sample(wavplayera,255,0,1000,0);
          if(level == 1)
     {draw_sprite(screen,zyarsa,pdeadplace,y);
      play_sample(wavzyarsa,255,0,1000,0);}
     else if(level == 2)
     {draw_sprite(screen,vandya,pdeadplace,y);
      play_sample(wavvandya,255,0,1000,0);}
     else if(level == 3)
     {draw_sprite(screen,mitsua,pdeadplace,y);
      play_sample(wavmitsua,255,0,1000,0);}
     else if(level == 4)
     {draw_sprite(screen,ryokua,pdeadplace,y);
      play_sample(wavryokua,255,0,1000,0);}
     else if(level == 5)
     {draw_sprite(screen,drkspa,pdeadplace,y);
      play_sample(wavdrkspa,255,0,1000,0);}
}

void allthings::enemyattack()
{
     clear_bitmap(screen);
     draw_sprite(screen,valley,0,0);
     draw_sprite(screen,playerd,pdeadplace,y);
          if(level == 1)
     {draw_sprite(screen,zyarsa,center,y);
      play_sample(wavzyarsa,255,0,1000,0);}
     else if(level == 2)
     {draw_sprite(screen,vandya,center,y);
     play_sample(wavvandya,255,0,1000,0);}
     else if(level == 3)
     {draw_sprite(screen,mitsua,center,y);
     play_sample(wavmitsua,255,0,1000,0);}
     else if(level == 4)
     {draw_sprite(screen,ryokua,center,y);
     play_sample(wavryokua,255,0,1000,0);}
     else if(level == 5)
     {draw_sprite(screen,drkspa,center,y);
     play_sample(wavdrkspa,255,0,1000,0);}
}
void allthings::warscreen()
{
     play_sample(wavwind,255,0,1000,5);
     draw_sprite(screen,valley,0,0);
     
          if(level == 1){draw_sprite(screen,zyars,e,y);}
     else if(level == 2){draw_sprite(screen,vandy,e,y);}
     else if(level == 3){draw_sprite(screen,mitsu,e,y);}
     else if(level == 4){draw_sprite(screen,ryoku,e,y);}
     else if(level == 5){draw_sprite(screen,drksp,e,y);}
     
     draw_sprite(screen,player,p,y);
     
          if(level == 1){striketime = 1500;}
     else if(level == 2){striketime = 1300;}
     else if(level == 3){striketime = 1100;}
     else if(level == 4){striketime = 1000;}
     else if(level == 5){striketime =  900;}
     
     attacktime = rand() % 10 + 4;
     attackcount = 0;
     
     while(attackcount < attacktime)
     {
                       if(key[KEY_SPACE])
                       {
                                         failure = true;
                                         draw_sprite(screen,failx,p,y);
                       }
     }
     play_sample(attacksignal,255,1000,0,1);
     while(strikecount < striketime - 100)
     {
                       if(key[KEY_SPACE])
                       {
                                         stop_sample(wavwind);
                                         playerattack();
                                         nextlevel();
                       }
     }
     while(strikecount > striketime - 100 && strikecount < strikecount)
     {
                       if(key[KEY_SPACE])
                       {
                                         stop_sample(wavwind);
                                         attacktie();
                                         resetlevel();
                       }
     }
     if(strikecount >= striketime && haswon == false)
     {
                    stop_sample(wavwind);
                    enemyattack();
                    faillevel();
     }
}

void allthings::menu()
{
     draw_sprite(screen,start,0,0);
     if(key[KEY_ENTER])
     {
                       warscreen();
     }
}

int main()
{
    allegro_init();
    
    install_keyboard();
    
    install_timer();
    install_int_ex(attackplus,SECS_TO_TIMER(1));
    install_int_ex(strikeplus,MSEC_TO_TIMER(100));
    LOCK_VARIABLE(attackcount);
    LOCK_FUNCTION(attackplus);
    LOCK_VARIABLE(strikecount);
    LOCK_FUNCTION(strikeplus);
    
    install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL);
    
    set_color_depth(16);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);
    
    srand(time(NULL));
    
    allthings*control=new allthings;
    
    while(!key[KEY_ESC])
    {
                      control->menu();
    }
    
     delete control;
     clear_keybuf();
     return 0;
}END_OF_MAIN();




Share this post


Link to post
Share on other sites
yurian    182
Quote:
Original post by Boder
Have you made love to the debugger yet?


It went down screaming, fire bursting from it's many orfices for over one hour. Now I need help. ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this