Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Level {
- entities: Vec<Entity>,
- current_entity: usize,
- foo: i32,
- }
- struct Entity;
- enum Action {
- Walk,
- }
- impl Level {
- fn update(&mut self) {
- while self.current_entity < self.entities.len() {
- let action = self.entities[self.current_entity].get_action(self);
- action.perform(self);
- //logic...
- self.current_entity += 1;
- }
- self.current_entity = 0;
- }
- }
- impl Entity {
- fn get_action(&mut self, _level: &Level) -> Action {
- // logic...
- Action::Walk
- }
- }
- impl Action {
- fn perform(&self, level: &mut Level) -> bool {
- level.foo += 1; // mutate level
- //logic...
- true
- }
- }
- fn main() {
- let mut level = Level { entities: vec![Entity], current_entity: 0, foo: 0 };
- level.update();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement