This is going to expand on the previous thread.
Here's a few new functions you will need to know.
key[KEY_] is used with if statements to determine if a key was pressed. An example is if(key[KEY_UP]) I can do something if the up key is pressed.
textout_ex(); takes many parameters.
textout_ex(where_to_draw, font_type, "Text to draw", x_coord, y_coord, color, background_color);
In that function is the makecol() function. It takes 3 rgb parameters of red, green, blue. Any of those range from 0 to 255.
[code]
#include <allegro.h>
short x = 30;//Coordinates for drawing
short y = 20;
int main()
{
allegro_init();
install_keyboard();
set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
while(!key[KEY_ESC])
{
clear_keybuf();//Clears input of keys
if(key[KEY_UP]) y-=5;
if(key[KEY_DOWN]) y+=5;
if(key[KEY_LEFT]) x-=5;
if(key[KEY_RIGHT]) x+=5;
textout_ex(screen, font, "******", x, y, makecol(255, 0, 0), makecol(0, 0, 0));
rest(50);//Prevent flickering
}
return 0;
}
END_OF_MAIN()
[/code]
Here's a few new functions you will need to know.
key[KEY_] is used with if statements to determine if a key was pressed. An example is if(key[KEY_UP]) I can do something if the up key is pressed.
textout_ex(); takes many parameters.
textout_ex(where_to_draw, font_type, "Text to draw", x_coord, y_coord, color, background_color);
In that function is the makecol() function. It takes 3 rgb parameters of red, green, blue. Any of those range from 0 to 255.
[code]
#include <allegro.h>
short x = 30;//Coordinates for drawing
short y = 20;
int main()
{
allegro_init();
install_keyboard();
set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
while(!key[KEY_ESC])
{
clear_keybuf();//Clears input of keys
if(key[KEY_UP]) y-=5;
if(key[KEY_DOWN]) y+=5;
if(key[KEY_LEFT]) x-=5;
if(key[KEY_RIGHT]) x+=5;
textout_ex(screen, font, "******", x, y, makecol(255, 0, 0), makecol(0, 0, 0));
rest(50);//Prevent flickering
}
return 0;
}
END_OF_MAIN()
[/code]