This commit is contained in:
Michael Zhang 2020-06-08 11:33:47 -05:00
parent 17dfebda6c
commit c9dac158ee
2 changed files with 31 additions and 13 deletions

View file

@ -70,5 +70,6 @@ fn main() {
target.finish().unwrap();
prev = now;
std::thread::sleep(std::time::Duration::from_millis(17));
}
}

View file

@ -15,8 +15,9 @@ const LEVEL_1: &str = include_str!("../../levels/level1.json");
pub struct PlayScreen {
animations: AnimationState,
levels: Vec<Level>,
current_level: usize,
levels: Vec<&'static str>,
current_level: Level,
current_level_idx: usize,
}
impl Screen for PlayScreen {
@ -61,6 +62,11 @@ impl Screen for PlayScreen {
btn_handler!(VirtualKeyCode::J, Board::Right, PushDir::Left);
btn_handler!(VirtualKeyCode::K, Board::Right, PushDir::Down);
btn_handler!(VirtualKeyCode::L, Board::Right, PushDir::Right);
if keymap.is_pressed(VirtualKeyCode::R) {
// restart the level
self.restart_level();
}
}
ScreenAction::None
@ -74,34 +80,45 @@ impl Screen for PlayScreen {
impl PlayScreen {
pub fn get_current_level(&self) -> &Level {
self.levels.get(self.current_level).unwrap()
&self.current_level
}
pub fn get_current_level_mut(&mut self) -> &mut Level {
self.levels.get_mut(self.current_level).unwrap()
&mut self.current_level
}
pub fn new() -> PlayScreen {
let levels = vec![
Level::from_json(&LEVEL_TUTORIAL),
Level::from_json(&LEVEL_TUTORIAL2),
Level::from_json(&LEVEL_1),
LEVEL_TUTORIAL,
LEVEL_TUTORIAL2,
LEVEL_1,
];
PlayScreen {
levels,
current_level: 0,
current_level: Level::from_json(&LEVEL_TUTORIAL),
current_level_idx: 0,
animations: AnimationState::new(),
}
}
fn go_to_next_level(&mut self) {
self.current_level += 1;
// TODO: make an actual win screen
if self.current_level >= self.levels.len() {
self.current_level = 0;
fn restart_level(&mut self) {
self.switch_to_level(self.current_level_idx);
}
fn switch_to_level(&mut self, idx: usize) {
self.current_level = Level::from_json(self.levels[idx]);
self.current_level_idx = idx;
}
fn go_to_next_level(&mut self) {
// TODO: make an actual win screen
let next_level = if self.current_level_idx + 1 >= self.levels.len() {
0
} else {
self.current_level_idx + 1
};
self.switch_to_level(next_level);
}
fn check_win_condition(&mut self) {