Last active
March 5, 2019 21:04
-
-
Save JesseTG/c9895a3f0d59fc3a9c735114a8a9fc9f to your computer and use it in GitHub Desktop.
Simplifying someone's component design
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assumptions: | |
// - Each analog stick is a separate entity | |
// - There is no central "controller" entity, but there is a controller ID | |
// - It's up to you to decide which entities should have which of these components | |
public enum StickMode { | |
Movement, | |
Attack, | |
// And possibly other things like camera or cursor movement, depending on the nature of your game | |
// and on other architecture decisions you make | |
} | |
[Input] | |
public class GamepadComponent : IComponent { | |
[EntityIndex] | |
public int DeviceId; // contexts.input.GetEntitiesWithDeviceId(3) | |
} | |
[Input] | |
public class AnalogStickComponent : IComponent { | |
public StickMode Mode; | |
} | |
[Input] | |
public class RawStickComponent : IComponent { | |
public float X { get; set; } | |
public float Y { get; set; } | |
public float Magnitude { get; set; } | |
} | |
[Input] | |
public class NormalizedStickComponent : IComponent { | |
public float X { get; set; } | |
public float Y { get; set; } | |
public float AngleRadians { get; set; } | |
public float Magnitude { get; set; } | |
} | |
[Input] | |
public class DeadzoneComponent : IComponent { | |
public float Inner { get; set; } | |
public float Outer { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment