Skip to content

Instantly share code, notes, and snippets.

@kennethlove
Created April 22, 2017 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennethlove/18fca313f2590d4da10f7d84e9cde6cc to your computer and use it in GitHub Desktop.
Save kennethlove/18fca313f2590d4da10f7d84e9cde6cc to your computer and use it in GitHub Desktop.
extern crate ggez;
use ggez::conf;
use ggez::event::*;
use ggez::{GameResult, Context};
use ggez::graphics;
use std::time::Duration;
struct MainState {}
impl MainState {
fn new(ctx: &mut Context) -> GameResult<MainState> {
println!("{:?}", ctx.filesystem);
let s = MainState {};
Ok(s)
}
}
impl EventHandler for MainState {
fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
graphics::clear(ctx);
Ok(())
}
fn update(&mut self, ctx: &mut Context, _dt: Duration) -> GameResult<()> {
graphics::clear(ctx);
Ok(())
}
fn key_down_event(&mut self, keycode: Keycode, _keymod: Mod, _repeat: bool) {
match keycode {
Keycode::Space => {
println!("Down!");
}
_ => (),
}
}
fn key_up_event(&mut self, keycode: Keycode, _keymod: Mod, _repeat: bool) {
match keycode {
Keycode::Space => {
println!("Up!");
}
_ => (),
}
}
}
fn main() {
let c = conf::Conf::new();
let ctx = &mut Context::load_from_conf("foo", "kd38", c).unwrap();
match MainState::new(ctx) {
Err(e) => {
println!("Could not load game!");
println!("Error: {}", e);
}
Ok(ref mut game) => {
let result = run(ctx, game);
if let Err(e) = result {
println!("Error: {}", e);
} else {
println!("Clean exit");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment