• R/O
  • SSH

silny-kombat: Commit

Mercurial repo for silny-kombat project


Commit MetaInfo

Revision2a6e5ed50462ca01b82926d6afdd569db60157b4 (tree)
Time2022-08-05 04:38:49
AuthorPiotr Kozka <piotoor@gmai...>
CommiterPiotr Kozka

Log Message

Switched from events to manual keyboard checking

Change Summary

Incremental Difference

diff -r c60f8646d4ad -r 2a6e5ed50462 src/controller.rs
--- a/src/controller.rs Tue Apr 05 21:19:21 2022 +0200
+++ b/src/controller.rs Thu Aug 04 21:38:49 2022 +0200
@@ -89,82 +89,59 @@
8989 loop {
9090 let mut output_A: Result<Option<character_state_machine::CharacterFSMOutput>, TransitionImpossibleError> = character_A.trigger(character_state_machine::CharacterFSMInput::Released);
9191 let mut output_B: Result<Option<character_state_machine::CharacterFSMOutput>, TransitionImpossibleError> = character_B.trigger(character_state_machine::CharacterFSMInput::Released);
92-
93- while let Some(event) = window.poll_event() {
94- let mut key_result = key_processor.match_key(event);
95-
96-
97- match key_result {
98- KeyEvents::Escape => return,
99- KeyEvents::KeyTesting => {
100- //testing
101- println!("Testing: dump values to check");
102- save_test_data_to_file(groundLevel, &character_A.char_sprite, &character_B.char_sprite);
103- }
104- KeyEvents::Char_Left => { output_A = process_key_result_for_character(&key_processor, &mut character_A, key_result); }
105- KeyEvents::Char_Right => { output_A = process_key_result_for_character(&key_processor, &mut character_A, key_result); }
106- KeyEvents::Char_Key_Release => { output_A = process_key_result_for_character(&key_processor, &mut character_A, key_result); }
107- KeyEvents::Char_B_Left => {
108- //second char
109- output_B = process_key_result_for_character(&key_processor, &mut character_B, KeyEvents::Char_Left);
110- }
111- KeyEvents::Char_B_Right => {
112- //second char
113- output_B = process_key_result_for_character(&key_processor, &mut character_B, KeyEvents::Char_Right);
114- }
115- KeyEvents::Char_B_Key_Release => {
116- //second char
117- output_B = process_key_result_for_character(&key_processor, &mut character_B, KeyEvents::Char_Key_Release);
118- }
119- KeyEvents::None => {}
120- }
121-
122-
123- // if key_result == 0 {
124- // //close program
125- // return;
126- // }
127- //
128- // if key_result == 99 {
129- // //testing
130- // println!("Testing: dump values to check");
131- // save_test_data_to_file(groundLevel, &character_A.char_sprite, &character_B.char_sprite);
132- // }
133- //
134- //
135- // if key_result < KeyProcessor::KEY_BASE {
136- // //first char
137- // process_key_result_for_character(&key_processor, &mut character_A, key_result);
138- //
139- // } else {
140- // //second char
141- // key_result = key_result - KeyProcessor::KEY_BASE;
142- // process_key_result_for_character(&key_processor, &mut character_B, key_result);
143- // }
144-
145-
146- // //first char/////////////
147- // if key_result == 3 {
148- // state = 0;
149- // counter = 0;
150- // }
151- // if key_result == 1 || key_result == 2 || key_result == 3 {
152- // keyProcessor.process_key(key_result, &mut state);
153- // }
154- // //second char///////////
155- // else if key_result == KeyProcessor::KEY_BASE + 1 || key_result == KeyProcessor::KEY_BASE + 2 {
156- // keyProcessor.process_key(key_result - KeyProcessor::KEY_BASE, &mut state_b);
157- // } else if key_result == KeyProcessor::KEY_BASE + 3 {
158- // state_b = 0;
159- // counter = 0;
160- // }
92+ //let mut key_result = key_processor.match_key();
93+ if Key::A.is_pressed()
94+ {
95+ output_B = process_key_result_for_character(&key_processor, &mut character_B, KeyEvents::Char_B_Left);
16196 }
162-
97+ if Key::D.is_pressed()
98+ {
99+ output_B = process_key_result_for_character(&key_processor, &mut character_B, KeyEvents::Char_B_Right);
100+ }
101+ if Key::F4.is_pressed()
102+ {
103+ println!("Testing: dump values to check");
104+ save_test_data_to_file(groundLevel, &character_A.char_sprite, &character_B.char_sprite);
105+ }
106+ if Key::ESCAPE.is_pressed()
107+ {
108+ return;
109+ }
110+ if Key::LEFT.is_pressed()
111+ {
112+ output_A = process_key_result_for_character(&key_processor, &mut character_A, KeyEvents::Char_Left);
113+ }
114+ if Key::RIGHT.is_pressed()
115+ {
116+ output_A = process_key_result_for_character(&key_processor, &mut character_A, KeyEvents::Char_Right);
117+ }
118+ // match key_result {
119+ // KeyEvents::Char_B_Left => {
120+ // //second char
121+ //
122+ // }
123+ // KeyEvents::Char_B_Right => {
124+ // //second char
125+ //
126+ // }
127+ // // KeyEvents::Char_B_Key_Release => {
128+ // // //second char
129+ // // output_B = process_key_result_for_character(&key_processor, &mut character_B, key_result);
130+ // // }
131+ //
132+ // //KeyEvents::Char_Key_Release => { output_A = process_key_result_for_character(&key_processor, &mut character_A, key_result); }
133+ // }
163134
164135 // if(!checkCollision(&character_A,&character_B)) {
165136 // character_A.update_sprite();
166137 // character_B.update_sprite();
167138 // }
139+ match output_B {
140+ Ok(v) => {
141+ character_B.update_sprite(v);
142+ },
143+ Err(e) => println!("Unsupported key_result")
144+ }
168145
169146 match output_A {
170147 Ok(v) => {
@@ -172,12 +149,6 @@
172149 },
173150 Err(e) => println!("Unsupported key_result")
174151 }
175- match output_B {
176- Ok(v) => {
177- character_B.update_sprite(v);
178- },
179- Err(e) => println!("Unsupported key_result")
180- }
181152
182153
183154 window.clear(Color::rgb(50, 200, 50));
diff -r c60f8646d4ad -r 2a6e5ed50462 src/key_processing.rs
--- a/src/key_processing.rs Tue Apr 05 21:19:21 2022 +0200
+++ b/src/key_processing.rs Thu Aug 04 21:38:49 2022 +0200
@@ -1,7 +1,9 @@
11 use sfml::{
22 window::{ Event, Key},
33
4+
45 };
6+
57 use crate::key_processing::KeyEvents::{Char_Left, Char_Right, Char_Key_Release};
68
79 //use crate::sprite_rendering;
@@ -45,9 +47,13 @@
4547 pub fn process_key(&self, key_result: KeyEvents) -> SignalForSM {
4648
4749 match key_result {
50+ KeyEvents::Char_B_Left => return SignalForSM::MoveToLeft,
51+ KeyEvents::Char_B_Right => return SignalForSM::MoveToRight,
52+ KeyEvents::Char_Key_Release => return SignalForSM::KeyRelease,
4853 KeyEvents::Char_Left => return SignalForSM::MoveToLeft,
4954 KeyEvents::Char_Right => return SignalForSM::MoveToRight,
5055 KeyEvents::Char_Key_Release => return SignalForSM::KeyRelease,
56+
5157 _ => {return SignalForSM::None}
5258 }
5359
@@ -69,49 +75,35 @@
6975
7076
7177
72- pub fn match_key(&self, event: Event) -> KeyEvents {
78+ pub fn match_key(&self) -> KeyEvents {
7379
7480 //TODO: refactor enum->i32 conversions, just return a enum
75-
76- match event {
77- Event::Closed
78- | Event::KeyPressed {
79- code: Key::ESCAPE, ..
80- } => return KeyEvents::Escape,
81-
82- //testing
83- Event::KeyPressed {
84- code: Key::F4, ..
85- } => return KeyEvents::KeyTesting,
81+ //TODO: refactor enum->i32 conversions, just return a enum
82+ if Key::A.is_pressed()
83+ {
84+ return KeyEvents::Char_B_Left;
85+ }
86+ if Key::D.is_pressed()
87+ {
88+ return KeyEvents::Char_B_Right;
89+ }
90+ if Key::F4.is_pressed()
91+ {
92+ return KeyEvents::KeyTesting;
93+ }
94+ if Key::ESCAPE.is_pressed()
95+ {
96+ return KeyEvents::Escape;
97+ }
98+ if Key::LEFT.is_pressed()
99+ {
100+ return KeyEvents::Char_Left;
101+ }
102+ if Key::RIGHT.is_pressed()
103+ {
104+ return KeyEvents::Char_Right;
105+ }
86106
87- Event::KeyPressed {
88- code: Key::LEFT, ..
89- } => return KeyEvents::Char_Left,
90- Event::KeyPressed {
91- code: Key::RIGHT, ..
92- } => return KeyEvents::Char_Right,
93- Event::KeyReleased {
94- code:Key::RIGHT, ..
95- } => return KeyEvents::Char_Key_Release,
96- Event::KeyReleased {
97- code:Key::LEFT, ..
98- } => return KeyEvents::Char_Key_Release,
99-
100-
101- Event::KeyPressed {
102- code: Key::A, .. //move left for second character
103- } => return KeyEvents::Char_B_Left,
104- Event::KeyPressed {
105- code: Key::D, .. //move right for second character
106- } => return KeyEvents::Char_B_Right,
107- Event::KeyReleased {
108- code:Key::A, ..
109- } => return KeyEvents::Char_B_Key_Release,
110- Event::KeyReleased {
111- code:Key::D, ..
112- } => return KeyEvents::Char_B_Key_Release,
113- _ => {}
114- }
115107 return KeyEvents::None;
116108 }
117109
diff -r c60f8646d4ad -r 2a6e5ed50462 src/main.rs
--- a/src/main.rs Tue Apr 05 21:19:21 2022 +0200
+++ b/src/main.rs Thu Aug 04 21:38:49 2022 +0200
@@ -3,6 +3,7 @@
33 RenderWindow, Transformable
44 },
55 window::{ ContextSettings, Style},
6+
67 };
78 use crate::sprite_rendering::CharacterSprite;
89
Show on old repository browser