2007-11-01 13:36:59 +01:00
|
|
|
unit LRLEditor;
|
|
|
|
|
2008-03-24 00:44:28 +01:00
|
|
|
{$mode objfpc}
|
|
|
|
{$asmmode intel}
|
|
|
|
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
interface
|
|
|
|
|
2008-03-24 00:44:28 +01:00
|
|
|
|
|
|
|
uses
|
|
|
|
LRLRoutines, LRLSprites, LRLLevels;
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
|
|
|
|
procedure LRLEditLevels;
|
|
|
|
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
implementation
|
|
|
|
|
2008-03-24 00:44:28 +01:00
|
|
|
|
|
|
|
const
|
|
|
|
RefreshDelay = 5; { 1 = 1/100 sec }
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
var
|
2008-03-24 00:44:28 +01:00
|
|
|
CurrentLevel: Word;
|
|
|
|
CurrentTool: Word;
|
|
|
|
TotalLevels: Word;
|
|
|
|
MouseX, MouseY: Integer;
|
|
|
|
|
|
|
|
TimeToRefresh : Boolean;
|
|
|
|
LastRefreshTime: DWord;
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
|
|
|
|
procedure LRLRedrawLevel;
|
|
|
|
var
|
2008-03-24 00:44:28 +01:00
|
|
|
i, j: Integer;
|
2007-11-01 13:36:59 +01:00
|
|
|
begin
|
|
|
|
ImageClear(LRLScreen^);
|
2008-03-24 00:44:28 +01:00
|
|
|
|
|
|
|
for i := 1 to 16 do for j := 1 to 30 do
|
|
|
|
with LRLLevel.Field[j, i] do
|
|
|
|
ImagePut(LRLScreen^, LRLEnvironment[Image].Image[Count].Data^, j * 10, i * 10, 0, 0, 319, 199);
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
for i := 1 to 10 do
|
2008-03-24 00:44:28 +01:00
|
|
|
with LRLLevel.Player[i] do
|
|
|
|
if Controller <> 0 then
|
|
|
|
ImagePutTransparent(LRLScreen^, LRLFigure[Colour, SpriteData].Image[Sprite].Data^, Position.x * 10 + Position.xoffs, Position.y * 10 + Position.yoffs, 0, 0, 319, 199);
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
ImageFill(LRLFontBuffer^, 12, 12, 252);
|
|
|
|
ImagePut(LRLScreen^, LRLFontBuffer^, 10, 184, 0, 0, 319, 199);
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
for i := 1 to 13 do
|
2008-03-24 00:44:28 +01:00
|
|
|
if i > 9 then
|
|
|
|
ImagePut(LRLScreen^, LRLFigure[i - 9, 1].Image[1].Data^, i * 15 - 4, 185, 0, 0, 319, 199) else
|
|
|
|
ImagePut(LRLScreen^, LRLEnvironment[i].Image[1].Data^, i * 15 - 4, 185, 0, 0, 319, 199);
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
for i := 1 to 6 do
|
2008-03-24 00:44:28 +01:00
|
|
|
if LRLEditorButton[i].Lit then
|
|
|
|
ImagePut(LRLScreen^, LRLEditorButton[i].LightIcon^, LRLEditorButton[i].x1, LRLEditorButton[i].y1, 0, 0, 319, 199) else
|
|
|
|
ImagePut(LRLScreen^, LRLEditorButton[i].DarkIcon^, LRLEditorButton[i].x1, LRLEditorButton[i].y1, 0, 0, 319, 199);
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
LRLDrawOrnamental(0, 0, 31, 17, 1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure LRLMoveMouse;
|
|
|
|
var
|
2008-03-24 00:44:28 +01:00
|
|
|
s, s2: String[20];
|
2007-11-01 13:36:59 +01:00
|
|
|
begin
|
2008-03-24 00:44:28 +01:00
|
|
|
MSMouseGetXY(MouseX, MouseY);
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
if not MSMouseInArea(200, 180, 325, 205) then
|
|
|
|
if CurrentTool < 10 then
|
2008-03-24 00:44:28 +01:00
|
|
|
ImagePut(LRLScreen^, LRLEnvironment[CurrentTool].Image[1].Data^, MouseX - 5, MouseY - 5, 0, 0, 319, 199) else
|
|
|
|
ImagePut(LRLScreen^, LRLFigure[CurrentTool - 9, 1].Image[1].Data^, MouseX - 5, MouseY - 5, 0, 0, 319, 199);
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
if not MSMouseInArea(-2, -2, 55, 20) then
|
|
|
|
begin
|
|
|
|
ImageFill(LRLFontBuffer^, 50, 15, 0);
|
|
|
|
ImagePut(LRLScreen^, LRLFontBuffer^, 0, 0, 0, 0, 319, 199);
|
2008-03-24 00:44:28 +01:00
|
|
|
Str(CurrentLevel, s);
|
|
|
|
Str(TotalLevels, s2);
|
2007-11-01 13:36:59 +01:00
|
|
|
ImageStringGet(s + '/' + s2, LRLFont^, LRLFontBuffer^, 251);
|
|
|
|
ImagePut(LRLScreen^, LRLFontBuffer^, 25 - ImageSizex(LRLFontBuffer^) div 2, 0, 0, 0, 319, 199);
|
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
|
|
|
ImagePutTransparent(LRLScreen^, LRLMousePointer^, MouseX, MouseY, 0, 0, 319, 199);
|
2007-11-01 13:36:59 +01:00
|
|
|
end;
|
|
|
|
|
2008-03-24 00:44:28 +01:00
|
|
|
|
|
|
|
procedure Repress;
|
2007-11-01 13:36:59 +01:00
|
|
|
var
|
2008-03-24 00:44:28 +01:00
|
|
|
x, y: Integer;
|
2007-11-01 13:36:59 +01:00
|
|
|
begin
|
2008-03-24 00:44:28 +01:00
|
|
|
MSMouseButtonWasPressed(0, x, y);
|
|
|
|
MSMouseButtonWasReleased(0, x, y);
|
2007-11-01 13:36:59 +01:00
|
|
|
MSMouseButtonWasPressed(1, x, y);
|
|
|
|
MSMouseButtonWasReleased(1, x, y);
|
|
|
|
end;
|
|
|
|
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
procedure LRLEditLevels;
|
|
|
|
var
|
2008-03-24 00:44:28 +01:00
|
|
|
Keypress: Word;
|
|
|
|
DrawNow: Boolean;
|
|
|
|
i, j: Integer;
|
|
|
|
x, y: Integer;
|
|
|
|
Cmd: Word;
|
2007-11-01 13:36:59 +01:00
|
|
|
begin
|
|
|
|
if not MSMouseDriverExist then Exit;
|
|
|
|
Repress;
|
2008-03-24 00:44:28 +01:00
|
|
|
Palette256Set(LRLPalette^);
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
ShowLives := False;
|
|
|
|
ShowScore := False;
|
2008-03-24 00:44:28 +01:00
|
|
|
Keypress := 0;
|
2007-11-01 13:36:59 +01:00
|
|
|
CurrentLevel := 1;
|
2008-03-24 00:44:28 +01:00
|
|
|
CurrentTool := 2;
|
|
|
|
TotalLevels := LRLLevelCount;
|
|
|
|
|
|
|
|
DrawNow := False;
|
|
|
|
TimeToRefresh := True;
|
|
|
|
LastRefreshTime := 0;
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
MSMouseSetXY(160, 100);
|
|
|
|
LRLLoadLevel(CurrentLevel);
|
2008-03-24 00:44:28 +01:00
|
|
|
|
|
|
|
WaitForEvent(1);
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
repeat
|
2008-03-24 00:44:28 +01:00
|
|
|
if not TimeToRefresh then
|
|
|
|
TimeToRefresh := kos_timecounter() - LastRefreshTime >= RefreshDelay;
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
if TimeToRefresh then
|
|
|
|
begin
|
|
|
|
LRLRedrawLevel;
|
|
|
|
LRLMoveMouse;
|
|
|
|
ScreenApply(LRLScreen^);
|
2008-03-24 00:44:28 +01:00
|
|
|
TimeToRefresh := False;
|
|
|
|
LastRefreshTime := kos_timecounter();
|
2007-11-01 13:36:59 +01:00
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
if Keypressed then
|
|
|
|
Keypress := Readkey;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
if MSMouseButtonWasReleased(1, x, y) then
|
|
|
|
begin
|
|
|
|
LRLScore := 0;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
FadeClear;
|
|
|
|
ImageClear(LRLScreen^);
|
|
|
|
ScreenApply(LRLScreen^);
|
|
|
|
Palette256Set(LRLPalette^);
|
|
|
|
LRLPlayLevel(CurrentLevel);
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
FadeClear;
|
|
|
|
ImageClear(LRLScreen^);
|
|
|
|
ScreenApply(LRLScreen^);
|
|
|
|
Palette256Set(LRLPalette^);
|
|
|
|
LRLLoadLevel(CurrentLevel);
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
Repress;
|
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
if MSMouseButtonWasPressed(0, x, y) then
|
|
|
|
DrawNow := True;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
if MSMouseButtonWasReleased(0, x, y) then
|
|
|
|
begin
|
|
|
|
DrawNow := False;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
Cmd := 0;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
for i := 1 to 6 do
|
|
|
|
LRLEditorButton[i].Lit := False;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
for i := 1 to 6 do
|
2008-03-24 00:44:28 +01:00
|
|
|
if MSMouseInArea(LRLEditorButton[i].x1, LRLEditorButton[i].y1, LRLEditorButton[i].x2, LRLEditorButton[i].y2) then
|
2007-11-01 13:36:59 +01:00
|
|
|
begin
|
2008-03-24 00:44:28 +01:00
|
|
|
Cmd := LRLEditorButton[i].Command;
|
|
|
|
Break;
|
2007-11-01 13:36:59 +01:00
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
|
|
|
if Cmd = 1 then
|
|
|
|
begin
|
2007-11-01 13:36:59 +01:00
|
|
|
LRLSaveLevel(CurrentLevel);
|
2008-03-24 00:44:28 +01:00
|
|
|
|
|
|
|
Repress;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Cmd = 2 then
|
2007-11-01 13:36:59 +01:00
|
|
|
begin
|
|
|
|
LRLInsertLevel(CurrentLevel);
|
|
|
|
Inc(CurrentLevel);
|
|
|
|
TotalLevels := LRLLevelCount;
|
|
|
|
LRLLoadLevel(CurrentLevel);
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
Repress;
|
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
if (Cmd = 3) and (CurrentLevel < TotalLevels) then
|
|
|
|
begin
|
|
|
|
Inc(CurrentLevel);
|
|
|
|
LRLLoadLevel(CurrentLevel);
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
Repress;
|
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
|
|
|
if Cmd = 4 then
|
2007-11-01 13:36:59 +01:00
|
|
|
begin
|
2008-03-24 00:44:28 +01:00
|
|
|
for i := 1 to 16 do for j := 1 to 30 do
|
|
|
|
LRLLevel.Field[j, i].Image := 1;
|
2007-11-01 13:36:59 +01:00
|
|
|
for i := 1 to 10 do
|
|
|
|
LRLLevel.Player[i].Controller := 0;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
Repress;
|
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
if (Cmd = 5) and (TotalLevels > 1) then
|
|
|
|
begin
|
|
|
|
LRLDeleteLevel(CurrentLevel);
|
|
|
|
TotalLevels := LRLLevelCount;
|
|
|
|
if CurrentLevel > TotalLevels then
|
|
|
|
CurrentLevel := TotalLevels;
|
|
|
|
LRLLoadLevel(CurrentLevel);
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
Repress;
|
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
if (Cmd = 6) and (CurrentLevel > 1) then
|
|
|
|
begin
|
|
|
|
Dec(CurrentLevel);
|
|
|
|
LRLLoadLevel(CurrentLevel);
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
Repress;
|
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
|
|
|
MSMouseGetXY(MouseX, MouseY);
|
|
|
|
|
|
|
|
if MouseY > 180 then
|
2007-11-01 13:36:59 +01:00
|
|
|
for i := 1 to 13 do
|
2008-03-24 00:44:28 +01:00
|
|
|
if (MouseY > 184) and (MouseY < 195) and (MouseX > i * 15 - 5) and (MouseX < i * 15 + 6) then
|
2007-11-01 13:36:59 +01:00
|
|
|
begin
|
2008-03-24 00:44:28 +01:00
|
|
|
CurrentTool := i;
|
|
|
|
Break;
|
2007-11-01 13:36:59 +01:00
|
|
|
end;
|
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
if DrawNow then
|
|
|
|
begin
|
|
|
|
for i := 1 to 6 do
|
|
|
|
LRLEditorButton[i].Lit := False;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
for i := 1 to 6 do
|
2008-03-24 00:44:28 +01:00
|
|
|
if MSMouseInArea(LRLEditorButton[i].x1, LRLEditorButton[i].y1, LRLEditorButton[i].x2, LRLEditorButton[i].y2) then
|
2007-11-01 13:36:59 +01:00
|
|
|
begin
|
2008-03-24 00:44:28 +01:00
|
|
|
LRLEditorButton[i].Lit := True;
|
|
|
|
Break;
|
2007-11-01 13:36:59 +01:00
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
|
|
|
MSMouseGetXY(MouseX, MouseY);
|
|
|
|
|
|
|
|
x := MouseX div 10;
|
|
|
|
y := MouseY div 10;
|
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
if (x > 0) and (x < 31) and (y > 0) and (y < 17) then
|
|
|
|
begin
|
|
|
|
for i := 1 to 10 do
|
2008-03-24 00:44:28 +01:00
|
|
|
if (LRLLevel.Player[i].Controller <> 0) and (LRLLevel.Player[i].Position.x = x) and (LRLLevel.Player[i].Position.y = y) and
|
|
|
|
(CurrentTool <> 2) and (CurrentTool <> 3) and (CurrentTool <> 4) and (CurrentTool <> 7) then
|
2007-11-01 13:36:59 +01:00
|
|
|
begin
|
2008-03-24 00:44:28 +01:00
|
|
|
LRLLevel.Player[i].Controller := 0;
|
|
|
|
Break;
|
2007-11-01 13:36:59 +01:00
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
if CurrentTool < 10 then
|
2008-03-24 00:44:28 +01:00
|
|
|
LRLLevel.Field[x, y].Image := CurrentTool else
|
|
|
|
if (LRLLevel.Field[x, y].Image = 2) or (LRLLevel.Field[x, y].Image = 3) or
|
|
|
|
(LRLLevel.Field[x, y].Image = 4) or (LRLLevel.Field[x, y].Image = 1) then
|
2007-11-01 13:36:59 +01:00
|
|
|
begin
|
2008-03-24 00:44:28 +01:00
|
|
|
if CurrentTool = 10 then
|
2007-11-01 13:36:59 +01:00
|
|
|
begin
|
2008-03-24 00:44:28 +01:00
|
|
|
LRLLevel.Player[1].Controller := 1;
|
|
|
|
LRLLevel.Player[1].Position.x := x;
|
|
|
|
LRLLevel.Player[1].Position.y := y;
|
|
|
|
LRLLevel.Player[1].Colour := 1;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
j := 2;
|
|
|
|
for i := 2 to 10 do
|
|
|
|
if LRLLevel.Player[i].Controller = 0 then
|
2007-11-01 13:36:59 +01:00
|
|
|
begin
|
2008-03-24 00:44:28 +01:00
|
|
|
j := i;
|
|
|
|
Break;
|
2007-11-01 13:36:59 +01:00
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
LRLLevel.Player[j].Controller := 2;
|
|
|
|
LRLLevel.Player[j].Position.x := x;
|
|
|
|
LRLLevel.Player[j].Position.y := y;
|
|
|
|
LRLLevel.Player[j].Colour := CurrentTool - 9;
|
2007-11-01 13:36:59 +01:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2008-03-24 00:44:28 +01:00
|
|
|
|
|
|
|
WaitForEvent(5);
|
|
|
|
|
|
|
|
until (Keypress = KEY_ESC);
|
2007-11-01 13:36:59 +01:00
|
|
|
end;
|
|
|
|
|
2008-03-24 00:44:28 +01:00
|
|
|
|
2007-11-01 13:36:59 +01:00
|
|
|
end.
|