gdritter repos wenaglia / ad5e08d
rustfmt Getty Ritter 5 years ago
5 changed file(s) with 22 addition(s) and 18 deletion(s). Collapse all Expand all
1 use crate::types::World;
12 use specs::world::WorldExt;
23 use specs::{Component, NullStorage, VecStorage};
3 use crate::types::World;
44
55 /// Register all the components with the world.
66 pub fn register(world: &mut specs::World) {
121121 impl Blocking {
122122 /// create a `Blocking` component for an entity given a specified shape
123123 pub fn new_shape<S>(e: specs::Entity, w: &mut World, volume: S) -> Blocking
124 where S: ncollide2d::shape::Shape<f32>
124 where
125 S: ncollide2d::shape::Shape<f32>,
125126 {
126127 let (handle, _) = w.add(
127128 nalgebra::geometry::Isometry::identity(),
130131 ncollide2d::pipeline::object::GeometricQueryType::Proximity(0.0),
131132 e,
132133 );
133 Blocking {
134 handle,
135 }
134 Blocking { handle }
136135 }
137136
138137 /// create an 11pxx11px box for an entity
139138 pub fn new_box(e: specs::Entity, w: &mut World) -> Blocking {
140 Blocking::new_shape(e, w, ncollide2d::shape::Cuboid::new(nalgebra::Vector2::new(
141 11.0, 11.0,
142 )))
139 Blocking::new_shape(
140 e,
141 w,
142 ncollide2d::shape::Cuboid::new(nalgebra::Vector2::new(11.0, 11.0)),
143 )
143144 }
144145
145146 /// create a 11px ball for an entity
1 use ggez::event::EventHandler;
12 use ggez::{Context, GameResult};
2 use ggez::event::EventHandler;
33
44 use specs::world::WorldExt;
55
6 use crate::{components,resources,sys};
6 use crate::{components, resources, sys};
77
88 /// The shared values that the game state needs, specifically as the specs world
99 pub struct MyGame {
5151 if keycode == winit::VirtualKeyCode::Escape {
5252 ggez::event::quit(ctx);
5353 }
54 self.world.write_resource::<resources::KeySet>().insert(keycode);
54 self.world
55 .write_resource::<resources::KeySet>()
56 .insert(keycode);
5557 }
5658
5759 fn key_up_event(
6062 keycode: winit::VirtualKeyCode,
6163 _keymod: ggez::event::KeyMods,
6264 ) {
63 self.world.write_resource::<resources::KeySet>().remove(&keycode);
65 self.world
66 .write_resource::<resources::KeySet>()
67 .remove(&keycode);
6468 }
6569 }
99 pub mod types;
1010
1111 fn main() -> Result<(), ggez::error::GameError> {
12
1312 // Make a Context and an EventLoop.
1413 let (mut ctx, mut evloop) = ggez::ContextBuilder::new("game", "me")
1514 .add_resource_path({
5656 let y = y as f32 * consts::TILE_SIZE;
5757 let u = ((n - 1) % 32) as u8;
5858 let v = ((n - u as u32 - 1) / 32) as u8;
59 let is_blocking = tilesets[0].tiles[(n-1) as usize].properties["pass"]
59 let is_blocking = tilesets[0].tiles[(n - 1) as usize].properties["pass"]
6060 == consts::TILED_FALSE;
6161 let mut e = w
6262 .create_entity_unchecked()
8181 }
8282 }
8383
84 let e = w.create_entity_unchecked()
84 let e = w
85 .create_entity_unchecked()
8586 .with(Position {
8687 x: 3.0 * consts::TILE_SIZE,
8788 y: 3.0 * consts::TILE_SIZE,
99100 let mut h = w.write_resource::<World>();
100101 Blocking::new_ball(entity, &mut h)
101102 })
102 .build();
103 .build();
103104 }
3030 pos.clone()
3131 };
3232 let obj = w.get_mut(bl.handle).unwrap();
33 obj.set_position(
34 Isometry2::new(Vector2::new(np.x, np.y), nalgebra::zero()));
33 obj.set_position(Isometry2::new(Vector2::new(np.x, np.y), nalgebra::zero()));
3534 })
3635 .collect();
3736 w.update();