simulation.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # coding: utf-8
  2. from sandbox.engulf.behaviour import GrassSpawnBehaviour
  3. from sandbox.engulf.subject import Cell, Grass
  4. from synergine2.xyz import XYZSubjects, XYZSubjectMixin, XYZSimulation
  5. __author__ = 'bux'
  6. class EngulfSubjects(XYZSubjects):
  7. def __init__(self, *args, **kwargs):
  8. super().__init__(*args, **kwargs)
  9. # TODO: accept multiple subjects as same position
  10. # TODO: init xyz with given list
  11. self.cell_xyz = {}
  12. self.grass_xyz = {}
  13. def remove(self, value: XYZSubjectMixin):
  14. super().remove(value)
  15. if isinstance(value, Cell):
  16. del self.cell_xyz[value.position]
  17. if isinstance(value, Grass):
  18. del self.grass_xyz[value.position]
  19. def append(self, p_object: XYZSubjectMixin):
  20. super().append(p_object)
  21. if isinstance(p_object, Cell):
  22. self.cell_xyz[p_object.position] = p_object
  23. if isinstance(p_object, Grass):
  24. self.grass_xyz[p_object.position] = p_object
  25. class Engulf(XYZSimulation):
  26. behaviours_classes = [
  27. GrassSpawnBehaviour,
  28. ]
  29. def is_possible_position(self, position: tuple) -> bool:
  30. top_left = (-35, -35, 0)
  31. bottom_right = (35, 35, 0)
  32. pos_x = position[0]
  33. pos_y = position[1]
  34. if pos_x < top_left[0] or pos_x > bottom_right[0]:
  35. return False
  36. if pos_y < top_left[1] or pos_y > bottom_right[1]:
  37. return False
  38. return True