Bladeren bron

MapEditor: auto tile corners

Arthur Yefimov 1 jaar geleden
bovenliggende
commit
65d8d6d443
2 gewijzigde bestanden met toevoegingen van 43 en 15 verwijderingen
  1. 41 5
      Programs/Examples/Game/GameEngine.Mod
  2. 2 10
      Programs/Examples/Game/MapEditor.Mod

+ 41 - 5
Programs/Examples/Game/GameEngine.Mod

@@ -22,8 +22,9 @@ CONST
 
 TYPE
   Cell* = RECORD (** A single cell of the map *)
-    kind*: INTEGER;
-    tile*: INTEGER
+    kind*: INTEGER; (** What is saved in a file *)
+    tile*: INTEGER; (** What is displayed on screen *)
+    corners*: SET (** Set of upRight, upLeft, downRight, downLeft *)
   END;
 
   Map* = RECORD
@@ -38,6 +39,34 @@ TYPE
 VAR
   tiles*: G.Bitmap;
 
+PROCEDURE DrawCell*(cell: Cell; x, y, toX, toY: INTEGER);
+VAR kx, ky: INTEGER;
+  PROCEDURE DrawCorner(tile, offX, offY, toX, toY: INTEGER);
+  BEGIN G.DrawPart(tiles,
+        tile MOD tilesInRow * cellW + offX,
+        tile DIV tilesInRow * cellH + offY,
+        cellW DIV 2, cellH DIV 2, toX + offX, toY + offY)
+  END DrawCorner;
+BEGIN
+  kx := cell.tile MOD tilesInRow * cellW;
+  ky := cell.tile DIV tilesInRow * cellH;
+  G.DrawPart(tiles, kx, ky, cellW, cellH, toX, toY);
+  IF cell.corners # {} THEN
+    IF upLeft IN cell.corners THEN
+      DrawCorner(cell.kind + tilesInRow + 5, 0, 0, toX, toY)
+    END;
+    IF upRight IN cell.corners THEN
+      DrawCorner(cell.kind + tilesInRow + 4, cellW DIV 2, 0, toX, toY)
+    END;
+    IF downLeft IN cell.corners THEN
+      DrawCorner(cell.kind + 5, 0, cellH DIV 2, toX, toY)
+    END;
+    IF downRight IN cell.corners THEN
+      DrawCorner(cell.kind + 4, cellW DIV 2, cellH DIV 2, toX, toY)
+    END
+  END
+END DrawCell;
+
 PROCEDURE CheckNeighbours(VAR map: Map; x, y, kind: INTEGER): SET;
 VAR s: SET;
   PROCEDURE P(VAR map: Map; x, y, dir: INTEGER; VAR s: SET);
@@ -63,10 +92,12 @@ RETURN s END CheckNeighbours;
 PROCEDURE UpdateMapTile*(VAR map: Map; x, y: INTEGER);
 VAR kind, tile, xx, yy: INTEGER;
   dirs: SET; (* Set of directions of neighbours where kind is the same *)
+  corners: SET;
 BEGIN
   kind := map.cells[y, x].kind;
   tile := kind;
-  IF (kind = 64) OR (kind = 96) THEN
+  corners := {};
+  IF (kind >= 32) & (kind MOD 32 = 0) THEN
     dirs := CheckNeighbours(map, x, y, kind);
     xx := 3; yy := 3;
     IF up IN dirs THEN
@@ -97,9 +128,14 @@ BEGIN
       END
     ELSIF right IN dirs THEN xx := 0; yy := 3
     END;
-    tile := kind + xx + yy * tilesInRow
+    tile := kind + xx + yy * tilesInRow;
+    IF {up, left, upLeft} - dirs = {upLeft} THEN INCL(corners, upLeft) END;
+    IF {up, right, upRight} - dirs = {upRight} THEN INCL(corners, upRight) END;
+    IF {down, left, downLeft} - dirs = {downLeft} THEN INCL(corners, downLeft) END;
+    IF {down, right, downRight} - dirs = {downRight} THEN INCL(corners, downRight) END
   END;
-  map.cells[y, x].tile := tile
+  map.cells[y, x].tile := tile;
+  map.cells[y, x].corners := corners
 END UpdateMapTile;
 
 PROCEDURE UpdateMapTiles*(VAR map: Map);

+ 2 - 10
Programs/Examples/Game/MapEditor.Mod

@@ -37,14 +37,6 @@ RETURN x END Limit;
 
 (** Map Widget **)
 
-PROCEDURE DrawCell(cell: E.Cell; x, y, toX, toY: INTEGER);
-VAR kx, ky: INTEGER;
-BEGIN
-  kx := cell.tile MOD E.tilesInRow * E.cellW;
-  ky := cell.tile DIV E.tilesInRow * E.cellH;
-  G.DrawPart(E.tiles, kx, ky, E.cellW, E.cellH, toX, toY)
-END DrawCell;
-
 PROCEDURE MapWidgetHandleDraw(c: S.Widget; VAR msg: S.DrawMsg);
 VAR x: INTEGER;
   X, Y, i, j: INTEGER;
@@ -80,7 +72,7 @@ BEGIN
   FOR i := y0 TO y1 DO
     X := x;
     FOR j := x0 TO x1 DO
-      DrawCell(game.map.cells[i, j], i, j, X, Y);
+      E.DrawCell(game.map.cells[i, j], i, j, X, Y);
       INC(X, E.cellW)
     END;
     INC(Y, E.cellH)
@@ -250,7 +242,7 @@ RETURN TRUE END InitInterface;
 PROCEDURE Init(): BOOLEAN;
 VAR ok: BOOLEAN;
 BEGIN ok := TRUE;
-  G.Settings(320, 200, {});
+  (*G.Settings(320, 200, {});*)
   IF window THEN G.Settings(1240, 780, {G.window(*, G.maximized*)}) END;
   G.Init;
   IF ~G.Done THEN ok := FALSE END;