Skip to content

Commit

Permalink
ran rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Object905 committed Aug 4, 2017
1 parent 5960c1b commit b8cc8fa
Show file tree
Hide file tree
Showing 18 changed files with 746 additions and 560 deletions.
47 changes: 27 additions & 20 deletions examples/astroblasto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extern crate rand;
use ggez::audio;
use ggez::conf;
use ggez::event::*;
use ggez::{GameResult, Context};
use ggez::{Context, GameResult};
use ggez::graphics;
use ggez::timer;
use std::time::Duration;
Expand Down Expand Up @@ -321,13 +321,13 @@ impl Assets {
let shot_sound = audio::Source::new(ctx, "/pew.ogg")?;
let hit_sound = audio::Source::new(ctx, "/boom.ogg")?;
Ok(Assets {
player_image: player_image,
shot_image: shot_image,
rock_image: rock_image,
font: font,
shot_sound: shot_sound,
hit_sound: hit_sound,
})
player_image: player_image,
shot_image: shot_image,
rock_image: rock_image,
font: font,
shot_sound: shot_sound,
hit_sound: hit_sound,
})
}

fn actor_image(&mut self, actor: &Actor) -> &mut graphics::Image {
Expand Down Expand Up @@ -500,11 +500,12 @@ fn print_instructions() {
}


fn draw_actor(assets: &mut Assets,
ctx: &mut Context,
actor: &Actor,
world_coords: (u32, u32))
-> GameResult<()> {
fn draw_actor(
assets: &mut Assets,
ctx: &mut Context,
actor: &Actor,
world_coords: (u32, u32),
) -> GameResult<()> {
let (screen_w, screen_h) = world_coords;
let pos = world_to_screen_coords(screen_w, screen_h, &actor.pos);
// let pos = Vec2::new(1.0, 1.0);
Expand Down Expand Up @@ -539,9 +540,11 @@ impl EventHandler for MainState {
// Update the physics for all actors.
// First the player...
update_actor_position(&mut self.player, seconds);
wrap_actor_position(&mut self.player,
self.screen_width as f64,
self.screen_height as f64);
wrap_actor_position(
&mut self.player,
self.screen_width as f64,
self.screen_height as f64,
);

// Then the shots...
for act in &mut self.shots {
Expand Down Expand Up @@ -607,10 +610,14 @@ impl EventHandler for MainState {


// And draw the GUI elements in the right places.
let level_dest = graphics::Point::new((self.level_display.width() / 2) as f32 + 10.0,
(self.level_display.height() / 2) as f32 + 10.0);
let score_dest = graphics::Point::new((self.score_display.width() / 2) as f32 + 200.0,
(self.score_display.height() / 2) as f32 + 10.0);
let level_dest = graphics::Point::new(
(self.level_display.width() / 2) as f32 + 10.0,
(self.level_display.height() / 2) as f32 + 10.0,
);
let score_dest = graphics::Point::new(
(self.score_display.width() / 2) as f32 + 200.0,
(self.score_display.height() / 2) as f32 + 10.0,
);
// let source_rect = graphics::Rect::one();
graphics::draw(ctx, &self.level_display, level_dest, 0.0)?;
graphics::draw(ctx, &self.score_display, score_dest, 0.0)?;
Expand Down
80 changes: 41 additions & 39 deletions examples/cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use gfx::Factory;

use ggez::conf;
use ggez::event;
use ggez::{GameResult, Context};
use ggez::{Context, GameResult};
use ggez::graphics;
use std::time::Duration;

Expand Down Expand Up @@ -109,37 +109,38 @@ void main() {

let vertex_data = [
// top (0, 0, 1)
Vertex::new([-100, -100, 100], [0, 0]),
Vertex::new([ 100, -100, 100], [1, 0]),
Vertex::new([ 100, 100, 100], [1, 1]),
Vertex::new([-100, 100, 100], [0, 1]),
Vertex::new([-100, -100, 100], [0, 0]),
Vertex::new([100, -100, 100], [1, 0]),
Vertex::new([100, 100, 100], [1, 1]),
Vertex::new([-100, 100, 100], [0, 1]),
// bottom (0, 0, -1)
Vertex::new([-100, 100, -100], [1, 0]),
Vertex::new([ 100, 100, -100], [0, 0]),
Vertex::new([ 100, -100, -100], [0, 1]),
Vertex::new([-100, 100, -100], [1, 0]),
Vertex::new([100, 100, -100], [0, 0]),
Vertex::new([100, -100, -100], [0, 1]),
Vertex::new([-100, -100, -100], [1, 1]),
// right (1, 0, 0)
Vertex::new([ 100, -100, -100], [0, 0]),
Vertex::new([ 100, 100, -100], [1, 0]),
Vertex::new([ 100, 100, 100], [1, 1]),
Vertex::new([ 100, -100, 100], [0, 1]),
Vertex::new([100, -100, -100], [0, 0]),
Vertex::new([100, 100, -100], [1, 0]),
Vertex::new([100, 100, 100], [1, 1]),
Vertex::new([100, -100, 100], [0, 1]),
// left (-1, 0, 0)
Vertex::new([-100, -100, 100], [1, 0]),
Vertex::new([-100, 100, 100], [0, 0]),
Vertex::new([-100, 100, -100], [0, 1]),
Vertex::new([-100, -100, 100], [1, 0]),
Vertex::new([-100, 100, 100], [0, 0]),
Vertex::new([-100, 100, -100], [0, 1]),
Vertex::new([-100, -100, -100], [1, 1]),
// front (0, 1, 0)
Vertex::new([ 100, 100, -100], [1, 0]),
Vertex::new([-100, 100, -100], [0, 0]),
Vertex::new([-100, 100, 100], [0, 1]),
Vertex::new([ 100, 100, 100], [1, 1]),
Vertex::new([100, 100, -100], [1, 0]),
Vertex::new([-100, 100, -100], [0, 0]),
Vertex::new([-100, 100, 100], [0, 1]),
Vertex::new([100, 100, 100], [1, 1]),
// back (0, -1, 0)
Vertex::new([ 100, -100, 100], [0, 0]),
Vertex::new([-100, -100, 100], [1, 0]),
Vertex::new([100, -100, 100], [0, 0]),
Vertex::new([-100, -100, 100], [1, 0]),
Vertex::new([-100, -100, -100], [1, 1]),
Vertex::new([ 100, -100, -100], [0, 1]),
Vertex::new([100, -100, -100], [0, 1]),
];

#[cfg_attr(rustfmt, rustfmt_skip)]
let index_data: &[u16] = &[
0, 1, 2, 2, 3, 0, // top
4, 5, 6, 6, 7, 4, // bottom
Expand All @@ -152,21 +153,19 @@ void main() {
let (vbuf, slice) = factory.create_vertex_buffer_with_slice(&vertex_data, index_data);

let texels = [[0x20, 0xA0, 0xC0, 0x00]];
let (_, texture_view) = factory.create_texture_immutable::<gfx::format::Rgba8>(
texture::Kind::D2(1, 1, texture::AaMode::Single), &[&texels]
).unwrap();
let (_, texture_view) = factory
.create_texture_immutable::<gfx::format::Rgba8>(
texture::Kind::D2(1, 1, texture::AaMode::Single),
&[&texels],
)
.unwrap();

let sinfo = texture::SamplerInfo::new(
texture::FilterMethod::Bilinear,
texture::WrapMode::Clamp);
let sinfo =
texture::SamplerInfo::new(texture::FilterMethod::Bilinear, texture::WrapMode::Clamp);

let pso = factory.create_pipeline_simple(
vs,
fs,
pipe::new()
).unwrap();
let pso = factory.create_pipeline_simple(vs, fs, pipe::new()).unwrap();

let proj = cgmath::perspective(Deg(45.0f32), 4.0/3.0, 1.0, 10.0);
let proj = cgmath::perspective(Deg(45.0f32), 4.0 / 3.0, 1.0, 10.0);

let data = pipe::Data {
vbuf: vbuf,
Expand All @@ -182,7 +181,6 @@ void main() {
let s = MainState {
text: text,
frames: 0,

data: data,
pso: pso,
encoder: encoder,
Expand All @@ -199,8 +197,10 @@ impl event::EventHandler for MainState {
}

fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
let dest_point = graphics::Point::new(self.text.width() as f32 / 2.0 + 10.0,
self.text.height() as f32 / 2.0 + 10.0);
let dest_point = graphics::Point::new(
self.text.width() as f32 / 2.0 + 10.0,
self.text.height() as f32 / 2.0 + 10.0,
);
// self.encoder.clear(&self.data.out_color, [0.3, 0.2, 0.1, 1.0].into());
// self.encoder.draw(&self.slice, &self.pso, &self.data);
// self.encoder.flush(ctx.gfx_context.get_device());
Expand All @@ -212,8 +212,10 @@ impl event::EventHandler for MainState {
}


let dest_point = graphics::Point::new(self.text.width() as f32 / 2.0 + 10.0,
self.text.height() as f32 / 2.0 + 10.0);
let dest_point = graphics::Point::new(
self.text.width() as f32 / 2.0 + 10.0,
self.text.height() as f32 / 2.0 + 10.0,
);
graphics::draw(ctx, &self.text, dest_point, 0.0)?;
graphics::present(ctx);
self.frames += 1;
Expand Down
76 changes: 41 additions & 35 deletions examples/drawing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate ggez;
use ggez::conf;
use ggez::event;
use ggez::{GameResult, Context};
use ggez::{Context, GameResult};
use ggez::graphics;
use ggez::graphics::{DrawMode, Point};
use std::time::Duration;
Expand Down Expand Up @@ -48,28 +48,32 @@ impl event::EventHandler for MainState {
let scale = graphics::Point::new(40.0, 40.0);
// let shear = graphics::Point::new(self.zoomlevel, self.zoomlevel);
// graphics::set_color(ctx, graphics::Color::new(1.0, 1.0, 1.0, 1.0));
graphics::draw_ex(ctx,
&self.image2_linear,
graphics::DrawParam {
// src: src,
dest: dst,
rotation: self.zoomlevel,
// offset: Point::new(-16.0, 0.0),
scale: scale,
// shear: shear,
..Default::default()
})?;
graphics::draw_ex(ctx,
&self.image2_nearest,
graphics::DrawParam {
// src: src,
dest: dst2,
rotation: self.zoomlevel,
// offset: Point::new(-16.0, 0.0),
scale: scale,
// shear: shear,
..Default::default()
})?;
graphics::draw_ex(
ctx,
&self.image2_linear,
graphics::DrawParam {
// src: src,
dest: dst,
rotation: self.zoomlevel,
// offset: Point::new(-16.0, 0.0),
scale: scale,
// shear: shear,
..Default::default()
},
)?;
graphics::draw_ex(
ctx,
&self.image2_nearest,
graphics::DrawParam {
// src: src,
dest: dst2,
rotation: self.zoomlevel,
// offset: Point::new(-16.0, 0.0),
scale: scale,
// shear: shear,
..Default::default()
},
)?;

let rect = graphics::Rect::new(450.0, 450.0, 50.0, 50.0);
graphics::rectangle(ctx, graphics::DrawMode::Fill, rect)?;
Expand All @@ -81,19 +85,21 @@ impl event::EventHandler for MainState {
graphics::set_color(ctx, graphics::WHITE)?;

graphics::set_line_width(ctx, 4.0);
graphics::line(ctx,
&[Point { x: 200.0, y: 200.0 },
Point { x: 400.0, y: 200.0 },
Point { x: 400.0, y: 400.0 },
Point { x: 200.0, y: 400.0 },
Point { x: 200.0, y: 200.0 }])?;
graphics::line(
ctx,
&[Point { x: 200.0, y: 200.0 }, Point { x: 400.0, y: 200.0 },
Point { x: 400.0, y: 400.0 }, Point { x: 200.0, y: 400.0 },
Point { x: 200.0, y: 200.0 }],
)?;

graphics::ellipse(ctx,
DrawMode::Fill,
Point { x: 600.0, y: 200.0 },
50.0,
120.0,
32)?;
graphics::ellipse(
ctx,
DrawMode::Fill,
Point { x: 600.0, y: 200.0 },
50.0,
120.0,
32,
)?;

graphics::circle(ctx, DrawMode::Fill, Point { x: 600.0, y: 380.0 }, 40.0, 32)?;

Expand Down
8 changes: 5 additions & 3 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate ggez;
use ggez::conf;
use ggez::event;
use ggez::{GameResult, Context};
use ggez::{Context, GameResult};
use ggez::graphics;
use std::time::Duration;

Expand Down Expand Up @@ -38,8 +38,10 @@ impl event::EventHandler for MainState {
fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
graphics::clear(ctx);
// Drawables are drawn from their center.
let dest_point = graphics::Point::new(self.text.width() as f32 / 2.0 + 10.0,
self.text.height() as f32 / 2.0 + 10.0);
let dest_point = graphics::Point::new(
self.text.width() as f32 / 2.0 + 10.0,
self.text.height() as f32 / 2.0 + 10.0,
);
graphics::draw(ctx, &self.text, dest_point, 0.0)?;
graphics::present(ctx);
self.frames += 1;
Expand Down
6 changes: 3 additions & 3 deletions examples/imageview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate sdl2;
use ggez::audio;
use ggez::conf;
use ggez::event;
use ggez::{GameResult, Context};
use ggez::{Context, GameResult};
use ggez::graphics;
use ggez::graphics::Color;
use ggez::timer;
Expand Down Expand Up @@ -54,8 +54,8 @@ impl MainState {

let font = graphics::Font::new(ctx, "/DejaVuSerif.ttf", 48).unwrap();
let text = graphics::Text::new(ctx, "Hello world!", &font).unwrap();
let bmpfont = graphics::Font::new_bitmap(ctx, "/arial.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
.unwrap();
let bmpfont =
graphics::Font::new_bitmap(ctx, "/arial.png", "ABCDEFGHIJKLMNOPQRSTUVWXYZ").unwrap();
let bmptext = graphics::Text::new(ctx, "ZYXWVYTSRQPONMLKJIHGFEDCBA", &bmpfont).unwrap();
let sound = audio::Source::new(ctx, "/sound.ogg").unwrap();

Expand Down
Loading

0 comments on commit b8cc8fa

Please sign in to comment.