Mercurial repo for silny-kombat project
修订版 | 2875f41afa744a12354667a77a92a705e1a556b6 (tree) |
---|---|
时间 | 2023-03-06 14:37:08 |
作者 | SecT <grzegorzstarowicz@gmai...> |
Commiter | SecT |
Added test for resolve_combat
@@ -147,60 +147,6 @@ | ||
147 | 147 | |
148 | 148 | } |
149 | 149 | |
150 | - | |
151 | - | |
152 | - //let mut key_result = key_processor.match_key(); | |
153 | - // if Key::A.is_pressed() | |
154 | - // { | |
155 | - // output_b = self.process_key_result_for_character( character_b, KeyEvents::CharBLeft); | |
156 | - // } | |
157 | - // if Key::D.is_pressed() | |
158 | - // { | |
159 | - // output_b = self.process_key_result_for_character( character_b, KeyEvents::CharBRight); | |
160 | - // } | |
161 | - // if Key::S.is_pressed() | |
162 | - // { | |
163 | - // output_b = self.process_key_result_for_character( character_b, KeyEvents::CharBDown); | |
164 | - // } | |
165 | - // if Key::Q.is_pressed() | |
166 | - // { | |
167 | - // output_b = self.process_key_result_for_character( character_b, KeyEvents::CharBPunch); | |
168 | - // } | |
169 | - // if Key::E.is_pressed() | |
170 | - // { | |
171 | - // output_b = self.process_key_result_for_character( character_b, KeyEvents::CharBKick); | |
172 | - // } | |
173 | - // | |
174 | - // if Key::F4.is_pressed() | |
175 | - // { | |
176 | - // println!("Testing: dump values to check"); | |
177 | - // controller::save_test_data_to_file(ground_level, &character_a.char_sprite, &character_b.char_sprite); | |
178 | - // } | |
179 | - // if Key::ESCAPE.is_pressed() | |
180 | - // { | |
181 | - // window.close(); | |
182 | - // } | |
183 | - // if Key::LEFT.is_pressed() | |
184 | - // { | |
185 | - // output_a = self.process_key_result_for_character( character_a, KeyEvents::CharLeft); | |
186 | - // } | |
187 | - // if Key::RIGHT.is_pressed() | |
188 | - // { | |
189 | - // output_a = self.process_key_result_for_character( character_a, KeyEvents::CharRight); | |
190 | - // } | |
191 | - // if Key::DOWN.is_pressed() | |
192 | - // { | |
193 | - // output_a = self.process_key_result_for_character( character_a, KeyEvents::CharDown); | |
194 | - // } | |
195 | - // if Key::ENTER.is_pressed() | |
196 | - // { | |
197 | - // output_a = self.process_key_result_for_character( character_a, KeyEvents::CharPunch); | |
198 | - // } | |
199 | - // if Key::RSHIFT.is_pressed() | |
200 | - // { | |
201 | - // output_a = self.process_key_result_for_character( character_a, KeyEvents::CharKick); | |
202 | - // } | |
203 | - | |
204 | 150 | controller::try_updating_sprites(character_a, character_b, output_a, output_b); |
205 | 151 | |
206 | 152 |
@@ -23,7 +23,7 @@ | ||
23 | 23 | mod tests { |
24 | 24 | use sfml::graphics::Transformable; |
25 | 25 | use sfml::system::Vector2f; |
26 | - use crate::controller::{CHAR_WIDTH, Combat_status, get_combat_status, is_chars_in_attack_range, KICK_RANGE, PUNCH_RANGE}; | |
26 | + use crate::controller::{CHAR_WIDTH, Combat_status, get_combat_status, is_chars_in_attack_range, KICK_DMG, KICK_RANGE, PUNCH_DMG, PUNCH_RANGE}; | |
27 | 27 | use crate::key_processing::KeyEvents; |
28 | 28 | use super::*; |
29 | 29 |
@@ -108,6 +108,69 @@ | ||
108 | 108 | } |
109 | 109 | |
110 | 110 | #[test] |
111 | + fn test_resolve_combat() | |
112 | + { | |
113 | + ///////Set up test | |
114 | + | |
115 | + let textures = renderer::myTextures::new(); | |
116 | + | |
117 | + | |
118 | + let mut character_a = character::Character::new("Sub Zero", 100, true, &textures.texturesArray); | |
119 | + let mut character_b = character::Character::new("Sub Zero", 100, true, &textures.texturesArray); | |
120 | + | |
121 | + character_a.char_sprite.sprite.set_scale(Vector2f::new(1.0, 1.0)); | |
122 | + character_b.char_sprite.sprite.set_scale(Vector2f::new(-1.0, 1.0)); | |
123 | + | |
124 | + character_a.char_sprite.sprite.set_position(Vector2f::new(0.0, 0.0)); | |
125 | + character_b.char_sprite.sprite.set_position(Vector2f::new(600.0, 0.0)); | |
126 | + | |
127 | + /////end setup | |
128 | + | |
129 | + { | |
130 | + character_b.char_sprite.sprite.set_position(Vector2f::new(CHAR_WIDTH*4.0, 0.0)); | |
131 | + controller::resolve_combat(&mut character_a, &mut character_b); | |
132 | + | |
133 | + assert_eq!( character_a.get_hp(), 100 ); | |
134 | + assert_eq!( character_b.get_hp(), 100 ); | |
135 | + } | |
136 | + | |
137 | + { | |
138 | + character_b.char_sprite.sprite.set_position(Vector2f::new(CHAR_WIDTH*4.0, 0.0)); | |
139 | + character_a.trigger(character_state_machine::CharacterFSMInput::Punch); | |
140 | + controller::resolve_combat(&mut character_a, &mut character_b); | |
141 | + | |
142 | + assert_eq!( character_a.get_hp(), 100 ); | |
143 | + assert_eq!( character_b.get_hp(), 100 ); | |
144 | + | |
145 | + character_a.trigger(character_state_machine::CharacterFSMInput::Released); | |
146 | + } | |
147 | + | |
148 | + { | |
149 | + character_b.char_sprite.sprite.set_position(Vector2f::new(CHAR_WIDTH+PUNCH_RANGE, 0.0)); | |
150 | + character_a.trigger(character_state_machine::CharacterFSMInput::Punch); | |
151 | + controller::resolve_combat(&mut character_a, &mut character_b); | |
152 | + | |
153 | + assert_eq!( character_a.get_hp(), 100 ); | |
154 | + assert_eq!( character_b.get_hp(), 100 - PUNCH_DMG); | |
155 | + | |
156 | + character_a.trigger(character_state_machine::CharacterFSMInput::Released); | |
157 | + character_b.update_hp(PUNCH_DMG); | |
158 | + } | |
159 | + | |
160 | + { | |
161 | + character_b.char_sprite.sprite.set_position(Vector2f::new(CHAR_WIDTH+KICK_RANGE, 0.0)); | |
162 | + character_a.trigger(character_state_machine::CharacterFSMInput::Kick); | |
163 | + controller::resolve_combat(&mut character_a, &mut character_b); | |
164 | + | |
165 | + assert_eq!( character_a.get_hp(), 100 ); | |
166 | + assert_eq!( character_b.get_hp(), 100 - KICK_DMG); | |
167 | + | |
168 | + character_a.trigger(character_state_machine::CharacterFSMInput::Released); | |
169 | + character_b.update_hp(KICK_DMG); | |
170 | + } | |
171 | + } | |
172 | + | |
173 | + #[test] | |
111 | 174 | fn test_integration() |
112 | 175 | { |
113 | 176 |