Skip to content

Instantly share code, notes, and snippets.

@JesseTG
Last active March 5, 2019 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JesseTG/c9895a3f0d59fc3a9c735114a8a9fc9f to your computer and use it in GitHub Desktop.
Save JesseTG/c9895a3f0d59fc3a9c735114a8a9fc9f to your computer and use it in GitHub Desktop.
Simplifying someone's component design
// 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