Всем привет. Написал небольшую программу. Одно изображение - мой самолет (имейдж2), второе вражеский (имейдж1). Не могу создать модель столкновений. По лефт и топ если сделать, то столкновение требует соблюдения слишком четких позиций. Как я понял надо создать интервал в каком и определять есть столкновение или нет, но как это сделать? И еще момент - как создать стрельбу? Внизу как видно попытался сделать что-то, но дальше понять не могу. Помогите плз ;)
| Код | //---------------------------------------------------------------------------
#include <vcl.h> #pragma hdrstop
#include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; int x; int rand1;
int left1; TShape *shp; //---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender) { Image1->Top=-150; Image1->Left=500;
} //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {
int c; c=rand ()%980;
shp = new TShape (this); shp->Parent = Panel1; shp->Width = 20; shp->Height = 20; shp->Shape=stRoundRect; shp->Brush->Color=clMoneyGreen; shp->Top = 0; shp->Left = c;
if ((shp->Top == Shape1->Top)&&(shp->Left == Shape1->Left)) delete shp;
} //---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if(Key==VK_RIGHT) Image2->Left=Image2->Left+20;
if(Key==VK_LEFT) Image2->Left=Image2->Left-20;
if(Key==VK_UP) Image2->Top=Image2->Top-5;
if(Key==VK_DOWN) Image2->Top=Image2->Top+5;
} //---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender) {
Image1->Top=Image1->Top+5; rand1=rand ()%4; if (rand1==0) left1=100; if (rand1==1) left1=250; if (rand1==2) left1=500; if (rand1==3) left1=750; if (rand1==4) left1=900;
if (Image1->Top>650) {Image1->Top=-150; Image1->Left=left1;};
int t1; t1=Image1->Top;
if ((Image1->Top==Image2->Top)&&(Image1->Left==Image2->Left)) {Image1->Top=-150;};
} //---------------------------------------------------------------------------
|
|