diff --git a/resources/corbel.ttf b/resources/corbel.ttf new file mode 100644 index 0000000000000000000000000000000000000000..34fd5aa9e3b76c264eacf17b5671475b91e875e1 Binary files /dev/null and b/resources/corbel.ttf differ diff --git a/src/main.rs b/src/main.rs index cb0df5c50d6421e81617ad09ba0db9249239eb1c..c79c92fd7b5de5a2f847ff9779a0d771a6f5aaf3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use tetra::graphics::text::{Font, Text, VectorFontBuilder}; use tetra::graphics::{self, Color, DrawParams, Texture}; use tetra::input::{self, Key}; use tetra::math::Vec2; @@ -7,10 +8,10 @@ use rand::{thread_rng, Rng}; //constants -const WINDOW_WIDTH: f32 = 1280.0; -const WINDOW_HEIGHT: f32 = 720.0; -const BOARD_WIDTH: usize = 39; -const BOARD_HEIGHT: usize = 22; +const WINDOW_WIDTH: f32 = 1920.0; +const WINDOW_HEIGHT: f32 = 1080.0; +const BOARD_WIDTH: usize = 58; +const BOARD_HEIGHT: usize = 28; fn main() -> tetra::Result { ContextBuilder::new("rusttest", WINDOW_WIDTH as i32, WINDOW_HEIGHT as i32) @@ -24,6 +25,8 @@ player: Entity, foes: Foes, tile: Texture, world: World, +ui: UI, +stats: Stats, } impl GameState { @@ -35,11 +38,17 @@ impl GameState { //set initial position let player_position = Vec2::new(5,7); + //UI + let font = VectorFontBuilder::new("./resources/corbel.ttf")?; + let font2 = font.with_size(ctx, 16.0)?; + Ok(GameState { player: Entity::new_pos(player_texture, player_position, 1), foes: Foes::generate(6, Texture::new(ctx, "./resources/spike.png")?), tile: tile_texture, world: World::new(), + ui: UI::new(font2), + stats: Stats::new(), }) } } @@ -72,6 +81,9 @@ impl State for GameState { for id in &ids{ self.foes.list[id].draw(ctx); } + self.ui.updateStats(ctx, self.stats); + self.ui.updateEvents(ctx, "Something happend."); + Ok(()) } @@ -255,4 +267,49 @@ impl Foes{ } Foes{list:entities} } +} + +struct UI{ + font: Font +} + +impl UI{ + fn new(font:Font) -> UI{ + UI{ + font: font, + } + } + fn updateStats(&mut self, ctx: &mut Context, stats:Stats){ + let mut health = Text::new(format!("Health: {}", stats.health), self.font.clone()); + let mut attack = Text::new(format!("Attack: {}", stats.attack), self.font.clone()); + let mut level = Text::new(format!("Lvl: {}", stats.level), self.font.clone()); + let mut score = Text::new(format!("Score: {}", stats.score), self.font.clone()); + health.draw(ctx, Vec2::new(100.0, 950.0)); + attack.draw(ctx, Vec2::new(100.0, 970.0)); + level.draw(ctx, Vec2::new(100.0, 990.0)); + score.draw(ctx, Vec2::new(100.0, 1010.0)); + } + fn updateEvents(&mut self, ctx: &mut Context, event: &str){ + let mut event1 = Text::new(event, self.font.clone()); + event1.draw(ctx, Vec2::new(500.0, 950.0)); + } +} + +#[derive(Copy, Clone)] +struct Stats{ + health: u32, + attack: u32, + level: u32, + score: u32, +} + +impl Stats{ + fn new() -> Stats{ + Stats{ + health: 100, + attack: 10, + level: 1, + score: 0, + } + } } \ No newline at end of file