• R/O
  • SSH

silny-kombat: Commit

Mercurial repo for silny-kombat project


Commit MetaInfo

Revision4894f8e433a753ff58b5a2a80b6d719159825b07 (tree)
Time2022-04-06 04:07:15
AuthorPiotr Kozka <piotoor@gmai...>
CommiterPiotr Kozka

Log Message

Build successful

Change Summary

Incremental Difference

diff -r e4cdb3f1a39d -r 4894f8e433a7 src/character.rs
--- a/src/character.rs Tue Apr 05 20:17:46 2022 +0200
+++ b/src/character.rs Tue Apr 05 21:07:15 2022 +0200
@@ -2,6 +2,7 @@
22 use crate::sprite_rendering;
33
44 use crate::key_processing::SignalForSM;
5+use rust_fsm::TransitionImpossibleError;
56
67 use sfml::{
78 graphics::{
@@ -28,23 +29,26 @@
2829 &self.name
2930 }
3031
31- // pub fn get_state(&self) -> &character_state_machine::CharacterFSMState {
32- // &self.machine.get_state()
33- // }
34-
35- pub fn get_num_state(&self) -> i32 {
36- self.machine.get_num_state()
32+ pub fn get_state(&self) -> &character_state_machine::CharacterFSMState {
33+ &self.machine.get_state()
3734 }
3835
39- // pub fn set_num_state(&mut self, num_state: i32) {
40- // self.machine.set_num_state(num_state)
36+ // pub fn get_num_state(&self) -> i32 {
37+ // self.machine.get_num_state()
4138 // }
4239
43- pub fn trigger(&mut self, signal: SignalForSM) -> i32 {
44- self.machine.trigger(signal as i32)
40+ pub fn trigger(&mut self, signal: character_state_machine::CharacterFSMInput) -> Result<Option<character_state_machine::CharacterFSMOutput>, TransitionImpossibleError> {
41+ let machine_output = self.machine.trigger(signal);
42+ machine_output
4543 }
4644
47- pub fn update_sprite(&mut self){
48- self.char_sprite.show_sprite(self.get_num_state());
45+ pub fn update_sprite(&mut self, state: Option<character_state_machine::CharacterFSMOutput>){
46+ //self.char_sprite.show_sprite(self.get_num_state());
47+ match state {
48+ Some(character_state_machine::CharacterFSMOutput::Back) => self.char_sprite.show_sprite(1),
49+ Some(character_state_machine::CharacterFSMOutput::Front) => self.char_sprite.show_sprite(2),
50+ Some(character_state_machine::CharacterFSMOutput::Idle) => self.char_sprite.show_sprite(0),
51+ None => println!("No output provided")
52+ }
4953 }
5054 }
\ No newline at end of file
diff -r e4cdb3f1a39d -r 4894f8e433a7 src/character_state_machine.rs
--- a/src/character_state_machine.rs Tue Apr 05 20:17:46 2022 +0200
+++ b/src/character_state_machine.rs Tue Apr 05 21:07:15 2022 +0200
@@ -32,7 +32,7 @@
3232 &self.machine.state()
3333 }
3434
35- pub fn trigger_(&mut self, signal: CharacterFSMInput) -> Result<Option<CharacterFSMOutput>, TransitionImpossibleError> {
35+ pub fn trigger(&mut self, signal: CharacterFSMInput) -> Result<Option<CharacterFSMOutput>, TransitionImpossibleError> {
3636 self.machine.consume(&signal)
3737 }
3838
diff -r e4cdb3f1a39d -r 4894f8e433a7 src/controller.rs
--- a/src/controller.rs Tue Apr 05 20:17:46 2022 +0200
+++ b/src/controller.rs Tue Apr 05 21:07:15 2022 +0200
@@ -1,6 +1,7 @@
11
22 use crate::character::Character;
3-
3+use rust_fsm::TransitionImpossibleError;
4+use crate::character_state_machine;
45 use crate::key_processing;
56
67 //use crate::key_processing::KeyProcessor;
@@ -86,6 +87,9 @@
8687
8788
8889 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);
92+
8993 while let Some(event) = window.poll_event() {
9094 let mut key_result = key_processor.match_key(event);
9195
@@ -100,8 +104,8 @@
100104 KeyEvents::Char_Right => { process_key_result_for_character(&key_processor, &mut character_A, key_result); }
101105 KeyEvents::Char_Key_Release => { process_key_result_for_character(&key_processor, &mut character_A, key_result); }
102106 KeyEvents::Char_B_Left => {
103- //second char
104- process_key_result_for_character(&key_processor, &mut character_B, KeyEvents::Char_Left);
107+ //second char
108+ process_key_result_for_character(&key_processor, &mut character_B, KeyEvents::Char_Left);
105109 }
106110 KeyEvents::Char_B_Right => {
107111 //second char
@@ -156,10 +160,24 @@
156160 }
157161
158162
159- if(!checkCollision(&character_A,&character_B)) {
160- character_A.update_sprite();
161- character_B.update_sprite();
163+ // if(!checkCollision(&character_A,&character_B)) {
164+ // character_A.update_sprite();
165+ // character_B.update_sprite();
166+ // }
167+
168+ match output_A {
169+ Ok(v) => {
170+ character_A.update_sprite(v);
171+ },
172+ Err(e) => println!("Unsupported key_result")
162173 }
174+ match output_B {
175+ Ok(v) => {
176+ character_B.update_sprite(v);
177+ },
178+ Err(e) => println!("Unsupported key_result")
179+ }
180+
163181
164182 window.clear(Color::rgb(50, 200, 50));
165183 window.draw(&character_A.char_sprite.sprite);
@@ -173,48 +191,48 @@
173191 }
174192
175193 }
176-
177-pub fn checkCollision(characterA: & Character, characterB: & Character) -> bool
178-{
179- let pos_A : Vector2f = characterA.char_sprite.sprite.position();
180- let pos_B : Vector2f = characterB.char_sprite.sprite.position();
181-
182- let char_width = 120.0;
183-
184- //println!("checkCollision. A.state: {} B.state: {}", characterA.get_num_state(), characterB.get_num_state() );
185-
186- if(characterA.get_num_state() == 1 && characterB.get_num_state() == 0)
187- {
188- return (pos_A.x + 1.0 + char_width - pos_B.x).abs() < 1.0;
189- }
190-
191- if(characterA.get_num_state() == 2 && characterB.get_num_state() == 0)
192- {
193- return (pos_A.x - 1.0 + char_width - pos_B.x).abs() < 1.0;
194- }
195-
196- if(characterA.get_num_state() == 0 && characterB.get_num_state() == 1)
197- {
198- return (pos_A.x + char_width - pos_B.x - 1.0).abs() < 1.0;
199- }
200-
201- if(characterA.get_num_state() == 0 && characterB.get_num_state() == 2)
202- {
203- return (pos_A.x + char_width - pos_B.x + 1.0).abs() < 1.0;
204- }
205-
206- if(characterA.get_num_state() == 1 && characterB.get_num_state() == 2)
207- {
208- return (pos_A.x + char_width - pos_B.x).abs() < 2.0;
209- }
210-
211- if(characterA.get_num_state() == 2 && characterB.get_num_state() == 1)
212- {
213- return (pos_A.x + char_width - pos_B.x ).abs() < 1.0;
214- }
215-
216- return false;
217-}
194+//
195+// pub fn checkCollision(characterA: & Character, characterB: & Character) -> bool
196+// {
197+// let pos_A : Vector2f = characterA.char_sprite.sprite.position();
198+// let pos_B : Vector2f = characterB.char_sprite.sprite.position();
199+//
200+// let char_width = 120.0;
201+//
202+// //println!("checkCollision. A.state: {} B.state: {}", characterA.get_num_state(), characterB.get_num_state() );
203+//
204+// if(characterA.get_num_state() == 1 && characterB.get_num_state() == 0)
205+// {
206+// return (pos_A.x + 1.0 + char_width - pos_B.x).abs() < 1.0;
207+// }
208+//
209+// if(characterA.get_num_state() == 2 && characterB.get_num_state() == 0)
210+// {
211+// return (pos_A.x - 1.0 + char_width - pos_B.x).abs() < 1.0;
212+// }
213+//
214+// if(characterA.get_num_state() == 0 && characterB.get_num_state() == 1)
215+// {
216+// return (pos_A.x + char_width - pos_B.x - 1.0).abs() < 1.0;
217+// }
218+//
219+// if(characterA.get_num_state() == 0 && characterB.get_num_state() == 2)
220+// {
221+// return (pos_A.x + char_width - pos_B.x + 1.0).abs() < 1.0;
222+// }
223+//
224+// if(characterA.get_num_state() == 1 && characterB.get_num_state() == 2)
225+// {
226+// return (pos_A.x + char_width - pos_B.x).abs() < 2.0;
227+// }
228+//
229+// if(characterA.get_num_state() == 2 && characterB.get_num_state() == 1)
230+// {
231+// return (pos_A.x + char_width - pos_B.x ).abs() < 1.0;
232+// }
233+//
234+// return false;
235+// }
218236
219237 pub fn prepare_window() -> RenderWindow {
220238 let context_settings = ContextSettings::default();
@@ -234,14 +252,21 @@
234252 window
235253 }
236254
237-pub fn process_key_result_for_character(key_processor:&key_processing::KeyProcessor, character: & mut Character, key_result:KeyEvents)
255+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>
238256 {
239257 // if key_result == KeyEvents::Char_Left as i32
240258 // || key_result == KeyEvents::Char_Right as i32
241259 // || key_result == KeyEvents::Char_Key_Release as i32
242260 //{
243- character.trigger(key_processor.process_key(key_result));
261+ // character.trigger(key_processor.process_key(key_result));
244262 //}
263+
264+ match key_processor.process_key(key_result) {
265+ SignalForSM::MoveToRight => character.trigger(character_state_machine::CharacterFSMInput::BackPressed),
266+ SignalForSM::MoveToLeft => character.trigger(character_state_machine::CharacterFSMInput::FrontPressed),
267+ SignalForSM::KeyRelease => character.trigger(character_state_machine::CharacterFSMInput::Released),
268+ _ => Err(TransitionImpossibleError)
269+ }
245270 }
246271
247272 pub fn save_test_data_to_file(groundLevel:f32, spriteA: &CharacterSprite, spriteB: &CharacterSprite)
Show on old repository browser