extern crate ggez;
use ggez::conf;
use ggez::game::{Game, GameState};
use ggez::{GameResult, Context};
use ggez::graphics;
use ggez::timer;
use std::time::Duration;
struct MainState {
text: graphics::Text,
}
impl GameState for MainState {
fn load(ctx: &mut Context, _conf: &conf::Conf) -> GameResult<MainState> {
let font = graphics::Font::new(ctx, "DejaVuSerif.ttf", 48).unwrap();
let text = graphics::Text::new(ctx, "Hello world!", &font).unwrap();
let s = MainState { text: text };
Ok(s)
}
fn update(&mut self, _ctx: &mut Context, _dt: Duration) -> GameResult<()> {
Ok(())
}
fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
ctx.renderer.clear();
try!(graphics::draw(ctx, &mut self.text, None, None));
ctx.renderer.present();
timer::sleep_until_next_frame(ctx, 60);
Ok(())
}
}
pub fn main() {
let c = conf::Conf::new();
let mut game: Game<MainState> = Game::new("helloworld", c).unwrap();
if let Err(e) = game.run() {
println!("Error encountered: {:?}", e);
} else {
println!("Game exited cleanly.");
}
}