• R/O
  • SSH

silny-kombat: Commit

Mercurial repo for silny-kombat project


Commit MetaInfo

Révisionbd7764e9f6865f446db54b7816ad2dcb4905dc7b (tree)
l'heure2022-09-22 03:08:00
AuteurPiotr Kozka <piotoor@gmai...>
CommiterPiotr Kozka

Message de Log

merge merging_state_machine->default

Change Summary

Modification

diff -r 1373908174ca -r bd7764e9f686 src/character.rs
--- a/src/character.rs Wed Feb 09 21:38:31 2022 +0100
+++ b/src/character.rs Wed Sep 21 20:08:00 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 1373908174ca -r bd7764e9f686 src/character_state_machine.rs
--- a/src/character_state_machine.rs Wed Feb 09 21:38:31 2022 +0100
+++ b/src/character_state_machine.rs Wed Sep 21 20:08:00 2022 +0200
@@ -18,66 +18,24 @@
1818 }
1919
2020 pub struct StateMachineWrapper {
21- machine: StateMachine<CharacterFSM>,
22- num_state: i32
21+ machine: StateMachine<CharacterFSM>
2322 }
2423
2524 impl StateMachineWrapper {
2625 pub fn new() -> StateMachineWrapper {
2726 StateMachineWrapper {
28- machine: StateMachine::new(),
29- num_state: 0
27+ machine: StateMachine::new()
3028 }
3129 }
3230
33- // pub fn get_state(&self) -> &CharacterFSMState {
34- // &self.machine.state()
35- // }
36-
37- pub fn get_num_state(&self) -> i32 {
38- self.num_state
31+ pub fn get_state(&self) -> &CharacterFSMState {
32+ &self.machine.state()
3933 }
40- pub fn trigger(&mut self, signal: i32) -> i32 {
41- let output: Result<Option<CharacterFSMOutput>, TransitionImpossibleError>;
42- let mut ans = 1;
43- if signal == 1 {
44- output = self.machine.consume(&CharacterFSMInput::BackPressed);
45- match output {
46- Ok(v) => match v {
47- Some(CharacterFSMOutput::Back) => ans = 1,
48- Some(CharacterFSMOutput::Front) => ans = 2,
49- Some(CharacterFSMOutput::Idle) => ans = 0,
50- None => println!("None"),
51- }
52- Err(e) => println!("State machine error back pressed {}", e),
53- }
54- } else if signal == 2 {
55- output = self.machine.consume(&CharacterFSMInput::FrontPressed);
56- match output {
57- Ok(v) => match v {
58- Some(CharacterFSMOutput::Back) => ans = 1,
59- Some(CharacterFSMOutput::Front) => ans = 2,
60- Some(CharacterFSMOutput::Idle) => ans = 0,
61- None => println!("None"),
62- }
63- Err(e) => println!("State machine error front pressed {}", e),
64- }
65- } else {
66- output = self.machine.consume(&CharacterFSMInput::Released);
67- match output {
68- Ok(v) => match v {
69- Some(CharacterFSMOutput::Back) => ans = 1,
70- Some(CharacterFSMOutput::Front) => ans = 2,
71- Some(CharacterFSMOutput::Idle) => ans = 0,
72- None => println!("None"),
73- }
74- Err(e) => println!("State machine error released {}", e),
75- }
76- }
77- println!("ans = {}", ans);
78- self.num_state = ans;
79- ans
34+
35+ pub fn trigger(&mut self, signal: CharacterFSMInput) -> Result<Option<CharacterFSMOutput>, TransitionImpossibleError> {
36+ self.machine.consume(&signal)
8037 }
8138
8239
40+
8341 }
diff -r 1373908174ca -r bd7764e9f686 src/controller.rs
--- a/src/controller.rs Wed Feb 09 21:38:31 2022 +0100
+++ b/src/controller.rs Wed Sep 21 20:08:00 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;
@@ -23,8 +24,8 @@
2324 use sfml::window::Key;
2425
2526 pub struct Controller<'a> {
26- characterA : Option<&'a Character<'a>>,
27- characterB : Option<&'a Character<'a>>,
27+ character_a : Option<&'a Character<'a>>,
28+ character_b : Option<&'a Character<'a>>,
2829
2930 textures: [&'a SfBox<Texture>; 4]
3031 }
@@ -34,18 +35,18 @@
3435 pub fn new(textures: [&'a SfBox<Texture>;4] ) -> Self {
3536
3637 Controller {
37- characterA: None,
38- characterB: None,
38+ character_a: None,
39+ character_b: None,
3940 textures
4041 }
4142 }
4243
43- pub fn set_characterA(&mut self, new_character: &'a Character){
44- self.characterA = Some(new_character);
44+ pub fn set_character_a(&mut self, new_character: &'a Character){
45+ self.character_a = Some(new_character);
4546 }
4647
47- pub fn set_characterB(&mut self, new_character: &'a Character){
48- self.characterB = Some(new_character);
48+ pub fn set_character_b(&mut self, new_character: &'a Character){
49+ self.character_b = Some(new_character);
4950 }
5051
5152 //TODO: find a better name
@@ -62,23 +63,23 @@
6263
6364 let mut window = prepare_window();
6465
65- let key_processor = key_processing::KeyProcessor::new();
66+ let key_processor = KeyProcessor::new();
6667
6768
6869 //let mut character_sprite = sprite_rendering::CharacterSprite::new(&textures);
6970 //let mut character_sprite_b = sprite_rendering::CharacterSprite::new(&textures);
7071
71- let mut character_A: Character = Character ::new("Sub Zero", &self.textures);
72- let mut character_B: Character = Character ::new("Sub Zero", &self.textures);
73-
74- println!("{} vs {}", character_A.get_name(), character_B.get_name());
72+ let mut character_a: Character = Character ::new("Sub Zero", &self.textures);
73+ let mut character_b: Character = Character ::new("Sub Zero", &self.textures);
7574
76- let groundLevel = 100.0;
75+ println!("{} vs {}", character_a.get_name(), character_b.get_name());
7776
78- character_A.char_sprite.sprite.set_position(Vector2f::new(0.0, groundLevel + 0.0));
77+ let ground_level = 100.0;
7978
80- character_B.char_sprite.sprite.set_position(Vector2f::new(600.0, groundLevel + 0.0));
81- character_B.char_sprite.sprite.set_scale(Vector2f::new(-1.0, 1.0));
79+ character_a.char_sprite.sprite.set_position(Vector2f::new(0.0, ground_level + 0.0));
80+
81+ character_b.char_sprite.sprite.set_position(Vector2f::new(600.0, ground_level + 0.0));
82+ character_b.char_sprite.sprite.set_scale(Vector2f::new(-1.0, 1.0));
8283
8384 //loop
8485
@@ -86,84 +87,73 @@
8687
8788
8889 loop {
89- while let Some(event) = window.poll_event() {
90- let mut key_result = key_processor.match_key(event);
91-
92- match key_result {
93- KeyEvents::Escape => return,
94- KeyEvents::KeyTesting => {
95- //testing
96- println!("Testing: dump values to check");
97- save_test_data_to_file(groundLevel, &character_A.char_sprite, &character_B.char_sprite);
98- }
99- KeyEvents::Char_Left => { process_key_result_for_character(&key_processor, &mut character_A, key_result); }
100- KeyEvents::Char_Right => { process_key_result_for_character(&key_processor, &mut character_A, key_result); }
101- KeyEvents::Char_Key_Release => { process_key_result_for_character(&key_processor, &mut character_A, key_result); }
102- KeyEvents::Char_B_Left => {
103- //second char
104- process_key_result_for_character(&key_processor, &mut character_B, KeyEvents::Char_Left);
105- }
106- KeyEvents::Char_B_Right => {
107- //second char
108- process_key_result_for_character(&key_processor, &mut character_B, KeyEvents::Char_Right);
109- }
110- KeyEvents::Char_B_Key_Release => {
111- //second char
112- process_key_result_for_character(&key_processor, &mut character_B, KeyEvents::Char_Key_Release);
113- }
114- KeyEvents::None => {}
115- }
116-
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+ //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::CharBLeft);
96+ }
97+ if Key::D.is_pressed()
98+ {
99+ output_b = process_key_result_for_character(&key_processor, &mut character_b, KeyEvents::CharBRight);
100+ }
101+ if Key::F4.is_pressed()
102+ {
103+ println!("Testing: dump values to check");
104+ save_test_data_to_file(ground_level, &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::CharLeft);
113+ }
114+ if Key::RIGHT.is_pressed()
115+ {
116+ output_a = process_key_result_for_character(&key_processor, &mut character_a, KeyEvents::CharRight);
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+ // }
117134
118- // if key_result == 0 {
119- // //close program
120- // return;
121- // }
122- //
123- // if key_result == 99 {
124- // //testing
125- // println!("Testing: dump values to check");
126- // save_test_data_to_file(groundLevel, &character_A.char_sprite, &character_B.char_sprite);
127- // }
128- //
129- //
130- // if key_result < KeyProcessor::KEY_BASE {
131- // //first char
132- // process_key_result_for_character(&key_processor, &mut character_A, key_result);
133- //
134- // } else {
135- // //second char
136- // key_result = key_result - KeyProcessor::KEY_BASE;
137- // process_key_result_for_character(&key_processor, &mut character_B, key_result);
138- // }
135+ if(!checkCollision(&character_a,&character_b)) {
136+ //character_A.update_sprite();
137+ //character_B.update_sprite();
139138
140-
141- // //first char/////////////
142- // if key_result == 3 {
143- // state = 0;
144- // counter = 0;
145- // }
146- // if key_result == 1 || key_result == 2 || key_result == 3 {
147- // keyProcessor.process_key(key_result, &mut state);
148- // }
149- // //second char///////////
150- // else if key_result == KeyProcessor::KEY_BASE + 1 || key_result == KeyProcessor::KEY_BASE + 2 {
151- // keyProcessor.process_key(key_result - KeyProcessor::KEY_BASE, &mut state_b);
152- // } else if key_result == KeyProcessor::KEY_BASE + 3 {
153- // state_b = 0;
154- // counter = 0;
155- // }
139+ match output_b {
140+ Ok(v) => {
141+ character_b.update_sprite(v);
142+ },
143+ Err(e) => println!("Unsupported key_result")
156144 }
157145
158-
159- if(!checkCollision(&character_A,&character_B)) {
160- character_A.update_sprite();
161- character_B.update_sprite();
146+ match output_a {
147+ Ok(v) => {
148+ character_a.update_sprite(v);
149+ },
150+ Err(e) => println!("Unsupported key_result")
151+ }
162152 }
163153
164154 window.clear(Color::rgb(50, 200, 50));
165- window.draw(&character_A.char_sprite.sprite);
166- window.draw(&character_B.char_sprite.sprite);
155+ window.draw(&character_a.char_sprite.sprite);
156+ window.draw(&character_b.char_sprite.sprite);
167157 window.display();
168158
169159 //end main loop
@@ -176,6 +166,9 @@
176166
177167 pub fn checkCollision(characterA: & Character, characterB: & Character) -> bool
178168 {
169+ println!("Check collision Enter");
170+
171+
179172 let pos_A : Vector2f = characterA.char_sprite.sprite.position();
180173 let pos_B : Vector2f = characterB.char_sprite.sprite.position();
181174
@@ -183,33 +176,68 @@
183176
184177 //println!("checkCollision. A.state: {} B.state: {}", characterA.get_num_state(), characterB.get_num_state() );
185178
186- if(characterA.get_num_state() == 1 && characterB.get_num_state() == 0)
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)
187206 {
207+ println!("Check collision A");
188208 return (pos_A.x + 1.0 + char_width - pos_B.x).abs() < 1.0;
189209 }
190210
191- if(characterA.get_num_state() == 2 && characterB.get_num_state() == 0)
192- {
211+ if(stateA == 2 && stateB == 0)
212+ { println!("Check collision B");
213+
193214 return (pos_A.x - 1.0 + char_width - pos_B.x).abs() < 1.0;
194215 }
195216
196- if(characterA.get_num_state() == 0 && characterB.get_num_state() == 1)
217+ if(stateA == 0 && stateB == 1)
197218 {
219+ println!("Check collision C");
220+
198221 return (pos_A.x + char_width - pos_B.x - 1.0).abs() < 1.0;
199222 }
200223
201- if(characterA.get_num_state() == 0 && characterB.get_num_state() == 2)
224+ if(stateA == 0 && stateB == 2)
202225 {
226+ println!("Check collision D");
227+
203228 return (pos_A.x + char_width - pos_B.x + 1.0).abs() < 1.0;
204229 }
205230
206- if(characterA.get_num_state() == 1 && characterB.get_num_state() == 2)
231+ if(stateA == 1 && stateB == 2)
207232 {
233+ println!("Check collision E");
234+
208235 return (pos_A.x + char_width - pos_B.x).abs() < 2.0;
209236 }
210237
211- if(characterA.get_num_state() == 2 && characterB.get_num_state() == 1)
238+ if(stateA == 2 && stateB == 1)
212239 {
240+ println!("Check collision F");
213241 return (pos_A.x + char_width - pos_B.x ).abs() < 1.0;
214242 }
215243
@@ -234,46 +262,53 @@
234262 window
235263 }
236264
237-pub fn process_key_result_for_character(key_processor:&key_processing::KeyProcessor, character: & mut Character, key_result:KeyEvents)
265+pub fn process_key_result_for_character(key_processor:& KeyProcessor, character: & mut Character, key_result:KeyEvents) -> Result<Option<character_state_machine::CharacterFSMOutput>, TransitionImpossibleError>
238266 {
239267 // if key_result == KeyEvents::Char_Left as i32
240268 // || key_result == KeyEvents::Char_Right as i32
241269 // || key_result == KeyEvents::Char_Key_Release as i32
242270 //{
243- character.trigger(key_processor.process_key(key_result));
271+ // character.trigger(key_processor.process_key(key_result));
244272 //}
273+
274+ match key_processor.process_key(key_result) {
275+ SignalForSM::MoveToRight => character.trigger(character_state_machine::CharacterFSMInput::BackPressed),
276+ SignalForSM::MoveToLeft => character.trigger(character_state_machine::CharacterFSMInput::FrontPressed),
277+ SignalForSM::KeyRelease => character.trigger(character_state_machine::CharacterFSMInput::Released),
278+ _ => Err(TransitionImpossibleError)
279+ }
245280 }
246281
247-pub fn save_test_data_to_file(groundLevel:f32, spriteA: &CharacterSprite, spriteB: &CharacterSprite)
282+pub fn save_test_data_to_file(ground_level:f32, sprite_a: &CharacterSprite, sprite_b: &CharacterSprite)
248283 {
249284 let mut data_to_dump: String = "spriteAData\n".to_string();
250285
251286 //data_to_dump = &String::from("spriteAData");
252287
253- data_to_dump.push_str(&groundLevel.to_string());
288+ data_to_dump.push_str(&ground_level.to_string());
254289 data_to_dump.push_str("\n");
255- data_to_dump.push_str( &spriteA.sprite.position().x.to_string());
290+ data_to_dump.push_str( &sprite_a.sprite.position().x.to_string());
256291 data_to_dump.push_str("\n");
257- data_to_dump.push_str( &spriteA.sprite.position().y.to_string());
292+ data_to_dump.push_str( &sprite_a.sprite.position().y.to_string());
258293 data_to_dump.push_str("\n");
259294
260295 data_to_dump.push_str("spriteBData\n");
261296
262- data_to_dump.push_str( &spriteB.sprite.position().x.to_string());
297+ data_to_dump.push_str( &sprite_b.sprite.position().x.to_string());
263298 data_to_dump.push_str("\n");
264- data_to_dump.push_str( &spriteB.sprite.position().y.to_string());
299+ data_to_dump.push_str( &sprite_b.sprite.position().y.to_string());
265300 data_to_dump.push_str("\n");
266301
267302 let path = Path::new("dump.txt");
268303
269304 let mut file = match File::create(&path) {
270305 //Err(why) => panic!("couldn't create {}: {}", display, why),
271- Err(why) => panic!("couldn't create test dump file"),
306+ Err(_why) => panic!("couldn't create test dump file"),
272307 Ok(file) => file,
273308 };
274309
275310 match file.write_all(data_to_dump.as_bytes()) {
276- Err(why) => panic!("couldn't write to test dump file"),
311+ Err(_why) => panic!("couldn't write to test dump file"),
277312 Ok(_) => println!("successfully wrote to test dump file"),
278313 }
279314 }
diff -r 1373908174ca -r bd7764e9f686 src/key_processing.rs
--- a/src/key_processing.rs Wed Feb 09 21:38:31 2022 +0100
+++ b/src/key_processing.rs Wed Sep 21 20:08:00 2022 +0200
@@ -1,8 +1,10 @@
11 use sfml::{
22 window::{ Event, Key},
33
4+
45 };
5-use crate::key_processing::KeyEvents::{Char_Left, Char_Right, Char_Key_Release};
6+
7+use crate::key_processing::KeyEvents::{CharLeft, CharRight, CharKeyRelease};
68
79 //use crate::sprite_rendering;
810
@@ -11,12 +13,12 @@
1113 pub enum KeyEvents {
1214 None = -1,
1315 Escape,
14- Char_Left,
15- Char_Right,
16- Char_Key_Release,
17- Char_B_Left = 11,
18- Char_B_Right = 12,
19- Char_B_Key_Release = 13,
16+ CharLeft,
17+ CharRight,
18+ CharKeyRelease,
19+ CharBLeft = 11,
20+ CharBRight = 12,
21+ CharBKeyRelease = 13,
2022 KeyTesting = 99
2123 }
2224
@@ -43,75 +45,48 @@
4345 }
4446
4547 pub fn process_key(&self, key_result: KeyEvents) -> SignalForSM {
46-
47- match key_result {
48- KeyEvents::Char_Left => return SignalForSM::MoveToLeft,
49- KeyEvents::Char_Right => return SignalForSM::MoveToRight,
50- KeyEvents::Char_Key_Release => return SignalForSM::KeyRelease,
51- _ => {return SignalForSM::None}
52- }
48+ return match key_result {
49+ KeyEvents::CharBLeft => SignalForSM::MoveToLeft,
50+ KeyEvents::CharBRight => SignalForSM::MoveToRight,
51+ CharKeyRelease => SignalForSM::KeyRelease,
52+ CharLeft => SignalForSM::MoveToLeft,
53+ CharRight => SignalForSM::MoveToRight,
5354
54- // if key_result == KeyEvents::Char_Left
55- // {
56- // return SignalForSM::MoveToLeft;
57- //
58- //
59- // } else if key_result == KeyEvents::Char_Right as i32
60- // {
61- // return SignalForSM::MoveToRight;
62- //
63- // } else if key_result == KeyEvents::Char_Key_Release as i32
64- // {
65- // return SignalForSM::KeyRelease;
66- // }
67- // return SignalForSM::None;
55+ _ => { SignalForSM::None }
56+ }
6857 }
6958
7059
7160
72- pub fn match_key(&self, event: Event) -> KeyEvents {
61+ pub fn match_key(&self) -> KeyEvents {
7362
7463 //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,
64+ //TODO: refactor enum->i32 conversions, just return a enum
65+ if Key::A.is_pressed()
66+ {
67+ return KeyEvents::CharBLeft;
68+ }
69+ if Key::D.is_pressed()
70+ {
71+ return KeyEvents::CharBRight;
72+ }
73+ if Key::F4.is_pressed()
74+ {
75+ return KeyEvents::KeyTesting;
76+ }
77+ if Key::ESCAPE.is_pressed()
78+ {
79+ return KeyEvents::Escape;
80+ }
81+ if Key::LEFT.is_pressed()
82+ {
83+ return CharLeft;
84+ }
85+ if Key::RIGHT.is_pressed()
86+ {
87+ return CharRight;
88+ }
8689
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- }
11590 return KeyEvents::None;
11691 }
11792
diff -r 1373908174ca -r bd7764e9f686 src/main.rs
--- a/src/main.rs Wed Feb 09 21:38:31 2022 +0100
+++ b/src/main.rs Wed Sep 21 20:08:00 2022 +0200
@@ -3,6 +3,7 @@
33 RenderWindow, Transformable
44 },
55 window::{ ContextSettings, Style},
6+
67 };
78 use crate::sprite_rendering::CharacterSprite;
89
diff -r 1373908174ca -r bd7764e9f686 src/sprite_rendering.rs
--- a/src/sprite_rendering.rs Wed Feb 09 21:38:31 2022 +0100
+++ b/src/sprite_rendering.rs Wed Sep 21 20:08:00 2022 +0200
@@ -36,13 +36,13 @@
3636 }
3737
3838 fn move_left(&mut self) {
39- let v = Vector2f::new(-1.0, 0.0);
39+ let v = Vector2f::new(-10.0, 0.0);
4040 self.sprite.move_(v);
4141 }
4242
4343
4444 pub fn move_right(&mut self) {
45- let v = Vector2f::new(1.0, 0.0);
45+ let v = Vector2f::new(10.0, 0.0);
4646 self.sprite.move_(v);
4747 }
4848
@@ -55,33 +55,33 @@
5555
5656 if state == States::Idle as i32
5757 {
58- if self.counter % 10 == 0
58+ if self.counter % 4 == 0
5959 {
6060 self.sprite.set_texture(&self.textures[1], true);
6161 }
62- if self.counter % 20 == 0
62+ if self.counter % 8 == 0
6363 {
6464 self.sprite.set_texture(&self.textures[0], true);
6565 }
6666 } else if state == States::MovingRight as i32
6767 {
6868 self.move_right();
69- if self.counter % 10 == 0
69+ if self.counter % 4 == 0
7070 {
7171 self.sprite.set_texture(&self.textures[2], true);
7272 }
73- if self.counter % 20 == 0
73+ if self.counter % 8 == 0
7474 {
7575 self.sprite.set_texture(&self.textures[3], true);
7676 }
7777 } else if state == States::MovingLeft as i32
7878 {
7979 self.move_left();
80- if self.counter % 10 == 0
80+ if self.counter % 4 == 0
8181 {
8282 self.sprite.set_texture(&self.textures[3], true);
8383 }
84- if self.counter % 20 == 0
84+ if self.counter % 8 == 0
8585 {
8686 self.sprite.set_texture(&self.textures[2], true);
8787 }
Afficher sur ancien navigateur de dépôt.