Added several method implementations for menu
This commit is contained in:
parent
c45cdd8573
commit
698b11855f
49
src/main.rs
49
src/main.rs
@ -4,6 +4,11 @@ struct State {
|
|||||||
mode: GameMode,
|
mode: GameMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Player {
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
velocity: f32,
|
||||||
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
fn new() -> State {
|
fn new() -> State {
|
||||||
@ -11,8 +16,46 @@ impl State {
|
|||||||
mode: GameMode::Menu,
|
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 {
|
enum GameMode {
|
||||||
Menu,
|
Menu,
|
||||||
@ -31,6 +74,8 @@ impl GameState for State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> BError {
|
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())
|
main_loop(context, State::new())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user