From 802a5650ed5d33363c53a7032a58eb1d574a81bf Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sun, 31 Jan 2021 18:15:31 +0100 Subject: background added --- src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 42595ad..edbb973 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ use rand::{ Rng, }; -pub const TILE_SCALE: f32 = 2.0; +pub const TILE_SCALE: f32 = 3.0; pub const TILE_HEIGHT: f32 = 16.0; pub const TILE_WIDTH: f32 = 16.0; pub const BORDER_SIZE: f32 = 3.0; @@ -140,10 +140,14 @@ struct Game { selected: Option<(usize, usize)>, spritebatch: SpriteBatch, grid: Vec>, + background: Image, } impl Game { fn new(context: &mut Context) -> GameResult { + let mut background = Image::new(context, "/background.png")?; + background.set_filter(FilterMode::Nearest); + let mut image = Image::new(context, "/gem.png")?; image.set_filter(FilterMode::Nearest); image.set_wrap(WrapMode::Mirror, WrapMode::Mirror); @@ -190,6 +194,7 @@ impl Game { grid, selected: None, spritebatch: SpriteBatch::new(image), + background, }) } } @@ -275,7 +280,8 @@ impl EventHandler for Game { } fn draw(&mut self, context: &mut Context) -> GameResult { - graphics::clear(context, [0.1, 0.2, 0.3, 1.0].into()); + graphics::clear(context, [0.0, 0.0, 0.0, 1.0].into()); + graphics::draw(context, &self.background, DrawParam::default())?; for row in self.grid.iter() { for cell in row.iter() { -- cgit v1.2.3