| Help: Basic Sprite Drawing | ||||||||||
| < -------------------------------------------------------------------------------------------------------------------> | ||||||||||
| Main News Links Gunman Downloads Help Filez |
||||||||||
| /* This code can be copyed directly into a C file and compiled and linked with allegro. It works no my mingw setup and DJGPP. I made this as a post too some one on www.allegro.cc and now its on this site 4 every one 2 see :-) */ //Basic sprite drawing by Dennis Dryden #include <stdio.h> #include <allegro.h> int main() { int x=0; int y=0; //hold the x and y screen cords PALETTE pal; BITMAP *sprite; BITMAP *buffer; allegro_init(); install_keyboard(); /* Load the bitmap and the bitmap's Palette. */ sprite = load_bitmap("bob.bmp",pal); /* Now check if it was loaded correctly */ if (!sprite) { allegro_exit(); printf("Couldn't load: 'bitmap.bmp'\n"); return 1; } /* The below section will close the program if the gfx mode can't be set */ if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) { allegro_exit(); printf("Couldn't set mode 320x200x8\n"); return 1; } buffer=create_bitmap(SCREEN_W,SCREEN_H); //set up the screen buffer /* This is where u draw everything be4 u put it on the screen */ set_palette(pal); draw_sprite(screen,sprite,0,0); do { clear(buffer); if(key[KEY_RIGHT]) x++; if(key[KEY_LEFT]) x--; if(key[KEY_DOWN]) y++; if(key[KEY_UP]) y--; /*redraws the sprite on the buffer*/ draw_sprite(buffer, sprite, x, y); blit(buffer, screen,0,0,0,0,SCREEN_W,SCREEN_H); } while (!key[KEY_ESC]); allegro_exit(); return 0; } END_OF_MAIN() /*The above line must be added in all allegro programs so that it will compile on windows and dos and Mac and Linux and...*/ /* Pyroboy dislexia at its best! come to www.nuttersoft.com */ |
||||||||||
| < -------------------------------------------------------------------------------------------------------------------> | ||||||||||