Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

43 righe
777 B

  1. use glc::vector::Vector2f;
  2. use serde::{Deserialize, Serialize};
  3. use specs::{Component, VecStorage};
  4. #[derive(Clone, Debug, Default, Serialize, Deserialize)]
  5. pub struct Position {
  6. pub pos: Vector2f,
  7. pub shape: Shape,
  8. }
  9. #[derive(Clone, Debug, Serialize, Deserialize)]
  10. pub enum Shape {
  11. Dot,
  12. Circle(f32),
  13. }
  14. impl Component for Position {
  15. type Storage = VecStorage<Self>;
  16. }
  17. impl Shape {
  18. pub fn radius(&self) -> f32 {
  19. match self {
  20. Self::Dot => 0.0,
  21. Self::Circle(r) => *r,
  22. }
  23. }
  24. pub fn circle(&self) -> Option<f32> {
  25. if let Self::Circle(r) = &self {
  26. Some(*r)
  27. } else {
  28. None
  29. }
  30. }
  31. }
  32. impl Default for Shape {
  33. fn default() -> Self {
  34. Self::Dot
  35. }
  36. }