e-dt 4 years ago
parent
commit
837c74f7b8
  1. 23
      src/main.rs

23
src/main.rs

@ -1,7 +1,6 @@
use ggez::{Context, ContextBuilder, GameResult};
use ggez::graphics::{self, Color, Mesh, MeshBuilder, DrawMode};
use ggez::event::{self, EventHandler}; use ggez::event::{self, EventHandler};
use ggez::graphics::{self, Color, DrawMode, Mesh, MeshBuilder};
use ggez::{Context, ContextBuilder, GameResult};
struct Apr { struct Apr {
grid: Mesh, grid: Mesh,
@ -20,14 +19,19 @@ fn make_grid(ctx : &mut Context, r: i32, c: i32) -> GameResult<Mesh> {
let mut colour = start_white; let mut colour = start_white;
for col in 0..c { for col in 0..c {
builder.rectangle( builder.rectangle(
if colour { DrawMode::stroke(1.0) } else { DrawMode::fill() }, if colour {
DrawMode::stroke(1.0)
} else {
DrawMode::fill()
},
graphics::Rect { graphics::Rect {
x: start_x + (size * col as f32), x: start_x + (size * col as f32),
y: start_y + (size * row as f32), y: start_y + (size * row as f32),
w: size, w: size,
h : size h: size,
}, },
Color::BLACK)?; Color::BLACK,
)?;
colour = !colour; colour = !colour;
} }
start_white = !start_white; start_white = !start_white;
@ -40,18 +44,13 @@ impl Apr {
pub fn new(_ctx: &mut Context) -> Apr { pub fn new(_ctx: &mut Context) -> Apr {
// Load/create resources such as images here. // Load/create resources such as images here.
Apr { Apr {
grid : make_grid(_ctx, 8, 8).unwrap() grid: make_grid(_ctx, 8, 8).unwrap(),
} }
} }
} }
impl EventHandler for Apr { impl EventHandler for Apr {
fn update(&mut self, _ctx: &mut Context) -> GameResult<()> { fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
// Err(ggez::GameError::CustomError("You done messed up trying to play this game!".to_string())) // Err(ggez::GameError::CustomError("You done messed up trying to play this game!".to_string()))
// Update code here... // Update code here...
Ok(()) Ok(())

Loading…
Cancel
Save