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: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, ComCtrls;
type TForm1 = class(TForm) Image1: TImage; Button1: TButton; Timer1: TTimer; Label1: TLabel; Edit1: TEdit; Panel2: TPanel; Panel3: TPanel; Panel4: TPanel; Panel5: TPanel; Panel6: TPanel; Panel7: TPanel; Panel8: TPanel; Panel9: TPanel; Panel10: TPanel; Panel11: TPanel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Panel1: TPanel;
procedure Button1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
private public end;
var Form1: TForm1; x1,y1,vx,vy:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); begin
Form1.Image1.Picture:=Nil; x1:=random (image1.Width)-20 ; y1:=150; vx:=1; vy:=1; if x1 < 0 then x1:=0;
timer1.Enabled:=true; Form1.Image1.Canvas.Pen.Mode:=pmnotxor; Form1.Image1.canvas.Pen.color:=clred; Form1.Image1.canvas.Brush.color:=clred; Form1.Image1.Canvas.ellipse(x1,y1,x1+20,y1+20); Button1.Visible:=false; label1.visible:=false; label2.visible:=false; label3.Visible:=true; label4.Visible:=false; edit1.Visible:=true; panel1.Visible:=true; panel2.Visible:=true; panel3.Visible:=true; panel4.Visible:=true; panel5.Visible:=true; panel6.Visible:=true; panel7.Visible:=true; panel8.Visible:=true; panel9.Visible:=true; panel10.Visible:=true; panel11.Visible:=true;
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
panel1.Left:=x;
Problem Nummer 1: dieser Panel wandert aus der Leinwand heraus. wie kann man das verhindern?
end;
procedure TForm1.Timer1Timer(Sender: TObject); begin
Form1.Image1.Canvas.Ellipse(x1,y1,x1+20,y1+20);
x1:=x1+vx; y1:=y1+vy;
Form1.Image1.Canvas.Ellipse(x1,y1,x1+20,y1+20);
if ((x1+20)>Form1.Image1.Width) or ((x1)<0) then vx:=(-1)*vx;
if (y1<0) then vy:=(-1)*vy;
Problem 2: Dummerweise klappt dass nicht mit dem wert der bei y1+20 steht. der pall ändert erst seine richtung wenn der ball mitten im panel ist. ich will aber, dass das passiert, wenn aber gerade die kante berührt
if (y1+20>panel1.top) and (x1<(panel1.Left+panel1.Width)) then vy:=(-1)*vy;
if (y1+20>panel1.top) then edit1.Text:=inttostr(strtoint(Edit1.Text)+1);
if strtoint(edit1.text)=3 then begin label4.visible:=true; button1.Visible:=false; button1.Caption:='Neuer Versuch'; edit1.Text:=inttostr(strtoint(Edit1.Text)*0) end;
if (y1+20>panel1.top) then begin Button1.Visible:=true; label1.Visible:=true; Button1.Caption:='Neuer Ball'; beep; timer1.enabled:=false; end;
auch hier ist das problem, dass der ball erst in der mitte ders panels seine richtung ändert. außerdemverschwinden die panels manchmal auch wenn der ball ganz nah herankommt. ich vermute, dass das daran leigt, dass die ursprünglichen koordinaten des kreises ja ein quadrat sind (stimmt das :))
if panel2.visible=true then begin if (y1+20>panel2.top)and(y1<panel2.top+panel2.height) then if (x1>panel2.left) and (x1<(panel2.Left+panel2.Width)) then begin panel2.visible:=false; vy:=(-1)*vy; end; end;
if panel3.visible=true then begin if (y1+20>panel3.top)and(y1<panel3.top+panel3.height) then if (x1>panel3.left) and (x1<(panel3.Left+panel3.Width)) then begin panel3.visible:=false; vy:=(-1)*vy; end; end;
if panel4.visible=true then begin if (y1+20>panel4.top)and(y1<panel4.top+panel4.height) then if (x1>panel4.left) and (x1<(panel4.Left+panel4.Width)) then begin panel4.visible:=false; vy:=(-1)*vy; end; end;
if panel5.visible=true then begin if (y1+20>panel5.top)and(y1<panel5.top+panel5.height) then if (x1>panel5.left) and (x1<(panel5.Left+panel5.Width)) then begin panel5.visible:=false; vy:=(-1)*vy; end; end;
if panel6.visible=true then begin if (y1+20>panel6.top)and(y1<panel6.top+panel6.height) then if (x1>panel6.left) and (x1<(panel6.Left+panel6.Width)) then begin panel6.visible:=false; vy:=(-1)*vy; end; end;
if panel7.visible=true then begin if (y1+20>panel7.top)and(y1<panel7.top+panel7.height) then if (x1>panel7.left) and (x1<(panel7.Left+panel7.Width)) then begin panel7.visible:=false; vy:=(-1)*vy; end; end;
if panel8.visible=true then begin if (y1+20>panel8.top)and(y1<panel8.top+panel8.height) then if (x1>panel8.left) and (x1<(panel8.Left+panel8.Width)) then begin panel8.visible:=false; vy:=(-1)*vy; end; end;
if panel9.visible=true then begin if (y1+20>panel9.top)and(y1<panel9.top+panel9.height) then if (x1>panel9.left) and (x1<(panel9.Left+panel9.Width)) then begin panel9.visible:=false; vy:=(-1)*vy; end; end;
if panel10.visible=true then begin if (y1+20>panel10.top)and(y1<panel10.top+panel10.height) then if (x1>panel10.left) and (x1<(panel10.Left+panel10.Width)) then begin panel10.visible:=false; vy:=(-1)*vy; end; end;
if panel11.visible=true then begin if (y1+20>panel11.top)and(y1<panel11.top+panel11.height) then if (x1>panel11.left) and (x1<(panel11.Left+panel11.Width)) then begin panel11.visible:=false; vy:=(-1)*vy; end; end;
if panel2.Visible=false then begin if panel3.Visible=false then begin if panel4.Visible=false then begin if panel5.Visible=false then begin if panel6.Visible=false then begin if panel7.Visible=false then begin if panel8.Visible=false then begin if panel9.Visible=false then begin if panel10.Visible=false then begin if panel11.Visible=false
then label2.visible:=true; end; end; end; end; end; end; end; end; end;
if label2.visible=true then begin label1.Visible:=false; Form1.Image1.Picture:=Nil; panel1.visible:=false; end;
end;
end. |