Einzelnen Beitrag anzeigen

AddiDelphi

Registriert seit: 19. Mär 2010
18 Beiträge
 
#5

Re: Frage zu Shapes: Shape2 soll Shape1 abblocken/reflektier

  Alt 19. Mär 2010, 13:34
Suuper!

Danke dir.

Jetzt muss ich es nurnoch hinbekommen, den Ball vom Schläger abprallen zu lassen..

das krieg ich nicht hin.

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls,mtBall, mTBrett, StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    Shape1: TShape;
    Button8: TButton;
    Button10: TButton;
    Timer1: TTimer;
    Button3: TButton;
    Button12: TButton;
    Shape2: TShape;
    BitBtn1: TBitBtn;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Timer1Timer(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Ball:TBall;
  Brett:TBrett;
  rechts:Integer;
  runter:Integer;
implementation

{$R *.dfm}




procedure TForm1.FormCreate(Sender: TObject);
begin
  Ball:=TBall.create;
  Brett:=TBrett.create;
  Ball.setzex (Shape1.left);
  Ball.setzey (Shape1.top);
  Brett.setzea (Shape2.left);
  Brett.Setzeb (Shape2.top);
  rechts:=5;
  runter:=5;

end;




procedure TForm1.Button8Click(Sender: TObject); //Brett links
begin
  Brett.bewegebrett(-20,0);
  Shape2.Left:=Brett.GibA;
  Shape2.Top:=Brett.GibB;
end;


procedure TForm1.Button10Click(Sender: TObject); //Brett rechts
begin
  Brett.bewegebrett(20,0);
  Shape2.Left:=Brett.GibA;
  Shape2.Top:=Brett.GibB;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Ball.free;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
  begin
    Ball.bewege(rechts,runter);
    Shape1.Left:=Ball.GibX;
    Shape1.Top:=Ball.GibY;

      if Ball.gibX>Form1.clientwidth-Shape1.width
          then
            begin
              rechts:=-rechts;
              Ball.setzeFarbe(clblue);
              Shape1.brush.color:=Ball.gibFarbe;
            end
      else
          if Ball.gibY>Form1.clientheight-Shape1.height
              then
                  begin
                        runter:=-runter;
                        timer1.Enabled:=false;
                        showmessage('Game Over Baby!')
                  end
      else
          if Ball.gibX<0
              then
                begin
                  rechts:=-rechts;
                  Ball.setzeFarbe(clyellow);
                   Shape1.brush.color:=Ball.gibFarbe;
                end
      else
          if Ball.gibY<0
            then
              begin
                runter:=-runter;
                Ball.setzeFarbe(clred);
                Shape1.brush.color:=Ball.gibFarbe;
              end

      else
          if

                   [b]HIER MUSS ES REIN... ABER WAS?[/b]

            then runter:=-runter;

end;

procedure TForm1.Button12Click(Sender: TObject);
begin
  timer1.Enabled:=false;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  timer1.Enabled:=true;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  close;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  Shape2.Left := X - Shape2.Width div 2;
end;

end.
Wäre gern ein guter Programmierer
  Mit Zitat antworten Zitat