Ok i have something working now....but I need help...
unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons, Math;
type
TfrmMain = class(TForm)
pnlPingPong: TPanel;
pnlPaddle1: TPanel;
pnlPaddle2: TPanel;
pnlBall: TPanel;
btnStart: TBitBtn;
btnStop: TBitBtn;
btnExit: TBitBtn;
tmrGameOn: TTimer;
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure btnExitClick(Sender: TObject);
procedure btnStartClick(Sender: TObject);
procedure btnStopClick(Sender: TObject);
procedure tmrGameOnTimer(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
procedure MoveBall();
{ Public declarations }
end;
var
frmMain: TfrmMain;
blnWaitingForGameToResume: boolean = False;
PrevY : Integer = 0;
PrevX : Integer = 0;
PrevDirection : Integer = 0;
implementation
{$R *.dfm}
procedure TfrmMain.FormKeyPress(Sender: TObject; var Key: Char);
begin
{if Key = yadda then
begin
if Key = yadda then
begin
if Key = yadda then
begin
if Key = yadda then
begin
Application.ProcessMessages;
end;
end;
end;
end;}
end;
procedure TfrmMain.btnExitClick(Sender: TObject);
begin
// quit the program
Close;
end;
procedure TfrmMain.btnStartClick(Sender: TObject);
begin
// start the ball moving
tmrGameOn.Enabled := True;
end;
procedure TfrmMain.btnStopClick(Sender: TObject);
begin
// stop the ball moving
tmrGameOn.Enabled := False;
end;
procedure TfrmMain.tmrGameOnTimer(Sender: TObject);
begin
// This timer runs the whole program, essentially.
// first check if we're not waiting for the ball to be placed back in play
if Not blnWaitingForGameToResume then
// we are not waiting, so continue playing
begin
frmMain.MoveBall;
while pnlball.left+14 < pnlpaddle2.left do
pnlball.Left := pnlball.Left + 1 ;
sleep(5) ;
Application.ProcessMessages;
if pnlball.Left+14 = pnlpaddle2.left then
while pnlpaddle1.left+14 < pnlball.Left do
pnlball.Left := pnlball.Left -1 ;
sleep(5) ;
Application.ProcessMessages;
if pnlball.top <> pnlpaddle2.top then
Showmessage('Sorry!');
Application.ProcessMessages;
end;
Application.ProcessMessages;
end;
procedure TfrmMain.MoveBall();
var
NewDirection : Integer;
begin
NewDirection := 0;
// check if the ball is stationary
if PrevY = 0 then
begin
// the ball is stationary, either the game has just started or
// the ball has just been placed back in play after a point was
// scored.
PrevY := pnlBall.Left;
PrevX := pnlBall.Top;
NewDirection := RandomRange(25, 75)
// etc
end;
end;
procedure TfrmMain.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = VK_insert then
begin
pnlpaddle1.Top := pnlpaddle1.Top - 5;
pnlpaddle1.Refresh;
end;
if key = VK_delete then
begin
pnlpaddle1.Top := pnlpaddle1.Top + 5;
pnlpaddle1.Refresh;
end;
if key = VK_home then
begin
pnlpaddle2.Top := pnlpaddle2.Top - 5;
pnlpaddle2.Refresh;
end;
if key = VK_end then
begin
pnlpaddle2.Top := pnlpaddle2.Top + 5;
pnlpaddle2.Refresh;
end;
end;
end.
The ball only bounces across the screen and not into the paddles, help please....