• R/O
  • SSH

silny-kombat: コミット

Mercurial repo for silny-kombat project


コミットメタ情報

リビジョンda5d6c3bd739b4fa5a38730d05c37fa583e7a2df (tree)
日時2022-09-22 02:06:17
作者SecT
コミッターSecT

ログメッセージ

Collision checking partially works

変更サマリ

差分

diff -r 2a6e5ed50462 -r da5d6c3bd739 src/controller.rs
--- a/src/controller.rs Thu Aug 04 21:38:49 2022 +0200
+++ b/src/controller.rs Wed Sep 21 19:06:17 2022 +0200
@@ -132,10 +132,10 @@
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)) {
136- // character_A.update_sprite();
137- // character_B.update_sprite();
138- // }
135+ if(!checkCollision(&character_A,&character_B)) {
136+ //character_A.update_sprite();
137+ //character_B.update_sprite();
138+
139139 match output_B {
140140 Ok(v) => {
141141 character_B.update_sprite(v);
@@ -149,7 +149,7 @@
149149 },
150150 Err(e) => println!("Unsupported key_result")
151151 }
152-
152+ }
153153
154154 window.clear(Color::rgb(50, 200, 50));
155155 window.draw(&character_A.char_sprite.sprite);
@@ -163,48 +163,86 @@
163163 }
164164
165165 }
166-//
167-// pub fn checkCollision(characterA: & Character, characterB: & Character) -> bool
168-// {
169-// let pos_A : Vector2f = characterA.char_sprite.sprite.position();
170-// let pos_B : Vector2f = characterB.char_sprite.sprite.position();
171-//
172-// let char_width = 120.0;
173-//
174-// //println!("checkCollision. A.state: {} B.state: {}", characterA.get_num_state(), characterB.get_num_state() );
175-//
176-// if(characterA.get_num_state() == 1 && characterB.get_num_state() == 0)
177-// {
178-// return (pos_A.x + 1.0 + char_width - pos_B.x).abs() < 1.0;
179-// }
180-//
181-// if(characterA.get_num_state() == 2 && characterB.get_num_state() == 0)
182-// {
183-// return (pos_A.x - 1.0 + char_width - pos_B.x).abs() < 1.0;
184-// }
185-//
186-// if(characterA.get_num_state() == 0 && characterB.get_num_state() == 1)
187-// {
188-// return (pos_A.x + char_width - pos_B.x - 1.0).abs() < 1.0;
189-// }
190-//
191-// if(characterA.get_num_state() == 0 && characterB.get_num_state() == 2)
192-// {
193-// return (pos_A.x + char_width - pos_B.x + 1.0).abs() < 1.0;
194-// }
195-//
196-// if(characterA.get_num_state() == 1 && characterB.get_num_state() == 2)
197-// {
198-// return (pos_A.x + char_width - pos_B.x).abs() < 2.0;
199-// }
200-//
201-// if(characterA.get_num_state() == 2 && characterB.get_num_state() == 1)
202-// {
203-// return (pos_A.x + char_width - pos_B.x ).abs() < 1.0;
204-// }
205-//
206-// return false;
207-// }
166+
167+pub fn checkCollision(characterA: & Character, characterB: & Character) -> bool
168+{
169+ println!("Check collision Enter");
170+
171+
172+ let pos_A : Vector2f = characterA.char_sprite.sprite.position();
173+ let pos_B : Vector2f = characterB.char_sprite.sprite.position();
174+
175+ let char_width = 120.0;
176+
177+ //println!("checkCollision. A.state: {} B.state: {}", characterA.get_num_state(), characterB.get_num_state() );
178+
179+ let raw_stateA : &character_state_machine::CharacterFSMState = characterA.get_state();
180+ let raw_stateB : &character_state_machine::CharacterFSMState = characterB.get_state();
181+
182+
183+ let stateA:i32 = match raw_stateA {
184+ character_state_machine::CharacterFSMState::StandMoveBack => 2,
185+ character_state_machine::CharacterFSMState::StandMoveFront => 1,
186+ character_state_machine::CharacterFSMState::StandIdle => 0,
187+ //Some(character_state_machine::CharacterFSMOutput::Front) => 1,
188+ //Some(character_state_machine::CharacterFSMOutput::Idle) => 0,
189+ //None => -1
190+ };
191+
192+ let stateB:i32 = match raw_stateB {
193+ character_state_machine::CharacterFSMState::StandMoveBack => 2,
194+ character_state_machine::CharacterFSMState::StandMoveFront => 1,
195+ character_state_machine::CharacterFSMState::StandIdle => 0,
196+ //Some(character_state_machine::CharacterFSMOutput::Back) => 2,
197+ //Some(character_state_machine::CharacterFSMOutput::Front) => 1,
198+ //Some(character_state_machine::CharacterFSMOutput::Idle) => 0,
199+ //None => -1
200+ };
201+
202+
203+ println!("checkCollision. A.state: {} B.state: {}", stateA, stateB );
204+
205+ if(stateA == 1 && stateB == 0)
206+ {
207+ println!("Check collision A");
208+ return (pos_A.x + 1.0 + char_width - pos_B.x).abs() < 1.0;
209+ }
210+
211+ if(stateA == 2 && stateB == 0)
212+ { println!("Check collision B");
213+
214+ return (pos_A.x - 1.0 + char_width - pos_B.x).abs() < 1.0;
215+ }
216+
217+ if(stateA == 0 && stateB == 1)
218+ {
219+ println!("Check collision C");
220+
221+ return (pos_A.x + char_width - pos_B.x - 1.0).abs() < 1.0;
222+ }
223+
224+ if(stateA == 0 && stateB == 2)
225+ {
226+ println!("Check collision D");
227+
228+ return (pos_A.x + char_width - pos_B.x + 1.0).abs() < 1.0;
229+ }
230+
231+ if(stateA == 1 && stateB == 2)
232+ {
233+ println!("Check collision E");
234+
235+ return (pos_A.x + char_width - pos_B.x).abs() < 2.0;
236+ }
237+
238+ if(stateA == 2 && stateB == 1)
239+ {
240+ println!("Check collision F");
241+ return (pos_A.x + char_width - pos_B.x ).abs() < 1.0;
242+ }
243+
244+ return false;
245+}
208246
209247 pub fn prepare_window() -> RenderWindow {
210248 let context_settings = ContextSettings::default();
旧リポジトリブラウザで表示