Mercurial repo for silny-kombat project
修订版 | 93765506c9231c7fc78a4b8ec511a8bc0015d8ff (tree) |
---|---|
时间 | 2023-03-10 06:34:13 |
作者 | Piotr Kozka <piotoor@gmai...> |
Commiter | Piotr Kozka |
Added font. It's passed as a reference from main down to hp status bars
@@ -22,6 +22,7 @@ | ||
22 | 22 | system::Vector2f, |
23 | 23 | SfBox |
24 | 24 | }; |
25 | +use sfml::graphics::Font; | |
25 | 26 | use crate::key_processing::{KeyProcessor, KeyEvents}; |
26 | 27 | use sfml::window::{Key}; |
27 | 28 | use crate::controller::Combat_status::A_ATTACKS_B; |
@@ -72,17 +73,16 @@ | ||
72 | 73 | |
73 | 74 | pub(crate) key_processor : KeyProcessor, |
74 | 75 | myRenderer : Renderer<'a>, |
75 | - window : RenderWindow, | |
76 | - | |
76 | + window : RenderWindow | |
77 | 77 | } |
78 | 78 | |
79 | 79 | impl<'a> Controller<'a> { |
80 | 80 | |
81 | - pub fn new(char_a : Character<'a>, char_b: Character<'a>, textures: &'a [ SfBox<Texture>;TEXTURE_ARRAY_SIZE] , textures2: &'a [SfBox<Texture>;SYSTEM_TEXTURE_ARRAY_SIZE] ) -> Self { | |
82 | - | |
81 | + pub fn new(char_a : Character<'a>, char_b: Character<'a>, textures: &'a [ SfBox<Texture>;TEXTURE_ARRAY_SIZE] , textures2: &'a [SfBox<Texture>;SYSTEM_TEXTURE_ARRAY_SIZE], font: &'a SfBox<Font> ) -> Self { | |
83 | 82 | let rend = Renderer::new(800, |
84 | 83 | &textures2[System_texture_Ids::BACKGROUND as usize], |
85 | - &textures2[System_texture_Ids::HEALTH_BAR as usize] | |
84 | + &textures2[System_texture_Ids::HEALTH_BAR as usize], | |
85 | + &font | |
86 | 86 | ); |
87 | 87 | let myWindow = rend.prepare_window(); |
88 | 88 |
@@ -93,7 +93,7 @@ | ||
93 | 93 | system_textures: textures2, |
94 | 94 | key_processor : KeyProcessor::new() , |
95 | 95 | myRenderer : rend, |
96 | - window : myWindow | |
96 | + window : myWindow, | |
97 | 97 | } |
98 | 98 | } |
99 | 99 |
@@ -1,19 +1,19 @@ | ||
1 | 1 | use std::cmp::max; |
2 | +use std::ops::Deref; | |
2 | 3 | use csfml_graphics_sys::sfColor; |
3 | -use sfml::{ | |
4 | - graphics::{ | |
5 | - Texture, | |
6 | - Sprite | |
7 | - }, | |
8 | -}; | |
4 | +use sfml::{graphics::{ | |
5 | + Texture, | |
6 | + Sprite | |
7 | +}, SfBox}; | |
9 | 8 | |
10 | -use sfml::graphics::{Color, Drawable, RectangleShape, RenderStates, RenderTarget, Shape, Transformable}; | |
9 | +use sfml::graphics::{Color, Drawable, Font, RectangleShape, RenderStates, RenderTarget, Shape, Text, Transformable}; | |
11 | 10 | use sfml::system::Vector2f; |
12 | 11 | |
13 | 12 | pub struct HealthBar<'s> { |
14 | 13 | hp_rect_max_width: f32, |
15 | 14 | pub hp_bar_sprite: Sprite<'s>, |
16 | 15 | hp_damage_rect: RectangleShape<'s>, |
16 | + text: Text<'s>, | |
17 | 17 | left_player: bool |
18 | 18 | } |
19 | 19 |
@@ -31,7 +31,7 @@ | ||
31 | 31 | self.hp_damage_rect.set_position(Vector2f::new(self.hp_bar_sprite.position().x + self.hp_bar_sprite.global_bounds().width - new_width - 2.0, self.hp_damage_rect.position().y)); |
32 | 32 | } |
33 | 33 | } |
34 | - pub fn new(texture: &'s Texture, left_player: bool, window_width: u32) -> Self { | |
34 | + pub fn new(texture: &'s Texture, left_player: bool, window_width: u32, font: &'s SfBox<Font>) -> Self { | |
35 | 35 | let mut sprite = Sprite::with_texture(texture); |
36 | 36 | sprite.set_scale(Vector2f::new(2.0, 2.0)); |
37 | 37 | let mut hp_rect = RectangleShape::new(); |
@@ -52,6 +52,7 @@ | ||
52 | 52 | hp_rect_max_width: sprite.global_bounds().width - 4.0, |
53 | 53 | hp_bar_sprite: sprite, |
54 | 54 | hp_damage_rect: hp_rect, |
55 | + text: Text::new("Sub-Zero", font, 10), | |
55 | 56 | left_player |
56 | 57 | } |
57 | 58 | } |
@@ -1,3 +1,4 @@ | ||
1 | +use sfml::graphics::Font; | |
1 | 2 | |
2 | 3 | mod sprite_rendering; |
3 | 4 | mod key_processing; |
@@ -20,8 +21,9 @@ | ||
20 | 21 | let mut character_a = character::Character::new("Sub Zero", 100, true, &textures.texturesArray); |
21 | 22 | let mut character_b = character::Character::new("Sub Zero", 100, true, &textures.texturesArray); |
22 | 23 | |
24 | + let font = Font::from_file("fonts/mk1_font.ttf").unwrap(); | |
23 | 25 | |
24 | - let mut controller = controller::Controller::new( character_a, character_b, &textures.texturesArray, &textures.systemTexturesArray); | |
26 | + let mut controller = controller::Controller::new( character_a, character_b, &textures.texturesArray, &textures.systemTexturesArray, &font); | |
25 | 27 | |
26 | 28 | controller.init(); |
27 | 29 |
@@ -11,7 +11,7 @@ | ||
11 | 11 | system::Vector2f, |
12 | 12 | SfBox |
13 | 13 | }; |
14 | - | |
14 | +use sfml::graphics::Font; | |
15 | 15 | |
16 | 16 | |
17 | 17 | pub struct myTextures { |
@@ -54,15 +54,14 @@ | ||
54 | 54 | } |
55 | 55 | |
56 | 56 | impl<'a> Renderer<'a>{ |
57 | - pub fn new(window_width: u32, bgTexture : &'a Texture , HpTexture: &'a Texture) -> Self{ | |
58 | - | |
57 | + pub fn new(window_width: u32, bgTexture : &'a Texture , HpTexture: &'a Texture, font: &'a SfBox<Font>) -> Self{ | |
59 | 58 | |
60 | 59 | Renderer { |
61 | 60 | window_width, |
62 | 61 | background_sprite : Sprite::new(), |
63 | 62 | background_texture : bgTexture, |
64 | - left_health_bar : health_bar::HealthBar::new(&HpTexture, true, window_width), | |
65 | - right_health_bar : health_bar::HealthBar::new(&HpTexture, false, window_width) | |
63 | + left_health_bar : health_bar::HealthBar::new(&HpTexture, true, window_width, &font), | |
64 | + right_health_bar : health_bar::HealthBar::new(&HpTexture, false, window_width, &font), | |
66 | 65 | } |
67 | 66 | } |
68 | 67 |
@@ -21,7 +21,7 @@ | ||
21 | 21 | |
22 | 22 | #[cfg(test)] |
23 | 23 | mod tests { |
24 | - use sfml::graphics::Transformable; | |
24 | + use sfml::graphics::{Font, Transformable}; | |
25 | 25 | use sfml::system::Vector2f; |
26 | 26 | use crate::controller::{CHAR_WIDTH, Combat_status, get_combat_status, is_chars_in_attack_range, KICK_DMG, KICK_RANGE, PUNCH_DMG, PUNCH_RANGE}; |
27 | 27 | use crate::key_processing::KeyEvents; |
@@ -193,8 +193,9 @@ | ||
193 | 193 | |
194 | 194 | let mut character_a = character::Character::new("Sub Zero", 100, true, &textures.texturesArray); |
195 | 195 | let mut character_b = character::Character::new("Sub Zero", 100, true, &textures.texturesArray); |
196 | + let font = Font::from_file("fonts/mk1_font.ttf").unwrap(); | |
196 | 197 | |
197 | - let mut controller = controller::Controller::new( character_a, character_b, &textures.texturesArray, &textures.systemTexturesArray); | |
198 | + let mut controller = controller::Controller::new( character_a, character_b, &textures.texturesArray, &textures.systemTexturesArray, &font); | |
198 | 199 | |
199 | 200 | controller.init(); |
200 | 201 |