Advertisement
Guest User

Untitled

a guest
Apr 10th, 2016
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 KB | None | 0 0
  1. #include <graphics.h>
  2. #include <windows.h>
  3. #include <iostream>
  4. #include <stdio.h>
  5. #include <winbgim.h>
  6. #include <process.h>
  7.  
  8. using namespace std;
  9.  
  10. void ruch();
  11. class Obiekt;
  12.  
  13. int licz;
  14. int x, y, przyspieszenie=10, szybkosc=5;
  15. int szerOkna, wysOkna;
  16.  
  17. class Obiekt
  18. {
  19. public:
  20.     int x, y, w, h;
  21.     int speed;
  22.  
  23.     enum Direction
  24.     {
  25.      gora,
  26.      dol,
  27.      prawo,
  28.      lewo
  29.     };
  30.  
  31.     Direction direction;
  32.  
  33.     Obiekt(int iks=0, int igrek=0, int width=15, int height=15, int sp=1)
  34.     {
  35.         x = iks;
  36.         y = igrek;
  37.         w = width;
  38.         h = height;
  39.         speed = sp;
  40.     }
  41. };
  42.  
  43. Obiekt obiekty[10];
  44. obiekty[0].direction = Obiekt.Direction.dol;
  45.  
  46.  
  47. int main( )
  48. {
  49.     DWORD        mode;
  50.     INPUT_RECORD event;
  51.  
  52.     initwindow(400, 400, "Graficzny Program >.<", 80, 250);
  53.     szerOkna = getwindowwidth();
  54.     wysOkna = getwindowheight();
  55.     HANDLE hstdin = GetStdHandle( STD_INPUT_HANDLE );
  56.  
  57.     GetConsoleMode( hstdin, &mode );
  58.  
  59.     SetConsoleMode( hstdin, 0 );
  60.  
  61.  while (true)
  62.     {
  63.     Sleep(10);
  64.     {
  65.         ruch();
  66.     }
  67.     setbkcolor(123);
  68.         if (WaitForSingleObject( hstdin, 0 ) == WAIT_OBJECT_0)
  69.         {
  70.             DWORD count;
  71.  
  72.             ReadConsoleInput( hstdin, &event, 1, &count );
  73.  
  74.             if(event.Event.KeyEvent.wVirtualKeyCode == VK_LEFT){
  75.             printf("lewo\n");
  76.             x-= szybkosc;
  77.             ruch();
  78.             }
  79.             if(event.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT){
  80.             printf("prawo\n");
  81.             x+= szybkosc;
  82.             ruch();
  83.             }
  84.             if(event.Event.KeyEvent.wVirtualKeyCode == VK_DOWN){
  85.             printf("dol\n");
  86.             y+= szybkosc;
  87.             ruch();
  88.             }
  89.             if(event.Event.KeyEvent.wVirtualKeyCode == VK_UP){
  90.             printf("gora\n");
  91.             y-= szybkosc;
  92.             ruch();
  93.             }
  94.         }
  95.     }
  96.  
  97.     while (!kbhit( ))
  98.     {
  99.         delay(200);
  100.     }
  101.     return 0;
  102. }
  103.  
  104. void ruch()
  105. {
  106.   cleardevice();
  107.   for(int i=0; i<(sizeof(obiekty)/sizeof(*obiekty)); i++)
  108.   {
  109.    if(i == 0)
  110.         bar(x, y, x+15, y+15);
  111.     else
  112.     bar(obiekty[i].x, obiekty[i].y, obiekty[i].x+obiekty[i].w, obiekty[i].y+obiekty[i].h);
  113.  
  114.     if(obiekty[i].direction == Obiekt.Direction.dol)
  115.         obiekty[i].y+=obiekty[i].speed;
  116.  
  117.     else if(obiekty[i].direction == Obiekt.Direction.gora)
  118.         obiekty[i].y-=obiekty[i].speed;
  119.  
  120.     else if(obiekty[i].direction == Obiekt.Direction.lewo)
  121.         obiekty[i].x-=obiekty[i].speed;
  122.  
  123.     else if(obiekty[i].direction == Obiekt.Direction.prawo)
  124.         obiekty[i].x+=obiekty[i].speed;
  125.   }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement