• R/O
  • SSH

silny-kombat: Commit

Mercurial repo for silny-kombat project


Commit MetaInfo

Revision15c51e4f3af5ebc544193be016926a2a98470abb (tree)
Time2021-10-20 03:27:08
AuthorSecT
CommiterSecT

Log Message

Refactoring - move counter to character sprite struct

Change Summary

Incremental Difference

diff -r 691d57884b0f -r 15c51e4f3af5 src/controller.rs
--- a/src/controller.rs Tue Oct 19 19:37:37 2021 +0200
+++ b/src/controller.rs Tue Oct 19 20:27:08 2021 +0200
@@ -81,6 +81,7 @@
8181
8282 let mut character_A: Character = Character ::new("Sub Zero", &textures);
8383 let mut character_B: Character = Character ::new("Sub Zero", &textures);
84+
8485 println!("{} vs {}", character_A.get_name(), character_B.get_name());
8586 //let mut state = 0;
8687 //let mut state_b = 0;
@@ -89,7 +90,6 @@
8990 character_B.char_sprite.sprite.set_scale(Vector2f::new(-1.0, 1.0));
9091
9192 //loop
92- let mut counter = 0;
9393
9494 //let &mut mut stateReference: &mut i32;
9595
@@ -119,9 +119,6 @@
119119 process_key_result_for_character(&key_processor, &mut character_B, key_result);
120120 }
121121
122- if key_result == 3 {
123- counter = 0;
124- }
125122
126123 // //first char/////////////
127124 // if key_result == 3 {
@@ -141,18 +138,11 @@
141138 }
142139
143140
144- counter = counter + 1;
145-
146- if counter > 20000
147- {
148- counter = 0;
149- }
150-
151141 //character_A.char_sprite.show_sprite(state, counter);
152142 //character_B.char_sprite.show_sprite(state_b, counter);
153143
154- character_A.char_sprite.show_sprite(character_A.get_num_state(), counter);
155- character_B.char_sprite.show_sprite(character_B.get_num_state(), counter);
144+ character_A.char_sprite.show_sprite(character_A.get_num_state());
145+ character_B.char_sprite.show_sprite(character_B.get_num_state());
156146
157147 window.clear(Color::rgb(50, 200, 50));
158148 window.draw(&character_A.char_sprite.sprite);
diff -r 691d57884b0f -r 15c51e4f3af5 src/sprite_rendering.rs
--- a/src/sprite_rendering.rs Tue Oct 19 19:37:37 2021 +0200
+++ b/src/sprite_rendering.rs Tue Oct 19 20:27:08 2021 +0200
@@ -10,7 +10,9 @@
1010 pub struct CharacterSprite<'a> {
1111 //sprite : 'a mut Sprite<'a>
1212 pub sprite : Sprite<'a>,
13- textures: &'a [&'a SfBox<Texture>]
13+ textures: &'a [&'a SfBox<Texture>],
14+ counter: i32,
15+ currentState:i32
1416 }
1517 impl<'a> CharacterSprite<'a>{
1618 //fn new(new_sprite: &'a Sprite) -> Self{
@@ -19,7 +21,9 @@
1921 let sprite = Sprite::new();
2022 CharacterSprite{
2123 sprite,
22- textures
24+ textures,
25+ counter: 0,
26+ currentState: -1
2327 }
2428 }
2529
@@ -33,40 +37,53 @@
3337 self.sprite.move_(v);
3438 }
3539
36- pub fn show_sprite(&mut self, state: i32, counter: i32) {
40+ pub fn show_sprite(&mut self, state: i32) {
41+
42+ if state != self.currentState{
43+ self.counter = 0;
44+ self.currentState = state;
45+ }
46+
3747 if state == 0
3848 {
39- if counter % 10 == 0
49+ if self.counter % 10 == 0
4050 {
4151 self.sprite.set_texture(&self.textures[1], true);
4252 }
43- if counter % 20 == 0
53+ if self.counter % 20 == 0
4454 {
4555 self.sprite.set_texture(&self.textures[0], true);
4656 }
4757 } else if state == 1
4858 {
4959 self.move_right();
50- if counter % 10 == 0
60+ if self.counter % 10 == 0
5161 {
5262 self.sprite.set_texture(&self.textures[2], true);
5363 }
54- if counter % 20 == 0
64+ if self.counter % 20 == 0
5565 {
5666 self.sprite.set_texture(&self.textures[3], true);
5767 }
5868 } else if state == 2
5969 {
6070 self.move_left();
61- if counter % 10 == 0
71+ if self.counter % 10 == 0
6272 {
6373 self.sprite.set_texture(&self.textures[3], true);
6474 }
65- if counter % 20 == 0
75+ if self.counter % 20 == 0
6676 {
6777 self.sprite.set_texture(&self.textures[2], true);
6878 }
6979 }
80+
81+ self.counter = self.counter + 1;
82+
83+ if self.counter > 20000
84+ {
85+ self.counter = 0;
86+ }
7087 }
7188 }
7289
Show on old repository browser