Introduce pet-projects dir
[lcapit-junk-code.git] / pet-projects / games / allegro-demo / allegro-test.c
blob08628e48da24086c0672f0bdfa961ada33ec8e1c
1 #include <allegro.h>
3 static BITMAP *tux, *gnu, *buffer;
5 static inline void game_color_depth(void)
7 int depth;
9 depth = desktop_color_depth();
10 if (!depth)
11 depth = 32;
12 set_color_depth(depth);
15 static void game_init(void)
17 int ret;
19 allegro_init();
20 game_color_depth();
22 ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
23 if (ret) {
24 allegro_message(allegro_error);
25 exit(1);
28 install_timer();
29 install_keyboard();
30 install_mouse();
32 /* add other initializations here */
33 tux = load_bitmap("Tux.bmp", NULL);
34 if (!tux) {
35 allegro_message(allegro_error);
36 exit(1);
39 gnu = load_bitmap("gnu.bmp", NULL);
40 if (!gnu) {
41 allegro_message(allegro_error);
42 exit(1);
45 buffer = create_bitmap(SCREEN_W, SCREEN_H);
46 if (!buffer) {
47 allegro_message(allegro_error);
48 exit(1);
52 static void game_deinit(void)
54 clear_keybuf();
55 /* add other deinitializations here */
56 //FIXME: free tux, gnu and buffer
59 int main(void)
61 int col = 400;
62 int lin = 2;
64 game_init();
66 while (!key[KEY_ESC]) {
68 if (key[KEY_LEFT] && col > 0)
69 col--;
70 if (key[KEY_RIGHT] && col < (SCREEN_W - tux->w))
71 col++;
72 if (key[KEY_UP] && lin > 0)
73 lin--;
74 if (key[KEY_DOWN] && lin < (SCREEN_H - tux->h))
75 lin++;
77 clear_bitmap(buffer);
78 draw_sprite(buffer, tux, col, lin);
79 draw_sprite(buffer, gnu, 100, 40);
80 draw_sprite(screen, buffer, 0, 0);
83 game_deinit();
84 return 0;
86 END_OF_MAIN()