[][src]Struct block_breaker::GameState

pub struct GameState { /* fields omitted */ }

Struct to store the game items

Stored items include: ball, bar and blocks as well as game dimensions and paused state

Methods

impl GameState[src]

pub fn new(width: u16, height: u16, block_density: f64) -> GameState[src]

Create a new GameState struct. Uses width and height to set the game dimensions and along with block_density generate the blocks in the game. Generation of the blocks uses some padding around the game_dimensions so blocks aren't too close to the edge.

pub fn update_dimensions(&mut self, width: u16, height: u16)[src]

Updates the dimensions of the game, triggering updates to the bar and ball too

pub fn bar_mut(&mut self) -> &mut Bar[src]

Retrieve a mutable reference to the bar

pub fn bar(&self) -> &Bar[src]

Retrieve an immutable reference to the bar

pub fn ball_mut(&mut self) -> &mut Ball[src]

Retrieve a mutable reference to the ball

pub fn ball(&self) -> &Ball[src]

Retrieve an immutable reference to the ball

pub fn blocks(&self) -> &[Block][src]

Retrieve a slice of the blocks

pub fn width(&self) -> u16[src]

Retrieve the game width

pub fn height(&self) -> u16[src]

Retrieve the game height

pub fn tick(&mut self)[src]

Tick the game state

This checks if the game is paused or over and if not causes the game to take a tick. This means updating the position of the ball by one step and checking for collisions of the ball with the blocks or the bar. If there is a collision then the ball's velocity is updated for the next tick to use.

pub fn game_over(&self) -> bool[src]

Return whether the game is over or not

pub fn is_paused(&self) -> bool[src]

Return whether the game is paused or not

pub fn pause(&mut self)[src]

Pause the game

pub fn unpause(&mut self)[src]

Unpause the game

pub fn toggle_pause(&mut self)[src]

Toggle the paused state of the game

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]