WorldSize

Struct WorldSize 

Source
pub struct WorldSize {
    pub width: i64,
    pub height: i64,
}
Expand description

A size in the world

Fields§

§width: i64§height: i64

Implementations§

Source§

impl WorldSize

Source

pub fn new(width: i64, height: i64) -> Self

Examples found in repository?
examples/simple.rs (line 16)
7fn main() {
8    let (width, height) = term_size().expect("Can't get the term size? Can't play the game!");
9
10    // Viewport
11    let viewport_size = ScreenSize::new(width / 2, height / 2);
12    let mut viewport = Viewport::new(ScreenPos::new(0, 4), viewport_size);
13
14    // Camera
15    let (width, height) = (width as i64, height as i64);
16    let camera_size = WorldSize::new(width / 2, height / 2);
17    let camera_pos = WorldPos::new(width, height);
18    let camera = Camera::new(camera_pos, camera_size);
19
20    // Renderer
21    let stdout_renderer = StdoutTarget::new().expect("Failed to enter raw mode");
22    let mut renderer = Renderer::new(stdout_renderer);
23
24    // Player
25    let mut player = ('@', camera_pos);
26
27    let (_, events) = events::<()>(EventModel::Fps(20));
28    for event in events {
29        match event {
30            Event::User(()) => {}
31            Event::Tick => {
32                let pixel = Pixel::new(player.0, camera.to_screen(player.1), None, None);
33                viewport.draw_pixel(pixel);
34                let _ = renderer.render(&mut viewport);
35                viewport.swap_buffers();
36            }
37            Event::Key(KeyEvent { code: KeyCode::Esc, ..  }) => break,
38            Event::Key(KeyEvent { code: kc, .. }) => {
39                match kc {
40                    KeyCode::Left => { player.1.x -= 1; }
41                    KeyCode::Right => { player.1.x += 1; }
42                    KeyCode::Up => { player.1.y -= 1; }
43                    KeyCode::Down => { player.1.y += 1; }
44                    _ => {}
45                }
46            }
47            Event::Resize(_w, _h) => {}
48        }
49    }
50}

Trait Implementations§

Source§

impl Clone for WorldSize

Source§

fn clone(&self) -> WorldSize

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WorldSize

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for WorldSize

Source§

fn eq(&self, other: &WorldSize) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for WorldSize

Source§

impl StructuralPartialEq for WorldSize

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.