unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
tspieler=class(Tobject)
x,y:integer;
procedure show;
procedure bewegen(dir:
string);
end;
tblock =
class(TObject)
bx,by:integer;
da:boolean;
procedure show;
end;
TForm1 =
class(TForm)
Image1: TImage;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure malelevel(r:integer);
procedure Timer1Timer(Sender: TObject);
end;
var
Form1: TForm1;
block:
array of Tblock;
level:
array[0..13]
of string;
spieler:Tspieler;
implementation
{$R *.dfm}
procedure Tspieler.show;
begin
form1.Image1.Canvas.Brush.color:=clyellow;
form1.Image1.Canvas.Ellipse(x-8,y-8,x+8,y+8);
end;
procedure Tspieler.bewegen(dir:
string);
begin
if (dir='
links')
then dec(x,5);
if (dir='
rechts')
then inc(x,5);
if (dir='
oben')
then dec(y,5);
if (dir='
unten')
then inc(y,5);
end;
procedure Tblock.show;
begin
with form1.image1.Canvas
do begin
brush.color:=clskyblue;
rectangle(bx,by,bx+21,by+21)
end;
end;
procedure Tform1.malelevel(r:integer);
var i,k:integer;
begin
if r=1
then begin
level[0]:= '
xxxxxxxxxxxxxxxxxxxx';
level[1]:= '
x xxxx xx';
level[2]:= '
x xxx x x xx';
level[3]:= '
x x xx';
level[4]:= '
x xx x xxx xx xx';
level[5]:= '
x xx x xxx xx xx';
level[6]:= '
x xx x xxx xx xx';
level[7]:= '
xxxxx xxxxxxx xx';
level[8]:= '
xxxxxx xxxxxxxxxxxxx';
level[9]:= '
xx xxxxxx';
level[10]:= '
xxx xx xxxxxxx';
level[11]:= '
x xxxxxxx x';
level[12]:= '
xxxxxxxxxx xxxx';
level[13]:= '
xxxxxxxxxxxxxxxxxxxx';
end;
setlength(block,high(level)*length(level[1]));
for k:=0
to high(level)
do
for i:=0
to length(level[k])
do begin
block[i]:=tblock.Create;
block[i].bx:=i*20;
block[i].by:=k*20;
if level[k][i]='
x'
then block[i].da:=true
else block[i].da:=false;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var i:integer;
begin
spieler:=Tspieler.Create;
malelevel(1);
spieler.x:=100;
spieler.y:=50;
spieler.show;
timer1.Enabled:=true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var i:integer;
begin
if GetAsyncKeyState(VK_LEFT)<0
then spieler.bewegen('
links');
if GetAsyncKeyState(VK_RIGHT)<0
then spieler.bewegen('
rechts');
if GetAsyncKeyState(VK_UP)<0
then spieler.bewegen('
oben');
if GetAsyncKeyState(VK_DOWN)<0
then spieler.bewegen('
unten');
image1.Canvas.Brush.color:=clwhite;
image1.Canvas.FillRect(image1.ClientRect);
spieler.show;
for i:=0
to high(block)
do block[i].show;
end;
end.