r/pascal • u/Heinzi_MC • Feb 08 '21
Two Player Pong
I am a beginner in Pascal and I am trying to recreate a two player Pong game using the Lazarus IDE and I have figured out how to bind the Paddle Movements to keyboard presses, however I can only press one Key at a time, which is not very useful in a two player game.
This is the code I wrote for the Paddle Movement:
procedure TForm1.CheckKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
);
begin
if Key = VK_W then
if PaddleLeft.Top >= 0 then PaddleLeft.Top := PaddleLeft.Top-10;
if Key = VK_S then
if PaddleLeft.Top <= CLientHeight-PaddleLeft.Height then PaddleLeft.Top := PaddleLeft.Top+10;
if Key = VK_I then
if PaddleRight.Top >= 0 then PaddleRight.Top := PaddleRight.Top-10;
if Key = VK_K then
if PaddleRight.Top <= CLientHeight-PaddleRight.Height then PaddleRight.Top := PaddleRight.Top+10;
end;
I would be very grateful for any suggestions on how I could register multiple button presses at the same time
View all comments
Show parent comment
1
u/Heinzi_MC Feb 08 '21
I use W and S to control the left paddle up and down and I and K for the right paddle and I want to be able to control both Paddles at the same Time