Skip to content

Instantly share code, notes, and snippets.

@XMPPwocky
Created February 28, 2015 22:04
Show Gist options
  • Save XMPPwocky/ad2870853fa5054d1fa2 to your computer and use it in GitHub Desktop.
Save XMPPwocky/ad2870853fa5054d1fa2 to your computer and use it in GitHub Desktop.

so you want to have a Tank, and then you have different sub-tanks which have different AIs, yeah? and all the AIs need their own state

pub struct Tank<A> {
    pub pos: f32
    pub health: u32,
    pub ai: A
}
impl<A: TankAi> Tank<A> {
    fn think(&mut self) { <A as TankAi>::think(self) }
}

pub trait TankAi {
    fn think(&mut Tank<Self>);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment