Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5.  
  6. #include "Unit1.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. TForm1 *Form1;
  11.  
  12. int x=-8;
  13. int y=-8;
  14.  
  15. int do_wygranej=12;
  16.  
  17. bool kolizja(TImage* pilka, TImage * cegla )
  18.  
  19. {
  20.  
  21. if (pilka->Left >= cegla->Left-pilka->Width &&
  22. pilka->Left <= cegla->Left+cegla->Width &&
  23. pilka->Top >= cegla->Top-pilka->Height &&
  24. pilka->Top <= cegla->Top+cegla->Height )
  25. {
  26. return true;
  27.  
  28. }
  29.  
  30. else return false;
  31.  
  32. }
  33.  
  34.  
  35. //---------------------------------------------------------------------------
  36. __fastcall TForm1::TForm1(TComponent* Owner)
  37. : TForm(Owner)
  38. {
  39. }
  40. //---------------------------------------------------------------------------
  41.  
  42. void __fastcall TForm1::Timer_pilkaTimer(TObject *Sender)
  43. {
  44. b->Left+=x;
  45. b->Top+=y;
  46.  
  47. //odbij od lewej sciany
  48. if(b->Left-5 <= tlo->Left) x = -x;
  49. // odbij od górnej sciany
  50. if (b->Top-5 <=tlo->Top) y = -y;
  51. //odbij od prawek sciany
  52. if(b->Left+b->Width+5 >= tlo->Width) x= -x;
  53.  
  54. //skucha
  55. if (b->Top >= p->Top+p->Height+15)
  56.  
  57. {
  58. Timer_pilka->Enabled = false;
  59. b->Visible = false;
  60. Button1->Caption = "Przegrałes! jeszcze raz?";
  61. Button1->Visible = true;
  62.  
  63.  
  64. } else if (b->Left > p->Left-b->Width/2 && b->Left < p->Left+p->Width &&
  65. b->Top+b->Height > p->Top)
  66.  
  67. {
  68. if (y>0) y = -y;
  69.  
  70. }
  71.  
  72. if ( do_wygranej <=0)
  73. {
  74.  
  75. Timer_pilka->Enabled = false;
  76. b->Visible = false;
  77. Button1->Caption = "Wygrana! jeszcze raz?";
  78. Button1->Visible =true;
  79. }
  80.  
  81. //blok1
  82. if (kolizja(b,Image1)&& Image1->Visible==true)
  83. {x = -x; y=-y; Image1->Visible=false; do_wygranej--;}
  84.  
  85. //blok2
  86. if (kolizja(b,Image2)&& Image2->Visible==true)
  87. {x = -x; y=-y; Image2->Visible=false; do_wygranej--;}
  88.  
  89. //blok3
  90. if (kolizja(b,Image3)&& Image3->Visible==true)
  91. {x = -x; y=-y; Image3->Visible=false; do_wygranej--;}
  92.  
  93. //blok4
  94. if (kolizja(b,Image4)&& Image4->Visible==true)
  95. {x = -x; y=-y; Image4->Visible=false; do_wygranej--;}
  96.  
  97. //blok5
  98. if (kolizja(b,Image5)&& Image5->Visible==true)
  99. {x = -x; y=-y; Image5->Visible=false; do_wygranej--;}
  100.  
  101. //blok6
  102. if (kolizja(b,Image6)&& Image6->Visible==true)
  103. {x = -x; y=-y; Image6->Visible=false; do_wygranej--;}
  104.  
  105. //blok7
  106. if (kolizja(b,Image7)&& Image7->Visible==true)
  107. {x = -x; y=-y; Image7->Visible=false; do_wygranej--;}
  108.  
  109. //blok8
  110. if (kolizja(b,Image8)&& Image8->Visible==true)
  111. {x = -x; y=-y; Image8->Visible=false; do_wygranej--;}
  112.  
  113. //blok9
  114. if (kolizja(b,Image9)&& Image9->Visible==true)
  115. {x = -x; y=-y; Image9->Visible=false; do_wygranej--;}
  116.  
  117. //blok10
  118. if (kolizja(b,Image10)&& Image10->Visible==true)
  119. {x = -x; y=-y; Image10->Visible=false; do_wygranej--;}
  120.  
  121. //blok11
  122. if (kolizja(b,Image11)&& Image11->Visible==true)
  123. {x = -x; y=-y; Image11->Visible=false; do_wygranej--;}
  124.  
  125. //blok12
  126. if (kolizja(b,Image12)&& Image12->Visible==true)
  127. {x = -x; y=-y; Image12->Visible=false; do_wygranej--;}
  128. }
  129. //---------------------------------------------------------------------------
  130.  
  131.  
  132. void __fastcall TForm1::lewoTimer(TObject *Sender)
  133. {
  134. if (p-> Left >10) p->Left-=10;
  135.  
  136. }
  137. //---------------------------------------------------------------------------
  138.  
  139. void __fastcall TForm1::prawoTimer(TObject *Sender)
  140. {
  141. if (p ->Left+p->Width <tlo ->Width -10) p->Left+=10;
  142. }
  143. //---------------------------------------------------------------------------
  144. void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
  145. TShiftState Shift)
  146. {
  147. if (Key == VK_LEFT) lewo->Enabled = true;
  148. if (Key == VK_RIGHT) prawo->Enabled = true;
  149. }
  150. void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key,
  151. TShiftState Shift)
  152. {
  153. if (Key == VK_LEFT) lewo->Enabled = false;
  154. if (Key == VK_RIGHT) prawo->Enabled = false;
  155. }
  156. //---------------------------------------------------------------------------
  157.  
  158. void __fastcall TForm1::Button1Click(TObject *Sender)
  159. {
  160. b->Left = 50;
  161. b->Top = 50;
  162.  
  163. b->Visible = true;
  164. x=-8; y=-8
  165. Timer_pilka->Enabled =true;
  166.  
  167. Button1->Visible = false;
  168. do_wygranej =12;
  169. Image1->Visible =true; Image5->Visible =true; Image9->Visible =true;
  170. Image2->Visible =true; Image6->Visible =true; Image10->Visible =true;
  171. Image3->Visible =true; Image7->Visible =true; Image11->Visible =true;
  172. Image4->Visible =true; Image8->Visible =true; Image12->Visible =true;
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement