Autor Beitrag
-Nala-
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 62



BeitragVerfasst: So 04.02.07 15:06 
hey leute!
danke für eure hilfe !!
also ich hab den folgenden quelltext eingegeben und das abstoßen hat funktioniert !
allerdings funktioniert das abprallen nur an den oberen und unteren seiten rechts und links hat es nicht funktioniert könnt ihr mir helfen??

ausblenden volle Höhe Delphi-Quelltext
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:
unit Unit1;  

 
interface  

 
uses  
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,  
  ExtCtrls, StdCtrls;  

 
type  
  TForm1 = class(TForm)  
    ImReagenzglas: TImage;  
    ImNa1: TImage;  
    Timer1: TTimer;  
    ImNa2: TImage;  
    Schnell: TButton;  
    Langsam: TButton;  
    Stopp: TButton;  
    procedure FormCreate(Sender: TObject);  
    procedure Timer1Timer(Sender: TObject);  
    procedure SchnellClick(Sender: TObject);  
    procedure LangsamClick(Sender: TObject);  
    procedure StoppClick(Sender: TObject);  
  private  
    { Private-Deklarationen }  
  public  
    { Public-Deklarationen }  
  end;  

 
var  
  Form1: TForm1;  
  vv, vh, n, p:integer;  

 
implementation  

 
{$R *.DFM}  

 
procedure TForm1.FormCreate(Sender: TObject);  
begin  
ImNa1.canvas.ellipse(0,0,20,20);  
ImReagenzglas.canvas.ellipse(400,400,380,380);  
ImNa2.Canvas.ellipse(0,0,20,20);  
n:=7;  
p:=8;  
vv:=5;  
vh:=4;  
end;  

 
procedure TForm1.Timer1Timer(Sender: TObject);  
begin  
ImNa1.Top:=ImNa1.top+vv;  
ImNa1.left:=ImNa1.left+vh;  
ImNa2.top:=ImNa2.top+n;  
ImNa2.left:=ImNa2.left+p;  
if (ImNa1.top>200) then  
vv:=-vv;  
if (ImNa1.left>200) then  
vh:=-vh;  
if (ImNa1.top<20)  then  
vv:=-vv;  
if (ImNa1.left<20) then  
vh:=-vh;  
if (ImNa2.left>200) then  
p:=-p;  
if (ImNa2.top>200) then  
n:=-n;  
if (ImNa2.left<20) then  
p:=-p;  
if (ImNa2.top<20) then  
n:=-n;  
if ((ImNa1.Top+ImNa1.Height > ImNa2.Top) and (ImNa1.Top<ImNa2.top+ImNa2.Height))  
and  
  ((ImNa1.Left < ImNa2.Left+ImNa2.Width) and (ImNa1.Left+ImNa1.Width > ImNa2.Left)) then  
   begin  
vv:=-vv;  
vh:=-vh;  
 end;  
end;





EDIT//: der fehler is irgendwo beim lezten if satz
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 11.02.07 22:08 
Ersetz mal das vorletzte AND in ein OR.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
  if ((ImNa1.Top + ImNa1.Height > ImNa2.Top) AND (ImNa1.Top < ImNa2.Top + ImNa2.Height)) OR
   ((ImNa1.Left < ImNa2.Left + ImNa2.Width) AND (ImNa1.Left + ImNa1.Width > ImNa2.Left)) then    
  begin    
    vv := -vv;    
    vh := -vh;    
  end;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)