Advertisement
mixster

mixster

Sep 29th, 2008
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 17.50 KB | None | 0 0
  1. program ScaRPGMapEditor;
  2. type
  3.   TMap = record
  4.     tpTiles: array of array of array of TPoint;
  5.     x, y, z, p: Integer;
  6.     att: array of array of Integer;
  7.   end;
  8.   TNPC = record
  9.     s, m: TPoint;
  10.     sTalk: string;
  11.   end;
  12. var
  13.   frmMain: TForm;
  14.   mnuMain: TMainMenu;
  15.   mnuFile, mnuNew, mnuSave, mnuOpen, mnuRand: TMenuItem;
  16.   mnuAttr: TPopupMenu;
  17.   mnuBlnk, mnuBlck, mnuEnco: TMenuItem;
  18.   dlgOpen: TOpenDialog;
  19.   dlgSave: TSaveDialog;
  20.   imgMain, imgTiles: TImage;
  21.   pnlMain, pnlTiles: TPanel;
  22.   scbMainX, scbMainY: TScrollBar;
  23.   sbxTiles: TScrollBox;
  24.   cmbLay: TComboBox;
  25.   tiles, sprites: Integer;
  26.   mapMain: TMap;
  27.   npcMain: array of TNPC;
  28.   cp, tp, md, mu: TPoint;
  29.  
  30. // GenerateMap - Draws the map onto a canvas and also applies movement based on input
  31. procedure GenerateMap(x, y: Integer);
  32. var
  33.   bmpLay, bmpBuf, a, b, c, s, mapX, mapY, startX, startY: Integer;
  34. begin
  35.   bmpLay := BitmapFromString(480, 480, '');
  36.   bmpBuf := BitmapFromString(480, 480, '');
  37.  
  38.   cp.x := cp.x + x;
  39.   cp.y := cp.y + y;
  40.  
  41.   startX := cp.x - 7;
  42.   startY := cp.y - 7;
  43.  
  44.   with mapMain do
  45.   begin
  46.     for a := 0 to z - 1 do
  47.     begin
  48.       FastDrawClear(bmpLay, 16448505);
  49.       for b := startY to startY + 15 do
  50.       begin
  51.         if not InRange(b, 0, y - 1) then
  52.           Continue;
  53.         mapY := b - cp.y;
  54.         for c := startX to startX + 15 do
  55.         begin
  56.           if not InRange(c, 0, x - 1) then
  57.             Continue;
  58.           mapX := c - cp.x;
  59.           if not ((tpTiles[a][b][c].x < 0) and (tpTiles[a][b][c].y < 0)) then
  60.             CopyCanvas(imgTiles.Canvas, GetBitmapCanvas(bmpLay), tpTiles[a][b][c].x * 32, tpTiles[a][b][c].y * 32, (tpTiles[a][b][c].x * 32) + 32, (tpTiles[a][b][c].y * 32) + 32, (c - startX) * 32, (b - startY) * 32, ((c - startX) * 32) + 32, ((b - startY) * 32) + 32);
  61.         end;
  62.       end;
  63.       SetTransparentColor(bmpLay, 16448505);
  64.       FastDrawTransparent(0, 0, bmpLay, bmpBuf);
  65.       if a = p then
  66.       begin
  67.         FastDrawClear(bmpLay, 0);
  68.         if High(npcMain) >= 0 then
  69.           for s := 0 to High(npcMain) do
  70.             with npcMain[s] do
  71.             begin
  72.               If InRange(m.x, cp.x - 7, cp.x + 8) and InRange(m.y, cp.y - 7, cp.y + 8) then
  73.                 CopyCanvas(GetBitmapCanvas(sprites), GetBitmapCanvas(bmpLay), s.x * 32, s.y * 32, (s.x * 32) + 32, (s.y * 32) + 32, (m.x - startX) * 32, (m.y - startY) * 32, ((m.x - startX) * 32) + 32, ((m.y - startY) * 32) + 32);
  74.             end;
  75.         SetTransparentColor(bmpLay, 0);
  76.         FastDrawTransparent(0, 0, bmpLay, bmpBuf);
  77.       end;
  78.     end;
  79.   end;
  80.   SafeCopyCanvas(GetBitmapCanvas(bmpBuf), imgMain.Canvas, 0, 0, 480, 480, 0, 0, 480, 480);
  81.   FreeBitmap(bmpBuf);
  82.   FreeBitmap(bmpLay);
  83.   for b := 1 to 14 do
  84.   begin
  85.     imgMain.Canvas.MoveTo(0, b * 32);
  86.     imgMain.Canvas.LineTo(480, b * 32);
  87.   end;
  88.   for c := 1 to 14 do
  89.   begin
  90.     imgMain.Canvas.MoveTo(c * 32, 0);
  91.     imgMain.Canvas.LineTo(c * 32, 480);
  92.   end;
  93. end;
  94.  
  95. // RandomizeMap - Makes a random map based on range input
  96. procedure RandomizeMap(xs, ys, zs, ss, xe, ye, ze, se: Integer);
  97. var
  98.   mx, my, a, b, c: Integer;
  99.   tsaRandTalk: TStringArray;
  100. begin
  101.   tsaRandTalk := ['Hai der', 'Howdy partner', 'Hi', 'SEX', 'How much wood could chuck norris chuck', 'I won''t kill you if you touch my penis'];
  102.   GetBitmapSize(tiles, mx, my);
  103.   with mapMain do
  104.   begin
  105.     x := RandomRange(xs, xe);
  106.     y := RandomRange(ys, ye);
  107.     z := RandomRange(zs, ze);
  108.     p := z - 3;
  109.     SetArrayLength(tpTiles, z);
  110.     for a := 0 to z - 1 do
  111.     begin
  112.       SetArrayLength(tpTiles[a], y);
  113.       SetArrayLength(att, y);
  114.       for b := 0 to y - 1 do
  115.       begin
  116.         SetArrayLength(tpTiles[a][b], x);
  117.         SetArrayLength(att[b], x);
  118.         for c := 0 to x - 1 do
  119.         begin
  120.           tpTiles[a][b][c].x := Random(mx div 32);
  121.           tpTiles[a][b][c].y := Random(my div 32);
  122.           if Random(10) <= 2 then
  123.             att[b][c] := 2
  124.           else
  125.             att[b][c] := 0;
  126.         end;
  127.       end;
  128.     end;
  129.   end;
  130.   GetBitmapSize(tiles, mx, my);
  131.   SetArrayLength(npcMain, RandomRange(ss, se));
  132.   for a := 0 to High(npcMain) do
  133.     with npcMain[a] do
  134.     begin
  135.       s.x := Random(mx div 128) * 3;
  136.       s.y := Random(my div 32);
  137.       m.x := Random(mapMain.x);
  138.       m.y := Random(mapMain.y);
  139.       sTalk := tsaRandTalk[Random(High(tsaRandTalk))];
  140.       mapMain.att[m.y][m.x] := 1;
  141.     end;
  142. end;
  143.  
  144. // BlankMap - Makes a blank map based on user input
  145. procedure BlankMap;
  146. var
  147.   a, b, c: Integer;
  148. begin
  149. with mapMain do
  150.   begin
  151.     x := StrToIntDef(Readln('Width'), 15);
  152.     y := StrToIntDef(Readln('Height'), 15);
  153.     z := StrToIntDef(Readln('Depth'), 5)
  154.     p := z - 2;
  155.     if p < 0 then
  156.       p := 0;
  157.     SetArrayLength(tpTiles, z);
  158.     for a := 0 to z - 1 do
  159.     begin
  160.       SetArrayLength(tpTiles[a], y);
  161.       SetArrayLength(att, y);
  162.       for b := 0 to y - 1 do
  163.       begin
  164.         SetArrayLength(tpTiles[a][b], x);
  165.         SetArrayLength(att[b], x);
  166.         for c := 0 to x - 1 do
  167.         begin
  168.           tpTiles[a][b][c].x := -1;
  169.           tpTiles[a][b][c].y := -1;
  170.         end;
  171.       end;
  172.     end;
  173.   end;
  174.   cp.x := mapMain.x div 2;
  175.   cp.y := mapMain.y div 2;
  176.   try
  177.     scbMainX.Max := mapMain.x - 8;
  178.   except
  179.     scbMainX.Max := scbMainX.Min + 1;
  180.   end;
  181.   try
  182.     scbMainY.Max := mapMain.y - 8;
  183.   except
  184.     scbMainY.Min := scbMainY.Min + 1;
  185.   end;
  186.   scbMainX.Position := cp.x;
  187.   scbMainY.Position := cp.y;
  188.   for a := 0 to cmbLay.Items.Count + 2 do
  189.     cmbLay.Items.Delete(0);
  190.   for a := 0 to mapMain.z - 1 do
  191.     cmbLay.Items.Add('Layer ' + IntToStr(a));
  192.   cmbLay.ItemIndex := 0;
  193.  
  194.   GenerateMap(0, 0);
  195. end;
  196.  
  197. // ExplodeInt - Like other languages explode excepts turns into integers
  198. function ExplodeInt(str, del: string): TIntegerArray;
  199. var
  200.   i: Integer;
  201. begin
  202.   repeat
  203.     i := Pos(del, str);
  204.     SetArrayLength(Result, High(Result) + 2);
  205.     if i <= 0 then
  206.       Break;
  207.     Result[High(Result)] := StrToIntDef(Copy(str, 1, i - 1), 0);
  208.     Delete(str, 1, i);
  209.   until false;
  210.   Result[High(Result)] := StrToIntDef(Copy(str, 1, Length(str)), 0);
  211. end;
  212.  
  213. // OpenMap - Reads the selected map then puts into mapMain
  214. procedure OpenMap;
  215. var
  216.   titMap: TIntegerArray;
  217.   a, b, c: Integer;
  218. begin
  219.   if not dlgOpen.Execute then
  220.     Exit;
  221.  
  222.   with mapMain do
  223.   begin
  224.     x := StrToIntDef(ReadINI('Layout', 'Width', dlgOpen.FileName), 15);
  225.     y := StrToIntDef(ReadINI('Layout', 'Height', dlgOpen.FileName), 15);
  226.     z := StrToIntDef(ReadINI('Layout', 'Depth', dlgOpen.FileName), 15);
  227.     p := z - 2;
  228.     if p < 0 then
  229.       p := 0;
  230.    
  231.     SetArrayLength(tpTiles, 0);
  232.     SetArrayLength(tpTiles, z);
  233.     SetArrayLength(att, 0);
  234.     SetArrayLength(att, y);
  235.     for a := 0 to z - 1 do
  236.     begin
  237.       SetArrayLength(tpTiles[a], 0);
  238.       SetArrayLength(tpTiles[a], y);
  239.       for b := 0 to y - 1 do
  240.       begin
  241.         SetArrayLength(tpTiles[a][b], 0);
  242.         SetArrayLength(tpTiles[a][b], x);
  243.         titMap := ExplodeInt(ReadINI('Layer' + IntToStr(a), 'Row' + IntToStr(b), dlgOpen.FileName), ',');
  244.         for c := 0 to x - 1 do
  245.         begin
  246.           try
  247.             tpTiles[a][b][c].x := titMap[c * 2];
  248.             tpTiles[a][b][c].y := titMap[c * 2 + 1];
  249.           except
  250.             if not Lowercase(Readln('Map corrupted - open anyway?(yes/no)')) = 'yes' then
  251.               frmMain.Close;
  252.           end;
  253.         end;
  254.         if a = 0 then
  255.         begin
  256.           SetArrayLength(att[b], 0);
  257.           SetArrayLength(att[b], x);
  258.           mapMain.att[b] := ExplodeInt(ReadINI('Attrib', 'Row' + IntToStr(b), dlgOpen.FileName), ',');
  259.         end;
  260.         SetArrayLength(titMap, 0);
  261.       end;
  262.     end;
  263.   end;
  264.  
  265.   cp.x := mapMain.x div 2;
  266.   cp.y := mapMain.y div 2;
  267.   try
  268.     scbMainX.Max := mapMain.x - 8;
  269.   except
  270.     scbMainX.Max := scbMainX.Min;
  271.   end;
  272.   try
  273.     scbMainY.Max := mapMain.y - 8;
  274.   except
  275.     scbMainY.Min := scbMainY.Min;
  276.   end;
  277.   scbMainX.Position := cp.x;
  278.   scbMainY.Position := cp.y;
  279.   while cmbLay.Items.Count > 0 do
  280.     cmbLay.Items.Delete(0);
  281.   for a := 0 to mapMain.z - 1 do
  282.     cmbLay.Items.Add('Layer ' + IntToStr(a));
  283.   cmbLay.ItemIndex := 0;
  284.   GenerateMap(0, 0);
  285. end;
  286.  
  287. // ImplodeInt - Reverse of explode, takes a TIntegerArray and turns it into a string based on the delimiter
  288. function ImplodeInt(tit: TIntegerArray; del: string): string;
  289. var
  290.   i: Integer;
  291. begin
  292.   for i :=  0 to High(tit) do
  293.     Result := Result + IntToStr(tit[i]) + del;
  294.   Delete(Result, Length(Result), 1);
  295. end;
  296.  
  297. // SaveMap - Takes apart the map and puts it into strings before saving in selected file
  298. procedure SaveMap;
  299. var
  300.   a, b, c: Integer;
  301.   titMap: TIntegerArray;
  302. begin
  303.   if not dlgSave.Execute then
  304.     Exit;
  305.   with mapMain do
  306.   begin
  307.     WriteINI('Layout', 'Width', IntToStr(x), dlgSave.FileName);
  308.     WriteINI('Layout', 'Height', IntToStr(y), dlgSave.FileName);
  309.     WriteINI('Layout', 'Depth', IntToStr(z), dlgSave.FileName);
  310.     SetArrayLength(titMap, x * 2);
  311.     for a := 0 to z - 1 do
  312.     begin
  313.       for b := 0 to y - 1 do
  314.       begin
  315.         for c := 0 to x - 1 do
  316.         begin
  317.           titMap[c * 2] := mapMain.tpTiles[a][b][c].x;
  318.           titMap[c * 2 + 1] := mapMain.tpTiles[a][b][c].y;
  319.         end;
  320.         WriteINI('Layer' + IntToStr(a), 'Row' + IntToStr(b), ImplodeInt(titMap, ','), dlgSave.Filename);
  321.       end;
  322.     end;
  323.   end;
  324.   with mapMain do
  325.   begin
  326.     for b := 0 to y - 1 do
  327.       WriteINI('Attrib', 'Row' + IntToStr(b), ImplodeInt(mapMain.att[b], ','), dlgSave.Filename)
  328.   end;
  329. end;
  330.  
  331. // RandMap - Generates a random map based on user input
  332. procedure RandMap;
  333. var
  334.   a, b, c: Integer;
  335. begin
  336. with mapMain do
  337.   begin
  338.     x := StrToIntDef(Readln('Width'), 15);
  339.     y := StrToIntDef(Readln('Height'), 15);
  340.     z := StrToIntDef(Readln('Depth'), 4)
  341.     p := z - 2;
  342.     SetArrayLength(tpTiles, z);
  343.     for a := 0 to z - 1 do
  344.     begin
  345.       SetArrayLength(tpTiles[a], y);
  346.       SetArrayLength(att, y);
  347.       for b := 0 to y - 1 do
  348.       begin
  349.         SetArrayLength(tpTiles[a][b], x);
  350.         SetArrayLength(att[b], x);
  351.         for c := 0 to x - 1 do
  352.         begin
  353.           tpTiles[a][b][c].x := Random(imgTiles.Width div 32);
  354.           tpTiles[a][b][c].y := Random(imgTiles.Height div 32);
  355.         end;
  356.       end;
  357.     end;
  358.   end;
  359.   cp.x := mapMain.x div 2;
  360.   cp.y := mapMain.y div 2;
  361.   try
  362.     scbMainX.Max := mapMain.x - 8;
  363.   except
  364.     scbMainX.Max := scbMainX.Min + 1;
  365.   end;
  366.   try
  367.     scbMainY.Max := mapMain.y - 8;
  368.   except
  369.     scbMainY.Min := scbMainY.Min + 1;
  370.   end;
  371.   scbMainX.Position := cp.x;
  372.   scbMainY.Position := cp.y;
  373.   for a := 0 to cmbLay.Items.Count + 2 do
  374.     cmbLay.Items.Delete(0);
  375.   for a := 0 to mapMain.z - 1 do
  376.     cmbLay.Items.Add('Layer ' + IntToStr(a));
  377.   cmbLay.ItemIndex := 0;
  378.  
  379.   GenerateMap(0, 0);
  380. end;
  381.  
  382. // HandleMenu - Does appropriate task based on what menu item selected
  383. procedure HandleMenu(Sender: TObject);
  384. begin
  385.   case Sender of
  386.     mnuNew: BlankMap;
  387.     mnuOpen: OpenMap;
  388.     mnuSave: SaveMap;
  389.     mnuRand: RandMap;
  390.   end;
  391. end;
  392.  
  393. // HandlePopup - Changes attribute of square to selected one
  394. procedure HandlePopup(Sender: TObject);
  395. var
  396.   x, y, a: Integer;
  397. begin
  398.   case Sender of
  399.     mnuBlnk: a := 0;
  400.     mnuBlck: a := 1;
  401.     mnuEnco: a := 2;
  402.   end;
  403.   for y := md.y to mu.y do
  404.     for x := md.x to mu.x do
  405.       mapMain.att[y][x] := a;
  406. end;
  407.  
  408. // HandleScroll - Repaints map if map scroll bar sent or changes visible tiles if tile scroll bar sent
  409. procedure HandleScroll(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
  410. begin
  411.   case Sender of
  412.     scbMainX: if ScrollPos = cp.x then
  413.       Exit;
  414.     scbMainY: if ScrollPos = cp.y then
  415.       Exit;
  416.   end;
  417.  
  418.   if Sender is TScrollBar then
  419.     TScrollBar(Sender).OnScroll := nil;
  420.   case Sender of
  421.     scbMainX: GenerateMap(Scrollpos - cp.x, 0);
  422.     scbMainY: GenerateMap(0, Scrollpos - cp.y);
  423.   end;
  424.   if Sender is TScrollBar then
  425.     TScrollBar(Sender).OnScroll := @HandleScroll;
  426. end;
  427.  
  428. // HandleMouseDown - Sets tile to selected tile when left clicking or shows popup menu when right clicking
  429. procedure HandleMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  430. begin
  431.   X := ((X div 32) * 32) + 16;
  432.   Y := ((Y div 32) * 32) + 16;
  433.   if Button = mbRight then
  434.   begin
  435.     md.x := X div 32;
  436.     md.y := Y div 32;
  437.     imgMain.Canvas.MoveTo(X, Y);
  438.     imgMain.Canvas.Pen.Width := 8;
  439.     imgMain.Canvas.LineTo(X, Y);
  440.     imgMain.Canvas.Pen.Width := 1;
  441.     Exit;
  442.   end;
  443.   if Sender = imgTiles then
  444.   begin
  445.     tp.x := X div 32;
  446.     tp.y := Y div 32;
  447.   end
  448.   else if Sender = imgMain then
  449.   begin
  450.     imgMain.Canvas.MoveTo(X, Y);
  451.     imgMain.Canvas.Pen.Width := 8;
  452.     imgMain.Canvas.LineTo(X, Y);
  453.     imgMain.Canvas.Pen.Width := 1;
  454.     md.x := X div 32;
  455.     md.y := Y div 32;
  456.   end;
  457. end;
  458.  
  459. procedure HandleMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  460. begin
  461.   mu.x := X div 32;
  462.   mu.y := Y div 32;
  463.   if Button = mbRight then
  464.   begin
  465.     GenerateMap(0, 0);
  466.     if md.x > mu.x then
  467.       Swap(md.x, mu.x);
  468.     if md.y > mu.y then
  469.       Swap(md.y, mu.y);
  470.     GetMousePos(X, Y);
  471.     mnuAttr.Popup(X, Y);
  472.     Exit;
  473.   end;
  474.   if Sender = imgMain then
  475.   begin
  476.     if md.x > mu.x then
  477.       Swap(md.x, mu.x);
  478.     if md.y > mu.y then
  479.       Swap(md.y, mu.y);
  480.     for Y := md.y to mu.y do
  481.       for X := md.x to mu.x do
  482.       begin
  483.         mapMain.tpTiles[cmbLay.ItemIndex][Y + cp.y - 7][X + cp.x - 7].x := tp.x;
  484.         mapMain.tpTiles[cmbLay.ItemIndex][Y + cp.y - 7][X + cp.x - 7].y := tp.y;
  485.       end;
  486.     GenerateMap(0, 0);
  487.   end;
  488. end;
  489.  
  490. // SetupForm - Sets up all the forms objects
  491. procedure SetupForm;
  492. var
  493.   sw, sh, bw, bh, i: Integer;
  494. begin
  495.   GetClientDimensions(sw, sh);
  496.   GetBitmapSize(tiles, bw, bh);
  497.   frmMain := CreateForm;
  498.  
  499.   dlgOpen := TOpenDialog.Create(frmMain);
  500.   dlgOpen.Filter := 'maps| *.ini';
  501.  
  502.   dlgSave := TSaveDialog.Create(frmMain);
  503.   dlgSave.Filter := 'maps| *.ini';
  504.  
  505.   mnuMain := TMainMenu.Create(frmMain);
  506.  
  507.   mnuFile := TMenuItem.Create(frmMain);
  508.   mnuFile.Caption := 'File';
  509.   mnuMain.Items.Add(mnuFile);
  510.  
  511.   mnuNew := TMenuItem.Create(frmMain);
  512.   mnuNew.Caption := 'New';
  513.   mnuNew.OnClick := @HandleMenu;
  514.   mnuMain.Items.Items[0].Add(mnuNew);
  515.  
  516.   mnuOpen := TMenuItem.Create(frmMain);
  517.   mnuOpen.Caption := 'Open';
  518.   mnuOpen.OnClick := @HandleMenu;
  519.   mnuMain.Items.Items[0].Add(mnuOpen);
  520.  
  521.   mnuSave := TMenuItem.Create(frmMain);
  522.   mnuSave.Caption := 'Save';
  523.   mnuSave.OnClick := @HandleMenu;
  524.   mnuMain.Items.Items[0].Add(mnuSave);
  525.  
  526.   mnuRand := TMenuItem.Create(frmMain);
  527.   mnuRand.Caption := 'Random';
  528.   mnuRand.OnClick := @HandleMenu;
  529.   mnuMain.Items.Items[0].Add(mnuRand);
  530.  
  531.   mnuAttr := TPopupMenu.Create(frmMain);
  532.  
  533.   mnuBlnk := TMenuItem.Create(frmMain);
  534.   mnuBlnk.Caption := 'No attribute';
  535.   mnuBlnk.OnClick := @HandlePopup;
  536.   mnuAttr.Items.Add(mnuBlnk);
  537.  
  538.   mnuBlck := TMenuItem.Create(frmMain);
  539.   mnuBlck.Caption := 'Blocked';
  540.   mnuBlck.OnClick := @HandlePopup;
  541.   mnuAttr.Items.Add(mnuBlck);
  542.  
  543.   mnuEnco := TMenuItem.Create(frmMain);
  544.   mnuEnco.Caption := 'Encounter';
  545.   mnuEnco.OnClick := @HandlePopup;
  546.   mnuAttr.Items.Add(mnuEnco);
  547.  
  548.   with frmMain do
  549.   begin
  550.     Caption := 'ScaRPG Map Editor by mixster';
  551.     ClientWidth := 554 + bw;
  552.     ClientHeight := 522;
  553.     Left := (sw - Width) div 2;
  554.     Top := (sh - Height) div 2;
  555.   end;
  556.  
  557.   pnlMain := TPanel.Create(frmMain);
  558.   with pnlMain do
  559.   begin
  560.     Parent := frmMain;
  561.     Width := 502;
  562.     Height := 502;
  563.     Left := 10;
  564.     Top := 10;
  565.   end;
  566.  
  567.   scbMainX := TScrollBar.Create(pnlMain)
  568.   with scbMainX do
  569.   begin
  570.     Parent := pnlMain;
  571.     Width := 480;
  572.     Top := 480;
  573.     Min := 7;
  574.     Max := mapMain.x - 8;
  575.     Position := mapMain.x div 2;
  576.     Kind := sbHorizontal;
  577.     OnScroll := @HandleScroll;
  578.   end;
  579.  
  580.   scbMainY := TScrollBar.Create(pnlMain)
  581.   with scbMainY do
  582.   begin
  583.     Parent := pnlMain;
  584.     Width := 480;
  585.     Left := 480;
  586.     Min := 7;
  587.     Max := mapMain.y - 8;
  588.     Position := mapMain.y div 2;
  589.     Kind := sbVertical;
  590.     OnScroll := @HandleScroll;
  591.   end;
  592.  
  593.   imgMain := TImage.Create(pnlMain);
  594.   with imgMain do
  595.   begin
  596.     Parent := pnlMain;
  597.     Width := 480;
  598.     Height := 480;
  599.     OnMouseDown := @HandleMouseDown;
  600.     OnMouseUp := @HandleMouseUp;
  601.     Canvas.Pen.Color := clYellow;
  602.   end;
  603.  
  604.   pnlTiles := TPanel.Create(frmMain);
  605.   with pnlTiles do
  606.   begin
  607.     Parent := frmMain;
  608.     Width := bw + 22;
  609.     Height := 480;
  610.     Left := 522;
  611.     Top := 10;
  612.   end;
  613.  
  614.   sbxTiles := TScrollBox.Create(pnlTiles);
  615.   with sbxTiles do
  616.   begin
  617.     Parent := pnlTiles;
  618.     Align := alClient;
  619.     sbxTiles.VertScrollBar.Range := bh;
  620.     sbxTiles.VertScrollBar.Increment := 4;
  621.     sbxTiles.VertScrollBar.Tracking := True;
  622.   end;
  623.  
  624.   imgTiles := TImage.Create(sbxTiles);
  625.   with imgTiles do
  626.   begin
  627.     Parent := sbxTiles;
  628.     Width := bw;
  629.     Height := bh;
  630.     SafeDrawBitmap(tiles, Canvas, 0, 0);
  631.     OnMouseDown := @HandleMouseDown;
  632.   end;
  633.  
  634.   cmbLay := TComboBox.Create(frmMain);
  635.   with cmbLay do
  636.   begin
  637.     Parent := frmMain;
  638.     Left := 522;
  639.     Top := 490;
  640.     for i := 0 to mapMain.z - 1 do
  641.       Items.Add('Layer ' + IntToStr(i));
  642.     ItemIndex := 0;
  643.   end;
  644.  
  645.   FreeBitmap(sprites);
  646.   FreeBitmap(tiles);
  647.   GenerateMap(0, 0);
  648.   frmMain.ShowModal;
  649. end;
  650.  
  651. var
  652.   v: TVariantArray;
  653. begin
  654.   tiles := LoadBitmap(ScriptPath + 'Tiles.bmp');
  655.   sprites := LoadBitmap(ScriptPath + 'Sprites.bmp');
  656.   RandomizeMap(50, 50, 4, 0, 50, 50, 4, 0);
  657.   cp.x := mapMain.x div 2;
  658.   cp.y := mapMain.y div 2;
  659.   ThreadSafeCall('SetupForm', v);
  660.   FreeForm(frmMain);
  661. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement