restructure with windows
This commit is contained in:
parent
fe4543ae41
commit
64f4ea529a
7 changed files with 68 additions and 130 deletions
69
src/game.rs
69
src/game.rs
|
|
@ -1,14 +1,13 @@
|
|||
use crate::bar::Bar;
|
||||
use crate::queue::PacketQueue;
|
||||
use crate::label::Label;
|
||||
use crate::{Currency, GenerateCommands, Progressable};
|
||||
use servicepoint::{Origin, TILE_WIDTH};
|
||||
use crate::{
|
||||
bar::Bar,
|
||||
Currency,
|
||||
Progressable
|
||||
};
|
||||
use servicepoint::{Bitmap, CharGrid, CharGridMutExt, WindowMut, TILE_SIZE};
|
||||
use std::time::Duration;
|
||||
|
||||
const STEP_COUNT: usize = 11;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Game {
|
||||
pub struct Game<const STEP_COUNT:usize=11> {
|
||||
pub(crate) currency: Currency,
|
||||
pub(crate) bars: [Bar; STEP_COUNT],
|
||||
pub(crate) names: [&'static str; STEP_COUNT],
|
||||
|
|
@ -19,17 +18,17 @@ impl Game {
|
|||
Self {
|
||||
currency: 0f64,
|
||||
bars: [
|
||||
Bar::new(1f64, Origin::new(0, 1)).add_speed(1.0),
|
||||
Bar::new(2f64, Origin::new(0, 2)).add_speed(0.5),
|
||||
Bar::new(4f64, Origin::new(0, 3)).add_speed(0.25),
|
||||
Bar::new(8f64, Origin::new(0, 4)).add_speed(0.125),
|
||||
Bar::new(16f64, Origin::new(0, 5)).add_speed(0.0625),
|
||||
Bar::new(32f64, Origin::new(0, 6)).add_speed(0.03125),
|
||||
Bar::new(64f64, Origin::new(0, 7)).add_speed(0.015625),
|
||||
Bar::new(128f64, Origin::new(0, 8)).add_speed(0.0078125),
|
||||
Bar::new(256f64, Origin::new(0, 9)).add_speed(0.00390625),
|
||||
Bar::new(512f64, Origin::new(0, 10)).add_speed(0.001953125),
|
||||
Bar::new(1024f64, Origin::new(0, 11)).add_speed(0.000976562),
|
||||
Bar::new(1f64,1.0),
|
||||
Bar::new(2f64, 0.5),
|
||||
Bar::new(4f64, 0.25),
|
||||
Bar::new(8f64,0.125),
|
||||
Bar::new(16f64, 0.0625),
|
||||
Bar::new(32f64, 0.03125),
|
||||
Bar::new(64f64, 0.015625),
|
||||
Bar::new(128f64, 0.0078125),
|
||||
Bar::new(256f64, 0.00390625),
|
||||
Bar::new(512f64, 0.001953125),
|
||||
Bar::new(1024f64,0.000976562),
|
||||
],
|
||||
names: [
|
||||
"Powering infrastructure",
|
||||
|
|
@ -68,28 +67,26 @@ impl Progressable for Game {
|
|||
}
|
||||
}
|
||||
|
||||
impl GenerateCommands for Game {
|
||||
fn generate_commands(&self, queue: &mut impl PacketQueue) {
|
||||
Label::new(Origin::ZERO, TILE_WIDTH / 2, "Discordia Boot Procedure")
|
||||
.generate_commands(queue);
|
||||
Label::new(
|
||||
Origin::new(TILE_WIDTH / 2 + 1, 0),
|
||||
TILE_WIDTH / 2,
|
||||
format!("Cycles: {}", self.currency.floor()),
|
||||
)
|
||||
.generate_commands(queue);
|
||||
impl Game {
|
||||
pub fn draw(&self, text_layer: &mut WindowMut<char, CharGrid>, pixel_layer: &mut WindowMut<bool, Bitmap>) {
|
||||
text_layer.set_row_str(0, "Discordia Boot Procedure").unwrap();
|
||||
let middle = text_layer.width() / 2;
|
||||
text_layer.window_mut( middle, 0, middle, 1)
|
||||
.unwrap()
|
||||
.set_row_str(0, &format!(" Cycles: {}", self.currency.floor()))
|
||||
.unwrap();
|
||||
|
||||
for (index, bar) in self.bars.iter().enumerate() {
|
||||
let row = 1 + index;
|
||||
let mut bar_window = pixel_layer.window_mut(0, row * TILE_SIZE, pixel_layer.width() / 2, TILE_SIZE).unwrap();
|
||||
let mut label_window = text_layer.window_mut(middle, row, middle, 1).unwrap();
|
||||
|
||||
if !bar.is_enabled() {
|
||||
continue;
|
||||
}
|
||||
bar.generate_commands(queue);
|
||||
Label::new(
|
||||
Origin::new(TILE_WIDTH / 2 + 1, 1 + index),
|
||||
TILE_WIDTH / 2 - 1,
|
||||
self.names[index],
|
||||
)
|
||||
.generate_commands(queue);
|
||||
|
||||
bar.draw(&mut bar_window);
|
||||
label_window.set_row_str(0, self.names[index]).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue