Code:
procedure TMain.ScrollMap;
var x,y,z : integer;
i : integer;
a,b,c : integer;
begin
if RanOnce = false then
begin
for z:=0 to 3 do
SetLength(AnimTable.Layer[z].TileAnim, Map.MapLength);
if MapOffset in [0..15] then
begin
MapOffset:=Map.MapLength-15;
end;
LineHeight:=0;
GameDrawGrid;
RanOnce:=true;
end;
if MapOffset > 0 then
begin
LineHeight:=LineHeight+ScrollSpeed;
// Background : Layers [0..3], Tiles [0..19], Lines [0..15] of TBackGround;
// Map.Record : Layers [0..3], Lines [0..Map.Length-1] , Tiles [0..19]
// move available sprites down
for z:=0 to 3 do
for y:=0 to 15 do
for x:=0 to 19 do
begin
if BackGround[z,x,y] <> nil then
begin
BackGround[z,x,y].Y:=BackGround[z,x,y].Y+ScrollSpeed;
if BackGround[z,x,y].Y = 480 then
begin
BackGround[z,x,y].Dead;
BackGround[z,x,y]:=nil;
end;
end;
end; // X loop
// screen scrolled down one line
if LineHeight = 32 then
begin
Dec(MapOffset,1);
OffsetEdit.Value:=MapOffset;
LineHeight:=0;
// locate an empty line in the BackGround array
if MapOffset > 0 then
begin
a:=0;
y:=0;
c:=0;
repeat
for z:=0 to 3 do
for x:=0 to 19 do
if BackGround[z,x,y] <> nil then
a:=-1;
if a = -1 then
begin
inc(y);
a:=0;
end
else
begin
b:=y;
c:=-1;
end;
until c = -1;
// get next line of tiles and put into free line in background array
for z:=0 to 3 do
for i:=0 to 19 do
if Map.Layer[z].Lines[MapOffset-1,i].ImageIndex <> 0 then
begin
BackGround[z,i,b] := TBackGround.Create(SpriteEngine);
BackGround[z,i,b].ImageName:= Images.Item[map.Layer[z].Lines[MapOffset-1,i].ImageIndex].Name;
BackGround[z,i,b].X:=i*32;
BackGround[z,i,b].Y:=-32;
BackGround[z,i,b].Z:=z;
// animation properties
if BackGround[z,i,b].PatternCount = 1 then
begin
BackGround[z,i,b].DoAnimate:=false;
end
else
begin
BackGround[z,i,b].AnimStart:=0;
BackGround[z,i,b].AnimCount:=map.Layer[z].Lines[MapOffset-1,i].AnimCount;
BackGround[z,i,b].AnimSpeed:=map.Layer[z].Lines[MapOffset-1,i].AnimSpeed;
BackGround[z,i,b].AnimPos:=AnimTable.Layer[z].TileAnim[MapOffset-1,i];
BackGround[z,i,b].DoAnimate:=true;
BackGround[z,i,b].AnimLooped:=true;
end;
end;
end;
end;
end // if Offset
else
begin
// Destroy sprites
for x:=0 to SpriteEngine.Count-1 do
SpriteEngine.Items[x].Dead;
// Clear dynamic array
for z:=0 to 3 do
for y:=0 to 15 do
for x:= 0 to 19 do
BackGround[z,x,y]:=nil;
// Start again
RanOnce:=false;
end;
end;
Bookmarks