Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "string.h"
- #include <math.h>
- namespace Project1 {
- using namespace System;
- using namespace System::ComponentModel;
- using namespace System::Collections;
- using namespace System::Windows::Forms;
- using namespace System::Data;
- using namespace System::Drawing;
- /// <summary>
- /// Summary for MyForm
- /// </summary>
- public ref class MyForm : public System::Windows::Forms::Form
- {
- public:
- MyForm(void)
- {
- InitializeComponent();
- //
- //TODO: Add the constructor code here
- //
- jugador1 = new char[50];
- jugador2 = new char[50];
- w1=w2=h1=h2=0;
- x1=x2=y1=y2=0;
- }
- protected:
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- ~MyForm()
- {
- if (components)
- {
- delete components;
- }
- }
- private: System::ComponentModel::IContainer^ components;
- protected:
- private:
- /// <summary>
- /// Required designer variable.
- /// </summary>
- char *jugador1,*jugador2;
- int w1,w2,h1,h2;
- int x1,x2,y1,y2;
- Bitmap ^img1;
- Bitmap ^img2;
- int debajo1,arriba2,arriba1,debajo2;
- int derecha1, izquierda2;
- int izquierda1, derecha2;
- private: System::Windows::Forms::Label^ label1;
- private: System::Windows::Forms::Label^ label2;
- private: System::Windows::Forms::Label^ label3;
- private: System::Windows::Forms::Label^ label4;
- private: System::Windows::Forms::Label^ label5;
- private: System::Windows::Forms::Label^ label6;
- private: System::Windows::Forms::Timer^ timer1;
- #pragma region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- void InitializeComponent(void)
- {
- this->components = (gcnew System::ComponentModel::Container());
- this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
- this->label1 = (gcnew System::Windows::Forms::Label());
- this->label2 = (gcnew System::Windows::Forms::Label());
- this->label3 = (gcnew System::Windows::Forms::Label());
- this->label4 = (gcnew System::Windows::Forms::Label());
- this->label5 = (gcnew System::Windows::Forms::Label());
- this->label6 = (gcnew System::Windows::Forms::Label());
- this->SuspendLayout();
- //
- // timer1
- //
- this->timer1->Enabled = true;
- this->timer1->Tick += gcnew System::EventHandler(this, &MyForm::timer1_Tick);
- //
- // label1
- //
- this->label1->AutoSize = true;
- this->label1->Location = System::Drawing::Point(705, 27);
- this->label1->Name = L"label1";
- this->label1->Size = System::Drawing::Size(35, 13);
- this->label1->TabIndex = 0;
- this->label1->Text = L"label1";
- //
- // label2
- //
- this->label2->AutoSize = true;
- this->label2->Location = System::Drawing::Point(516, 26);
- this->label2->Name = L"label2";
- this->label2->Size = System::Drawing::Size(35, 13);
- this->label2->TabIndex = 1;
- this->label2->Text = L"label2";
- //
- // label3
- //
- this->label3->AutoSize = true;
- this->label3->Location = System::Drawing::Point(39, 274);
- this->label3->Name = L"label3";
- this->label3->Size = System::Drawing::Size(35, 13);
- this->label3->TabIndex = 2;
- this->label3->Text = L"label3";
- //
- // label4
- //
- this->label4->AutoSize = true;
- this->label4->Location = System::Drawing::Point(757, 274);
- this->label4->Name = L"label4";
- this->label4->Size = System::Drawing::Size(35, 13);
- this->label4->TabIndex = 3;
- this->label4->Text = L"label4";
- //
- // label5
- //
- this->label5->AutoSize = true;
- this->label5->Location = System::Drawing::Point(39, 301);
- this->label5->Name = L"label5";
- this->label5->Size = System::Drawing::Size(35, 13);
- this->label5->TabIndex = 4;
- this->label5->Text = L"label5";
- //
- // label6
- //
- this->label6->AutoSize = true;
- this->label6->Location = System::Drawing::Point(757, 301);
- this->label6->Name = L"label6";
- this->label6->Size = System::Drawing::Size(35, 13);
- this->label6->TabIndex = 5;
- this->label6->Text = L"label6";
- //
- // MyForm
- //
- this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
- this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
- this->BackColor = System::Drawing::Color::White;
- this->ClientSize = System::Drawing::Size(840, 586);
- this->Controls->Add(this->label6);
- this->Controls->Add(this->label5);
- this->Controls->Add(this->label4);
- this->Controls->Add(this->label3);
- this->Controls->Add(this->label2);
- this->Controls->Add(this->label1);
- this->Name = L"MyForm";
- this->Text = L"Use las teclas direccionales para picachu y las teclas \"A\"W\"S\"D\" para mover el ot"
- L"ro personajes";
- this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
- this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::MyForm_Paint);
- this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &MyForm::MyForm_KeyDown);
- this->ResumeLayout(false);
- this->PerformLayout();
- }
- #pragma endregion
- private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
- //copia el nombre de las imagenes de los jugadores
- strcpy(jugador1,"picachu1.png");
- strcpy(jugador2,"pokemon.png");
- //Leemos el archivo imagen
- img1 = gcnew Bitmap(gcnew String(jugador1));
- img2 = gcnew Bitmap(gcnew String(jugador2));
- w1=img1->Width;
- h1=img1->Height;
- w2=img2->Width;
- h2=img2->Height;
- //posiciones iniciales
- x1 = 50;
- x2 = 550;
- y1 = 150;
- y2 = 370;
- //radios de las imagenes
- //r1=w1/2;
- //r2=w2/2;
- izquierda1=x1 ;
- derecha2 = x2 + w2;
- debajo1 = h1+y1;
- arriba2 = y2;
- derecha1 = x1 + w1;
- izquierda2 = x2;
- arriba1 = y1;
- debajo2 = h2+y2;
- }
- private: System::Void MyForm_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
- //lienzo
- Graphics ^gr = this->CreateGraphics();
- //dibuja jugadores
- gr->DrawImage(img1,x1,y1);
- gr->DrawImage(img2,x2,y2);
- }
- private: System::Void MyForm_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
- if (e->KeyCode == Keys::W)
- y1-=40;
- if (e->KeyCode == Keys::A)
- x1-=40;
- if (e->KeyCode == Keys::S)
- y1+=40;
- if (e->KeyCode == Keys::D)
- x1+=40;
- if (e->KeyCode == Keys::Right)
- x2+=40;
- if (e->KeyCode == Keys::Down)
- y2+=40;
- if(e->KeyCode == Keys::Left)
- x2-=40;
- if (e->KeyCode == Keys::Up)
- y2-=40;
- }
- private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
- //lienzo
- Graphics ^gr = this->CreateGraphics();
- //buffer
- System::Drawing::BufferedGraphicsContext ^bc= BufferedGraphicsManager::Current;
- System::Drawing::BufferedGraphics ^bg= bc->Allocate(gr,this->ClientRectangle);
- bg->Graphics->Clear(Color::White);
- //dibuja jugadores
- bg->Graphics->DrawImage(img1,x1,y1);
- bg->Graphics->DrawImage(img2,x2,y2);
- //verifica colision
- //centro1= x1+r1;
- //centro2= x2+r2;
- izquierda1 = x1;
- derecha2 = x2 + w2;
- debajo1 = h1 + y1;
- arriba2 = y2;
- derecha1 = x1 + w1;
- izquierda2 = x2;
- arriba1 = y1;
- debajo2 = h2 + y2;
- if(abs(derecha1)<abs(izquierda2)||derecha2<izquierda1||debajo1<arriba2||arriba1>debajo2)
- label1->Text="NO Colision";
- else
- label1->Text="Colision";
- // label2->Text = Convert::ToString(centro2-centro1);
- label3->Text = Convert::ToString(x1);
- label4->Text = Convert::ToString(x2);
- label5->Text = Convert::ToString(y1);
- label6->Text = Convert::ToString(y2);
- bg->Render(gr);
- delete bc;
- delete bg;
- delete gr;
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement