Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: waste on February 17, 2014

Title: Allegro help !
Post by: waste on February 17, 2014
hi all ,

I'm begginer in demoscene effects ( though i used to do that on z80 assembly ...)  , 

i'm trying to merge two source code i 've found ,  one starfield and  one scroller text (no sine first) , using allegro for both

the two codes compile and execute well, but when i want to insert my scroller text with the starfield , the program stops ,

i can provide source code by mail or mp,  here are sections  i suppose that cause the crash,  (when i put the line "problem 1,2,3" in comments , text scroller runs without starfield )   

sorry for my english ... i hope it's quite correct

Main function

Code: [Select]
int main(int argc, char *argv[]) {
 
    int framecount;
    framecount=0;
 
    allegro_init();       
install_keyboard();   
 
    LOCK_VARIABLE(speed_counter);
    LOCK_FUNCTION(increment_speed_counter);
    install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));
 
set_color_depth(8) ;   // 8 bit colour
if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, screen_x, screen_y, 0, 0)<0)
{
    //set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); 
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, screen_w, screen_h, 0, 0);
 
     allegro_message("Failure to init video mode!\n%s\n", allegro_error);
    exit(1); // force abort
}
 
  off_screen = create_bitmap(screen_x, screen_y); 
 
 
  Init_Music();
    Init_Font();
    install_timer();
    Play_Music();
    srand(time(NULL));
Star star[maxstars];     // problem one !
 
 while ((!key[KEY_ESC])&&(!key[KEY_SPACE]))
    {
 
        clear_bitmap(off_screen);
 
 
 
 
 
        DrawString((framecount % 2550)-820,508,"TEST SCROLL LEFT TO RIGHT...NO SINUS EFFECT FIRST....");  // draw scroller
        framecount+=6;
        vsync();
       blit(off_screen, screen, 0, 0, 0, 0, screen_x, screen_y); 
        rest(1);
    };
    while(speed_counter > 0)
        {
         for(int i = 0; i < maxstars; ++i)
                            {
                                    star[i].movestars();                // problem two !
                            }
                            speed_counter --;
         }
 
        draw_sprite(screen, buffer, 0, 0);       // third problem , linked to the Star Class, supposed to draw starfield
 
 
    destroy_bitmap(off_screen);     
    Kill_Music();
    Kill_Font();
    remove_timer();     
return 0;     
}     
END_OF_MAIN();


here is the Star Class that causes problems

Code: [Select]

 
Star::Star()
{
            posx = (rand() % screen_w);
            posy = (rand() % screen_h);
            speed = (rand() % 5) + 1;
            putpixel(buffer, posx, posy, makecol(255, 255, 255));
 
void Star::movestars()
{
          putpixel(buffer, posx, posy, makecol(0, 0, 0));
          posx -= speed;
          if (posx <= 0)
          {
             posx = screen_w;
          }
          putpixel(buffer, posx, posy, makecol(255, 255, 255 ));
}

thanks in advance for your advices


Title: Re: Allegro help !
Post by: waste on February 18, 2014
ooops , buffer init missing

Code: [Select]
buffer = create_bitmap(screen_w, screen_h);
it's better now though i don't have the two effects at same time ..... problem with While ....
Title: Re: Allegro help !
Post by: waste on February 20, 2014
that's ok now, 


thanks even if i feel abit alone  !!

Title: Re: Allegro help !
Post by: Gore Motel on February 20, 2014
Yo! I glanced over the code snippets, but I can't really help much since I never used Allegro and haven't written any C++ code since my college years. Maybe you could post the full source if you're still having trouble.

And your English is fine, I understood what you wrote.
Title: Re: Allegro help !
Post by: Yaloopy on February 20, 2014
Glad you figured out the solution. If you want to post long source code you could attach it as a .txt file with your post.
Title: Re: Allegro help !
Post by: Hotshot on February 20, 2014
I used do allergo years ago but now they change bit which is Allergo 5 that I am not try it yet.

Just wondering what IDE do you used?

Cant see anythings wrong with your code but dont understand why your program crash!
Title: Re: Allegro help !
Post by: waste on February 24, 2014
Title: Re: Allegro help !
Post by: Hotshot on February 26, 2014
Hello waste,

You have done very well to do it on your own :)

 :clap:

It is good to learn from it as being it is Allergo 5 and the code of itself is really good!

I used CodeBlocks IDE at the moment :)

Number 1 Challange - Try Change Starfield going up
Number 2 Challange - Try make Font scrolling in Sine wave :)
Number 3 Challange - Try make 2 rainbow bar from top and one middle with starfield in the middle :)

Title: Re: Allegro help !
Post by: waste on February 28, 2014
 :carrot:

thanks !! , i also begin PureBasic  at same time !!  so as soon as possible , i will upgrade my c++ allegro projects with all of that  !! it 's more  difficult in c++ for me !!

i waste a lot of time to set my IDE configured !! with libs, headers etc ...
Title: Re: Allegro help !
Post by: Hotshot on February 28, 2014
Quote
thanks !! , i also begin PureBasic  at same time !!  so as soon as possible , i will upgrade my c++ allegro projects with all of that  !! it 's more  difficult in c++ for me !!


Purebasic is where is like straight to the point and get job done quicker but learning C++ is good things as it is hard to master them which take time!

Quote
i waste a lot of time to set my IDE configured !! with libs, headers etc ...

I hate that as I wish there was IDE Allergo(someone who make em) where it setup everythings for ya on every time you make project which would be good otherwise it would be too much hassle like you say

I found Allergo 5 Tutorials and I will post it on either Useful links, or general chat soon or C / C++ /C# :)