AGB  ·  Datenschutz  ·  Impressum  







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

Ping-Pong

Ein Thema von whiteshark · begonnen am 14. Mai 2004 · letzter Beitrag vom 15. Mai 2004
Antwort Antwort
Benutzerbild von whiteshark
whiteshark

Registriert seit: 4. Dez 2003
Ort: Cottbus
222 Beiträge
 
Delphi 2005 Personal
 
#1

Ping-Pong

  Alt 14. Mai 2004, 18:12
Hallo Leute,

ich habe ein Problem und zwar will ich ein PINK-PONK programmiern. Es funktioniert ja soweit mit an den Seiten abprallen und so, aber ich kann den balken nicht richtig bewegen bzw. garnicht. Beim Compilieren brinnt er aber keinen Fehler. Wer kann mir helfen?

CODE:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
const radius=15;
      balkenbreite=70;
      balkenhoehe=15;
begin
loeschcolor:=form1.color;
loeschpen:=form1.color;
loeschbrush:=form1.color;
canvas.brush.color:=clblue;
canvas.pen.color:=clblue;
balkenmitte := form1.clientwidth div 2;
balkenbx:=4;
x:=width div 2;
y:=height div 2; // Position
bx:= 2;
by:=2;

canvas.pen.color:=clgreen;
canvas.Brush.color:=clyellow;
  rechteck.Left := 80;
  rechteck.Top := 70;
  rechteck.Right := 130;
  rechteck.Bottom := 120;
form1.Canvas.Rectangle(rechteck); //Rechteck


repeat
stop:=false;

form1.canvas.Pen.Color:=clgreen;
form1.canvas.Brush.color:=clyellow;
canvas.Ellipse(x-radius,y-radius,x+radius,y+radius); //malen

sleep(5); //warten

form1.canvas.Pen.color:=loeschpen;
form1.canvas.Brush.color:=loeschbrush;
form1.Canvas.ellipse(x-radius,y-radius,x+radius,y+radius); //loeschen#



x:=x+bx;
y:=y+by; //rechnen

if (x<radius) or(x>form1.clientwidth-radius) then begin
                bx:=-bx;
                end;

if (y<radius) or(y>form1.ClientHeight-radius) then begin
                by:=-by;
                end;
application.ProcessMessages;
until stop=true;
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if Key=vk_F1 then begin
                     rechteck.Left:=rechteck.left-5;
                     rechteck.bottom:=rechteck.bottom-5;
                     rechteck.Right:=rechteck.right-5;
                     rechteck.Top:=rechteck.top-5;
                     end;

 if Key=vk_F2 then begin
                      rechteck.Left:=rechteck.left+5;
                      rechteck.bottom:=rechteck.bottom+5;
                      rechteck.Right:=rechteck.right+5;
                      rechteck.Top:=rechteck.top+5;
                      end;

end;




end.
[edit=MrSpock]Doppelpost gelöscht. Code Tags gesetzt. Mfg, MrSpock[/edit]
  Mit Zitat antworten Zitat
Niko

Registriert seit: 23. Jun 2003
416 Beiträge
 
Delphi 2006 Professional
 
#2

Re: Ping-Pong

  Alt 14. Mai 2004, 18:31
So wird das nicht funktionieren. Du müsstes das Rechteck im Keydown schon neu zeichnen - und vorher das alte löschen - damit man die Änderung sieht.
"Electricity is actually made up of extremely tiny particles called electrons, that you cannot see with the naked eye unless you have been drinking." (Dave Barry)
  Mit Zitat antworten Zitat
Benutzerbild von fred.reichbier
fred.reichbier

Registriert seit: 27. Apr 2004
154 Beiträge
 
#3

Re: Ping-Pong

  Alt 14. Mai 2004, 18:47
ausserdem würde ich empfehlen, das mit einem TShape zu machen.
->Muss man nicht neu zeichnen, sondern nur Top verändern.
Und wegen F1 und F2:
Nimm einfach VK_UP (pfeil hoch) und VK_DOWN (pfeil runter).
Ansonsten, falls du Beispiel suchst, hab auch schon eins programmiert
und
kann dir evtl. Quellcode schicken.
Friedrich Weber
  Mit Zitat antworten Zitat
Niko

Registriert seit: 23. Jun 2003
416 Beiträge
 
Delphi 2006 Professional
 
#4

Re: Ping-Pong

  Alt 14. Mai 2004, 19:22
Da ich um Code gebeten worden bin - so in etwa könnte dein KeyDown dann aussehen:
Delphi-Quellcode:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  canvas.pen.color := form1.color
  canvas.Brush.color := form1.color;
  form1.Canvas.Rectangle(rechteck); // Rechteck löschen
  if Key=vk_F1 then
  begin
    rechteck.Left:=rechteck.left-5;
    rechteck.bottom:=rechteck.bottom-5;
    rechteck.Right:=rechteck.right-5;
    rechteck.Top:=rechteck.top-5;
  end;

  if Key=vk_F2 then
  begin
    rechteck.Left:=rechteck.left+5;
    rechteck.bottom:=rechteck.bottom+5;
    rechteck.Right:=rechteck.right+5;
    rechteck.Top:=rechteck.top+5;
  end;

  canvas.pen.color:=clgreen;
  canvas.Brush.color:=clyellow;
  form1.Canvas.Rectangle(rechteck); // Rechteck an neuer Position zeichnen

end;
"Electricity is actually made up of extremely tiny particles called electrons, that you cannot see with the naked eye unless you have been drinking." (Dave Barry)
  Mit Zitat antworten Zitat
StefanDP

Registriert seit: 11. Apr 2004
294 Beiträge
 
#5

Re: Ping-Pong

  Alt 14. Mai 2004, 19:24
Stichwort:

TForm.KeyPreview!
  Mit Zitat antworten Zitat
Nicodius

Registriert seit: 25. Apr 2003
Ort: Graz
2.234 Beiträge
 
Delphi 2006 Architect
 
#6

Re: Ping-Pong

  Alt 14. Mai 2004, 21:41
Naja ohne DelphiX kannst du sowieso nur eine Taste einlesen
Nico Müller
  Mit Zitat antworten Zitat
Benutzerbild von Jens Schumann
Jens Schumann

Registriert seit: 27. Apr 2003
Ort: Bad Honnef
1.644 Beiträge
 
Delphi 2009 Professional
 
#7

Re: Ping-Pong

  Alt 14. Mai 2004, 23:02
Zitat von Nicodius:
Naja ohne DelphiX kannst du sowieso nur eine Taste einlesen
Das ist nicht richtig !!! Ich verweise hier auf GeyKeyState und/oder GetAsyncKeyState
I come from outer space to save the human race
  Mit Zitat antworten Zitat
Nicodius

Registriert seit: 25. Apr 2003
Ort: Graz
2.234 Beiträge
 
Delphi 2006 Architect
 
#8

Re: Ping-Pong

  Alt 15. Mai 2004, 05:47
aso? ... naja aber das muss man dann ja die ganze Zeit abfragen ?! ist auch keine gute lösung

oder versteh ich das jetzt nicht ganz
Nico Müller
  Mit Zitat antworten Zitat
Benutzerbild von Jens Schumann
Jens Schumann

Registriert seit: 27. Apr 2003
Ort: Bad Honnef
1.644 Beiträge
 
Delphi 2009 Professional
 
#9

Re: Ping-Pong

  Alt 15. Mai 2004, 08:27
Zitat von Nicodius:
aso? ... naja aber das muss man dann ja die ganze Zeit abfragen ?! ist auch keine gute lösung

oder versteh ich das jetzt nicht ganz
DelphiX macht doch auch nichts anderes als in bestimmten Zeitabständen (Interval) alle Eingabemöglichkeiten (DXInput o. so heißt das - glaube ich) abzufragen.
I come from outer space to save the human race
  Mit Zitat antworten Zitat
Benutzerbild von whiteshark
whiteshark

Registriert seit: 4. Dez 2003
Ort: Cottbus
222 Beiträge
 
Delphi 2005 Personal
 
#10

Re: Ping-Pong

  Alt 15. Mai 2004, 09:37
Danke an alle, die mir helfen konnten
Men are born ignorant, not stupid; they are made stupid by education. - Bertrand Russell

I cannot teach anybody anything, i can only make them think. - Socrates
  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 03:49 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz