mirror of
https://github.com/processing/processing4.git
synced 2026-01-30 03:41:15 +01:00
Re-adding Topics to SVN
This commit is contained in:
50
java/examples/Topics/Advanced Data/ArrayListClass/Ball.pde
Normal file
50
java/examples/Topics/Advanced Data/ArrayListClass/Ball.pde
Normal file
@@ -0,0 +1,50 @@
|
||||
// Simple bouncing ball class
|
||||
|
||||
class Ball {
|
||||
|
||||
float x;
|
||||
float y;
|
||||
float speed;
|
||||
float gravity;
|
||||
float w;
|
||||
float life = 255;
|
||||
|
||||
Ball(float tempX, float tempY, float tempW) {
|
||||
x = tempX;
|
||||
y = tempY;
|
||||
w = tempW;
|
||||
speed = 0;
|
||||
gravity = 0.1;
|
||||
}
|
||||
|
||||
void move() {
|
||||
// Add gravity to speed
|
||||
speed = speed + gravity;
|
||||
// Add speed to y location
|
||||
y = y + speed;
|
||||
// If square reaches the bottom
|
||||
// Reverse speed
|
||||
if (y > height) {
|
||||
// Dampening
|
||||
speed = speed * -0.8;
|
||||
y = height;
|
||||
}
|
||||
}
|
||||
|
||||
boolean finished() {
|
||||
// Balls fade out
|
||||
life--;
|
||||
if (life < 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void display() {
|
||||
// Display the circle
|
||||
fill(0,life);
|
||||
//stroke(0,life);
|
||||
ellipse(x,y,w,w);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user