rustfmt
Getty Ritter
5 years ago
| 1 |
use crate::types::World;
|
1 | 2 |
use specs::world::WorldExt;
|
2 | 3 |
use specs::{Component, NullStorage, VecStorage};
|
3 | |
use crate::types::World;
|
4 | 4 |
|
5 | 5 |
/// Register all the components with the world.
|
6 | 6 |
pub fn register(world: &mut specs::World) {
|
|
121 | 121 |
impl Blocking {
|
122 | 122 |
/// create a `Blocking` component for an entity given a specified shape
|
123 | 123 |
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>,
|
125 | 126 |
{
|
126 | 127 |
let (handle, _) = w.add(
|
127 | 128 |
nalgebra::geometry::Isometry::identity(),
|
|
130 | 131 |
ncollide2d::pipeline::object::GeometricQueryType::Proximity(0.0),
|
131 | 132 |
e,
|
132 | 133 |
);
|
133 | |
Blocking {
|
134 | |
handle,
|
135 | |
}
|
| 134 |
Blocking { handle }
|
136 | 135 |
}
|
137 | 136 |
|
138 | 137 |
/// create an 11pxx11px box for an entity
|
139 | 138 |
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 |
)
|
143 | 144 |
}
|
144 | 145 |
|
145 | 146 |
/// create a 11px ball for an entity
|
| 1 |
use ggez::event::EventHandler;
|
1 | 2 |
use ggez::{Context, GameResult};
|
2 | |
use ggez::event::EventHandler;
|
3 | 3 |
|
4 | 4 |
use specs::world::WorldExt;
|
5 | 5 |
|
6 | |
use crate::{components,resources,sys};
|
| 6 |
use crate::{components, resources, sys};
|
7 | 7 |
|
8 | 8 |
/// The shared values that the game state needs, specifically as the specs world
|
9 | 9 |
pub struct MyGame {
|
|
51 | 51 |
if keycode == winit::VirtualKeyCode::Escape {
|
52 | 52 |
ggez::event::quit(ctx);
|
53 | 53 |
}
|
54 | |
self.world.write_resource::<resources::KeySet>().insert(keycode);
|
| 54 |
self.world
|
| 55 |
.write_resource::<resources::KeySet>()
|
| 56 |
.insert(keycode);
|
55 | 57 |
}
|
56 | 58 |
|
57 | 59 |
fn key_up_event(
|
|
60 | 62 |
keycode: winit::VirtualKeyCode,
|
61 | 63 |
_keymod: ggez::event::KeyMods,
|
62 | 64 |
) {
|
63 | |
self.world.write_resource::<resources::KeySet>().remove(&keycode);
|
| 65 |
self.world
|
| 66 |
.write_resource::<resources::KeySet>()
|
| 67 |
.remove(&keycode);
|
64 | 68 |
}
|
65 | 69 |
}
|
9 | 9 |
pub mod types;
|
10 | 10 |
|
11 | 11 |
fn main() -> Result<(), ggez::error::GameError> {
|
12 | |
|
13 | 12 |
// Make a Context and an EventLoop.
|
14 | 13 |
let (mut ctx, mut evloop) = ggez::ContextBuilder::new("game", "me")
|
15 | 14 |
.add_resource_path({
|
56 | 56 |
let y = y as f32 * consts::TILE_SIZE;
|
57 | 57 |
let u = ((n - 1) % 32) as u8;
|
58 | 58 |
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"]
|
60 | 60 |
== consts::TILED_FALSE;
|
61 | 61 |
let mut e = w
|
62 | 62 |
.create_entity_unchecked()
|
|
81 | 81 |
}
|
82 | 82 |
}
|
83 | 83 |
|
84 | |
let e = w.create_entity_unchecked()
|
| 84 |
let e = w
|
| 85 |
.create_entity_unchecked()
|
85 | 86 |
.with(Position {
|
86 | 87 |
x: 3.0 * consts::TILE_SIZE,
|
87 | 88 |
y: 3.0 * consts::TILE_SIZE,
|
|
99 | 100 |
let mut h = w.write_resource::<World>();
|
100 | 101 |
Blocking::new_ball(entity, &mut h)
|
101 | 102 |
})
|
102 | |
.build();
|
| 103 |
.build();
|
103 | 104 |
}
|
30 | 30 |
pos.clone()
|
31 | 31 |
};
|
32 | 32 |
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()));
|
35 | 34 |
})
|
36 | 35 |
.collect();
|
37 | 36 |
w.update();
|