116 lines
3.3 KiB
Rust
116 lines
3.3 KiB
Rust
use crate::border_panel::{INNER_BORDER, OUTER_BORDER, draw_border_panel};
|
|
use crate::row::Row;
|
|
use crate::{Currency, unlocks::UnlockSystem};
|
|
use servicepoint::{Bitmap, CharGrid, TILE_SIZE, WindowMut};
|
|
use std::time::Duration;
|
|
|
|
#[derive(Debug)]
|
|
pub struct Game {
|
|
total_currency: Currency,
|
|
unlocks: UnlockSystem,
|
|
state: State,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct State {
|
|
pub currency: Currency,
|
|
pub speed: f64,
|
|
pub productivity: f64,
|
|
pub rows: Vec<Row>,
|
|
}
|
|
|
|
impl Game {
|
|
const BAR_NAMES: [&'static str; 11] = [
|
|
"Powering infrastructure",
|
|
"Activating colorful lights",
|
|
"Dimming darkroom",
|
|
"Refilling Matemat",
|
|
"Pre-heating convectiomat",
|
|
"Resetting chair heights",
|
|
"Untangling 'block chain'",
|
|
"Refilling sticker box",
|
|
"Setting room to public",
|
|
"Welcoming creatures",
|
|
"Making Discordia proud",
|
|
];
|
|
|
|
pub fn new() -> Self {
|
|
let bars = Self::BAR_NAMES
|
|
.iter()
|
|
.enumerate()
|
|
.map(|(index, name)| {
|
|
Row::new(
|
|
5usize.pow(index as u32) as f64,
|
|
1.0 * (0.5f64.powi(index as i32)),
|
|
name,
|
|
)
|
|
})
|
|
.collect();
|
|
let state = State {
|
|
rows: bars,
|
|
currency: 1f64,
|
|
speed: 1f64,
|
|
productivity: 1f64,
|
|
};
|
|
Self {
|
|
total_currency: 0f64,
|
|
unlocks: UnlockSystem::new(&state),
|
|
state,
|
|
}
|
|
}
|
|
|
|
pub fn progress(&mut self, delta: Duration) {
|
|
let adjusted_delta = delta.mul_f64(self.state.speed);
|
|
|
|
let extra_currency = self.state.productivity
|
|
* self
|
|
.state
|
|
.rows
|
|
.iter_mut()
|
|
.map(|bar| bar.progress(adjusted_delta))
|
|
.sum::<Currency>();
|
|
self.state.currency += extra_currency;
|
|
self.total_currency += extra_currency;
|
|
self.unlocks.progress(&mut self.state);
|
|
}
|
|
|
|
pub fn draw(
|
|
&self,
|
|
text_layer: WindowMut<char, CharGrid>,
|
|
pixel_layer: WindowMut<bool, Bitmap>,
|
|
) {
|
|
let (text_layer, pixel_layer) = draw_border_panel(
|
|
text_layer,
|
|
pixel_layer,
|
|
" Discordia Boot Procedure ",
|
|
OUTER_BORDER,
|
|
);
|
|
|
|
let unlocks_height = 3 + 2;
|
|
let (unlocks_text, bars_text) = text_layer.split_vertical_mut(unlocks_height).unwrap();
|
|
let (unlocks_pixel, bars_pixel) = pixel_layer
|
|
.split_vertical_mut(unlocks_height * TILE_SIZE)
|
|
.unwrap();
|
|
self.unlocks.draw(unlocks_text, unlocks_pixel);
|
|
|
|
self.draw_bars(bars_text, bars_pixel);
|
|
}
|
|
|
|
fn draw_bars(
|
|
&self,
|
|
text_layer: WindowMut<char, CharGrid>,
|
|
pixel_layer: WindowMut<bool, Bitmap>,
|
|
) {
|
|
let (mut text_layer, mut pixel_layer) =
|
|
draw_border_panel(text_layer, pixel_layer, " Processes ", INNER_BORDER);
|
|
|
|
for row in self.state.rows.iter() {
|
|
let bar_window;
|
|
(bar_window, pixel_layer) = pixel_layer.split_vertical_mut(TILE_SIZE).unwrap();
|
|
let label_window;
|
|
(label_window, text_layer) = text_layer.split_vertical_mut(1).unwrap();
|
|
row.draw(label_window, bar_window);
|
|
}
|
|
}
|
|
}
|