key inv display
This commit is contained in:
@@ -4,12 +4,56 @@ use crate::log::LogLine;
|
||||
use crate::script::ScriptHost;
|
||||
use crate::utils::{Direction, ObjectId, Player, ScriptArg};
|
||||
use crate::world::World;
|
||||
use color::Rgba8;
|
||||
use std::cell::{Ref, RefMut};
|
||||
use std::time::Duration;
|
||||
|
||||
/// How long a `say()` speech bubble stays on screen, in seconds.
|
||||
pub const SAY_DURATION: f64 = 3.0;
|
||||
|
||||
/// The player's key inventory: one boolean per key color.
|
||||
///
|
||||
/// Each field is `true` when the player holds a key of that color. Use
|
||||
/// [`colors`](Keyring::colors) to iterate all eight in display order, each
|
||||
/// paired with its [`Rgba8`] color for rendering.
|
||||
#[derive(Copy, Clone, Default)]
|
||||
pub struct Keyring {
|
||||
/// Blue key.
|
||||
pub blue: bool,
|
||||
/// Green key.
|
||||
pub green: bool,
|
||||
/// Cyan key.
|
||||
pub cyan: bool,
|
||||
/// Red key.
|
||||
pub red: bool,
|
||||
/// Purple key.
|
||||
pub purple: bool,
|
||||
/// Orange key (custom color, not in the standard EGA palette).
|
||||
pub orange: bool,
|
||||
/// Yellow key.
|
||||
pub yellow: bool,
|
||||
/// White key.
|
||||
pub white: bool,
|
||||
}
|
||||
|
||||
impl Keyring {
|
||||
/// Returns all eight keys in display order, each paired with its color.
|
||||
///
|
||||
/// Order: blue, green, cyan, red, purple, orange, yellow, white.
|
||||
pub fn colors(&self) -> [(bool, Rgba8); 8] {
|
||||
[
|
||||
(self.blue, Rgba8 { r: 0x00, g: 0x00, b: 0xAA, a: 255 }),
|
||||
(self.green, Rgba8 { r: 0x00, g: 0xAA, b: 0x00, a: 255 }),
|
||||
(self.cyan, Rgba8 { r: 0x00, g: 0xAA, b: 0xAA, a: 255 }),
|
||||
(self.red, Rgba8 { r: 0xAA, g: 0x00, b: 0x00, a: 255 }),
|
||||
(self.purple, Rgba8 { r: 0xAA, g: 0x00, b: 0xAA, a: 255 }),
|
||||
(self.orange, Rgba8 { r: 0xFF, g: 0x88, b: 0x00, a: 255 }),
|
||||
(self.yellow, Rgba8 { r: 0xFF, g: 0xFF, b: 0x55, a: 255 }),
|
||||
(self.white, Rgba8 { r: 0xFF, g: 0xFF, b: 0xFF, a: 255 }),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
// Re-export ScrollLine so kiln-tui can pattern-match scroll content without
|
||||
// accessing the private `action` module directly.
|
||||
pub use crate::action::ScrollLine;
|
||||
@@ -74,6 +118,8 @@ pub struct GameState {
|
||||
/// [`player_health`](GameState::player_health); starts at `0` and is
|
||||
/// display-only for now.
|
||||
pub player_gems: u32,
|
||||
/// The player's key inventory. Game-global; persists across board transitions.
|
||||
pub player_keys: Keyring,
|
||||
}
|
||||
|
||||
impl GameState {
|
||||
@@ -102,6 +148,8 @@ impl GameState {
|
||||
board_transition: None,
|
||||
player_health: 5,
|
||||
player_gems: 0,
|
||||
// Test starting keys: red, green, orange, white.
|
||||
player_keys: Keyring { red: true, green: true, orange: true, white: true, ..Default::default() },
|
||||
};
|
||||
state.drain_errors();
|
||||
state
|
||||
|
||||
Reference in New Issue
Block a user