1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
   |  
procedure TForm1.FormCreate(Sender: TObject);
 
begin
 
nbobjets:=1;
vitesse:=10;
ResolutionX:=500;
ResolutionY:=650;
ClientWidth := ResolutionX;
Clientheight := ResolutionY;
                        //Taille fenêtre
Fond := TBitmap.Create;
Arbre := TBitmap.Create;
Balle := TBitmap.Create;
Balle2 := TBitmap.Create;
Buffer := TBitmap.Create;
 
  Fond.LoadFromFile('./FOND.bmp');        //objets
  Balle.LoadFromFile('./BALLE.bmp');
  Balle2.LoadFromFile('./BALLE2.bmp');
  Arbre.LoadFromFile('./Arbre.bmp');
 
Arbre.TransparentColor:=clFuchsia;
Arbre.Transparent:=true;
Balle.TransparentColor:=clFuchsia;           //Transparence
Balle.Transparent:=true;
Balle2.TransparentColor:=clFuchsia;
Balle2.Transparent:=true;
 
 
x:=-((fond.width-ResolutionX) div 2);
y:=-((fond.Height-ResolutionY) div 2);                     //Possition Map
TempPosX:=((resolutionX div 2) - balle.Width div 2)  ;
TempPosY:=((resolutionY div 2) - balle.Height div 2)  ;
PosX:=TempPosX ;                           // Position Objet dans fenêtre
PosY:=TempPosY ;
 
Pas:=true;
Remplir_Buffer;
 
end;
 
 
procedure Tform1.Remplir_Buffer;
begin
 with buffer do
  begin
   assign(fond);
   Canvas.Draw(0+x,0+y,Buffer);
   if Pas=true then
    Canvas.Draw(PosX,PosY,Balle)
   else
    Canvas.Draw(PosX,PosY,Balle2);                  //Position Objets
 
    canvas.Draw(250+x,200+y,Arbre);
   end;
   paint;
end;
 
procedure TForm1.FormPaint(Sender: TObject);
 
begin
Canvas.Draw(0,0,Buffer);
end;
 
 
    //------------------------Mouvements------------------------//
    //----------------//
 
 
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
Varf:trect;
 
begin
 
if key = vk_left then
  begin
 
   Pas:=not(Pas);
 
   if (x<-10) and (PosX<ResolutionX div 2) then
     begin
       VarF:= Collision(Bounds((-x+ResolutionX div 2), y, 50, 50), Bounds((-x+ResolutionX div 2) + vitesse, y, 50, 50), Balle); //appel de fonction collision
       x := x + vitesse;
       paint;
   end
   else
     if  (PosX - Vitesse >x) then
      begin
      PosX:= PosX - vitesse;
      paint;
      end;
   end;
   Remplir_Buffer;
end;
 
 
      //------------------------Collision----------------------//
      //--------------//
 
 
function TForm1.Collision(cur_coord, new_coord: TRect; User_Pos: TBitmap): TRect;
var
i:integer;
collision_zone: TRect;
begin
  for i := 1 to nbobjets do
    begin
       BM_Objet_Test := TBitmap.Create;
       BM_Objet_Test.LoadFromFile('./Arbre.bmp');
  if  not IntersectRect(collision_zone, bounds(new_coord.Left, new_coord.Top, User_Pos.width, User_Pos.height),
    bounds(y,x, BM_Objet_Test.width, BM_Objet_Test.height))then
 
  abort;
 
  end;
  BM_Objet_Test.free;
end;
end. | 
Partager