AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

zwei bälle in bewegung

Ein Thema von Nicole · begonnen am 28. Jun 2006 · letzter Beitrag vom 28. Jun 2006
Antwort Antwort
Nicole

Registriert seit: 1. Feb 2006
18 Beiträge
 
#1

Re: zwei bälle in bewegung

  Alt 28. Jun 2006, 14:26
irgendwie häng ich grad völlig in der luft
Delphi-Quellcode:
 unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Image1: TImage;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

  tball = class
    x,y,vx,vy,r: single;
    farbe: tcolor;
    procedure init (fneu: tcolor; xneu, yneu, vxneu, vyneu, rneu: single);
    procedure zeigedich; zeigedich2;
    procedure bewegedich; bewegedich2;


     end;

var
  Form1: TForm1;
  ball: tball;
  ball2:tball;
implementation

{$R *.DFM}

procedure tball.init (fneu: tcolor; xneu, yneu, vxneu, vyneu, rneu: single);
begin
  farbe:= fneu;
  r:= rneu;
  x:=xneu;
  y:=yneu;
  vx:=vxneu;
  vy:=vyneu;
end;

procedure tball.zeigedich;
begin
  with form1.image1.canvas do
    begin
      brush.color:=farbe;
      ellipse(round(x-r),round(y-r),round(x+r),round(y+r));
    end;
end;

procedure tball.bewegedich;
begin
  x:=x+vx;
  y:=y+vy;
  with form1.Image1 do
    begin
      if (x>width-r-1) then
        begin
          x:=width-r-1;
          vx:=-vx;
        end;
      if x<r+1 then
        begin
          x:= r+1;
          vx:=-vx
        end;
      if (y>height-r-1) then
        begin
          y:=height-r-1;
          vy:=-vy;
        end;
      if y<r+1 then
        begin
          y:=r+1;
          vy:=-vy;
        end;
    end;
end;
 procedure tball2.init(fneu: tcolor; xneu, yneu, vxneu, vyneu, rneu: single);
begin
  farbe:= fneu;
  r:= rneu;
  x:=xneu;
  y:=yneu;
  vx:=vxneu;
  vy:=vyneu;
end;

procedure tball2.zeigedich;
begin
  with form1.image1.canvas do
    begin
      brush.color:=farbe;
      ellipse(round(x-r),round(y-r),round(x+r),round(y+r));
    end;
end;

procedure tball2.bewegedich;
begin
  x:=x+vx;
  y:=y+vy;
  with form1.Image1 do
    begin
      if (x>width-r-1) then
        begin
          x:=width-r-1;
          vx:=-vx;
        end;
      if x<r+1 then
        begin
          x:= r+1;
          vx:=-vx
        end;
      if (y>height-r-1) then
        begin
          y:=height-r-1;
          vy:=-vy;
        end;
      if y<r+1 then
        begin
          y:=r+1;
          vy:=-vy;
        end;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with image1.canvas do
    begin
      pen.width:=5;
      brush.color:=clwhite;
      rectangle(0,0,image1.width,image1.height);
      pen.width:=2;
      brush.style:=bssolid;
      pen.mode:=pmnotxor;
    end;
  ball.init(clred,random(image1.width-50)+25, random(image1.height-50)+25,random(9)-4,random(9)-20,20);
  ball.zeigedich;
end;

procedure stoss;
  var h:single;
begin
if sprt(spr(ball.x-ball2.x)+spr(ball.y-ball2.y))<40
  then begin
  h:=ball.vx;ball.vx:=ball2.vx; ball2.vx:=h;
  h:=ball.vy;ball.vy:=ball2.vy; ball2.vy:=h;
 end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  ball.zeigedich; ball2.zeigedich;
  image1.canvas.pixels[round(ball.x),round(ball.y)]:=clblack;
  image1.canvas.Pixels[round(ball2.x),round(ball2.y)):=clblue;
  ball.bewegedich; ball2.bewegedich;
stoss;
ball.zeigedich; ball2.zeigedich;
end;
initialization
  randomize;
  ball:=tball.create;
  ball2:=tball.create;
finalization
  ball.destroy;
  ball2.destroy;

end.

so,hätt ichs gemacht,aber es funktioniert so nciht...aber wie dann anders?
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:20 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz