#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ExitClick(TObject *Sender)
{
Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StartClick(TObject *Sender)
{
Form1->Visible=false;
Form2->Visible=true;
}
#include <vc1.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
int x=-8, y=-8;
int do_wygranej=9;
bool kolizja (TImage *pilka, TImage *cegla)
{
if (pilka->Left+pilka->Width >= cegla->Left &&
pilka->Left <= cegla->Left + cegla->Width &&
pilka->Top >= cegla->Top -pilka->Height &&
pilka->Top<=cegla->Top+cegla->Height)
{
return true;
}
else return false;
}
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Timer_pilkaTimer(TObject *Sender)
{
b->Left+=x;
b->Top+=y;
//odbij od lewej sciany
if (b->Left-5 <= tlo->Left) x=-x;
//odbij od prawej sciany
if (b->Top-5 <= tlo->Top) y=-y;
//odbij od prawej sciany
if (b->Left+b->Width+5 >= tlo->Width) x=-x;
//skucha
if(b->Top >= p->Top+p->Height+15)
{
Timer_pilka -> Enabled=false;
b-> Visible=false;
Button1->Caption="Przegrana";
Button1->Visible=true;
}
//odbicie od paletki
else if (b->Left > p->Left - b->Width/2 && b->Left < p->Left+p->Width &&
b->Top+b->Height >= p->Top)
{
if (y>0) y=-y;
}
if (do_wygranej <= 0)
{
Timer_pilka->Enabled=false;
b->Visible=false;
Button1->Caption="Wygrana";
Button1->Visible=true;
}
//blok1
if (kolizja(b,Image1)==true && Image1->Visible==true)
{x=-x; y=-y; Image1->Visible=false; do_wygranej--; }
//blok2
if (kolizja(b,Image2)==true && Image2->Visible==true)
{x=-x; y=-y; Image2->Visible=false; do_wygranej--; }
//blok3
if (kolizja(b,Image3)==true && Image3->Visible==true)
{x=-x; y=-y; Image3->Visible=false; do_wygranej--;}
//blok4
if (kolizja(b,Image4)==true && Image4->Visible==true)
{x=-x; y=-y; Image4->Visible=false; do_wygranej--;}
//blok5
if (kolizja(b,Image5)==true && Image5->Visible==true)
{x=-x; y=-y; Image5->Visible=false; do_wygranej--; }
//blok6
if (kolizja(b,Image6)==true && Image6->Visible==true)
{x=-x; y=-y; Image6->Visible=false;do_wygranej--; }
//blok7
if (kolizja(b,Image7)==true && Image7->Visible==true)
{x=-x; y=-y; Image7->Visible=false; do_wygranej--;}
//blok8
if (kolizja(b,Image8)==true && Image8->Visible==true)
{x=-x; y=-y; Image8->Visible=false; do_wygranej--;}
//blok9
if (kolizja(b,Image9)==true && Image9->Visible==true)
{x=-x; y=-y; Image9->Visible=false;do_wygranej--; }
}
//---------------------------------------------------------------------------
void __fastcall TForm2::lewoTimer(TObject *Sender)
{
if (p->Left>10) p->Left-=10;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::prawoTimer(TObject *Sender)
{
if (p->Left+ p->Width<tlo->Width-10)p->Left +=10;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key==VK_LEFT) lewo->Enabled=true;
if (Key==VK_RIGHT) prawo->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key==VK_LEFT) lewo->Enabled=false;
if (Key==VK_RIGHT) prawo->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
b->Left=50;
b->Top=30;
Timer_pilka -> Enabled=true;
x=-8;
y=-8;
b->Visible=true;
Button1->Visible=false;
do_wygranej=12;
Image1->Visible=true;
Image2->Visible=true;
Image3->Visible=true;
Image4->Visible=true;
Image5->Visible=true;
Image6->Visible=true;
Image7->Visible=true;
Image8->Visible=true;
Image9->Visible=true;
}
Moment błędu to przejście za pomocą przycisku "StartClick" z formy1 do formy2, może ktoś jakieś sugestie? Będę wdzięczny.