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
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
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