Mercurial repo for silny-kombat project
Revision | 7b7e9f3d78ac09563cab6ae95b503b7cbca38e79 (tree) |
---|---|
Time | 2022-09-08 03:45:31 |
Author | Piotr Kozka <piotoor@gmai...> |
Commiter | Piotr Kozka |
Fixed warnings in controller.rs
@@ -24,8 +24,8 @@ | ||
24 | 24 | use sfml::window::Key; |
25 | 25 | |
26 | 26 | 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>>, | |
29 | 29 | |
30 | 30 | textures: [&'a SfBox<Texture>; 4] |
31 | 31 | } |
@@ -35,18 +35,18 @@ | ||
35 | 35 | pub fn new(textures: [&'a SfBox<Texture>;4] ) -> Self { |
36 | 36 | |
37 | 37 | Controller { |
38 | - characterA: None, | |
39 | - characterB: None, | |
38 | + character_a: None, | |
39 | + character_b: None, | |
40 | 40 | textures |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
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); | |
46 | 46 | } |
47 | 47 | |
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); | |
50 | 50 | } |
51 | 51 | |
52 | 52 | //TODO: find a better name |
@@ -63,23 +63,23 @@ | ||
63 | 63 | |
64 | 64 | let mut window = prepare_window(); |
65 | 65 | |
66 | - let key_processor = key_processing::KeyProcessor::new(); | |
66 | + let key_processor = KeyProcessor::new(); | |
67 | 67 | |
68 | 68 | |
69 | 69 | //let mut character_sprite = sprite_rendering::CharacterSprite::new(&textures); |
70 | 70 | //let mut character_sprite_b = sprite_rendering::CharacterSprite::new(&textures); |
71 | 71 | |
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); | |
76 | 74 | |
77 | - let groundLevel = 100.0; | |
75 | + println!("{} vs {}", character_a.get_name(), character_b.get_name()); | |
78 | 76 | |
79 | - character_A.char_sprite.sprite.set_position(Vector2f::new(0.0, groundLevel + 0.0)); | |
77 | + let ground_level = 100.0; | |
80 | 78 | |
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)); | |
83 | 83 | |
84 | 84 | //loop |
85 | 85 |
@@ -87,21 +87,21 @@ | ||
87 | 87 | |
88 | 88 | |
89 | 89 | 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); | |
92 | 92 | //let mut key_result = key_processor.match_key(); |
93 | 93 | if Key::A.is_pressed() |
94 | 94 | { |
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); | |
96 | 96 | } |
97 | 97 | if Key::D.is_pressed() |
98 | 98 | { |
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); | |
100 | 100 | } |
101 | 101 | if Key::F4.is_pressed() |
102 | 102 | { |
103 | 103 | 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); | |
105 | 105 | } |
106 | 106 | if Key::ESCAPE.is_pressed() |
107 | 107 | { |
@@ -109,11 +109,11 @@ | ||
109 | 109 | } |
110 | 110 | if Key::LEFT.is_pressed() |
111 | 111 | { |
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); | |
113 | 113 | } |
114 | 114 | if Key::RIGHT.is_pressed() |
115 | 115 | { |
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); | |
117 | 117 | } |
118 | 118 | // match key_result { |
119 | 119 | // KeyEvents::Char_B_Left => { |
@@ -136,24 +136,24 @@ | ||
136 | 136 | // character_A.update_sprite(); |
137 | 137 | // character_B.update_sprite(); |
138 | 138 | // } |
139 | - match output_B { | |
139 | + match output_b { | |
140 | 140 | Ok(v) => { |
141 | - character_B.update_sprite(v); | |
141 | + character_b.update_sprite(v); | |
142 | 142 | }, |
143 | - Err(e) => println!("Unsupported key_result") | |
143 | + Err(_e) => println!("Unsupported key_result") | |
144 | 144 | } |
145 | 145 | |
146 | - match output_A { | |
146 | + match output_a { | |
147 | 147 | Ok(v) => { |
148 | - character_A.update_sprite(v); | |
148 | + character_a.update_sprite(v); | |
149 | 149 | }, |
150 | - Err(e) => println!("Unsupported key_result") | |
150 | + Err(_e) => println!("Unsupported key_result") | |
151 | 151 | } |
152 | 152 | |
153 | 153 | |
154 | 154 | 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); | |
157 | 157 | window.display(); |
158 | 158 | |
159 | 159 | //end main loop |
@@ -224,7 +224,7 @@ | ||
224 | 224 | window |
225 | 225 | } |
226 | 226 | |
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> | |
228 | 228 | { |
229 | 229 | // if key_result == KeyEvents::Char_Left as i32 |
230 | 230 | // || key_result == KeyEvents::Char_Right as i32 |
@@ -241,36 +241,36 @@ | ||
241 | 241 | } |
242 | 242 | } |
243 | 243 | |
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) | |
245 | 245 | { |
246 | 246 | let mut data_to_dump: String = "spriteAData\n".to_string(); |
247 | 247 | |
248 | 248 | //data_to_dump = &String::from("spriteAData"); |
249 | 249 | |
250 | - data_to_dump.push_str(&groundLevel.to_string()); | |
250 | + data_to_dump.push_str(&ground_level.to_string()); | |
251 | 251 | 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()); | |
253 | 253 | 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()); | |
255 | 255 | data_to_dump.push_str("\n"); |
256 | 256 | |
257 | 257 | data_to_dump.push_str("spriteBData\n"); |
258 | 258 | |
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()); | |
260 | 260 | 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()); | |
262 | 262 | data_to_dump.push_str("\n"); |
263 | 263 | |
264 | 264 | let path = Path::new("dump.txt"); |
265 | 265 | |
266 | 266 | let mut file = match File::create(&path) { |
267 | 267 | //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"), | |
269 | 269 | Ok(file) => file, |
270 | 270 | }; |
271 | 271 | |
272 | 272 | 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"), | |
274 | 274 | Ok(_) => println!("successfully wrote to test dump file"), |
275 | 275 | } |
276 | 276 | } |