struct GameOver { textures: HashMap, images: HashMap, ongameover: bool, mouse_x: f64, mouse_y: f64, play: bool, quit: bool, } impl GameOver{ fn init(&mut self){ self.create_texture(String::from("gameover_surcouche_off_play"), String::from("assets/gameover_surcouche_off_play.png"), 600.0 , 0.0 , 0.0); self.create_texture(String::from("gameover_surcouche_on_play"), String::from("assets/gameover_surcouche_on_play.png"), 600.0 , 0.0 , 0.0); self.create_texture(String::from("gameover_surcouche_off_quit"), String::from("assets/gameover_surcouche_off_quit.png"), 600.0 , 0.0 , 0.0); self.create_texture(String::from("gameover_surcouche_on_quit"), String::from("assets/gameover_surcouche_on_quit.png"), 600.0 , 0.0 , 0.0); //self.create_texture(String::from("2_off_play"), String::from("assets/off_play.png"), 600.0 , 0.0 , 0.0); self.create_texture(String::from("background"), String::from("assets/background.png"), 600.0,0.0,0.0); } fn create_texture(&mut self, name: String, path: String, size: f64, x: f64, y: f64){ self.images.insert(name.to_string(), Image::new().rect(square(x, y, size))); self.textures.insert(name.to_string(), Texture::from_path(Path::new(&path),&TextureSettings::new()).unwrap()); } fn mouse_move(&mut self, e: &piston::input::Event){ e.mouse_cursor(|x, y| { self.mouse_x = x; self.mouse_y = y; }); } fn mouse_click(&mut self, e: &piston::input::Event){ if let Some(Button::Mouse(button)) = e.press_args() { match button { _left => { if self.quit { process::exit(0); } if self.play { self.ongameover = false; } } } } } fn update(&mut self, _args: &UpdateArgs) { if self.mouse_x >= 120.0 { if self.mouse_x < (120.0 + 306.0) { if self.mouse_y >= 310.0 { if self.mouse_y < 310.0 + 45.0 { if !self.play { self.play = true; } }else{if self.play {self.play = false;}} }else{if self.play {self.play = false;}} }else{if self.play {self.play = false;}} }else{if self.play {self.play = false;}} if self.mouse_x >= 100.0 { if self.mouse_x < (100.0 + 350.0) { if self.mouse_y >= 400.0 { if self.mouse_y < 400.0 + 45.0 { if !self.quit { self.quit = true; } }else{if self.quit {self.quit = false;}} }else{if self.quit {self.quit = false;}} }else{if self.quit {self.quit = false;}} }else{if self.quit {self.quit = false;}} } }