小弟在做一个多人射击游戏
现在需要解决的是4个人同时玩,比如用键盘"a","s","d","f"键分别代表不同鼠标的左健(即射击发射子弹键)
现在关键是
不论用什么办法怎么模拟4个鼠标,如果都用键盘是不是会冲突。
大家有没有什么好办法或是有什么其他的好办法??
现在需要解决的是4个人同时玩,比如用键盘"a","s","d","f"键分别代表不同鼠标的左健(即射击发射子弹键)
现在关键是
不论用什么办法怎么模拟4个鼠标,如果都用键盘是不是会冲突。
大家有没有什么好办法或是有什么其他的好办法??
真是业内人士呀
顺便解决我的第一个问题吧
你能搞到射击“靶子”的图片吗?谢拉
1.写一个player类;
2.用4个线程分别控制player的4个实例;
3.每个实例检测一个键的状态,如果是按下的就打一枪.
Form1: TForm1;
Keys:array [0..3,0..3] of boolean;implementation{$R *.dfm}procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=Ord('A') then
Keys[0][0]:=true
else if Key=Ord('F') then
Keys[1][0]:=true
else if Key=Ord('J') then
Keys[2][0]:=true
else if Key=VK_LEFT then
Keys[3][0]:=true
else if Key=Ord('D') then
Keys[0][1]:=true
else if Key=Ord('H') then
Keys[1][1]:=true
else if Key=Ord('L') then
Keys[2][1]:=true
else if Key=VK_RIGHT then
Keys[3][1]:=true
else if Key=Ord('W') then
Keys[0][2]:=true
else if Key=Ord('T') then
Keys[1][2]:=true
else if Key=Ord('I') then
Keys[2][2]:=true
else if Key=VK_UP then
Keys[3][2]:=true
else if Key=Ord('S') then
Keys[0][3]:=true
else if Key=Ord('G') then
Keys[1][3]:=true
else if Key=Ord('K') then
Keys[2][3]:=true
else if Key=VK_DOWN then
Keys[3][3]:=true;
end;procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=Ord('A') then
Keys[0][0]:=false
else if Key=Ord('F') then
Keys[1][0]:=false
else if Key=Ord('J') then
Keys[2][0]:=false
else if Key=VK_LEFT then
Keys[3][0]:=false
else if Key=Ord('D') then
Keys[0][1]:=false
else if Key=Ord('H') then
Keys[1][1]:=false
else if Key=Ord('L') then
Keys[2][1]:=false
else if Key=VK_RIGHT then
Keys[3][1]:=false
else if Key=Ord('W') then
Keys[0][2]:=false
else if Key=Ord('T') then
Keys[1][2]:=false
else if Key=Ord('I') then
Keys[2][2]:=false
else if Key=VK_UP then
Keys[3][2]:=false
else if Key=Ord('S') then
Keys[0][3]:=false
else if Key=Ord('G') then
Keys[1][3]:=false
else if Key=Ord('K') then
Keys[2][3]:=false
else if Key=VK_DOWN then
Keys[3][3]:=false;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
if Keys[0][0] then
Image1.Left:=Image1.Left-1;
if Keys[0][1] then
Image1.Left:=Image1.Left+1;
if Keys[0][2] then
Image1.Top:=Image1.Top-1;
if Keys[0][3] then
Image1.Top:=Image1.Top+1;
if Keys[1][0] then
Image2.Left:=Image2.Left-1;
if Keys[1][1] then
Image2.Left:=Image2.Left+1;
if Keys[1][2] then
Image2.Top:=Image2.Top-1;
if Keys[1][3] then
Image2.Top:=Image2.Top+1;
if Keys[2][0] then
Image3.Left:=Image3.Left-1;
if Keys[2][1] then
Image3.Left:=Image3.Left+1;
if Keys[2][2] then
Image3.Top:=Image3.Top-1;
if Keys[2][3] then
Image3.Top:=Image3.Top+1;
if Keys[3][0] then
Image4.Left:=Image4.Left-1;
if Keys[3][1] then
Image4.Left:=Image4.Left+1;
if Keys[3][2] then
Image4.Top:=Image4.Top-1;
if Keys[3][3] then
Image4.Top:=Image4.Top+1;
Application.ProcessMessages;
end;
2个人,一个用大键盘,一个用小键盘,386上从来没有延迟!
(3)就不行了,486上都会有延迟给你个思路:程序中使用定时器(无限循环也可),将当前的键盘缓冲全部取出(同时清空键盘缓冲),然后进行计算,并将计算的结果反映在屏幕上。关于键盘缓冲,参见下面的地址
http://pagoda-ooos.51.net/os_book/driver/driver-keyboard_2.htm注意在编程的时候,要自己控制repeat code,而不要使用键盘产生的repeat code
tonylk(tony)自己做电子设备?有点夸张了
现在需要解决的是4个人同时玩,比如用键盘"a","s","d","f"键分别代表不同鼠标的左健(即射击发射子弹键)
现在关键是
不论用什么办法怎么模拟4个鼠标,如果都用键盘是不是会冲突。
大家有没有什么好办法或是有什么其他的好办法??^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
呵呵。仔细看看楼主的贴,哪里是接四个鼠标?分明是要用四个键来模拟鼠标左键,这么说其实也不对而是楼主不过要实现同时按下四个建不发生键盘冲突.....
为什么大家都这样?不知道这篇老贴子为什么又翻出来?其实只要一个人用鼠标,另外三个人用键盘不就行了?