Gondwana Game Engine Development (master) - 2.7.0
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
ObliqueLeftCoordinates.cs
1using System.Drawing;
3
5
23internal sealed class ObliqueLeftCoordinates : ISceneLayerCoordinates
24{
32 public Point GetAnchorPixelAtSceneLayerCoordinates(SceneLayer sceneLayer, PointF layerPoint)
33 {
34 GetGeometry(
35 sceneLayer,
36 out _,
37 out int H,
38 out int skewX,
39 out int faceWidth);
40
41 float x = -sceneLayer.OriginPx.X
42 + layerPoint.X * faceWidth
43 - layerPoint.Y * skewX;
44
45 float y = -sceneLayer.OriginPx.Y
46 + layerPoint.Y * H;
47
48 return new Point(
49 (int)Math.Floor(x),
50 (int)Math.Floor(y));
51 }
52
59 public PointF GetSceneLayerCoordinatesAtPixel(SceneLayer sceneLayer, PointF pixelPt)
60 {
61 GetGeometry(
62 sceneLayer,
63 out _,
64 out int H,
65 out int skewX,
66 out int faceWidth);
67
68 float row = (pixelPt.Y + sceneLayer.OriginPx.Y) / H;
69 float col = (pixelPt.X + sceneLayer.OriginPx.X + row * skewX) / faceWidth;
70
71 return new PointF(col, row);
72 }
73
81 public List<SceneLayerTile> GetSceneLayerTilesInPixelRange(
82 SceneLayer sceneLayer,
83 Rectangle worldPixelRange,
84 bool includeOverhang)
85 {
86 var result = new List<SceneLayerTile>();
87 var candidateRange = TileBounds.GetTransformedTileCandidateRange(sceneLayer, worldPixelRange, includeOverhang);
88
89 var upperLeft = GetSceneLayerCoordinatesAtPixel(
90 sceneLayer,
91 new PointF(candidateRange.Left, candidateRange.Top));
92
93 var upperRight = GetSceneLayerCoordinatesAtPixel(
94 sceneLayer,
95 new PointF(candidateRange.Right, candidateRange.Top));
96
97 var lowerLeft = GetSceneLayerCoordinatesAtPixel(
98 sceneLayer,
99 new PointF(candidateRange.Left, candidateRange.Bottom));
100
101 var lowerRight = GetSceneLayerCoordinatesAtPixel(
102 sceneLayer,
103 new PointF(candidateRange.Right, candidateRange.Bottom));
104
105 int minX = (int)Math.Floor(
106 new[]
107 {
108 upperLeft.X,
109 upperRight.X,
110 lowerLeft.X,
111 lowerRight.X
112 }.Min()) - 1;
113
114 int maxX = (int)Math.Ceiling(
115 new[]
116 {
117 upperLeft.X,
118 upperRight.X,
119 lowerLeft.X,
120 lowerRight.X
121 }.Max()) + 1;
122
123 int minY = (int)Math.Floor(
124 new[]
125 {
126 upperLeft.Y,
127 upperRight.Y,
128 lowerLeft.Y,
129 lowerRight.Y
130 }.Min()) - 1;
131
132 int maxY = (int)Math.Ceiling(
133 new[]
134 {
135 upperLeft.Y,
136 upperRight.Y,
137 lowerLeft.Y,
138 lowerRight.Y
139 }.Max()) + 1;
140
141 for (int y = minY; y <= maxY; y++)
142 {
143 for (int x = minX; x <= maxX; x++)
144 {
145 var tile = sceneLayer[x, y];
146
147 if (tile is null)
148 continue;
149
150 var tileRange = GetPixelRangeForTile(tile, includeOverhang);
151
152 if (tileRange.IntersectsWith(worldPixelRange))
153 result.Add(tile);
154 }
155 }
156
157 return result;
158 }
159
166 public Rectangle GetPixelRangeForTile(Tile tile, bool includeOverhang)
167 {
168 var anchor = GetAnchorPixelAtSceneLayerCoordinates(
169 tile.SceneLayer,
170 tile.SceneLayerCoordinates);
171
172 var baseRect = new Rectangle(
173 anchor.X,
174 anchor.Y,
175 tile.SceneLayer.TileWidth,
176 tile.SceneLayer.TileHeight);
177
178 return TileBounds.ApplyTileGeometry(baseRect, tile, includeOverhang);
179 }
180
187 public Rectangle GetPixelRangeForTileList(List<Tile> tileList, bool includeOverhang)
188 {
189 Rectangle result = Rectangle.Empty;
190
191 foreach (var tile in tileList)
192 {
193 var tileRange = GetPixelRangeForTile(tile, includeOverhang);
194
195 result = result.IsEmpty
196 ? tileRange
197 : Rectangle.Union(result, tileRange);
198 }
199
200 return result;
201 }
202
210 public SceneLayerTile GetAdjacentSceneLayerTile(
211 SceneLayerTile layerPoint,
212 CardinalDirections direction)
213 {
214 var sceneLayer = layerPoint.SceneLayer;
215 int x = layerPoint.GridCoordinatesAbs.X;
216 int y = layerPoint.GridCoordinatesAbs.Y;
217
218 return direction switch
219 {
220 CardinalDirections.N => sceneLayer.ResolveWrappedTile(x, y - 1),
221 CardinalDirections.NE => sceneLayer.ResolveWrappedTile(x + 1, y - 1),
222 CardinalDirections.E => sceneLayer.ResolveWrappedTile(x + 1, y),
223 CardinalDirections.SE => sceneLayer.ResolveWrappedTile(x + 1, y + 1),
224 CardinalDirections.S => sceneLayer.ResolveWrappedTile(x, y + 1),
225 CardinalDirections.SW => sceneLayer.ResolveWrappedTile(x - 1, y + 1),
226 CardinalDirections.W => sceneLayer.ResolveWrappedTile(x - 1, y),
227 CardinalDirections.NW => sceneLayer.ResolveWrappedTile(x - 1, y - 1),
228 _ => null
229 };
230 }
231
238 public Point[] GetPolygonPts(Tile tile, bool includeOverhang)
239 {
240 GetGeometry(
241 tile.SceneLayer,
242 out int W,
243 out int H,
244 out int skewX,
245 out int faceWidth);
246
247 var anchor = GetAnchorPixelAtSceneLayerCoordinates(
248 tile.SceneLayer,
249 tile.SceneLayerCoordinates);
250
251 var overhang = includeOverhang
252 ? tile.Overhang
253 : Spacing.None;
254
255 return new[]
256 {
257 new Point(
258 anchor.X + skewX - overhang.Left,
259 anchor.Y - overhang.Top),
260
261 new Point(
262 anchor.X + W + overhang.Right,
263 anchor.Y - overhang.Top),
264
265 new Point(
266 anchor.X + faceWidth + overhang.Right,
267 anchor.Y + H + overhang.Bottom),
268
269 new Point(
270 anchor.X - overhang.Left,
271 anchor.Y + H + overhang.Bottom)
272 };
273 }
274
282 public PointF FindEquivalentSceneLayerCoordinates(
283 PointF valColRow,
284 int xUpperBound,
285 int yUpperBound)
286 {
287 float modX = valColRow.X % (xUpperBound + 1);
288 float modY = valColRow.Y % (yUpperBound + 1);
289
290 if (modX < 0)
291 modX += xUpperBound + 1;
292
293 if (modY < 0)
294 modY += yUpperBound + 1;
295
296 return new PointF(modX, modY);
297 }
298
299 private static void GetGeometry(
300 SceneLayer sceneLayer,
301 out int width,
302 out int height,
303 out int skewX,
304 out int faceWidth)
305 {
306 width = sceneLayer.TileWidth;
307 height = sceneLayer.TileHeight;
308
309 // The full tile image remains W x H. Half of W is used by the
310 // row-wise shear; the remaining width is the horizontal tile face.
311 skewX = width / 2;
312 faceWidth = width - skewX;
313 }
314}
Point GridCoordinatesAbs
Gets the absolute grid coordinates of this tile within its parent scene layer as integer values.
override SceneLayer SceneLayer
Gets the parent scene layer that contains this tile.
Point OriginPx
Gets or sets the world-space pixel origin of this layer's (0,0) tile position.
int TileHeight
Gets or sets the height of each tile in this layer, measured in pixels.
int TileWidth
Gets or sets the width of each tile in this layer, measured in pixels.
CardinalDirections
Represents the eight cardinal and intercardinal directions of the compass.
@ Rectangle
Particles are spawned uniformly within a rectangular area. This is the default distribution.
record struct Spacing([property:JsonProperty("left")] int Left, [property:JsonProperty("top")] int Top, [property:JsonProperty("right")] int Right, [property:JsonProperty("bottom")] int Bottom)
Represents dimensions in pixels when spacing Tilesheets.
Definition Spacing.cs:12