From 25651d5c82145b2283b14d3fc65017e858194950 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sat, 13 Nov 2021 15:49:48 +0100 Subject: [PATCH] Main menu and saving --- src/main.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main.rs b/src/main.rs index 03537cf..9b3fb41 100644 --- a/src/main.rs +++ b/src/main.rs @@ -376,6 +376,19 @@ fn handle_keys(tcod: &mut Tcod, game: &mut Game, objects: &mut Vec) -> P DidntTakeTurn } + (Key { code: Text, .. }, "d", true) => { + // Show the inventory; if an item is selected, drop it + let inventory_index = inventory_menu( + &game.inventory, + "Press the key next to an item to drop it, or any other to cancel.\n", + &mut tcod.root, + ); + if let Some(inventory_index) = inventory_index { + drop_item(inventory_index, game, objects); + } + DidntTakeTurn + } + _ => DidntTakeTurn, } } @@ -1058,6 +1071,15 @@ fn target_monster( } } +fn drop_item(inventory_id: usize, game: &mut Game, objects: &mut Vec) { + let mut item = game.inventory.remove(inventory_id); + item.set_pos(objects[PLAYER].x, objects[PLAYER].y); + game + .messages + .add(format!("You dropped a {}.", item.name), YELLOW); + objects.push(item); +} + fn render_all(tcod: &mut Tcod, game: &mut Game, objects: &[Object], fov_recompute: bool) { if fov_recompute { let player = &objects[PLAYER];