Skip to content
Snippets Groups Projects
Commit 3c21d6d6 authored by radow's avatar radow
Browse files

ui stuff on old setup

parent d3653bb7
No related branches found
No related tags found
No related merge requests found
File added
use std::collections::HashMap; use std::collections::HashMap;
use tetra::graphics::text::{Font, Text, VectorFontBuilder};
use tetra::graphics::{self, Color, DrawParams, Texture}; use tetra::graphics::{self, Color, DrawParams, Texture};
use tetra::input::{self, Key}; use tetra::input::{self, Key};
use tetra::math::Vec2; use tetra::math::Vec2;
...@@ -7,10 +8,10 @@ use rand::{thread_rng, Rng}; ...@@ -7,10 +8,10 @@ use rand::{thread_rng, Rng};
//constants //constants
const WINDOW_WIDTH: f32 = 1280.0; const WINDOW_WIDTH: f32 = 1920.0;
const WINDOW_HEIGHT: f32 = 720.0; const WINDOW_HEIGHT: f32 = 1080.0;
const BOARD_WIDTH: usize = 39; const BOARD_WIDTH: usize = 58;
const BOARD_HEIGHT: usize = 22; const BOARD_HEIGHT: usize = 28;
fn main() -> tetra::Result { fn main() -> tetra::Result {
ContextBuilder::new("rusttest", WINDOW_WIDTH as i32, WINDOW_HEIGHT as i32) ContextBuilder::new("rusttest", WINDOW_WIDTH as i32, WINDOW_HEIGHT as i32)
...@@ -24,6 +25,8 @@ player: Entity, ...@@ -24,6 +25,8 @@ player: Entity,
foes: Foes, foes: Foes,
tile: Texture, tile: Texture,
world: World, world: World,
ui: UI,
stats: Stats,
} }
impl GameState { impl GameState {
...@@ -35,11 +38,17 @@ impl GameState { ...@@ -35,11 +38,17 @@ impl GameState {
//set initial position //set initial position
let player_position = Vec2::new(5,7); 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 { Ok(GameState {
player: Entity::new_pos(player_texture, player_position, 1), player: Entity::new_pos(player_texture, player_position, 1),
foes: Foes::generate(6, Texture::new(ctx, "./resources/spike.png")?), foes: Foes::generate(6, Texture::new(ctx, "./resources/spike.png")?),
tile: tile_texture, tile: tile_texture,
world: World::new(), world: World::new(),
ui: UI::new(font2),
stats: Stats::new(),
}) })
} }
} }
...@@ -72,6 +81,9 @@ impl State for GameState { ...@@ -72,6 +81,9 @@ impl State for GameState {
for id in &ids{ for id in &ids{
self.foes.list[id].draw(ctx); self.foes.list[id].draw(ctx);
} }
self.ui.updateStats(ctx, self.stats);
self.ui.updateEvents(ctx, "Something happend.");
Ok(()) Ok(())
} }
...@@ -256,3 +268,48 @@ impl Foes{ ...@@ -256,3 +268,48 @@ impl Foes{
Foes{list:entities} 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment