Well I've made some code for the menu background to my game, which I will double buffer the menu text above, It generates a random set of blue lines (looks better than it sounds). Well, anyway, I want to cycle through the colors of the background [as an animation], instead of it being blue, by changing the pallete.
Can anybody help me?
Code:
#include <allegro.h> // Uses allegro.
#include <time.h> // Time.h needed for random numbers.
#include <stdlib.h> // Stdlib needed for rand()
#define SW 640 // Screen width
#define SH 480 // Screen height
int main( void )
{
int y = 0;
int color = 0;
int z;
srand(time(NULL)); // Initialise randomness.
allegro_init(); // Initialise the
set_color_depth(32); // graphics
set_gfx_mode(GFX_AUTODETECT, SW, SH, 0, 0); // mode.
install_keyboard(); // Get keyboard ready.
BITMAP *bmp = create_bitmap(SW, SH); // Make the bitmap.
clear_bitmap(bmp); // Clear it.
while(y < SH) // Loop while y is less
{ // Than screen height.
hline(bmp, 0, y, SW, color); // Draw line to bmp.
y++; // Increase y.
z = rand() % 30; // Generate random number.
if(z <= 15)
{
if(color < 255)
color+= 3;
else
color-=3;
}
else
{
if(color > 0)
color-= 3;
else
color+=3;
}
}
blit(bmp, screen, 0, 0, 0, 0, SW, SH); // Draw BMP to screen.
while(!key[KEY_ESC]) // Wait till esc, then quit.
poll_keyboard(); // This is needed for some.
allegro_exit(); // Bye!
return 0;
}
END_OF_MAIN();