Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #include <allegro.h>
  2. #include <stdbool.h>
  3. using namespace std;
  4. void Camera(int PlayerPosX, int PlayerPosY, int &cameraX, int &cameraY)
  5. {
  6.     cameraX = PlayerPosX = 320;
  7.     cameraY = PlayerPosY = 240;
  8.  
  9.     if(cameraX < 0)
  10.         cameraX = 0;
  11.  
  12.     if(cameraY < 0)
  13.         cameraY = 0;
  14. }
  15.  
  16. int main()
  17. {
  18.     allegro_init();
  19.     install_keyboard();
  20.     install_mouse();
  21.     install_timer();
  22.     set_color_depth(16);
  23.     set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
  24.  
  25.     BITMAP *buffer = create_bitmap(1280, 960);
  26.  
  27.     int x = 10;
  28.     int y = 10;
  29.     int dir = 360;
  30.     bool done = false;
  31.     int cameraX, cameraY;
  32.     cameraX = cameraY = 0;
  33.  
  34.     while(!done)
  35.     {
  36.         if(key[KEY_ESC])
  37.         {
  38.             done = true;
  39.         }
  40.  
  41.         if(key[KEY_RIGHT])
  42.         {
  43.             x += 10;
  44.             dir = 360;
  45.         }
  46.         else if(key[KEY_LEFT])
  47.         {
  48.             x -= 10;
  49.             dir =  180;
  50.         }
  51.         if(key[KEY_UP])
  52.         {
  53.             y -= 10;
  54.             dir = 90;
  55.         }
  56.         else if(key[KEY_DOWN])
  57.         {
  58.              y += 10;
  59.             dir = 270;
  60.         }
  61.  
  62.     ////CAMERA////////
  63.         rectfill(buffer,0,0,640,480,makecol(255, 0,0));
  64.         rectfill(buffer,640,480,1280,960,makecol(0,255,0));
  65.         rectfill(buffer, x, y,x,y,makecol(0,0,255));
  66.         Camera(x ,y, cameraX, cameraY);
  67.         blit(buffer, screen, cameraX, cameraY, 0, 0, 640, 480);
  68.         rest(60);
  69.         clear_bitmap(buffer);
  70.     }
  71.     //////////////////
  72.  
  73.  
  74.         return 0;
  75. }
  76. END_OF_MAIN();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement