// // Programme d'accompagnement de l'ouvrage // "C++ Builder 3" // Gérard Leblanc // Editions Eyrolles, 1998 // //--------------------------------------------------------------------------- #include #pragma hdrstop #include #include "AnimFP.h" //--------------------------------------------------------------------------- #pragma resource "*.dfm" #define N 5 TFP *FP; Graphics::TBitmap *ImageFond, *Mask1, *Mask2; int FenW, FenH, MaskW, MaskH; struct { int x, y, dx, dy; } Pos[N]; //--------------------------------------------------------------------------- __fastcall TFP::TFP(TComponent* Owner) : TForm(Owner) { // Charger l'image de fond ImageFond = new Graphics::TBitmap(); ImageFond->LoadFromResourceName((int)HInstance, "Fond"); Mask1 = new Graphics::TBitmap(); Mask1->LoadFromResourceName((int)HInstance, "Msk1"); MaskW = Mask1->Width; MaskH = Mask1->Height; Mask2 = new Graphics::TBitmap(); Mask2->LoadFromResourceName((int)HInstance, "Msk2"); randomize(); } __fastcall TFP::~TFP() { delete ImageFond, Mask1, Mask2; } //--------------------------------------------------------------------------- void __fastcall TFP::FormCreate(TObject *Sender) { ClientWidth = ImageFond->Width; FenW = ClientWidth; ClientHeight = ImageFond->Height; FenH = ClientHeight; for (int i=0; iCanvas->CopyMode = cmSrcCopy; Fond->Picture->Bitmap = ImageFond; for (int i=0; iCanvas->CopyMode = cmSrcAnd; Fond->Canvas->Draw(Pos[i].x, Pos[i].y, Mask1); Fond->Canvas->CopyMode = cmSrcPaint; Fond->Canvas->Draw(Pos[i].x, Pos[i].y, Mask2); Pos[i].x += Pos[i].dx; Pos[i].y += Pos[i].dy; if (Pos[i].x<0 || Pos[i].x+MaskW>FenW) Pos[i].dx *= -1; if (Pos[i].y<0 || Pos[i].y+MaskH>FenH) Pos[i].dy *= -1; } } //---------------------------------------------------------------------------