Add background image to main menu

This commit is contained in:
Timothy Warren 2021-11-29 14:59:46 -05:00
parent 9d1851be17
commit 1f8869879c
3 changed files with 53 additions and 8 deletions

View File

@ -1,7 +1,7 @@
use crate::components::{ use crate::components::{
CombatStats, HungerClock, HungerState, InBackpack, Name, Player, Position, Viewshed, CombatStats, HungerClock, HungerState, InBackpack, Name, Player, Position, Viewshed,
}; };
use crate::{game_log::GameLog, Equipped, Map, RunState, State}; use crate::{game_log::GameLog, rex_assets::RexAssets, Equipped, Map, RunState, State};
use rltk::{Point, Rltk, VirtualKeyCode, RGB}; use rltk::{Point, Rltk, VirtualKeyCode, RGB};
use specs::prelude::*; use specs::prelude::*;
@ -540,61 +540,87 @@ pub enum MainMenuResult {
pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult { pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult {
let save_exists = crate::saveload_system::does_save_exist(); let save_exists = crate::saveload_system::does_save_exist();
let runstate = gs.ecs.fetch::<RunState>(); let runstate = gs.ecs.fetch::<RunState>();
let assets = gs.ecs.fetch::<RexAssets>();
ctx.render_xp_sprite(&assets.menu, 0, 0);
ctx.draw_box_double(
24,
18,
31,
10,
RGB::named(rltk::WHEAT),
RGB::named(rltk::BLACK),
);
ctx.print_color_centered( ctx.print_color_centered(
15, 20,
RGB::named(rltk::YELLOW), RGB::named(rltk::YELLOW),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
"Rust Roguelike Tutorial", "Rust Roguelike Tutorial",
); );
ctx.print_color_centered(
21,
RGB::named(rltk::CYAN),
RGB::named(rltk::BLACK),
"by Herbert Wolverson",
);
ctx.print_color_centered(
22,
RGB::named(rltk::GRAY),
RGB::named(rltk::BLACK),
"Use Up/Down Arrows and Enter",
);
let mut y = 24;
if let RunState::MainMenu { if let RunState::MainMenu {
menu_selection: selection, menu_selection: selection,
} = *runstate } = *runstate
{ {
if selection == MainMenuSelection::NewGame { if selection == MainMenuSelection::NewGame {
ctx.print_color_centered( ctx.print_color_centered(
24, y,
RGB::named(rltk::MAGENTA), RGB::named(rltk::MAGENTA),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
"Begin New Game", "Begin New Game",
); );
} else { } else {
ctx.print_color_centered( ctx.print_color_centered(
24, y,
RGB::named(rltk::WHITE), RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
"Begin New Game", "Begin New Game",
); );
} }
y += 1;
if save_exists { if save_exists {
if selection == MainMenuSelection::LoadGame { if selection == MainMenuSelection::LoadGame {
ctx.print_color_centered( ctx.print_color_centered(
25, y,
RGB::named(rltk::MAGENTA), RGB::named(rltk::MAGENTA),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
"Load Game", "Load Game",
); );
} else { } else {
ctx.print_color_centered( ctx.print_color_centered(
25, y,
RGB::named(rltk::WHITE), RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
"Load Game", "Load Game",
); );
} }
y += 1;
} }
if selection == MainMenuSelection::Quit { if selection == MainMenuSelection::Quit {
ctx.print_color_centered( ctx.print_color_centered(
26, y,
RGB::named(rltk::MAGENTA), RGB::named(rltk::MAGENTA),
RGB::named(rltk::BLACK), RGB::named(rltk::BLACK),
"Quit", "Quit",
); );
} else { } else {
ctx.print_color_centered(26, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), "Quit"); ctx.print_color_centered(y, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), "Quit");
} }
match ctx.key { match ctx.key {

View File

@ -16,6 +16,7 @@ mod particle_system;
mod player; mod player;
pub mod random_table; pub mod random_table;
mod rect; mod rect;
mod rex_assets;
pub mod saveload_system; pub mod saveload_system;
mod spawner; mod spawner;
mod visibility_system; mod visibility_system;
@ -532,6 +533,7 @@ fn main() -> rltk::BError {
}); });
gs.ecs.insert(GameLog::new("Welcome to Rusty Roguelike")); gs.ecs.insert(GameLog::new("Welcome to Rusty Roguelike"));
gs.ecs.insert(particle_system::ParticleBuilder::new()); gs.ecs.insert(particle_system::ParticleBuilder::new());
gs.ecs.insert(rex_assets::RexAssets::new());
rltk::main_loop(context, gs) rltk::main_loop(context, gs)
} }

17
src/rex_assets.rs Normal file
View File

@ -0,0 +1,17 @@
use rltk::rex::XpFile;
rltk::embedded_resource!(SMALL_DUNGEON, "../resources/SmallDungeon_80x50.xp");
pub struct RexAssets {
pub menu: XpFile,
}
impl RexAssets {
pub fn new() -> RexAssets {
rltk::link_resource!(SMALL_DUNGEON, "../resources/SmallDungeon_80x50.xp");
RexAssets {
menu: XpFile::from_resource("../resources/SmallDungeon_80x50.xp").unwrap(),
}
}
}