Post Reply 
Social Buttons
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Allegro Input
Author Message
Scorch Offline
Intermediate C++
********

Trade Count: (0)
Posts: 83
Joined: Jan 2011
Reputation: 15
Post: #1
Allegro Input
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()


Attached File(s)
.zip  Allegro02.zip (Size: 5.13 KB / Downloads: 3)
(This post was last modified: 01-20-2011 01:22 AM by Scorch.)
01-20-2011 01:20 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: