public class

Ball

extends OvalShape
java.lang.Object
   ↳ sofia.graphics.Shape
     ↳ sofia.graphics.StrokedShape
       ↳ sofia.graphics.FillableShape
         ↳ sofia.graphics.OvalShape
           ↳ sofia.demos.breakout.Ball

Class Overview

A paddle in the Breakout game.

Summary

Public Constructors
Ball()
Creates a new Ball.
Public Methods
void onCollisionWith(ViewEdges edges)
Called when the ball has collided with an edge of the screen.
void onCollisionWith(Paddle paddle)
Called when the ball has collided with a paddle to cause it to bounce off (by inverting its horizontal velocity) and restarting the animation.
void onCollisionWith(Brick brick)
Called when the ball collides with a brick to cause it to bounce off (by modifying its velocity, depending on the angle of the collision) and restarting the animation.
void reset(Paddle paddle)
Resets the ball: positions it atop the specified paddle, gives it a random initial velocity, and after 0.5 seconds, starts it moving.
[Expand]
Inherited Methods
From class sofia.graphics.OvalShape
From class sofia.graphics.FillableShape
From class sofia.graphics.StrokedShape
From class sofia.graphics.Shape
From class java.lang.Object

Public Constructors

public Ball ()

Creates a new Ball.

Public Methods

public void onCollisionWith (ViewEdges edges)

Called when the ball has collided with an edge of the screen. If the edge involved was the left, right, or top, then the ball will bounce off. Otherwise, if the edge was the bottom, false will be returned so that the screen has an opportunity to handle it (to subtract a life).

Parameters
edges the edges of the view involved in the collision

public void onCollisionWith (Paddle paddle)

Called when the ball has collided with a paddle to cause it to bounce off (by inverting its horizontal velocity) and restarting the animation.

Parameters
paddle the paddle that the ball collided with

public void onCollisionWith (Brick brick)

Called when the ball collides with a brick to cause it to bounce off (by modifying its velocity, depending on the angle of the collision) and restarting the animation.

Parameters
brick the brick that the ball collided with

public void reset (Paddle paddle)

Resets the ball: positions it atop the specified paddle, gives it a random initial velocity, and after 0.5 seconds, starts it moving.

Parameters
paddle the paddle to start the ball atop