Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

help with collision in frogger game

jonny_vjonny_v Member Posts: 1
Ok i've got this code so far and now i'm working on try to find out when the collisions happen, and i can't seem to figure out how to do it. Any help would be greatly appreciated, thanks.

unit xFrogger1;

interface

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

type
TForm1 = class(TForm)
tmrFroggerTimer: TTimer;
procedure tmrFroggerTimerTimer(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
iBadLeft,iBadTop,iCount,iGoodLeft,iGoodTop,i,iBadLeft1,iBadTop1,iBadTop2,iBadLeft2:integer;

implementation

{$R *.dfm}

procedure TForm1.tmrFroggerTimerTimer(Sender: TObject);
begin
iBadLeft:=iBadLeft+10;
iBadLeft1:=iBadLeft+50;
iBadLeft2:=iBadLeft+90;
FormPaint(sender);
for iCount:=1 to 100 do//resets rows
begin
if iBadLeft>-100 then
begin
iBadLeft:=-400;
end;
end;

end;

procedure TForm1.FormPaint(Sender: TObject);
begin
Canvas.Pen.Color:=clwindow;
Canvas.Brush.Color:=clWindow;
Canvas.Rectangle(0,0,width,height);
Canvas.Brush.Color:=clLime; //set the pen colour
Canvas.Pen.Color:=clBlack; //set the fill colour

for i:=1 to 10 do//first row of badguys
begin
Canvas.Ellipse(iBadLeft+i*100,iBadTop,iBadLeft+i*100+40,iBadTop+40);
end;
for i:=1 to 10 do//Second Row of badguys
begin
Canvas.Ellipse(iBadLeft1+i*100,iBadTop1,iBadLeft1+i*100+40,iBadTop1+40);
end;
for i:=1 to 10 do//third row of badguys
begin
Canvas.Ellipse(iBadLeft2+i*100,iBadTop2,iBadLeft2+i*100+40,iBadTop2+40);
end;
//Good guy
Canvas.Pen.Color:=clBlack;
Canvas.Brush.Color:=clBlue;
Canvas.ellipse(iGoodLeft,iGoodTop,iGoodLeft+40,iGoodTop+40);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
iBadLeft:=0;
iBadTop:=50;
iBadLeft1:=0;
iBadTop1:=150;
iBadLeft2:=0;
iBadTop2:=250;
iGoodLeft:=300;
iGoodTop:=300;
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key='8' then
begin
iGoodTop:=iGoodTop-10;
FormPaint(sender);
end;
if key='4' then
begin
iGoodLeft:=iGoodLeft-10;
FormPaint(sender);
end;
if key='6' then
begin
iGoodLeft:=iGoodLeft+10;
FormPaint(sender);
end;
if key='2' then
begin
iGoodTop:=iGoodTop+10;
FormPaint(sender);
end;
end;

end.
Sign In or Register to comment.