473,322 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Allegro Game library

114 100+
Anyone here familiar with the allegro game library?

I have some code that does not work:

Expand|Select|Wrap|Line Numbers
  1. //This is a small test for allegro
  2.  
  3. #include <allegro.h>
  4.  
  5. #define WHITE makecol(255, 255, 255)
  6. BITMAP *img;
  7. char filename[50] = "D:\\clown.bmp";
  8. int x, y;
  9. char buffer[255];
  10.  
  11. int main()
  12. {
  13.     allegro_init();
  14.     install_keyboard();
  15.     install_mouse();
  16.     set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 800, 600, 0, 0);
  17.     textout_ex(screen, font, "This is a test", 0, 0, WHITE, 0);
  18.  
  19.     uszprintf(buffer, sizeof(buffer), "Resolution is = %dx%d", SCREEN_W, SCREEN_H);
  20.  
  21.     //load the sprite
  22.     img = load_bitmap(filename, NULL);
  23.  
  24.  
  25. //    set_mouse_sprite(img);
  26. //    show_mouse(img);
  27. //
  28.     textout_ex(screen, font, buffer, 0, 24, WHITE, 0); 
  29.  
  30.     //declare pos of sprite
  31.     x = SCREEN_W / 2 - 1;
  32.     y = SCREEN_H / 2 - 1;
  33.  
  34.  
  35.  
  36.  
  37.     //main loop
  38.     while(!key[KEY_ESC])
  39.     {
  40.         draw_sprite(screen, img, x, y);//note that the x and y as pos
  41.  
  42.         //check for arrow key
  43.         if(key[KEY_D])
  44.         {
  45.             if(x > SCREEN_W)
  46.             {
  47.                 x = SCREEN_W - 1;
  48.  
  49.                 uszprintf(buffer, sizeof(buffer), "The x = %d, and the y = %d", x, y);
  50.  
  51.                 textout_ex(screen, font, buffer, 200, 157, WHITE, 0);
  52.                 textout_ex(screen, font, "Tried 2 leave window", 200, 150, WHITE, 0);
  53.             }
  54.  
  55.             x = x + 1;
  56.         }
  57.     }
  58.  
  59.     destroy_bitmap(img);
  60.  
  61.     allegro_exit();
  62.  
  63.     return 0;
  64. }
  65. END_OF_MAIN()
  66.  
Basically, what im trying to do here is to have a 32 x 32 bitmap and put it on the screen and move it when the user presses the 'D' button.
Sep 25 '07 #1
10 2454
Firecore
114 100+
anyone?
I really need 2 finish my game
Sep 25 '07 #2
Savage
1,764 Expert 1GB
anyone?
I really need 2 finish my game
I'm not familiar, but can you tell me what the problem is?Perhaps we will be able to figure it out.

Is the problem that it doesn't move the image?

Savage
Sep 25 '07 #3
Studlyami
464 Expert 256MB
Yeah its a great library, but I havn't used it in a while. I'm not seeing any obvious errors. What problems are you having? All my allegro code is at home so i can't compare it when do you need this done by?
Sep 25 '07 #4
Firecore
114 100+
Yeah its a great library, but I havn't used it in a while. I'm not seeing any obvious errors. What problems are you having? All my allegro code is at home so i can't compare it when do you need this done by?
What happens is that when I press 'D', instead of going only 1 pixel to the right, it goes straight off the screen at an x of 791 or something like that.
Sep 25 '07 #5
Firecore
114 100+
Also, when I press d, it makes a trail of the image.
Sep 26 '07 #6
Studlyami
464 Expert 256MB
The trail is because you never erased the old image. You could just put a black square over it, but i remember there being a function that erases the bitmap. Ill have to check that when i get home tonight. After you capture the 'D' you need to put something up that delays the reading of the key press.

After you fix those minor problems the bitmap is going to flicker, you will need to look up double buffering or again i can give you small code sample after i get home from work.

Another suggestion that i should make is


if(x > SCREEN_W)
x = SCREEN_W - 1;

i would change to see if you can move X if so move it if not do nothing

if ((X + bitmap_width)<SCREEN_W)
x++; //move X position
else
//do nothing
Sep 26 '07 #7
Firecore
114 100+
i see.
When u find out, can u tell me what the function is to erase the sprite?
Sep 28 '07 #8
Studlyami
464 Expert 256MB
Yeah ill put it up after i get home from work.
Sep 28 '07 #9
Studlyami
464 Expert 256MB
I was wrong there isn't an erase sprite function for the screen. The easy way (for what you are trying to do) is to just erase the bitmap by using the rect fill function. then redrawing the bitmap using the new location. Later when you learn double buffering and using background images you will see how to keep your background.
Sep 29 '07 #10
Firecore
114 100+
I was wrong there isn't an erase sprite function for the screen. The easy way (for what you are trying to do) is to just erase the bitmap by using the rect fill function. then redrawing the bitmap using the new location. Later when you learn double buffering and using background images you will see how to keep your background.
I see. I just found a book on Allegro actually.
It took a bit of searching.
Its really good. The name is Game Programming all in one, third edition by Jonathan S. Harbour.

The next chapter after the one I am reading is all about double buffering.
Sep 30 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Karol | last post by:
I wonted to write programs with allegro library under Windows so I have downloaded Dev-c++, allegro library, mingw32 and dx70 for mingw. I configured allegro under mingw32 and installed Dev-c++. I...
6
by: pkochanek | last post by:
Hi, my program is using both allegro.h and windows.h, but during compilling it i'm getting a lot of errors like "conflicts with previous declaration typedef struct BITMAP BITMAP". Problem is...
7
by: Gasten | last post by:
Hello. The last weeks I've been coding a roguelike (you know, like nethack) in python using the nCurses library. Some week ago I ran into a problem: When I made the object for messagebar-output, I...
1
by: HugoScripts | last post by:
hi there, as i said i'm trying to compile a simple program that uses allegro, it's a small thing, indeed my goal was just to start using allegro, but until now i'm unable even to compile my simple...
3
PieCook
by: PieCook | last post by:
Error message: "The application has failed to start because MSVCR80.dll was not found. Re-installing the application may fix this problem." Basically, I recently purchased a game programming...
4
by: PatrickMinnesota | last post by:
I like to do fun stuff when learning a new language. I've been working with Python for a little while on real world problems mostly fixing bugs and writing a simulator for work. I was thinking...
1
by: drsmooth | last post by:
i am trying to get the allegro graphics library to work on my computer, im using visual c++ 6, i downloaded the binary version and copied the files to the right directories but then when i compile...
1
by: KefkaIIV | last post by:
I use Dev C++ and bought a book called Game Programming All in One which cost $60 - and it cannot be returned if I rip the CD out - which I did. I had every intention of buying this book, and still...
4
by: silverleaf | last post by:
I'm starting to learn how to use the Allegro library with C++ on my own. My compiler is MSVisual C++ 6.0. The book I am learning out of is "Game Programming All In One, Third Edition" by Jonathan...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.