AGB  ·  Datenschutz  ·  Impressum  







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

Problem bei Pong Programmierung

Ein Thema von Andi28 · begonnen am 6. Okt 2008 · letzter Beitrag vom 7. Okt 2008
 
Andi28

Registriert seit: 6. Okt 2008
23 Beiträge
 
Delphi 2006 Personal
 
#1

Problem bei Pong Programmierung

  Alt 6. Okt 2008, 19:34
Guten Abend alle zusammen !

zunächst einmal hier mein Quelltext zu dem ich Fragen habe :

Delphi-Quellcode:
procedure TForm1.Timer1Timer(Sender: TObject);
var rq,aq,ax,ay : integer;
begin
 // zuerst den Kreis bewegen
 shape1.left :=shape1.Left+ dx;
 shape1.top :=shape1.top + dy;

 // testen, ob der Kreis in x-Richtung an den Rand des Formulars stößt
 if shape1.left <= 0 then dx := +1;
 if (shape1.left >= form1.Width - shape1.width -8 ) then dx := -1;

 // testen, ob der Kreis in y-Richtung an den Rand des Formulars stößt
 if shape1.top <= 0 then dy:= +1;
 if (shape1.top >= form1.height - shape1.height-34 ) then dy:=-1;


 // testen, ob der Kreis mit dem untersten Punkt die Linie berührt
 if (shape1.Left+shape1.Width/2>shape2.Left)
 and (shape1.Left+shape1.Width/2<shape2.left+shape2.width)
 and (shape1.top+shape1.height=shape2.top)
 then dy:=-1;

 // testen, ob der Kreis mit dem obersten Punkt die Linie berührt
 if (shape1.Left+shape1.Width/2>shape2.Left)
 and (shape1.Left+shape1.Width/2<shape2.left+shape2.width)
 and (shape1.top=shape2.top+shape2.Height)
 then dy:=+1;

 // testen, ob der Kreis den linken Endpunkt der Linie berührt

 rq := (shape1.width div 2); rq := rq*rq; // rq = radius zum Quadrat
 ax := (shape1.Left + shape1.Width div 2) - shape2.left; // ax = abstand in x-richtung
 ay := (shape1.top + shape1.Height div 2) - shape2.top; // ay = abstand in y-richtung
 aq := ax*ax + ay*ay; // aq = Abstand zum Quadrat

 if aq > rq then
  begin
   dx := -dx;
   dy := -dy;
  end;

 ay := (shape1.top + shape1.Height div 2) - shape2.top - shape2.Height; // ay = abstand in y-richtung
 aq := ax*ax + ay*ay; // aq = Abstand zum Quadrat
 if aq > rq then
  begin
   dx := -dx;
   dy := -dy;
  end;

 // testen, ob der Kreis den rechten Endpunkt der Linie berührt


 ax := shape2.Left+shape2.width-shape1.left-shape1.width div 2; // ax = abstand in x-richtung
 aq := ax*ax + ay*ay; // aq = Abstand zum Quadrat



 if aq > rq then
  begin
   dx := -dx;
   dy := -dy;
  end;

 ax := shape2.Left+shape2.width-shape1.left-shape1.width div 2; // ax = abstand in x-richtung
 ay := (shape1.top + shape1.Height div 2) - shape2.top; // ay = abstand in y-richtung
 aq := ax*ax + ay*ay; // aq = Abstand zum Quadrat
 if aq > rq then
  begin
   dx := -dx;
   dy := -dy;
  end;

(**)(**)(**)(**)
(**)(**)(**)(**)
(**)(**)(**)(**)
(**)(**)(**)(**)
  // testen, ob der Kreis mit dem untersten Punkt die Linie2 berührt
 if (shape1.Left+shape1.Width/2>shape3.Left)
 and (shape1.Left+shape1.Width/2<shape3.left+shape3.width)
 and (shape1.top+shape1.height=shape3.top)
 then dy:=-1;

 // testen, ob der Kreis mit dem obersten Punkt die Linie2 berührt
 if (shape1.Left+shape1.Width/2>shape3.Left)
 and (shape1.Left+shape1.Width/2<shape3.left+shape3.width)
 and (shape1.top=shape3.top+shape3.Height)
 then dy:=+1;


 // testen, ob der Kreis den linken Endpunkt der Linie2 berührt

 rq := (shape1.width div 2); rq := rq*rq; // rq = radius zum Quadrat
 ax := (shape1.Left + shape1.Width div 2) - shape3.left; // ax = abstand in x-richtung
 ay := (shape1.top + shape1.Height div 2) - shape3.top; // ay = abstand in y-richtung
 aq := ax*ax + ay*ay; // aq = Abstand zum Quadrat

 if aq > rq then
  begin
   dx := -dx;
   dy := -dy;
  end;

 ay := (shape1.top + shape1.Height div 2) - shape3.top - shape3.Height; // ay = abstand in y-richtung
 aq := ax*ax + ay*ay; // aq = Abstand zum Quadrat
 if aq > rq then
  begin
   dx := -dx;
   dy := -dy;
  end;

 // testen, ob der Kreis den rechten Endpunkt der Linie berührt


 ax := shape3.Left+shape3.width-shape1.left-shape1.width div 2; // ax = abstand in x-richtung
 aq := ax*ax + ay*ay; // aq = Abstand zum Quadrat



 if aq > rq then
  begin
   dx := -dx;
   dy := -dy;
  end;

 ax := shape3.Left+shape3.width-shape1.left-shape1.width div 2; // ax = abstand in x-richtung
 ay := (shape1.top + shape1.Height div 2) - shape3.top; // ay = abstand in y-richtung
 aq := ax*ax + ay*ay; // aq = Abstand zum Quadrat
 if aq > rq then
  begin
   dx :=-dx;
   dy := -dy;
  end;

// Punkteberechnung für Spieler Rot
if shape1.top<=0
   then
   begin
   inc(score)
   end ;

label2.Caption:=FloatToStr(score);
// Punkteberechnung für Spieler Blau
if shape1.top+shape1.height>=form1.height-34
   then
   begin
   inc(score2)
   end ;

label4.Caption:=FloatToStr(score2) ;



//if score=5
//then showmessage ('Spieler Rot hat gewonnen');

end; // timer1
http://img204.imageshack.us/my.php?i...benannttv2.jpg


und jetzt meine Fragen :


1. zunächst einmal hab ich ein Problem damit , das meine Kugel , also mein Shape1 zwar oben , unten und an den Ecken des Shape2 und Shape3 abprallt , jedoch durch die linke und die rechte Seite durchläuft , doch hab ich keine Ahnung warum das passiert ?!zu sehen in Bild A

2. hab ich ein Problem , wenn ich das Shape2 bzw 3 mit der maus in richtung Kugel schieben sollte das die Kugel ja abprallen , jedoch bleibt sie dann auf/in dem Shape 2 bzw 3 hängen und geht nur ein wenig hin und her und ohne meine Beihilfe garnicht mehr weg vom Shape 2.


nun meine Frage ist , ob mir wer helfen kann das Problem 1 zu lösen , denn ich glaube das sich damit auch das Problem 2 löst
Vielleicht zu sagen ist noch , dass ich (bisher) nicht viel Ahnung von Delphi habe , da ich es erst seit einer Woche durch ein Schulpraktikum lerne .



Danke schonmal im voraus !

Mfg Andi
  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