Skip to content
Snippets Groups Projects
Commit 1944708c authored by pumapaul's avatar pumapaul
Browse files

Refactor drawing logic to be more compact

parent 8554f5f4
No related branches found
No related tags found
No related merge requests found
......@@ -402,35 +402,27 @@ impl GameState {
fn draw_exit(&mut self, x: usize, y: usize, ctx: &mut Context) {
GameState::draw_tile(self, Color::WHITE, x, y, ctx);
self.textures.exit.draw(ctx, DrawParams {
position: Vec2::new(x as f32 * 33.0, y as f32 * 33.0),
scale: Vec2::new(1.0, 1.0),
origin: Vec2::new(0.0, 0.0),
self.draw_texture(&self.textures.exit, x, y, 1.0, 0.0, Color::WHITE, ctx);
}
fn draw_texture(&self, texture: &Texture, x: usize, y: usize, scale: f32, inset: f32, color: Color, ctx: &mut Context) {
texture.draw(ctx, DrawParams {
position: Vec2::new(inset + (x as f32 * 33.0), inset + (y as f32 * 33.0)),
scale: Vec2::new(scale, scale),
origin: Vec2::new(inset, inset),
rotation: 0.0,
color: Color::WHITE,
color,
})
}
fn draw_treasure(&mut self, x: usize, y: usize, ctx: &mut Context) {
GameState::draw_tile(self, Color::WHITE, x, y, ctx);
self.textures.treasure.draw(ctx, DrawParams {
position: Vec2::new(x as f32 * 33.0, y as f32 * 33.0),
scale: Vec2::new(1.0, 1.0),
origin: Vec2::new(0.0, 0.0),
rotation: 0.0,
color: Color::WHITE,
})
self.draw_texture(&self.textures.treasure, x, y, 1.0, 0.0, Color::WHITE, ctx);
}
fn draw_tile(&mut self, color: Color, x: usize, y: usize, ctx: &mut Context) {
self.textures.tile.draw(ctx, DrawParams {
position: Vec2::new(x as f32 * 33.0, y as f32 * 33.0),
scale: Vec2::new(1.0, 1.0),
origin: Vec2::new(0.0, 0.0),
rotation: 0.0,
color,
})
self.draw_texture(&self.textures.tile, x, y, 1.0, 0.0, color, ctx);
}
fn draw_wall(&mut self, x: usize, y: usize, ctx: &mut Context) {
......@@ -442,13 +434,7 @@ impl GameState {
11111111 => tex = self.textures.tile.clone(),
_ => {}
}
tex.draw(ctx, DrawParams {
position: Vec2::new(x as f32 * 33.0, y as f32 * 33.0),
scale: Vec2::new(1.0, 1.0),
origin: Vec2::new(0.0, 0.0),
rotation: 0.0,
color: Color::WHITE,
})
self.draw_texture(&tex, x, y, 1.0, 0.0, Color::WHITE, ctx);
}
fn calc_walltype(&self, x: usize, y: usize) -> u32 {
......@@ -496,25 +482,13 @@ impl GameState {
fn draw_player(&mut self, x: usize, y: usize, ctx: &mut Context) {
GameState::draw_tile(self, Color::WHITE, x, y, ctx);
let draw_params = GameState::create_entity_draw_params(x, y);
self.textures.player.draw(ctx, draw_params)
self.draw_texture(&self.textures.player, x, y, 1.15, 16.0, Color::WHITE, ctx);
}
fn draw_enemy(&mut self, x: usize, y: usize, ctx: &mut Context) {
GameState::draw_tile(self, Color::WHITE, x, y, ctx);
let draw_params = GameState::create_entity_draw_params(x, y);
self.textures.enemy.draw(ctx, draw_params)
}
fn create_entity_draw_params(x: usize, y: usize) -> DrawParams {
DrawParams {
position: Vec2::new(16.0 + (x as f32) * 33.0, 16.0 + (y as f32) * 33.0),
scale: Vec2::new(1.0, 1.0),
origin: Vec2::new(16.0, 16.0),
rotation: 0.0,
color: Color::WHITE,
}
self.draw_texture(&self.textures.enemy, x, y, 1.15, 14.0, Color::WHITE, ctx);
}
fn draw_stats(&self, ctx: &mut Context) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment