• R/O
  • SSH

silny-kombat: Commit

Mercurial repo for silny-kombat project


Commit MetaInfo

Révision7b7e9f3d78ac09563cab6ae95b503b7cbca38e79 (tree)
l'heure2022-09-08 03:45:31
AuteurPiotr Kozka <piotoor@gmai...>
CommiterPiotr Kozka

Message de Log

Fixed warnings in controller.rs

Change Summary

Modification

diff -r 2a6e5ed50462 -r 7b7e9f3d78ac src/controller.rs
--- a/src/controller.rs Thu Aug 04 21:38:49 2022 +0200
+++ b/src/controller.rs Wed Sep 07 20:45:31 2022 +0200
@@ -24,8 +24,8 @@
2424 use sfml::window::Key;
2525
2626 pub struct Controller<'a> {
27- characterA : Option<&'a Character<'a>>,
28- characterB : Option<&'a Character<'a>>,
27+ character_a: Option<&'a Character<'a>>,
28+ character_b: Option<&'a Character<'a>>,
2929
3030 textures: [&'a SfBox<Texture>; 4]
3131 }
@@ -35,18 +35,18 @@
3535 pub fn new(textures: [&'a SfBox<Texture>;4] ) -> Self {
3636
3737 Controller {
38- characterA: None,
39- characterB: None,
38+ character_a: None,
39+ character_b: None,
4040 textures
4141 }
4242 }
4343
44- pub fn set_characterA(&mut self, new_character: &'a Character){
45- self.characterA = Some(new_character);
44+ pub fn set_character_a(&mut self, new_character: &'a Character){
45+ self.character_a = Some(new_character);
4646 }
4747
48- pub fn set_characterB(&mut self, new_character: &'a Character){
49- self.characterB = Some(new_character);
48+ pub fn set_character_b(&mut self, new_character: &'a Character){
49+ self.character_b = Some(new_character);
5050 }
5151
5252 //TODO: find a better name
@@ -63,23 +63,23 @@
6363
6464 let mut window = prepare_window();
6565
66- let key_processor = key_processing::KeyProcessor::new();
66+ let key_processor = KeyProcessor::new();
6767
6868
6969 //let mut character_sprite = sprite_rendering::CharacterSprite::new(&textures);
7070 //let mut character_sprite_b = sprite_rendering::CharacterSprite::new(&textures);
7171
72- let mut character_A: Character = Character ::new("Sub Zero", &self.textures);
73- let mut character_B: Character = Character ::new("Sub Zero", &self.textures);
74-
75- println!("{} vs {}", character_A.get_name(), character_B.get_name());
72+ let mut character_a: Character = Character ::new("Sub Zero", &self.textures);
73+ let mut character_b: Character = Character ::new("Sub Zero", &self.textures);
7674
77- let groundLevel = 100.0;
75+ println!("{} vs {}", character_a.get_name(), character_b.get_name());
7876
79- character_A.char_sprite.sprite.set_position(Vector2f::new(0.0, groundLevel + 0.0));
77+ let ground_level = 100.0;
8078
81- character_B.char_sprite.sprite.set_position(Vector2f::new(600.0, groundLevel + 0.0));
82- character_B.char_sprite.sprite.set_scale(Vector2f::new(-1.0, 1.0));
79+ character_a.char_sprite.sprite.set_position(Vector2f::new(0.0, ground_level + 0.0));
80+
81+ character_b.char_sprite.sprite.set_position(Vector2f::new(600.0, ground_level + 0.0));
82+ character_b.char_sprite.sprite.set_scale(Vector2f::new(-1.0, 1.0));
8383
8484 //loop
8585
@@ -87,21 +87,21 @@
8787
8888
8989 loop {
90- let mut output_A: Result<Option<character_state_machine::CharacterFSMOutput>, TransitionImpossibleError> = character_A.trigger(character_state_machine::CharacterFSMInput::Released);
91- let mut output_B: Result<Option<character_state_machine::CharacterFSMOutput>, TransitionImpossibleError> = character_B.trigger(character_state_machine::CharacterFSMInput::Released);
90+ let mut output_a: Result<Option<character_state_machine::CharacterFSMOutput>, TransitionImpossibleError> = character_a.trigger(character_state_machine::CharacterFSMInput::Released);
91+ let mut output_b: Result<Option<character_state_machine::CharacterFSMOutput>, TransitionImpossibleError> = character_b.trigger(character_state_machine::CharacterFSMInput::Released);
9292 //let mut key_result = key_processor.match_key();
9393 if Key::A.is_pressed()
9494 {
95- output_B = process_key_result_for_character(&key_processor, &mut character_B, KeyEvents::Char_B_Left);
95+ output_b = process_key_result_for_character(&key_processor, &mut character_b, KeyEvents::Char_B_Left);
9696 }
9797 if Key::D.is_pressed()
9898 {
99- output_B = process_key_result_for_character(&key_processor, &mut character_B, KeyEvents::Char_B_Right);
99+ output_b = process_key_result_for_character(&key_processor, &mut character_b, KeyEvents::Char_B_Right);
100100 }
101101 if Key::F4.is_pressed()
102102 {
103103 println!("Testing: dump values to check");
104- save_test_data_to_file(groundLevel, &character_A.char_sprite, &character_B.char_sprite);
104+ save_test_data_to_file(ground_level, &character_a.char_sprite, &character_b.char_sprite);
105105 }
106106 if Key::ESCAPE.is_pressed()
107107 {
@@ -109,11 +109,11 @@
109109 }
110110 if Key::LEFT.is_pressed()
111111 {
112- output_A = process_key_result_for_character(&key_processor, &mut character_A, KeyEvents::Char_Left);
112+ output_a = process_key_result_for_character(&key_processor, &mut character_a, KeyEvents::Char_Left);
113113 }
114114 if Key::RIGHT.is_pressed()
115115 {
116- output_A = process_key_result_for_character(&key_processor, &mut character_A, KeyEvents::Char_Right);
116+ output_a = process_key_result_for_character(&key_processor, &mut character_a, KeyEvents::Char_Right);
117117 }
118118 // match key_result {
119119 // KeyEvents::Char_B_Left => {
@@ -136,24 +136,24 @@
136136 // character_A.update_sprite();
137137 // character_B.update_sprite();
138138 // }
139- match output_B {
139+ match output_b {
140140 Ok(v) => {
141- character_B.update_sprite(v);
141+ character_b.update_sprite(v);
142142 },
143- Err(e) => println!("Unsupported key_result")
143+ Err(_e) => println!("Unsupported key_result")
144144 }
145145
146- match output_A {
146+ match output_a {
147147 Ok(v) => {
148- character_A.update_sprite(v);
148+ character_a.update_sprite(v);
149149 },
150- Err(e) => println!("Unsupported key_result")
150+ Err(_e) => println!("Unsupported key_result")
151151 }
152152
153153
154154 window.clear(Color::rgb(50, 200, 50));
155- window.draw(&character_A.char_sprite.sprite);
156- window.draw(&character_B.char_sprite.sprite);
155+ window.draw(&character_a.char_sprite.sprite);
156+ window.draw(&character_b.char_sprite.sprite);
157157 window.display();
158158
159159 //end main loop
@@ -224,7 +224,7 @@
224224 window
225225 }
226226
227-pub fn process_key_result_for_character(key_processor:&key_processing::KeyProcessor, character: & mut Character, key_result:KeyEvents) -> Result<Option<character_state_machine::CharacterFSMOutput>, TransitionImpossibleError>
227+pub fn process_key_result_for_character(key_processor:& KeyProcessor, character: & mut Character, key_result:KeyEvents) -> Result<Option<character_state_machine::CharacterFSMOutput>, TransitionImpossibleError>
228228 {
229229 // if key_result == KeyEvents::Char_Left as i32
230230 // || key_result == KeyEvents::Char_Right as i32
@@ -241,36 +241,36 @@
241241 }
242242 }
243243
244-pub fn save_test_data_to_file(groundLevel:f32, spriteA: &CharacterSprite, spriteB: &CharacterSprite)
244+pub fn save_test_data_to_file(ground_level:f32, sprite_a: &CharacterSprite, sprite_b: &CharacterSprite)
245245 {
246246 let mut data_to_dump: String = "spriteAData\n".to_string();
247247
248248 //data_to_dump = &String::from("spriteAData");
249249
250- data_to_dump.push_str(&groundLevel.to_string());
250+ data_to_dump.push_str(&ground_level.to_string());
251251 data_to_dump.push_str("\n");
252- data_to_dump.push_str( &spriteA.sprite.position().x.to_string());
252+ data_to_dump.push_str( &sprite_a.sprite.position().x.to_string());
253253 data_to_dump.push_str("\n");
254- data_to_dump.push_str( &spriteA.sprite.position().y.to_string());
254+ data_to_dump.push_str( &sprite_a.sprite.position().y.to_string());
255255 data_to_dump.push_str("\n");
256256
257257 data_to_dump.push_str("spriteBData\n");
258258
259- data_to_dump.push_str( &spriteB.sprite.position().x.to_string());
259+ data_to_dump.push_str( &sprite_b.sprite.position().x.to_string());
260260 data_to_dump.push_str("\n");
261- data_to_dump.push_str( &spriteB.sprite.position().y.to_string());
261+ data_to_dump.push_str( &sprite_b.sprite.position().y.to_string());
262262 data_to_dump.push_str("\n");
263263
264264 let path = Path::new("dump.txt");
265265
266266 let mut file = match File::create(&path) {
267267 //Err(why) => panic!("couldn't create {}: {}", display, why),
268- Err(why) => panic!("couldn't create test dump file"),
268+ Err(_why) => panic!("couldn't create test dump file"),
269269 Ok(file) => file,
270270 };
271271
272272 match file.write_all(data_to_dump.as_bytes()) {
273- Err(why) => panic!("couldn't write to test dump file"),
273+ Err(_why) => panic!("couldn't write to test dump file"),
274274 Ok(_) => println!("successfully wrote to test dump file"),
275275 }
276276 }
Afficher sur ancien navigateur de dépôt.