Mail Archives: djgpp/1998/04/14/01:16:57
laine wrote:
>
> > Hi, I'm really new to allegro... can someone please
> > tell me how to simply load a bmp, jpg, or pcx, and use arrow keys
> > to move it across the screen?
> >
> Sure,
>
> Here's a little something that might help you. A little program.
Which doesn't work. Thanks for the effort, but you need to test code
like this before posting it if at all possible.
First off, you forgot to #include <allegro.h>, which is rather a vital
first step to any Allegro program.
>
> void main(void)
Please don't post examples using this syntax. ANSI C requires that
main() return an integer. See question 11.12 of the comp.lang.c FAQ
(http://www.eskimo.com/~scs/C-faq/top.html) for more information.
> the_image=load_pcx("filename.pcx",palette); // This is the function you
> // have to use for loading .pcx-files, I havent used
> // the others, so I don't know about them, but
> // surely you can find them in the documentation
It would help to test for the failure of load_pcx() here; otherwise
you'll be risking major pointer catastrophes.
> create_bitmap(10,10); // Before you can use the bitmap, you have to
> create
> // it by telling it's size.
This call is useless, since load_pcx() should have already returned a
correctly sized BITMAP *. Besides, you don't assign its value to
anything.
> set_pallete(palette); // Sets the loaded palette
Umm, where do you define this 'palette' variable? You forgot a "PALETTE
palette;" at the top of main().
>
> while(!key[KEY_ESC]){ // While no-one has hit ESC
> blit(the_image,screen,0,0,x,y,10,10);
> // Blits the image on the screen from (0,0) to
> // (x,y) - the size of the image is 10,10
It's better to use the_image->h and the_image->w instead of preset
values; load_pcx() calculates these automatically so you might as well
use them.
> // Keyboard
> if(key[KEY_LEFT]) x--; // if you press left..
> if(key[KEY_RIGHT]) x++;
> if(key[KEY_UP]) y--;
> if(key[KEY_DOWN]) y++;
> // This is easy.. just: key[KEY_name_of_the_key]
> // ie. key[KEY_ALT] or key[KEY_A]
This rapid blitting without waiting for vsync() could cause a very
messed up image.
>
> }
>
> allegro_exit(); // Makes everything as it was before
> }
Add a return 0; before leaving main().
>
> There might be some faults in this program and it's not very good.
> It doesn't use double buffering (wich you should use..) or any other
> nice stuff. But it does what it's supposed to do (I hope so, I haven't
> tested it, I just wrote it here for you). Hope you find something
> in it. Good luck.
With code as dangerous to your computer's health as graphics is, you
should always test examples before posting. Please take this as
constructive criticism; I don't mean to offend.
l8r
--
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com |
| Proud owner of what might one | http://www.cs.com/fighteer/ |
| day be a spectacular MUD... | ICQ UIN#: 7406319 |
| Plan: To make Bill Gates suffer | HEAT User ID: Fighteer |
---------------------------------------------------------------------
- Raw text -