• R/O
  • SSH

silny-kombat: Commit

Mercurial repo for silny-kombat project


Commit MetaInfo

Revisiondd678f61dad00ae206ef53834523760efe5d890f (tree)
Time2021-10-20 04:02:59
AuthorSecT
CommiterSecT

Log Message

Refactoring - moved textures outside of controller

Change Summary

Incremental Difference

diff -r b183ed802ad4 -r dd678f61dad0 src/controller.rs
--- a/src/controller.rs Tue Oct 19 20:36:49 2021 +0200
+++ b/src/controller.rs Tue Oct 19 21:02:59 2021 +0200
@@ -25,14 +25,17 @@
2525 characterA : Option<&'a Character<'a>>,
2626 characterB : Option<&'a Character<'a>>,
2727
28+ textures: [&'a SfBox<Texture>; 4]
2829 }
2930
3031 impl<'a> Controller<'a> {
3132
32- pub fn new() -> Self {
33+ pub fn new(textures: [&'a SfBox<Texture>;4] ) -> Self {
34+
3335 Controller {
3436 characterA: None,
35- characterB: None
37+ characterB: None,
38+ textures
3639 }
3740 }
3841
@@ -60,31 +63,14 @@
6063
6164 let key_processor = key_processing::KeyProcessor::new();
6265
63- //Player A
64- let fighter = Texture::from_file("sprites//sub_zero//01.gif").unwrap();
65- let fighter2 = Texture::from_file("sprites//sub_zero//02.gif").unwrap();
66- let fighter_walk0 = Texture::from_file("sprites//sub_zero//a01.gif").unwrap();
67- let fighter_walk1 = Texture::from_file("sprites//sub_zero//a03.gif").unwrap();
68-
69- //Player B
70- // let fighter_b = Texture::from_file("sprites//sub_zero//01.gif").unwrap();
71- // let fighter_b2 = Texture::from_file("sprites//sub_zero//02.gif").unwrap();
72- // let fighter_b_walk0 = Texture::from_file("sprites//sub_zero//a01.gif").unwrap();
73- // let fighter_b_walk1 = Texture::from_file("sprites//sub_zero//a03.gif").unwrap();
74-
75-
76- let textures: [&SfBox<Texture>; 4] = [&fighter, &fighter2, &fighter_walk0, &fighter_walk1];
77-// let textures_b: [&SfBox<Texture>; 4] = [&fighter_b, &fighter_b2, &fighter_b_walk0, &fighter_b_walk1];
7866
7967 //let mut character_sprite = sprite_rendering::CharacterSprite::new(&textures);
8068 //let mut character_sprite_b = sprite_rendering::CharacterSprite::new(&textures);
8169
82- let mut character_A: Character = Character ::new("Sub Zero", &textures);
83- let mut character_B: Character = Character ::new("Sub Zero", &textures);
70+ let mut character_A: Character = Character ::new("Sub Zero", &self.textures);
71+ let mut character_B: Character = Character ::new("Sub Zero", &self.textures);
8472
8573 println!("{} vs {}", character_A.get_name(), character_B.get_name());
86- //let mut state = 0;
87- //let mut state_b = 0;
8874
8975 character_B.char_sprite.sprite.set_position(Vector2f::new(600.0, 0.0));
9076 character_B.char_sprite.sprite.set_scale(Vector2f::new(-1.0, 1.0));
@@ -136,7 +122,7 @@
136122 // counter = 0;
137123 // }
138124 }
139-
125+
140126
141127 character_A.update_sprite();
142128 character_B.update_sprite();
diff -r b183ed802ad4 -r dd678f61dad0 src/main.rs
--- a/src/main.rs Tue Oct 19 20:36:49 2021 +0200
+++ b/src/main.rs Tue Oct 19 21:02:59 2021 +0200
@@ -16,10 +16,24 @@
1616 mod character;
1717 mod controller;
1818
19+use sfml::{
20+ graphics::{
21+ Texture
22+ },
23+ SfBox
24+};
1925
2026 fn main() {
2127 println!("Silny-Kombat!");
22- let controller = controller::Controller::new();
28+
29+ let fighter = Texture::from_file("sprites//sub_zero//01.gif").unwrap();
30+ let fighter2 = Texture::from_file("sprites//sub_zero//02.gif").unwrap();
31+ let fighter_walk0 = Texture::from_file("sprites//sub_zero//a01.gif").unwrap();
32+ let fighter_walk1 = Texture::from_file("sprites//sub_zero//a03.gif").unwrap();
33+
34+ let textures: [&SfBox<Texture>; 4] = [&fighter, &fighter2, &fighter_walk0, &fighter_walk1];
35+
36+ let controller = controller::Controller::new(textures);
2337 controller.run();
2438 }
2539
Show on old repository browser