-
Notifications
You must be signed in to change notification settings - Fork 0
Core.Utilities.Direction
This code defines a static utility class named within the namespace. It provides a set of constant-like values representing the standard 8 directions in a 2D coordinate system. Direction``Meatcorps.Engine.Core.Utilities``Vector2
The class uses the System.Numerics.Vector2 structure to define the following directions:
-
Cardinal Directions: , , , and .
Left``Right``Top``Bottom -
Ordinal (Diagonal) Directions: , , , and .
LeftTop``RightTop``RightBottom``LeftBottom
Coordinate System Note: Based on the values provided, the engine uses a "Y-down" coordinate system (common in 2D graphics APIs like GDI+, WPF, or many UI frameworks):
- is
(0, -1)(moving up decreases the Y value).Top - is
(0, 1)(moving down increases the Y value).Bottom - is
(-1, 0)and is(1, 0).Left``Right
In the context of the other files you provided (like , , and ), this class serves several purposes: GenericAxisInput``BufferedDirection``SpatialEntityGrid
-
Standardization: Instead of hardcoding everywhere in the project (as seen in the constructor), developers can use
Direction.Right. This makes the code more readable and easier to maintain.new Vector2(1, 0)``GenericAxisInput -
Movement Logic: It's used to define the direction an entity should move. For example, if a player presses the "Up" key, the engine can multiply their speed by
Direction.Top. -
Grid Navigation: In systems like , these vectors are useful for checking neighboring cells. If you are at cell , the cell to the top-left is at
(x + Direction.LeftTop.X, y + Direction.LeftTop.Y).SpatialEntityGrid``(x, y) -
Input Mapping: It acts as a bridge between raw input (like a joystick or keyboard) and game actions. Classes like or use these vectors to calculate the final "intended" direction of a player.
BufferedDirection``GenericAxisInput -
Collision/Raycasting: If you need to check if there is an obstacle to the right of an object, you would cast a ray or check a bounding box offset by
Direction.Right.
Essentially, it is a centralized dictionary of spatial constants used to ensure that "Up" means the same thing across the entire engine.