Advertisement
BlyatBeard42

GRA_kor_movement{CLASS}

Nov 22nd, 2019
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <graphics.h>
  3. #include <time.h>
  4. using namespace std;
  5. class Pont
  6. {
  7. protected:
  8. int x,y,szin;
  9. public:
  10. Pont(int xx=0,int yy=0,int sz=MAGENTA)
  11. {
  12. x=xx;
  13. y=yy;
  14. szin=sz;
  15. }
  16. void beolvas();
  17. void kirajzol()
  18. {
  19. putpixel(x,y,szin);
  20. }
  21. void torol()
  22. {
  23. putpixel(x,y,BLACK);
  24. }
  25. void fel(int h)
  26. {
  27. y-=h;
  28. }
  29. void le(int h)
  30. {
  31. y+=h;
  32. }
  33. void jobb(int h)
  34. {
  35. x+=h;
  36. }
  37. void bal(int h)
  38. {
  39. x-=h;
  40. }
  41. void szinv(int sz)
  42. {
  43. szin=sz;
  44. }
  45. };
  46. void Pont::beolvas()
  47. {
  48. cout<<"Addja ma 300 dollart!(Es koordinatakat+szin):";
  49. cin>>x>>y>>szin;
  50. }
  51. class Kor:public Pont
  52. {
  53. private:
  54. int r;
  55. public:
  56. Kor(int xx=0,int yy=0,int sz=MAGENTA,int rr=50):Pont(xx,yy,sz)
  57. {
  58. r=rr;
  59. }
  60. void kirajzol();
  61. void torol();
  62. };
  63. void Kor::kirajzol()
  64. {
  65. setcolor(szin);
  66. circle(x,y,r);
  67. }
  68. void Kor::torol()
  69. {
  70. setcolor(BLACK);
  71. circle(x,y,r);
  72. }
  73. int main()
  74. {
  75. int gdriver=DETECT, gmode;
  76. initgraph(&gdriver, &gmode, "");
  77. srand(time(NULL));
  78. Kor k(getmaxx()/2,getmaxy()/2,rand()%15+1,50);
  79. k.kirajzol();
  80. int kilep=1,h=5;
  81. while(kilep)
  82. {
  83. if(GetAsyncKeyState(VK_UP)) k.fel(h);
  84. if(GetAsyncKeyState(VK_DOWN)) k.le(h);
  85. if(GetAsyncKeyState(VK_LEFT)) k.bal(h);
  86. if(GetAsyncKeyState(VK_RIGHT)) k.jobb(h);
  87. if(GetAsyncKeyState('R')) kilep=0;
  88. k.kirajzol();
  89. Sleep(10);
  90. }
  91. getch();
  92. return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement