hey there, i'm new at delphi, at my first prog actually. Been doing c/c++ for a while.
The prog is supposed to be simple game, and i need a level counter. I've strayed a bit from the tutorial i'm using and now when i run it the number in the label turns to a black rectangle and nothing works anymore, can only close with "right click->close".
can someone pls set me on the right path here?:-/
here's the code
unit game1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, jpeg;
type
TForm1 = class(TForm)
Timer1: TTimer;
bot1: TShape;
bot2: TShape;
Button1: TButton;
Panel1: TPanel;
Button2: TButton;
Leveltimer: TTimer;
Label1: TLabel;
procedure Timer1Timer(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure LeveltimerTimer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
var overlay:trect;
begin
if bot1.left>bot2.left then bot1.Left:=bot1.Left-1;
if bot1.left<bot2.left then bot1.Left:=bot1.Left+1;
if bot1.top>bot2.top then bot1.top:=bot1.top-1;
if bot1.top<bot2.top then bot1.top:=bot1.top+1;
//this part is collision detection
if intersectrect(overlay,bot1.BoundsRect,bot2.BoundsRect) then
begin
timer1.Enabled:=false;
leveltimer.Enabled:=false;
showmessage ('you are dead');
end;
end;
//procedure for moving your bot and reseting possition in case of death
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if timer1.Enabled=true then
begin
bot2.Left:=x-bot2.Width div 2;
bot2.Top:=y-bot2.Height div 2;
end
else
begin
sleep(1000);
bot2.left:=0;
bot2.top:=0;
bot1.Left:=0;
bot1.Top:=100;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
timer1.Enabled:=True;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
timer1.Enabled:=false;
end;
procedure TForm1.LeveltimerTimer(Sender: TObject);
var a:char;
begin
//level counter
if timer1.enabled=true then leveltimer.Enabled:=true;
label1.tag:=label1.tag+1;
a:=chr(label1.tag);
label1.caption:=a;
end;
end.