class Ball {
float r; //this is the circle's radius
float x,y;
float xspeed,yspeed;
color c;
Ball(float tempR) {
r = tempR;
x = random(width);
y = random(height);
xspeed = random( -5,5);
yspeed = random( -5,5);
}
void move() {
x += xspeed;
y += yspeed;
if (x > width || x < 0) {
xspeed *= - 1;
}
if (y > height || y < 0) {
yspeed *= - 1;
void display() {
stroke(0);
fill(c);
ellipse(x,y,r*2,r*2);
c = color(100,50);//using a basic grey colour for now
This code creates the Ball class and it sets it speed and colour (for now, later I will look to making these data from the XML feed). I have also set up for the ball to bounce of the sides of the stage.
No comments:
Post a Comment