aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuomas Siipola2019-07-07 03:21:23 +0300
committerTuomas Siipola2019-07-07 03:22:01 +0300
commitc9e9694d5d9d28ab50993a18b04b6c4ec11e22a5 (patch)
tree92608993011b9b9bd90ed427c22f277a576e81c7
parent5800af15422c87291ffcd4bfd91ea1a0483f5da7 (diff)
Add logo to menu
-rw-r--r--data/images/logo.bmpbin0 -> 28138 bytes
-rw-r--r--src/game.rs1
-rw-r--r--src/main.rs6
-rw-r--r--src/menu.rs13
-rw-r--r--src/state.rs1
5 files changed, 16 insertions, 5 deletions
diff --git a/data/images/logo.bmp b/data/images/logo.bmp
new file mode 100644
index 0000000..e628033
--- /dev/null
+++ b/data/images/logo.bmp
Binary files differ
diff --git a/src/game.rs b/src/game.rs
index 4bdcbca..855dc5b 100644
--- a/src/game.rs
+++ b/src/game.rs
@@ -73,6 +73,7 @@ impl State for Game {
canvas: &mut Canvas<Window>,
font: &Font,
tiles: &Texture,
+ _logo: &Texture,
) -> Action {
let mut next_direction = self.snake.head.direction;
diff --git a/src/main.rs b/src/main.rs
index 2c19909..14c6a7e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -30,6 +30,10 @@ fn main() {
.create_texture_from_surface(Surface::load_bmp("data/images/tiles.bmp").unwrap())
.unwrap();
+ let logo = texture_creator
+ .create_texture_from_surface(Surface::load_bmp("data/images/logo.bmp").unwrap())
+ .unwrap();
+
let font = Font::load_bmp(&texture_creator, "data/images/NeoSans.bmp");
let mut event_pump = sdl_context.event_pump().unwrap();
@@ -37,7 +41,7 @@ fn main() {
let mut current_state: Box<State> = Box::new(Menu::new());
loop {
- match current_state.update(event_pump.poll_iter(), &mut canvas, &font, &tiles) {
+ match current_state.update(event_pump.poll_iter(), &mut canvas, &font, &tiles, &logo) {
Action::Quit => break,
Action::Change(next_state) => current_state = next_state,
Action::None => {}
diff --git a/src/menu.rs b/src/menu.rs
index 417b5af..b229090 100644
--- a/src/menu.rs
+++ b/src/menu.rs
@@ -5,6 +5,7 @@ use std::time::Duration;
use sdl2::event::{Event, EventPollIterator};
use sdl2::keyboard::Scancode;
use sdl2::pixels::Color;
+use sdl2::rect::Rect;
use sdl2::render::{Canvas, Texture};
use sdl2::video::Window;
@@ -51,6 +52,7 @@ impl State for Menu {
canvas: &mut Canvas<Window>,
font: &Font,
tiles: &Texture,
+ logo: &Texture,
) -> Action {
for event in events {
match event {
@@ -87,15 +89,18 @@ impl State for Menu {
}
}
- canvas.set_draw_color(Color::RGB(255, 255, 255));
+ canvas.set_draw_color(Color::RGB(215, 227, 244));
canvas.clear();
- font.draw(canvas, 10, 10, "Natrix");
+
+ canvas
+ .copy(logo, None, Rect::new((320 - 175) / 2, 40, 175, 40))
+ .unwrap();
for (i, map) in self.maps.iter().enumerate() {
font.draw(
canvas,
- if i == self.selected_map { 20 } else { 10 },
- 30 + i as i32 * 10,
+ if i == self.selected_map { 120 } else { 110 },
+ 110 + i as i32 * 10,
&map.name,
);
}
diff --git a/src/state.rs b/src/state.rs
index 0db597c..afd9acb 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -17,5 +17,6 @@ pub trait State {
canvas: &mut Canvas<Window>,
font: &Font,
tiles: &Texture,
+ logo: &Texture,
) -> Action;
}