Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. struct Level {
  2. entities: Vec<Entity>,
  3. current_entity: usize,
  4. foo: i32,
  5. }
  6.  
  7. struct Entity;
  8.  
  9. enum Action {
  10. Walk,
  11. }
  12.  
  13. impl Level {
  14. fn update(&mut self) {
  15. while self.current_entity < self.entities.len() {
  16. let action = self.entities[self.current_entity].get_action(self);
  17.  
  18. action.perform(self);
  19. //logic...
  20. self.current_entity += 1;
  21. }
  22. self.current_entity = 0;
  23. }
  24. }
  25.  
  26. impl Entity {
  27. fn get_action(&mut self, _level: &Level) -> Action {
  28. // logic...
  29. Action::Walk
  30. }
  31. }
  32.  
  33. impl Action {
  34. fn perform(&self, level: &mut Level) -> bool {
  35. level.foo += 1; // mutate level
  36. //logic...
  37. true
  38. }
  39. }
  40.  
  41. fn main() {
  42. let mut level = Level { entities: vec![Entity], current_entity: 0, foo: 0 };
  43. level.update();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement