Gravitation

Description

Ben c est un petit exemple de Gravite ( pas ou peu reelle,mais ce n est pas le but rechercher).
Ce code peut tjs etre utile pr commencer un jeu de plateforme par exemple

Source / Exemple :


function Is_Collision(left1,top1,x1,y1,left2,top2,x2,y2 : Integer) : Boolean;
var Right1 : Integer;
    Bottom1 : Integer;
    Right2 : Integer;
    Bottom2 : Integer;
begin
    Result := False;
    Right1 := left1+x1;
    Bottom1 := top1+y1;
    Right2 := left2+x2;
    Bottom2 := top2+y2;
    if (left2 < Right1) and (top2 < Bottom1) and (Bottom2 > top1) and (Right2 > left1) Then
        Result := True;
end;

procedure TForm1.gravitationTimer(Sender: TObject);
begin
if gravite<>0 then  gravite :=gravite+1;
if gravite<>0 then carre.Top:=carre.Top+gravite;

if not is_collision(carre.Left,carre.Top+6,carre.Width,carre.Height,
sol.Left,sol.Top,sol.Width,sol.Height) then gravite:=gravite+1;;

if  is_collision(carre.Left,carre.Top+6,carre.Width,carre.Height,
plt1.Left,plt1.Top,plt1.Width,plt1.Height) then gravite :=0 ;

if  is_collision(carre.Left,carre.Top+6,carre.Width,carre.Height,
murplt1.Left,murplt1.Top,murplt1.Width,murplt1.Height) then
begin
if carre.Left<murplt1.Left then  carre.Left:=murplt1.Left-carre.Width;
if carre.Left>murplt1.Left then  carre.Left:=murplt1.Left+murplt1.Width;
end;

label1.Caption:=inttostr(gravite);
if  is_collision(carre.Left,carre.Top+6,carre.Width,carre.Height,
sol.Left,sol.Top,sol.Width,sol.Height)
 then
   begin
   carre.Top:=sol.top-carre.Height;
   gravite := 0;
end;
end;

Conclusion :


J aimerais savoir s il y a moyen d en faire une fonction , merci
Et comment peut t on autoriser avec OnKeyDown la possibilite d appuyer sur 2 touches simultanement sans qu une des 2 actions ne soient coupes

Codes Sources

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.