unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ImgList,ExtCtrls;
type
TForm1 = class(TForm)
ImageList1: TImageList;
ImageList2: TImageList;
Timer1: TTimer;
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
procedure view();
procedure sprite;
procedure map;
public
{ Public declarations }
end;
var
Form1: TForm1;
mas:array [0..20,0..20] of byte;
i,j: integer;
x,y,tx,ty,step:integer;
implementation
{$R *.dfm}
procedure TForm1.view();
begin
for i:=0 to 20 do
for j:=0 to 20 do
begin
imagelist1.Draw(form1.canvas,i*32,j*32,mas[i,j]);
end;
end;
procedure tform1.sprite;
begin
x:=200;
y:=630;
imagelist2.draw(form1.Canvas,x,y,step);
end;
procedure tform1.map;
begin
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
for i:=1 to 30 do
begin
x:=random(21);
y:=random(21);
mas[x,y]:=2;
end;
for i:=1 to 15 do
begin
x:=random(21);
y:=random(21);
mas[x,y]:=0;
end;
for i:=1 to 30 do
begin
x:=random(21);
y:=random(21);
mas[x,y]:=1;
end;
for i:=1 to 30 do
begin
x:=random(21);
y:=random(21);
mas[x,y]:=3;
end;
x:=0;
y:=0;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
tx:=x;
ty:=y;
if key=37 then tx:=x-1;
if key=37 then step:=1;
if key=38 then ty:=y-1;
if key=38 then step:=0;
if key=39 then tx:=x+1;
if key=39 then step:=3;
if key=40 then ty:=y+1;
if key=40 then step:=2;
if((mas[trunc(tx/32),trunc(ty/32)]=1) or (mas[trunc(tx/32),trunc(ty/32)]=0)) and
((mas[trunc((tx+32)/32),trunc(ty/32)]=1) or (mas[trunc((tx+32)/32),trunc(ty/32)]=0)) and
((mas[trunc(tx/32),trunc((ty+32)/32)]=1) or (mas[trunc(tx/32),trunc((ty+32)/32)]=0)) and
((mas[trunc((tx+32)/32),trunc((ty+32)/32)]=1) or (mas[trunc((tx+32)/32),trunc((ty+32)/32)]=0))
then
begin
x:=tx;
y:=ty;
view();
sprite();
end;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
view();
sprite();
end;
end.