Autor Beitrag
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 12.10.04 13:06 
Ich wollte mal anfangen, ein kleines Spiel zu programmieren,
wenn man Pfeil unten drückt, soll sich ein Bild so lange nach unten bewegen, bis man
die Taste loslässt also dachte ich mir
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key=#40 then down.enabled:=true;
end;

procedure TForm1.downTimer(Sender: TObject);
var
d:integer;
begin
d:=d+1;
l.top:=l.top+d;
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key=#81 then down.enabled:=false;
end;

aber beim compilieren steht da, dass das inkompatible typen sind, wie krieg ich das hin??? [l ist in diesem Fall das Bild]

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 12.10.04 13:20 
Du musst die virtuellen Tastencodes (siehe OH) benutzen. Mit dem "#" vor der Zahl stellst du einen Char mit Code-Nummer xx dar. Das vergleichst du dann mit Key vom Typ Word. Das kann nicht funktionieren.
Du brauchst aber z.B.: vk_down (vk=virtual key).
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 12.10.04 13:44 
kannst du mal ein beispiel code schreiben
zB wo ich das reinschreiben soll (zb on key down)
und if ... then
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 12.10.04 14:05 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;  
  Shift: TShiftState);  
begin  
down.enabled:=(key=vk_down);  // So würde ich das machen
end;
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 12.10.04 14:31 
danke :D
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 12.10.04 14:34 
wenn ich jetzt aber auf Pfeil unten drücke, passiert zunächst nix und dann ist das
bild auf einmal ganz weit unten :?
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 12.10.04 14:39 
ich hab den Timer jetzt mal modifiziert, aber dann springt das bild nach dem Timer-
intervallablauf einfach nach unten, ich möchte aber eine art animation haben,
die unterbrochen wird, wenn man den key loslässt
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.downTimer(Sender: TObject);
var
d:integer;
begin
d:=d+1;
if d > 88 then d:=88;
l.top:=l.top+d;
end;

Man soll nämlich mit den Pfeiltasten einen Balken hoch/runter bewegen können
(wie bei "Tennis")
d.h. wenn man die taste loslässt, hört der balken auf sich zu bewegen
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 12.10.04 14:42 
so geht das, aber jetzt funktioniert die Begrenzung von 88 Einheiten nicht mehr
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.downTimer(Sender: TObject);
var
d:integer;
begin
d:=0;
d:=d+1;
if d > 88 then d:=88;
l.top:=l.top+d;
end;
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 12.10.04 14:43 
und wenn ich die taste loslasse, hört der balken nicht auf sich zu bewegen.
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 12.10.04 14:46 
ich glaube der fehler steck hier:
ausblenden Quelltext
1:
2:
3:
4:
5:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
down.enabled:=(key=vk_down);
end;

da muss irgendwie als ergebnis false rauskommen, damit der Timer wieder abgeschaltet
wird
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 12.10.04 14:47 
Bin mir jetzt nicht ganz sicher, ob folgender Vorschlag funktioniert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;    
  Shift: TShiftState);    
begin    
down.enabled:=(key=vk_down);
key := 0; // Key auf neutralen Zustand setzen. 
// Beim festhalten, reagiert das Programm vielleicht darauf wie wiederholtes drücken
end;

oder
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;    
  Shift: TShiftState);    
begin    
down.enabled:=not (key=vk_down);
end;


Musst vielleicht mal ein bisschen rumexperimentieren. Im Moment habe ich genug Zeit, ein Testprogramm dafür zu basteln. Eventuell heute Abend.
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 12.10.04 15:27 
danke :wink:
ich werd n bisschen rumprobieren
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 12.10.04 15:31 
ICH HAB DIE LÖSUNG (und sie ist wirklich billig :lol: )
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key = vk_up then up.enabled:=false;
if key = vk_down then down.enabled:=false;
end;
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Do 14.10.04 11:39 
Der vollständige
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
up.enabled:=(key=vk_up);
down.enabled:=(key=vk_down);
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key = vk_up then up.enabled:=false;
if key = vk_down then down.enabled:=false;
end;

procedure TForm1.upTimer(Sender: TObject);
var
u:integer;
begin
down.enabled:=false;
u:=0;
u:=u+speed;
l.top:=l.top-u;
if l.top<spielfeld.top + 6 then l.top:=spielfeld.top + 6;
end;

procedure TForm1.downTimer(Sender: TObject);
var
d:integer;
begin
up.enabled:=false;
d:=0;
d:=d+speed;
l.top:=l.top+d;
if l.top>spielfeld.height + Spielfeld.top - l.height - 6 then l.top:=spielfeld.height + spielfeld.top - l.height - 6;
end;
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 27.10.04 14:16 
nach einigen fehlern mit der steuerung, hier noch mal :

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TGame.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
//Hoch/RunterCheck -> an
if key = vk_down then begin
LinksRunter := true;
LinksHoch := false;
end;
if key = vk_up then begin
LinksHoch := true;
LinksRunter := false;
end;
end;

procedure TGame.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
//Hoch/RunterCheck -> aus
if key = vk_down then LinksRunter := false;
if key = vk_up then LinksHoch := false;
end;


Dann fällt die abfrage nich mehr in den timer und verzögerungen werden so vermieden