[][src]Struct mief::elements::ball::Ball

pub struct Ball {
    diameter: f64,
    position: (f64, f64),
    speed: (f64, f64),
}

The ball used for playing.

Fields

diameter: f64

The diameter of the ball.

position: (f64, f64)

The current position of the ball: (x, y).

speed: (f64, f64)

The current speed of the ball: (x, y).

Methods

impl Ball[src]

pub fn new(window_size: [u32; 2]) -> Ball[src]

Create a new ball with a random speed at the center of the window (given by [width, height]).

pub fn change_speed(&mut self, amount: f64)[src]

Change the ball's speed by the given amount in both directions.

pub fn draw(&self, context: &Context, graphics: &mut G2d)[src]

Draw the ball.

pub fn update(
    &mut self,
    dt: f64,
    width: u32,
    height: u32,
    obstacles: &[[f64; 4]]
) -> BallStatus
[src]

Update the ball's position. dt is the change in time since the last update, width and height are the window's size.

fn collide_with(&mut self, next_position: (f64, f64), object: &[f64; 4])[src]

Check if the ball will collide with object's bounding box at next_position and reverse the ball's direction accordingly.