Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <allegro.h>
- #include <cmath>
- #include <stdlib.h>
- #include <time.h> //these are the header files it inherits
- #include <vector>
- #include <string>
- #include <sstream>
- #include <iostream>
- //this is how allegro draws stuff to the screen:
- // all objects have their own position ->>>> draw each objects bitmap to a 'back buffer' this is so it doesn't draw to the screen before everything has been rendered
- // ->>>>> next it will draw this bitmap directly to the screen
- // if you don't do it this way your screen will just constantly be flashing every time an object is drawn to it
- int setUpAllegro();
- int main()
- {
- setUpAllegro(); //calls the set up allegro function
- BITMAP *buffer;
- BITMAP *test;
- srand(time(NULL)); //initliases the random call
- test = load_bitmap("NAME.bmp", NULL);
- buffer = create_bitmap(SCREEN_W, SCREEN_H); //creates the buffer to stop screen flicker
- while (!key[KEY_ESC]) //this is the main game loop where all the different game functions will occur
- {
- clear_to_color(buffer, 0); //clears the buffer to colour black
- masked_blit(test, buffer, 0, 0, mouse_x, mouse_y, 32, 32); //this function draws the bitmap image to the back buffer where the mouse position is. The 32 values are the size of the bitmap;
- //mouse_x is mouse x position
- //mouse_y is mouse y position
- //mouse_b & 1 is left click
- //mouse_b & 2 is right click
- //key[KEY_W] gets if the w key is pressed
- int bitmapX, bitmapY;
- //for example
- if(key[KEY_W])
- {
- bitmapX += 1;
- blit(test, buffer, 0, 0, bitmapX, bitmapY, 10, 10); //this will basivcally draw a bitmap to the screen if the key w is pressed. It will draw the bitmap at the bitmapX&Y positions. As it is not masked blit it will not remove any magenta on the bitmap. 10, 10 is the size of the bitmap.
- }
- //key[KEY_UP] -- this is for the up arrow
- //once you have blit or masked blit or the objects you want to display on the screen then you:
- blit(buffer, screen, 0, 0, 0, 0, SCREEn_W, SCREEN_H); //this draws the back buffer to the screen
- }
- allegro_exit(); //exits allegro
- return 0;
- }
- END_OF_MAIN();
- int setUpAllegro() //sets up allegro
- {
- int retval = 0;
- int ret;
- set_color_depth(32);
- if (allegro_init() != 0)
- {
- retval = -1;
- }
- else
- {
- install_keyboard();
- install_timer(); //installs the required functions
- install_mouse();
- install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, "A");
- ret = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 880, 600, 0, 0);
- if (ret != 0)
- {
- allegro_message(allegro_error);
- retval = -2;
- }
- else
- {
- textprintf(screen, font, 0, 0, makecol(255, 255, 255), "%dx%d", SCREEN_W, SCREEN_H);
- }
- }
- return retval;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement