• R/O
  • SSH

silny-kombat: 提交

Mercurial repo for silny-kombat project


Commit MetaInfo

修订版93765506c9231c7fc78a4b8ec511a8bc0015d8ff (tree)
时间2023-03-10 06:34:13
作者Piotr Kozka <piotoor@gmai...>
CommiterPiotr Kozka

Log Message

Added font. It's passed as a reference from main down to hp status bars

更改概述

差异

diff -r 3704cec45aaa -r 93765506c923 src/controller.rs
--- a/src/controller.rs Thu Mar 09 19:54:12 2023 +0100
+++ b/src/controller.rs Thu Mar 09 22:34:13 2023 +0100
@@ -22,6 +22,7 @@
2222 system::Vector2f,
2323 SfBox
2424 };
25+use sfml::graphics::Font;
2526 use crate::key_processing::{KeyProcessor, KeyEvents};
2627 use sfml::window::{Key};
2728 use crate::controller::Combat_status::A_ATTACKS_B;
@@ -72,17 +73,16 @@
7273
7374 pub(crate) key_processor : KeyProcessor,
7475 myRenderer : Renderer<'a>,
75- window : RenderWindow,
76-
76+ window : RenderWindow
7777 }
7878
7979 impl<'a> Controller<'a> {
8080
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 {
8382 let rend = Renderer::new(800,
8483 &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
8686 );
8787 let myWindow = rend.prepare_window();
8888
@@ -93,7 +93,7 @@
9393 system_textures: textures2,
9494 key_processor : KeyProcessor::new() ,
9595 myRenderer : rend,
96- window : myWindow
96+ window : myWindow,
9797 }
9898 }
9999
diff -r 3704cec45aaa -r 93765506c923 src/health_bar.rs
--- a/src/health_bar.rs Thu Mar 09 19:54:12 2023 +0100
+++ b/src/health_bar.rs Thu Mar 09 22:34:13 2023 +0100
@@ -1,19 +1,19 @@
11 use std::cmp::max;
2+use std::ops::Deref;
23 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};
98
10-use sfml::graphics::{Color, Drawable, RectangleShape, RenderStates, RenderTarget, Shape, Transformable};
9+use sfml::graphics::{Color, Drawable, Font, RectangleShape, RenderStates, RenderTarget, Shape, Text, Transformable};
1110 use sfml::system::Vector2f;
1211
1312 pub struct HealthBar<'s> {
1413 hp_rect_max_width: f32,
1514 pub hp_bar_sprite: Sprite<'s>,
1615 hp_damage_rect: RectangleShape<'s>,
16+ text: Text<'s>,
1717 left_player: bool
1818 }
1919
@@ -31,7 +31,7 @@
3131 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));
3232 }
3333 }
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 {
3535 let mut sprite = Sprite::with_texture(texture);
3636 sprite.set_scale(Vector2f::new(2.0, 2.0));
3737 let mut hp_rect = RectangleShape::new();
@@ -52,6 +52,7 @@
5252 hp_rect_max_width: sprite.global_bounds().width - 4.0,
5353 hp_bar_sprite: sprite,
5454 hp_damage_rect: hp_rect,
55+ text: Text::new("Sub-Zero", font, 10),
5556 left_player
5657 }
5758 }
diff -r 3704cec45aaa -r 93765506c923 src/main.rs
--- a/src/main.rs Thu Mar 09 19:54:12 2023 +0100
+++ b/src/main.rs Thu Mar 09 22:34:13 2023 +0100
@@ -1,3 +1,4 @@
1+use sfml::graphics::Font;
12
23 mod sprite_rendering;
34 mod key_processing;
@@ -20,8 +21,9 @@
2021 let mut character_a = character::Character::new("Sub Zero", 100, true, &textures.texturesArray);
2122 let mut character_b = character::Character::new("Sub Zero", 100, true, &textures.texturesArray);
2223
24+ let font = Font::from_file("fonts/mk1_font.ttf").unwrap();
2325
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);
2527
2628 controller.init();
2729
diff -r 3704cec45aaa -r 93765506c923 src/renderer.rs
--- a/src/renderer.rs Thu Mar 09 19:54:12 2023 +0100
+++ b/src/renderer.rs Thu Mar 09 22:34:13 2023 +0100
@@ -11,7 +11,7 @@
1111 system::Vector2f,
1212 SfBox
1313 };
14-
14+use sfml::graphics::Font;
1515
1616
1717 pub struct myTextures {
@@ -54,15 +54,14 @@
5454 }
5555
5656 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{
5958
6059 Renderer {
6160 window_width,
6261 background_sprite : Sprite::new(),
6362 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),
6665 }
6766 }
6867
diff -r 3704cec45aaa -r 93765506c923 src/tests.rs
--- a/src/tests.rs Thu Mar 09 19:54:12 2023 +0100
+++ b/src/tests.rs Thu Mar 09 22:34:13 2023 +0100
@@ -21,7 +21,7 @@
2121
2222 #[cfg(test)]
2323 mod tests {
24- use sfml::graphics::Transformable;
24+ use sfml::graphics::{Font, Transformable};
2525 use sfml::system::Vector2f;
2626 use crate::controller::{CHAR_WIDTH, Combat_status, get_combat_status, is_chars_in_attack_range, KICK_DMG, KICK_RANGE, PUNCH_DMG, PUNCH_RANGE};
2727 use crate::key_processing::KeyEvents;
@@ -193,8 +193,9 @@
193193
194194 let mut character_a = character::Character::new("Sub Zero", 100, true, &textures.texturesArray);
195195 let mut character_b = character::Character::new("Sub Zero", 100, true, &textures.texturesArray);
196+ let font = Font::from_file("fonts/mk1_font.ttf").unwrap();
196197
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);
198199
199200 controller.init();
200201
Show on old repository browser