-
Notifications
You must be signed in to change notification settings - Fork 424
/
super_simple.rs
46 lines (39 loc) · 1.04 KB
/
super_simple.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! The simplest possible example that does something.
extern crate ggez;
use ggez::conf;
use ggez::event;
use ggez::graphics::{self, DrawMode, Point2};
use ggez::{Context, GameResult};
struct MainState {
pos_x: f32,
}
impl MainState {
fn new(_ctx: &mut Context) -> GameResult<MainState> {
let s = MainState { pos_x: 0.0 };
Ok(s)
}
}
impl event::EventHandler for MainState {
fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
self.pos_x = self.pos_x % 800.0 + 1.0;
Ok(())
}
fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
graphics::clear(ctx);
graphics::circle(
ctx,
DrawMode::Fill,
Point2::new(self.pos_x, 380.0),
100.0,
2.0,
)?;
graphics::present(ctx);
Ok(())
}
}
pub fn main() {
let c = conf::Conf::new();
let ctx = &mut Context::load_from_conf("super_simple", "ggez", c).unwrap();
let state = &mut MainState::new(ctx).unwrap();
event::run(ctx, state).unwrap();
}