public class

Ball

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

Class Overview

The ball in the Pong game.

Summary

Public Constructors
Ball()
Creates a new Ball.
Public Methods
void onCollisionWith(ViewEdges on)
Called when the ball collides with one or more of the edges of the view.
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 reset()
Resets the ball: centers it on the screen, 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 on)

Called when the ball collides with one or more of the edges of the view.

Parameters
on The edges "on" which the ball has touched.

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 object we collided with.

public void reset ()

Resets the ball: centers it on the screen, gives it a random initial velocity, and after 0.5 seconds, starts it moving.