pub struct Entity {
pub pos: Pnt,
pub frames: Vec<Vec<u32>>,
pub dim: (usize, usize),
pub anim_rate: (usize, usize),
/* private fields */
}Fields§
§pos: Pnt§frames: Vec<Vec<u32>>§dim: (usize, usize)§anim_rate: (usize, usize)Implementations§
Source§impl Entity
impl Entity
Sourcepub fn new(
pos: Pnt,
frames: Vec<Vec<u32>>,
dim: (usize, usize),
anim_rate: usize,
) -> Self
pub fn new( pos: Pnt, frames: Vec<Vec<u32>>, dim: (usize, usize), anim_rate: usize, ) -> Self
Examples found in repository?
examples/simple.rs (line 14)
3fn main() -> FigResult<()> {
4 // Initialize the canvas and input
5 let mut canvas = Canvas::new("simple example", (320, 320), 60)?;
6 let mut input = InputManager::new();
7
8 // Load assets from assets.tgz
9 let mut assets = AssetLoader::from_tar("examples/assets.tgz");
10 // You can also load assets from the assets directory
11 // let mut assets = AssetLoader::from_dir("examples/assets");
12
13 // Create some entities, using assets from the tarball
14 let mut bop = Entity::new((200.0, 200.0), vec![assets.load_png("bop.png")?], (8, 8), 20);
15 let mut blob = Entity::new((100.0, 100.0), assets.load_png_dir("blob")?, (8, 8), 20);
16
17 // We want to control blob with WASD or arrow keys
18 input.wasd();
19 input.arrows();
20
21 // We would also like to exit when ESC is pressed
22 input.add(Key::Escape);
23
24 // Main event loop (do something more interesting here)
25 while canvas.is_open() {
26 // Handle keypress events
27 for key in &input.keys {
28 if canvas.key_down(*key) {
29 match key {
30 Key::W | Key::Up => blob.mov(0.0, -1.0),
31 Key::A | Key::Left => blob.mov(-1.0, 0.0),
32 Key::S | Key::Down => blob.mov(0.0, 1.0),
33 Key::D | Key::Right => blob.mov(1.0, 0.0),
34 Key::Escape => return Ok(()),
35 _ => (),
36 }
37 }
38 }
39
40 // Update entities (advance animation, etc)
41 bop.update();
42 blob.update();
43
44 // Update the canvas with the entities
45 canvas.clear();
46 canvas.draw(&bop);
47 canvas.draw(&blob);
48 canvas.update()?;
49 }
50
51 Ok(())
52}pub fn next_frame(&mut self)
pub fn get_frame(&self) -> Vec<u32>
Sourcepub fn mov(&mut self, dx: f32, dy: f32)
pub fn mov(&mut self, dx: f32, dy: f32)
Examples found in repository?
examples/simple.rs (line 30)
3fn main() -> FigResult<()> {
4 // Initialize the canvas and input
5 let mut canvas = Canvas::new("simple example", (320, 320), 60)?;
6 let mut input = InputManager::new();
7
8 // Load assets from assets.tgz
9 let mut assets = AssetLoader::from_tar("examples/assets.tgz");
10 // You can also load assets from the assets directory
11 // let mut assets = AssetLoader::from_dir("examples/assets");
12
13 // Create some entities, using assets from the tarball
14 let mut bop = Entity::new((200.0, 200.0), vec![assets.load_png("bop.png")?], (8, 8), 20);
15 let mut blob = Entity::new((100.0, 100.0), assets.load_png_dir("blob")?, (8, 8), 20);
16
17 // We want to control blob with WASD or arrow keys
18 input.wasd();
19 input.arrows();
20
21 // We would also like to exit when ESC is pressed
22 input.add(Key::Escape);
23
24 // Main event loop (do something more interesting here)
25 while canvas.is_open() {
26 // Handle keypress events
27 for key in &input.keys {
28 if canvas.key_down(*key) {
29 match key {
30 Key::W | Key::Up => blob.mov(0.0, -1.0),
31 Key::A | Key::Left => blob.mov(-1.0, 0.0),
32 Key::S | Key::Down => blob.mov(0.0, 1.0),
33 Key::D | Key::Right => blob.mov(1.0, 0.0),
34 Key::Escape => return Ok(()),
35 _ => (),
36 }
37 }
38 }
39
40 // Update entities (advance animation, etc)
41 bop.update();
42 blob.update();
43
44 // Update the canvas with the entities
45 canvas.clear();
46 canvas.draw(&bop);
47 canvas.draw(&blob);
48 canvas.update()?;
49 }
50
51 Ok(())
52}Sourcepub fn update(&mut self)
pub fn update(&mut self)
Examples found in repository?
examples/simple.rs (line 41)
3fn main() -> FigResult<()> {
4 // Initialize the canvas and input
5 let mut canvas = Canvas::new("simple example", (320, 320), 60)?;
6 let mut input = InputManager::new();
7
8 // Load assets from assets.tgz
9 let mut assets = AssetLoader::from_tar("examples/assets.tgz");
10 // You can also load assets from the assets directory
11 // let mut assets = AssetLoader::from_dir("examples/assets");
12
13 // Create some entities, using assets from the tarball
14 let mut bop = Entity::new((200.0, 200.0), vec![assets.load_png("bop.png")?], (8, 8), 20);
15 let mut blob = Entity::new((100.0, 100.0), assets.load_png_dir("blob")?, (8, 8), 20);
16
17 // We want to control blob with WASD or arrow keys
18 input.wasd();
19 input.arrows();
20
21 // We would also like to exit when ESC is pressed
22 input.add(Key::Escape);
23
24 // Main event loop (do something more interesting here)
25 while canvas.is_open() {
26 // Handle keypress events
27 for key in &input.keys {
28 if canvas.key_down(*key) {
29 match key {
30 Key::W | Key::Up => blob.mov(0.0, -1.0),
31 Key::A | Key::Left => blob.mov(-1.0, 0.0),
32 Key::S | Key::Down => blob.mov(0.0, 1.0),
33 Key::D | Key::Right => blob.mov(1.0, 0.0),
34 Key::Escape => return Ok(()),
35 _ => (),
36 }
37 }
38 }
39
40 // Update entities (advance animation, etc)
41 bop.update();
42 blob.update();
43
44 // Update the canvas with the entities
45 canvas.clear();
46 canvas.draw(&bop);
47 canvas.draw(&blob);
48 canvas.update()?;
49 }
50
51 Ok(())
52}Auto Trait Implementations§
impl Freeze for Entity
impl RefUnwindSafe for Entity
impl Send for Entity
impl Sync for Entity
impl Unpin for Entity
impl UnsafeUnpin for Entity
impl UnwindSafe for Entity
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more