• R/O
  • SSH

silny-kombat: Commit

Mercurial repo for silny-kombat project


Commit MetaInfo

Révisionce024c46d810fcb3f76ed798f8b5b03ad18599cd (tree)
l'heure2022-09-22 03:28:08
AuteurSecT
CommiterSecT

Message de Log

Collision checking - partially works. Characters are stuck after colliding

Change Summary

Modification

diff -r bd7764e9f686 -r ce024c46d810 src/controller.rs
--- a/src/controller.rs Wed Sep 21 20:08:00 2022 +0200
+++ b/src/controller.rs Wed Sep 21 20:28:08 2022 +0200
@@ -132,7 +132,7 @@
132132 // //KeyEvents::Char_Key_Release => { output_A = process_key_result_for_character(&key_processor, &mut character_A, key_result); }
133133 // }
134134
135- if(!checkCollision(&character_a,&character_b)) {
135+ if !check_collision(&character_a, &character_b) {
136136 //character_A.update_sprite();
137137 //character_B.update_sprite();
138138
@@ -140,14 +140,14 @@
140140 Ok(v) => {
141141 character_b.update_sprite(v);
142142 },
143- Err(e) => println!("Unsupported key_result")
143+ Err(_e) => println!("Unsupported key_result")
144144 }
145145
146146 match output_a {
147147 Ok(v) => {
148148 character_a.update_sprite(v);
149149 },
150- Err(e) => println!("Unsupported key_result")
150+ Err(_e) => println!("Unsupported key_result")
151151 }
152152 }
153153
@@ -164,7 +164,7 @@
164164
165165 }
166166
167-pub fn checkCollision(characterA: & Character, characterB: & Character) -> bool
167+pub fn check_collision(characterA: & Character, characterB: & Character) -> bool
168168 {
169169 println!("Check collision Enter");
170170
@@ -202,43 +202,45 @@
202202
203203 println!("checkCollision. A.state: {} B.state: {}", stateA, stateB );
204204
205- if(stateA == 1 && stateB == 0)
205+ if stateA == 1 && stateB == 0
206206 {
207207 println!("Check collision A");
208- return (pos_A.x + 1.0 + char_width - pos_B.x).abs() < 1.0;
208+ return (pos_A.x + 1.0 + char_width - pos_B.x).abs() <= 1.0;
209209 }
210210
211- if(stateA == 2 && stateB == 0)
212- { println!("Check collision B");
211+ if stateA == 2 && stateB == 0
212+ { let val = (pos_A.x - 1.0 + char_width - pos_B.x).abs() ;
213+ println!("Check collision B : {}", val);
213214
214- return (pos_A.x - 1.0 + char_width - pos_B.x).abs() < 1.0;
215+ //return val < 1.0;
216+ return val <= 1.0;
215217 }
216218
217- if(stateA == 0 && stateB == 1)
219+ if stateA == 0 && stateB == 1
218220 {
219221 println!("Check collision C");
220222
221- return (pos_A.x + char_width - pos_B.x - 1.0).abs() < 1.0;
223+ return (pos_A.x + char_width - pos_B.x - 1.0).abs() <= 1.0;
222224 }
223225
224- if(stateA == 0 && stateB == 2)
226+ if stateA == 0 && stateB == 2
225227 {
226228 println!("Check collision D");
227229
228- return (pos_A.x + char_width - pos_B.x + 1.0).abs() < 1.0;
230+ return (pos_A.x + char_width - pos_B.x + 1.0).abs() <= 1.0;
229231 }
230232
231- if(stateA == 1 && stateB == 2)
233+ if stateA == 1 && stateB == 2
232234 {
233235 println!("Check collision E");
234236
235- return (pos_A.x + char_width - pos_B.x).abs() < 2.0;
237+ return (pos_A.x + char_width - pos_B.x).abs() <= 2.0;
236238 }
237239
238- if(stateA == 2 && stateB == 1)
240+ if stateA == 2 && stateB == 1
239241 {
240242 println!("Check collision F");
241- return (pos_A.x + char_width - pos_B.x ).abs() < 1.0;
243+ return (pos_A.x + char_width - pos_B.x ).abs() <= 1.0;
242244 }
243245
244246 return false;
Afficher sur ancien navigateur de dépôt.