extern crate gfx4games; use gfx4games::events::MainLoop; use gfx4games::events::run; use gfx4games::graphics; use gfx4games::graphics::context::Context; use gfx4games::rect::Rect; struct MainState { rect: Rect, other_rect: Rect, } impl MainState { pub fn new() -> MainState { MainState { rect: Rect::new(-30.0, 0.0, 5., 5.), other_rect: Rect::new(40.0, 0.0, 5.0, 5.0), } } } impl MainLoop for MainState { fn draw(&mut self, ctx: &mut Context) { self.rect.draw(ctx); self.other_rect.draw(ctx); } fn update(&mut self, _ctx: &mut Context, _dt: f32) { let mut x = 0.0; x = 0.57; if !self.rect.collide(&self.other_rect) { self.rect.dx += x; } else if self.rect.collide(&self.other_rect) { self.rect.set_color(graphics::INDIGO); self.other_rect.set_color([1.0, 0.0, 0.0]); } } } fn main() { let mut state = MainState::new(); let mut ctx = Context::new("Collision Example".to_string(), 512, 512); run(&mut ctx, &mut state); }