Autor Beitrag
0xCC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 150



BeitragVerfasst: Fr 19.05.06 19:02 
user profile iconJoachim Knutson hat folgendes geschrieben:
also ich wollte ursprünglich wissen, wie man nach Pansenen's variante diese variable 'speed' dekariert.
eigenlich weiß ich gar nich wie ich die dritte prozedur in mein progri bringe.

was willst du mit der dritten prozedur wenn du nicht mal weisst was sie macht ?

was willst du denn nun eigentlich machen ?
Joachim Knutson
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Sa 20.05.06 15:15 
user profile icon0xCC hat folgendes geschrieben:
user profile iconJoachim Knutson hat folgendes geschrieben:
also ich wollte ursprünglich wissen, wie man nach Pansenen's variante diese variable 'speed' dekariert.
eigenlich weiß ich gar nich wie ich die dritte prozedur in mein progri bringe.

was willst du mit der dritten prozedur wenn du nicht mal weisst was sie macht ?

was willst du denn nun eigentlich machen ?


also ich habe ein timage, welches ich schon nach allen seiten steuern kann.
doch ich will auch, dass man es in 2 richtungen zugleich gehen kann. also z.b. nach oben-rechts.

und dazu brauch ich ja noch 2 extra prozeduren. ich habe schon bei onkeydown und onkeyup reingeschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;  
  Shift: TShiftState);  
begin  
if (key = Ord('U'))  then keys[0]:= 1;  
if (key = Ord('J')) then keys[1]:=1;  
if (key = Ord('H')) then keys[2]:=1;  
if (key = Ord('K')) then keys[3]:=1;  
end;  
 
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;  
  Shift: TShiftState);  
begin  
if (key = Ord('U'))  then keys[0]:= 0;  
if (key = Ord('J')) then keys[1]:=0;  
if (key = Ord('H')) then keys[2]:=0;  
if (key = Ord('K')) then keys[3]:=0;  
end;

und nun muss ich doch noch sagen was ich machen soll wenn nun 2 tasten gedrückt werden oder?
und dazu hab ich für jeweils eine taste das hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm4.FormKeyPress(Sender: TObject; var Key: Char);
 begin
if key = 'd' then
Image1.Left:=Image1.Left+10;
if key = 'a' then
Image1.left:=Image1.left-10;
if key = 'w' then
Image1.top:=Image1.top-10;
if key = 's' then
Image1.top:=Image1.top+10;
end;

und jetz brauch ich halt noch das für 2 tasten, weiß aber nich wie ichs machen soll.
Pansenen hatte ja in seiner porzedur das:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.pmoveTimer(Sender: TObject);    
begin    
if (keys[1] = 1and (P[1].top>speed[1]+21then P[1].Top := P[1].top-speed[1];    
if (keys[2] = 1and (P[1].top<form1.ClientHeight-65-speed[1]) then P[1].Top := P[1].top+speed[1];    
if (keys[3] = 1and (P[1].left>0then P[1].left := P[1].left-speed[1];    
if (keys[4] = 1and (P[1].left<form1.Width-65-speed[1]) then P[1].left := P[1].left+speed[1];    
end;

nur da weiß ich nich wie ich speed deklariere.
villeicht hast du ja ne idee?
0xCC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 150



BeitragVerfasst: Sa 20.05.06 15:33 
benötigt ein timer mit interval 10:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if GetForeGroundWindow = handle then
  begin
     if GetKeyState(byte('W'))and $8000 >0 then
       image1.Top:=image1.Top-10;
     if GetKeyState(byte('S'))and $8000 >0 then
       image1.Top:=image1.Top+10;
     if GetKeyState(byte('A'))and $8000 >0 then
       image1.Left:=image1.Left-10;
     if GetKeyState(byte('D'))and $8000 >0 then
       image1.Left:=image1.Left+10;
  end;
end;
NeoInDerMATRIX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 245

Win95, Win98(+se), WinNT, Win2000, WinME, WinXP(+pro), VISTA, Linux(SuSe), DOS [MultiMon(3)], Vista
D6 PeE + (FP 2.0l) + D3 Pe + D2005+ D2006 Arch
BeitragVerfasst: Sa 20.05.06 18:52 
Hallo,

dann brauchst du garkeine onKeyPress mehr!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm4.CalcMovement;  
 begin  
  if key[1then  
   Image1.Left:=Image1.Left+10;  
  if key[2then  
   Image1.left:=Image1.left-10;  
  if key[3then  
   Image1.top:=Image1.top-10;  
  if key[4then  
   Image1.top:=Image1.top+10;  
End;


Und das rufst du for dem Rendern auf! Kann sein das du die Key Var sachen anpassen must! Weis leider nicht genau wie die deklariert sind.
Und wenn du das noch mit Movement Speed machen willst, dann machste noch ne var die nen durchlauf Timer beinhaltet.

Cu
Neo

P.S.: Habe mich mal eben hingesetzt und sowas in der art zusammen gebastelt.
ausblenden volle Höhe Delphi-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:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    StaticText1: TStaticText;
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    KeyState: Array[0..255]of Boolean;
    KeyTime: Array[0..255]of Integer;
    Procedure onIdle(Sender: TObject; var Done: Boolean);
    Procedure CalcMovement;
    Procedure CheckPlace;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
Const
 km_BackSlash = 8;
 km_TAB = 9;
 km_Return = 13;
 km_Shift = 16;
 km_Ctrl = 17;
 km_Alt = 18{ ? }
 km_Break = 19;
 km_ESC = 27;
 km_Lehrtaste = 32;
 km_ScreenUp = 33;
 km_ScreenDown = 34;
 km_End = 35;
 km_Home = 36;
 km_Left = 37;
 km_Up = 38;
 km_Rigth = 39;
 km_Down = 40;
 km_Print = 44;
 km_Ins = 45;
 km_Del = 46;
 km_0 = 47;
 km_1 = 48;
 km_2 = 49;
 km_3 = 50;
 km_4 = 51;
 km_5 = 52;
 km_6 = 53;
 km_7 = 54;
 km_8 = 55;
 km_9 = 56;
 km_A = 65;
 km_B = 66;
 km_C = 67;
 km_D = 68;
 km_E = 69;
 km_F = 70;
 km_G = 71;
 km_H = 72;
 km_I = 73;
 km_J = 74;
 km_K = 75;
 km_L = 76;
 km_M = 77;
 km_N = 78;
 km_O = 79;
 km_P = 80;
 km_Q = 81;
 km_R = 82;
 km_S = 83;
 km_T = 84;
 km_U = 85;
 km_V = 86;
 km_W = 87;
 km_X = 88;
 km_Y = 89;
 km_Z = 90;
 km_WinLeft = 91;
 km_WinRigth = 92;
 km_WinKontect =93;
 km_NUM0 = 96;
 km_NUM1 = 97;
 km_NUM2 = 98;
 km_NUM3 = 99;
 km_NUM4 = 100;
 km_NUM5 = 101;
 km_NUM6 = 102;
 km_NUM7 = 103;
 km_NUM8 = 104;
 km_NUM9 = 105;
 km_NUMMul = 106;
 km_NUMPlus = 107;
 km_NUMMinus = 109;
 km_NUMKomma = 110;
 km_NUMDiv = 111;
 km_F1 = 112;
 km_F2 = 113;
 km_F3 = 114;
 km_F4 = 115;
 km_F5 = 116;
 km_F6 = 117;
 km_F7 = 118;
 km_F8 = 119;
 km_F9 = 120;
 km_F10 = 121{ Geht nicht koreckt }
 km_F11 = 122;
 km_F12 = 123;
 km_NUMLook = 144;
 km_Roll = 145;
 km_Plus = 187;
 km_Komma = 188;
 km_Minus = 189;
 km_Punkt = 190;
 km_Raute = 191;
 km_Fragezeichen = 219;
 km_Dead0 = 220{ ^ }
 km_Dead2 = 221{ ´ }
 km_Dead1 = 226{ < }
{ Kann sein das dieses noch verlegt werden muss }
 km_MouseLeft = 246;
 km_MouseRigth = 247;
 km_MouseUp = 248;
 km_MouseDown = 249;
 km_MouseButtonLeft = 250;
 km_MouseButtonRigth = 251;
 km_MouseButtonMiddle = 252;
 km_MouseWheelUp = 253;
 km_MouseWheelDown = 254;
 km_MouseWheelPressed = 255;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 If KeyState[Key] Then
   KeyTime[Key]:=KeyTime[Key] + 1
  Else Begin
   KeyState[Key]:=TRUE;
   KeyTime[Key]:=1;
  End;
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 KeyState[Key]:=FALSE;
 KeyTime[Key]:=0;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 KeyPreview:=TRUE;
 Application.onIdle:=onIdle;
end;

Procedure tForm1.CalcMovement;
Begin
 If KeyState[km_S] Then
  Button1.Top:=Button1.Top + KeyTime[km_S];
 If KeyState[km_W] Then
  Button1.Top:=Button1.Top - KeyTime[km_W];
 If KeyState[km_A] Then
  Button1.Left:=Button1.Left - KeyTime[km_A];
 If KeyState[km_D] Then
  Button1.Left:=Button1.Left + KeyTime[km_D];
End;

Procedure tForm1.CheckPlace;
Begin
 If Button1.Left<5 Then
  Button1.Left:=5;
 If Button1.Left+Button1.Width>Width - 10 Then
  Button1.Left:=Width - Button1.Left - 10;
 If Button1.Top<5 Then
  Button1.Top:=5;
 If Button1.Top + Button1.Height>Height - 10 Then
  Button1.Top:=Height - Button1.Height - 10;
End;

Procedure tForm1.onIdle(Sender: TObject; var Done: Boolean);
Begin
 CalcMovement;
 CheckPlace;
 StaticText1.Caption:='X = ' + IntToStr(Button1.Left) + ' | Y = ' + IntToStr(Button1.Top);
End;

end.

Das geht bei mir bis auf die Kollision rechts und unten! Aber darn solltest du sehen wie du das recht simpel machen kannst! Ohne Polling.
Joachim Knutson
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Sa 20.05.06 20:52 
user profile iconNeoInDerMATRIX hat folgendes geschrieben:
Hallo,
P.S.: Habe mich mal eben hingesetzt und sowas in der art zusammen gebastelt.
ausblenden volle Höhe Delphi-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:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    StaticText1: TStaticText;
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    KeyState: Array[0..255]of Boolean;
    KeyTime: Array[0..255]of Integer;
    Procedure onIdle(Sender: TObject; var Done: Boolean);
    Procedure CalcMovement;
    Procedure CheckPlace;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
Const
 [...]

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 If KeyState[Key] Then
   KeyTime[Key]:=KeyTime[Key] + 1
  Else Begin
   KeyState[Key]:=TRUE;
   KeyTime[Key]:=1;
  End;
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 KeyState[Key]:=FALSE;
 KeyTime[Key]:=0;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 KeyPreview:=TRUE;
 Application.onIdle:=onIdle;
end;

Procedure tForm1.CalcMovement;
Begin
 If KeyState[km_S] Then
  Button1.Top:=Button1.Top + KeyTime[km_S];
 If KeyState[km_W] Then
  Button1.Top:=Button1.Top - KeyTime[km_W];
 If KeyState[km_A] Then
  Button1.Left:=Button1.Left - KeyTime[km_A];
 If KeyState[km_D] Then
  Button1.Left:=Button1.Left + KeyTime[km_D];
End;

Procedure tForm1.CheckPlace;
Begin
 If Button1.Left<5 Then
  Button1.Left:=5;
 If Button1.Left+Button1.Width>Width - 10 Then
  Button1.Left:=Width - Button1.Left - 10;
 If Button1.Top<5 Then
  Button1.Top:=5;
 If Button1.Top + Button1.Height>Height - 10 Then
  Button1.Top:=Height - Button1.Height - 10;
End;

Procedure tForm1.onIdle(Sender: TObject; var Done: Boolean);
Begin
 CalcMovement;
 CheckPlace;
 StaticText1.Caption:='X = ' + IntToStr(Button1.Left) + ' | Y = ' + IntToStr(Button1.Top);
End;

end.

Das geht bei mir bis auf die Kollision rechts und unten! Aber darn solltest du sehen wie du das recht simpel machen kannst! Ohne Polling.

cool thx, jetz hab ich hinbekommen. das leuchtet soweit ein.

(lustige sache mit dem StaticText1. :wink: )

also weißt du nich genau woran das liegt, dass er ganz rechts dann auf einmal wieder links erscheint?
NeoInDerMATRIX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 245

Win95, Win98(+se), WinNT, Win2000, WinME, WinXP(+pro), VISTA, Linux(SuSe), DOS [MultiMon(3)], Vista
D6 PeE + (FP 2.0l) + D3 Pe + D2005+ D2006 Arch
BeitragVerfasst: Sa 20.05.06 21:09 
Ist nur nen rechen oder prüf fehler den ich so auf die schnelle nicht seh! Aber ich denke das bekommst du mit ein wenig testen hin! Ach übrigens das ist so ungefair der source denn ich dir auch schon am anfang gezeigt habe. Nur das hier noch kein Mappen der Tasten gemacht wird. Und vergess nicht das du sicher auch noch etwas in der Time sache anpassen must!
Joachim Knutson
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Sa 20.05.06 21:40 
user profile iconNeoInDerMATRIX hat folgendes geschrieben:
Ist nur nen rechen oder prüf fehler den ich so auf die schnelle nicht seh! Aber ich denke das bekommst du mit ein wenig testen hin! Ach übrigens das ist so ungefair der source denn ich dir auch schon am anfang gezeigt habe. Nur das hier noch kein Mappen der Tasten gemacht wird. Und vergess nicht das du sicher auch noch etwas in der Time sache anpassen must!

ja das werd ich machen. nichts geht übers testen... :D

danke dafür.
Joachim Knutson
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Mo 22.05.06 17:16 
ich habe zwar nun schon sehr sehr (sehr) lange getestet, aber das nicht meinen bedürfnissen anpassen können.

also das größte problem ist:
je länger man auf eine taste drückt, desto schneller wird er. (d.h. irgendwann ist er so schnell, dass man ihn kaun noch sieht.)

sieht da jemand ne lösung? bin echt am ende, kann nich mehr.

ich denke ja, dass es an folgender prozedur liegt (bzw. die makierte zeile):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
Procedure tForm4.CalcMovement;
Begin  
 If KeyState[km_S] Then  
 -------> Image1.Top:=Image1.Top + KeyTime[km_S]; <-------
 If KeyState[km_W] Then 
  ------->  Image1.Top:=Image1.Top - KeyTime[km_W];<-------
 If KeyState[km_A] Then  
  ------->  Image1.Left:=Image1.Left - KeyTime[km_A];<-------
 If KeyState[km_D] Then  
  ------->  Image1.Left:=Image1.Left + KeyTime[km_D];<-------
End;
NeoInDerMATRIX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 245

Win95, Win98(+se), WinNT, Win2000, WinME, WinXP(+pro), VISTA, Linux(SuSe), DOS [MultiMon(3)], Vista
D6 PeE + (FP 2.0l) + D3 Pe + D2005+ D2006 Arch
BeitragVerfasst: Mo 22.05.06 18:03 
Hallo,

Du must dazu den KeyTime ein maximal wert zuordnen und dies vor jedem Verwenden Prüfen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Procedure tForm4.CalcMovement; 
Var
 Lauf: Integer;
  Begin   
   For Lauf:=0 to 255 do
    If KeyTime[Lauf]>10 Then
     KeyTime[Lauf]:=10;
   If KeyState[km_S] Then   
   -------> Image1.Top:=Image1.Top + KeyTime[km_S]; <------- 
   If KeyState[km_W] Then  
    ------->  Image1.Top:=Image1.Top - KeyTime[km_W];<------- 
   If KeyState[km_A] Then   
    ------->  Image1.Left:=Image1.Left - KeyTime[km_A];<------- 
   If KeyState[km_D] Then   
    ------->  Image1.Left:=Image1.Left + KeyTime[km_D];<------- 
  End;


Cu
Neo