From 698b11855ff2555699d4c54beeef7c21bd7d0c6f Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Fri, 28 Jan 2022 12:04:30 +0100 Subject: [PATCH] Added several method implementations for menu --- src/main.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8b9b338..30ed70d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,11 @@ struct State { mode: GameMode, } +struct Player { + x: i32, + y: i32, + velocity: f32, +} impl State { fn new() -> State { @@ -11,8 +16,46 @@ impl State { mode: GameMode::Menu, } } -} + fn play(&mut self, ctx: &mut BTerm) { + self.mode = GameMode::End; + } + + fn restart(&mut self) { + self.mode = GameMode::Playing; + } + + fn main_menu(&mut self, ctx: &mut BTerm) { + ctx.cls(); + ctx.print_centered(5, "Welcome to Flappy Dragon"); + ctx.print_centered(8, "(P) Play Game"); + ctx.print_centered(9, "(Q) Quit Game"); + + if let Some(key) = ctx.key { + match key { + VirtualKeyCode::P => self.restart(), + VirtualKeyCode::Q => ctx.quitting = true, + _ => {} + } + } + } + + fn dead(&mut self, ctx: &mut BTerm) { + ctx.cls(); + + ctx.print_centered(5, "You are dead!"); + ctx.print_centered(8, "(P) Play Game"); + ctx.print_centered(9, "(Q) Quit Game"); + + if let Some(key) = ctx.key { + match key { + VirtualKeyCode::P => self.restart(), + VirtualKeyCode::Q => ctx.quitting = true, + _ => {} + } + } + } +} enum GameMode { Menu, @@ -31,6 +74,8 @@ impl GameState for State { } fn main() -> BError { - let context = BTermBuilder::simple80x50().with_title("Flappy Dragon").build()?; + let context = BTermBuilder::simple80x50() + .with_title("Flappy Dragon") + .build()?; main_loop(context, State::new()) }