Advertisement
alfarovivecrj

Untitled

Jun 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.58 KB | None | 0 0
  1. #pragma once
  2. #include "string.h"
  3. #include<math.h>
  4. namespace Project1 {
  5.  
  6. using namespace System;
  7. using namespace System::ComponentModel;
  8. using namespace System::Collections;
  9. using namespace System::Windows::Forms;
  10. using namespace System::Data;
  11. using namespace System::Drawing;
  12.  
  13. /// <summary>
  14. /// Summary for MyForm
  15. /// </summary>
  16. public ref class MyForm : public System::Windows::Forms::Form
  17. {
  18. public:
  19. MyForm(void)
  20. {
  21. InitializeComponent();
  22. //
  23. //TODO: Add the constructor code here
  24. //
  25. jugador1 = new char[50];
  26. jugador2 = new char[50];
  27. w1=w2=h1=h2=0;
  28. x1=x2=y1=y2=0;
  29. }
  30.  
  31. protected:
  32. /// <summary>
  33. /// Clean up any resources being used.
  34. /// </summary>
  35. ~MyForm()
  36. {
  37. if (components)
  38. {
  39. delete components;
  40. }
  41. }
  42. private: System::ComponentModel::IContainer^ components;
  43. protected:
  44.  
  45. private:
  46. /// <summary>
  47. /// Required designer variable.
  48. /// </summary>
  49.  
  50.  
  51. char *jugador1,*jugador2;
  52. int w1,w2,h1,h2;
  53. int x1,x2,y1,y2;
  54. Bitmap ^img1;
  55. Bitmap ^img2;
  56. int r1,r2,r3,r4;
  57. int centro1,centro2,centro3,centro4;
  58. private: System::Windows::Forms::Label^ label1;
  59. private: System::Windows::Forms::Label^ label2;
  60. private: System::Windows::Forms::Label^ label3;
  61. private: System::Windows::Forms::Label^ label4;
  62. private: System::Windows::Forms::Label^ label5;
  63. private: System::Windows::Forms::Label^ label6;
  64. private: System::Windows::Forms::Timer^ timer1;
  65.  
  66.  
  67.  
  68. #pragma region Windows Form Designer generated code
  69. /// <summary>
  70. /// Required method for Designer support - do not modify
  71. /// the contents of this method with the code editor.
  72. /// </summary>
  73. void InitializeComponent(void)
  74. {
  75. this->components = (gcnew System::ComponentModel::Container());
  76. this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
  77. this->label1 = (gcnew System::Windows::Forms::Label());
  78. this->label2 = (gcnew System::Windows::Forms::Label());
  79. this->label3 = (gcnew System::Windows::Forms::Label());
  80. this->label4 = (gcnew System::Windows::Forms::Label());
  81. this->label5 = (gcnew System::Windows::Forms::Label());
  82. this->label6 = (gcnew System::Windows::Forms::Label());
  83. this->SuspendLayout();
  84. //
  85. // timer1
  86. //
  87. this->timer1->Enabled = true;
  88. this->timer1->Tick += gcnew System::EventHandler(this, &MyForm::timer1_Tick);
  89. //
  90. // label1
  91. //
  92. this->label1->AutoSize = true;
  93. this->label1->Location = System::Drawing::Point(705, 27);
  94. this->label1->Name = L"label1";
  95. this->label1->Size = System::Drawing::Size(35, 13);
  96. this->label1->TabIndex = 0;
  97. this->label1->Text = L"label1";
  98. //
  99. // label2
  100. //
  101. this->label2->AutoSize = true;
  102. this->label2->Location = System::Drawing::Point(516, 26);
  103. this->label2->Name = L"label2";
  104. this->label2->Size = System::Drawing::Size(35, 13);
  105. this->label2->TabIndex = 1;
  106. this->label2->Text = L"label2";
  107. //
  108. // label3
  109. //
  110. this->label3->AutoSize = true;
  111. this->label3->Location = System::Drawing::Point(757, 301);
  112. this->label3->Name = L"label3";
  113. this->label3->Size = System::Drawing::Size(35, 13);
  114. this->label3->TabIndex = 2;
  115. this->label3->Text = L"label3";
  116. //
  117. // label4
  118. //
  119. this->label4->AutoSize = true;
  120. this->label4->Location = System::Drawing::Point(36, 300);
  121. this->label4->Name = L"label4";
  122. this->label4->Size = System::Drawing::Size(35, 13);
  123. this->label4->TabIndex = 3;
  124. this->label4->Text = L"label4";
  125. //
  126. // label5
  127. //
  128. this->label5->AutoSize = true;
  129. this->label5->Location = System::Drawing::Point(48, 353);
  130. this->label5->Name = L"label5";
  131. this->label5->Size = System::Drawing::Size(35, 13);
  132. this->label5->TabIndex = 4;
  133. this->label5->Text = L"label5";
  134. //
  135. // label6
  136. //
  137. this->label6->AutoSize = true;
  138. this->label6->Location = System::Drawing::Point(763, 340);
  139. this->label6->Name = L"label6";
  140. this->label6->Size = System::Drawing::Size(35, 13);
  141. this->label6->TabIndex = 5;
  142. this->label6->Text = L"label6";
  143. //
  144. // MyForm
  145. //
  146. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  147. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  148. this->BackColor = System::Drawing::Color::White;
  149. this->ClientSize = System::Drawing::Size(840, 586);
  150. this->Controls->Add(this->label6);
  151. this->Controls->Add(this->label5);
  152. this->Controls->Add(this->label4);
  153. this->Controls->Add(this->label3);
  154. this->Controls->Add(this->label2);
  155. this->Controls->Add(this->label1);
  156. this->Name = L"MyForm";
  157. this->Text = L"Use las teclas direccionales para picachu y las teclas \"A\"W\"S\"D\" para mover el ot"
  158. L"ro personajes";
  159. this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
  160. this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::MyForm_Paint);
  161. this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &MyForm::MyForm_KeyDown);
  162. this->ResumeLayout(false);
  163. this->PerformLayout();
  164.  
  165. }
  166. #pragma endregion
  167. private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
  168.  
  169. //copia el nombre de las imagenes de los jugadores
  170. strcpy(jugador1, "picachu1.png");
  171. strcpy(jugador2, "pokemon.png");
  172. //Leemos el archivo imagen
  173. img1 = gcnew Bitmap(gcnew String(jugador1));
  174. img2 = gcnew Bitmap(gcnew String(jugador2));
  175.  
  176.  
  177. w1 = img1->Width;
  178. h1 = img1->Height;
  179. w2 = img2->Width;
  180. h2 = img2->Height;
  181.  
  182.  
  183. //posiciones iniciales
  184. x1 = 10;
  185. x2 = 500;
  186. y1 = 20;
  187. y2 = 20;
  188. //radios de las imagenes
  189. r1 = h1 / 2;
  190. r2 = h2 / 2;
  191. r3 = w1 / 2;
  192. r4 = w2 / 2;
  193.  
  194. centro1 = x1 + r1;
  195. centro2 = x2 + r2;
  196.  
  197.  
  198. }
  199. private: System::Void MyForm_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
  200.  
  201. //lienzo
  202. Graphics ^gr = this->CreateGraphics();
  203. //dibuja jugadores
  204.  
  205. gr->DrawImage(img1,x1,y1);
  206. gr->DrawImage(img2,x2,y2);
  207.  
  208. }
  209. private: System::Void MyForm_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
  210.  
  211.  
  212. if (e->KeyCode == Keys::W)
  213. y2-=40;
  214. if (e->KeyCode == Keys::S)
  215. y2+=40;
  216. if (e->KeyCode == Keys::A)
  217. x2-=40;
  218. if (e->KeyCode == Keys::D)
  219. x2+=40;
  220.  
  221.  
  222. if (e->KeyCode == Keys::Up)
  223. y1-=40;
  224. if (e->KeyCode == Keys::Down)
  225. y1 += 40;
  226. if (e->KeyCode == Keys::Right)
  227. x1+= 40;
  228. if (e->KeyCode == Keys::Left)
  229. x1-=40;
  230.  
  231.  
  232.  
  233. }
  234. private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
  235.  
  236. //lienzo
  237. Graphics ^gr = this->CreateGraphics();
  238. //buffer
  239. System::Drawing::BufferedGraphicsContext ^bc= BufferedGraphicsManager::Current;
  240. System::Drawing::BufferedGraphics ^bg= bc->Allocate(gr,this->ClientRectangle);
  241. bg->Graphics->Clear(Color::White);
  242.  
  243.  
  244.  
  245. //dibuja jugadores
  246. bg->Graphics->DrawImage(img1,x1,y1);
  247. bg->Graphics->DrawImage(img2,x2,y2);
  248.  
  249. //verifica colision
  250. centro1= y1+r1;
  251. centro2= y2+r2;
  252.  
  253. centro3 = x1 + r3;
  254. centro4 = x2 + r4;
  255. if(r1+r2>abs(centro2-centro1)&& r3 + r4 > abs(centro4 - centro3))
  256. label1->Text="Colision";
  257. else
  258. label1->Text="No hay Colision";
  259. /* if (r3 + r4 > centro4 - centro3)
  260. label2->Text = "Colision";
  261. else
  262. label2->Text = "No hay Colision";
  263. */
  264. label3->Text = Convert::ToString(x2);
  265. label4->Text = Convert::ToString(x1);
  266. label5->Text = Convert::ToString(y1);
  267. label6->Text = Convert::ToString(y2
  268. );
  269.  
  270. bg->Render(gr);
  271. delete bc;
  272. delete bg;
  273. delete gr;
  274.  
  275. }
  276. };
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement