AGB  ·  Datenschutz  ·  Impressum  







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

Ball soll abprallen!

Ein Thema von OMEGA · begonnen am 21. Jun 2006 · letzter Beitrag vom 21. Jun 2006
 
OMEGA

Registriert seit: 19. Jun 2006
5 Beiträge
 
#7

Re: Ball soll abprallen!

  Alt 21. Jun 2006, 20:55
Hier ist der ganze Quelltext.

Delphi-Quellcode:
var
  Form1: TForm1;
  Stop:boolean=false;
  balken1mitte,balken1breite, balken2mitte,balken2breite: integer;
  loeschcolor,ballcolor,balken1color,balken2color:Tcolor;
  x,y:integer;

implementation

{$R *.dfm}

procedure TForm1.BeendenClick(Sender: TObject);
begin
stop:=true;
close;
end;

procedure TForm1.Start1Click(Sender: TObject);
var bx,by,s:integer;

begin
    randomize;
    stop:=false;

    //Ball
    x:=form1.PaintBox1.width div (random(3)+2);
    y:=form1.PaintBox1.Height div(random(3)+2);
    bx:=random(3)+2;
    by:=random(3)+2;

    //Balken 1
    balken1breite:=80;
    balken1mitte:=form1.PaintBox1.Height div 2;

    //Farben wählen
    loeschcolor:=form1.PaintBox1.color;
    ballcolor:= clwhite;
    balken1color:= clgreen;

    //Zähler
    s:=0;
    Anzahl.Caption:='Anzahl:' + inttostr(s);
    Anzahl.height:=25;
    Anzahl.Width:=100;

    repeat
// malen
      //Ball
      form1.PaintBox1.Canvas.pen.color:=ballcolor;
      form1.PaintBox1.Canvas.brush.color:=ballcolor;
      form1.PaintBox1.canvas.ellipse(x-15,y-15,x+15,y+15);
      //Balken 1
      form1.PaintBox1.canvas.pen.color:=balken1color;
      form1.PaintBox1.canvas.brush.color:=balken1color;
      form1.PaintBox1.canvas.rectangle(5,balken1mitte-balken1breite,25,balken1mitte+balken1breite);
      //warten
      sleep(4);
//übermalen
      // Ball
      form1.PaintBox1.canvas.pen.color:=loeschcolor;
      form1.PaintBox1.canvas.brush.color:=loeschcolor;
      form1.PaintBox1.canvas.rectangle(x-15,y-15,x+15,y+15);
      // Balken 1
      form1.PaintBox1.canvas.pen.color:=loeschcolor;
      form1.PaintBox1.canvas.brush.color:=loeschcolor;
      form1.PaintBox1.canvas.rectangle(5,balken1mitte-balken1breite,25,balken1mitte+balken1breite);
//neue Ballposition
      x:=x+bx;
      y:=y+by;

//abprallen
      //ball am rechten rand
      if (x> form1.PaintBox1.clientwidth-15)
          or (x<15)
      then
      begin
        bx:=-bx
      end;

      //balken
   if (x-15 <= 25)
      then
      begin
           if (y>balken1mitte-balken1breite)
           and (y<balken1mitte+balken1breite)
       then
          begin
          bx:=-bx+1; // Beschleunigung und richtungsänderung
          by:=by+1; // Beschleunigung
          s:=s+1; // anzahl +1
          Anzahl.caption:='Anzahl:' + inttostr(s);
          Anzahl.height:=25;
          Anzahl.Width:=100;
          end
       else
         begin x:=form1.PaintBox1.width div 2;
               y:=form1.PaintBox1.Height div 2;
               bx:=random(3)+2;
               by:=random(3)+2;
               showmessage('Du hast '+inttostr(s)+' Ballwechsel geschafft!');
               s:=0;
               Anzahl.Caption:='Anzahl:' + inttostr(s);
               Anzahl.height:=25;
               Anzahl.Width:=100;
        end;
        if(s>=10)
        then
                begin form1.PaintBox1.canvas.pen.color:=clyellow;
      form1.PaintBox1.canvas.brush.color:=clred;
      form1.PaintBox1.canvas.rectangle(200,300,300,400);
      end;


Hier gehts nicht weiter



         // oben und unten
   if (y+15 > form1.PaintBox1.clientheight)
         or (y-15 < 0)
      then
       begin
        by:=-by
       end;

      application.ProcessMessages;
    until stop=true;

end;
Das wars dann eigentlich

[edit=Admin]Code in Delphi-Tags gesetzt. Künftig bitte selber machen, danke. Mfg, Daniel[/edit]
  Mit Zitat antworten Zitat
 


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 01:25 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