- 注册时间
- 2011-3-10
- 最后登录
- 1970-1-1
该用户从未签到
|
0楼 发表于: 2007-05-23
倒序阅读 ┊ 只看楼主 ┊ 小 中 大
给大家一个走路程序
本文以千年游戏做的
希望对大家有所帮助。
///////////////////////////////////////////////////////////
//函数:LoadMap
//功能:提取千年地图信息
//参数:地图文件名 string
//返回:true 成功 false 失败
//说明:千年地图数据格式为 40 * 40
// 从左到右 从上到下 如一个 200 * 200 的地图存储如下
// 1 2 3 4 5
//
// 6 7 8 9 10
//
// 11 12 13 14 15
//
// 16 17 18 19 20
//
// 21 22 23 24 25
//
// 每格之间用20个字节的0 组成
///////////////////////////////////////////////////////////
每个坐标点用12字节表示.第十二个字节是表示节点能否站立的信息。
0 : 可行走
1 :不能行走。障碍点
2,3,4,5,6 不能行走。但和1 有所区别
type
TMapHeader = record //千年地图文件头 28字节
name : array [0..15] of char;
a1 : dword;
Width : dword;
Height : dword;
end;
Function LoadMap ( FileName:string ):bool;
var
MapHeader : TMapHeader;
MapFile : File;
x,y,i,j,k,Size: integer;
count : integer;
temp : array [0..$4b14]of byte;
begin
if FileName <> '' then
begin
try
AssignFile (MapFile,FileName); //建立文件关联
Reset (MapFile,1); //打开文件
Seek (MapFile,0); //移动指针
Blockread (MapFile,MapHeader,28,size); //读取文件头
if Size <> 28 then
begin
ShowMessage ('读取文件头出错,请检查文件的有效性!');
LoadMap := False;
exit;
end
else
MapWidth := MapHeader.Width;
MapHeight:= MapHeader.Height;
j := 0;
k := 0;
MapData := nil;
// 40*40个坐标点 每点 12个字节 开头20个0 40*40*12+20= 4B14
count := MapHeight * MapWidth div 1600; //循环次数 地图数据数量
SetLength (MapData,MapWidth+1,MapHeight+1);
for i := 1 to count do
begin
BlockRead (MapFile,temp,$4B14,size); //读取地图信息
if Size <> $4B14 then
begin
ShowMessage ('读取的内容长度出错');
LoadMap := False;
exit;
end
else
for x := 0 to 39 do
begin
for y := 0 to 39 do
begin
MapData[x+j,y+k] := temp [31 + x * 480 + y * 12 ];
end;
end;
k := k + 40; //坐标轴操作
if k = MapWidth then
begin
k := 0;
j := j + 40;
end;
end;
Finally
CloseFile (MapFile);
LoadMap := True;
end;
end else
LoadMap := False;
end; |
|