summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2021-01-31 05:52:40 -0600
committerTom Barrett <tom@tombarrett.xyz>2021-01-31 05:52:40 -0600
commitc3649aaded50f3ca34f489254729d5f91dc62c94 (patch)
tree81d04201c81e6c5cf255218a8f038efade1c81fa
parentbcc6223dc9804fabd6e82b900dcf3214168cc798 (diff)
start
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs47
2 files changed, 46 insertions, 2 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 2858233..9c0202e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,3 +7,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+ggez = "0.5.1"
diff --git a/src/main.rs b/src/main.rs
index e7a11a9..d295f3a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,46 @@
-fn main() {
- println!("Hello, world!");
+use ggez;
+use ggez::event;
+use ggez::graphics;
+use ggez::nalgebra as na;
+
+struct MainState {
+ pos_x: f32,
+}
+
+impl MainState {
+ fn new() -> ggez::GameResult<MainState> {
+ let s = MainState { pos_x: 0.0 };
+ Ok(s)
+ }
+}
+
+impl event::EventHandler for MainState {
+ fn update(&mut self, _ctx: &mut ggez::Context) -> ggez::GameResult {
+ self.pos_x = self.pos_x % 800.0 + 1.0;
+ Ok(())
+ }
+
+ fn draw(&mut self, ctx: &mut ggez::Context) -> ggez::GameResult {
+ graphics::clear(ctx, [0.1, 0.2, 0.3, 1.0].into());
+
+ let circle = graphics::Mesh::new_circle(
+ ctx,
+ graphics::DrawMode::fill(),
+ na::Point2::new(self.pos_x, 380.0),
+ 100.0,
+ 2.0,
+ graphics::WHITE,
+ )?;
+ graphics::draw(ctx, &circle, (na::Point2::new(0.0, 0.0),))?;
+
+ graphics::present(ctx)?;
+ Ok(())
+ }
+}
+
+pub fn main() -> ggez::GameResult {
+ let cb = ggez::ContextBuilder::new("super_simple", "ggez");
+ let (ctx, event_loop) = &mut cb.build()?;
+ let state = &mut MainState::new()?;
+ event::run(ctx, event_loop, state)
}