Nicolas___
Messages postés992Date d'inscriptionjeudi 2 novembre 2000StatutMembreDernière intervention24 avril 20131 24 oct. 2005 à 22:53
Slt merci pour vos aides , je rep seulement now parce que je n etais pas chez moi ...
Manchester: je vais regarde ta solution , merci te dirai quoi qd j aurais le tps ...
Maurico :
J ai essaye un autre systeme de collision base sur la formule suivante
sqrt((xb-xa)²+(yb-ya)²):=distance entre 2 points
mais je ne sais pas ya pas moyen je n y arrive pas ...
Je vois c est quoi le prob ac la fonction ds le source mais je ne sais pas comment le resoudre
Je n ai pas telecharge tes compos dsl( sinon je t aurais laisse des comm, jt'assure!)
J attends tjs ac impatience si tu y pense tjs et si tu as le tps l amelioration que je t avais propose pr ta source "changer les pixels + ... "
Merci pour tes autres sources (je suis en train de regarder tt ca et j essaye de les digerer !!!)
Ciao
Nico
cs_ManChesTer
Messages postés374Date d'inscriptionvendredi 20 octobre 2000StatutModérateurDernière intervention15 janvier 2021 21 oct. 2005 à 00:42
Voici un "truc" pour faire une gravitation plus ou moins réaliste
faire un form mettre un bouton dessus copier le code.
Type TGraviteAnim = class(TThread) // Un thread pour l'anim
Private
DestHdc : HDC;
Image : Tbitmap;
Px : Integer;
Py : Integer;
Force : Integer;
Xmax : Integer;
Ymax : Integer;
Dw : Integer;
Dh : Integer;
Procedure DrawBouncingBall;
Public
Procedure Execute;Override;
end;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
MonAnim : TGraviteAnim;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var xd : boolean=True;
yd : Boolean=False;
Function Gravite(var x,y:Integer;f,Xm,Ym:Integer):Integer;
var pax,pay:Real;
begin
pax:=((x+1)/(xm/F))/2;
pay:=((y+1)/(ym/F))/2;
if (pax<1) and (not(xd)) then
begin
xd:=true;
end
else
if (x>Xm-10) and (xd) then
begin
x:=Xm-10;
xd:=false;
end;
if (pay<1) and (not(yd)) then
begin
yd:=True;
end
else
if y>ym-10 then
begin
y:=ym-10;
yd:=False;
end;
if xd then
X:=round(x+pax)
else
X:=round(x-pax);
if yd then
y:=round(y+pay)
else
y:=round(y-pay);
end;
Procedure TGraviteAnim.DrawBouncingBall;
begin
Image.Width:=dw;
Image.Height:=dh;
Image.Canvas.FillRect(Rect(0,0,dw,dh));
Ellipse(image.Canvas.Handle,px,py,px+10,py+10);
BitBlt(form1.Canvas.Handle,0,0,dw,dh,Image.Canvas.Handle,0,0,SRCCOPY);
end;
Procedure TGraviteAnim.Execute;
begin
Image:=Tbitmap.Create;
While not terminated do
begin
Gravite(px,py,Force,Xmax,Ymax);
Synchronize(DrawBouncingBall);
sleep(15);
end;
Image.Free;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
MonAnim.Terminate;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not assigned(MonAnim) then
MonAnim:=TGraviteAnim.Create(True);
MonAnim.px:=20;
MonAnim.py:=height;
MonAnim.Force:=50;
MonAnim.XMax:=Width;
MonAnim.YMax:=Height;
MonAnim.DestHdc:=getdc(Handle);
MonAnim.Dw:=Width;
MonAnim.Dh:=Height;
MonAnim.Resume;
end;
end.
Bon Coding....
ManChesTer.
Nicolas___
Messages postés992Date d'inscriptionjeudi 2 novembre 2000StatutMembreDernière intervention24 avril 20131 19 oct. 2005 à 14:05
la fonction de collision est tjs de Cyrille 2
Tjs Merci a lui et a CS en general
24 oct. 2005 à 22:53
Manchester: je vais regarde ta solution , merci te dirai quoi qd j aurais le tps ...
Maurico :
J ai essaye un autre systeme de collision base sur la formule suivante
sqrt((xb-xa)²+(yb-ya)²):=distance entre 2 points
mais je ne sais pas ya pas moyen je n y arrive pas ...
Je vois c est quoi le prob ac la fonction ds le source mais je ne sais pas comment le resoudre
Je n ai pas telecharge tes compos dsl( sinon je t aurais laisse des comm, jt'assure!)
J attends tjs ac impatience si tu y pense tjs et si tu as le tps l amelioration que je t avais propose pr ta source "changer les pixels + ... "
Merci pour tes autres sources (je suis en train de regarder tt ca et j essaye de les digerer !!!)
Ciao
Nico
21 oct. 2005 à 00:42
faire un form mettre un bouton dessus copier le code.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Type TGraviteAnim = class(TThread) // Un thread pour l'anim
Private
DestHdc : HDC;
Image : Tbitmap;
Px : Integer;
Py : Integer;
Force : Integer;
Xmax : Integer;
Ymax : Integer;
Dw : Integer;
Dh : Integer;
Procedure DrawBouncingBall;
Public
Procedure Execute;Override;
end;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
private
MonAnim : TGraviteAnim;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var xd : boolean=True;
yd : Boolean=False;
Function Gravite(var x,y:Integer;f,Xm,Ym:Integer):Integer;
var pax,pay:Real;
begin
pax:=((x+1)/(xm/F))/2;
pay:=((y+1)/(ym/F))/2;
if (pax<1) and (not(xd)) then
begin
xd:=true;
end
else
if (x>Xm-10) and (xd) then
begin
x:=Xm-10;
xd:=false;
end;
if (pay<1) and (not(yd)) then
begin
yd:=True;
end
else
if y>ym-10 then
begin
y:=ym-10;
yd:=False;
end;
if xd then
X:=round(x+pax)
else
X:=round(x-pax);
if yd then
y:=round(y+pay)
else
y:=round(y-pay);
end;
Procedure TGraviteAnim.DrawBouncingBall;
begin
Image.Width:=dw;
Image.Height:=dh;
Image.Canvas.FillRect(Rect(0,0,dw,dh));
Ellipse(image.Canvas.Handle,px,py,px+10,py+10);
BitBlt(form1.Canvas.Handle,0,0,dw,dh,Image.Canvas.Handle,0,0,SRCCOPY);
end;
Procedure TGraviteAnim.Execute;
begin
Image:=Tbitmap.Create;
While not terminated do
begin
Gravite(px,py,Force,Xmax,Ymax);
Synchronize(DrawBouncingBall);
sleep(15);
end;
Image.Free;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
MonAnim.Terminate;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not assigned(MonAnim) then
MonAnim:=TGraviteAnim.Create(True);
MonAnim.px:=20;
MonAnim.py:=height;
MonAnim.Force:=50;
MonAnim.XMax:=Width;
MonAnim.YMax:=Height;
MonAnim.DestHdc:=getdc(Handle);
MonAnim.Dw:=Width;
MonAnim.Dh:=Height;
MonAnim.Resume;
end;
end.
Bon Coding....
ManChesTer.
19 oct. 2005 à 14:05
Tjs Merci a lui et a CS en general