mirror of
https://github.com/processing/processing4.git
synced 2026-01-30 11:51:54 +01:00
40 lines
830 B
Plaintext
40 lines
830 B
Plaintext
class Module {
|
|
int xOffset;
|
|
int yOffset;
|
|
float x, y;
|
|
int unit;
|
|
int xDirection = 1;
|
|
int yDirection = 1;
|
|
float speed;
|
|
|
|
// Contructor
|
|
Module(int xOffsetTemp, int yOffsetTemp, int xTemp, int yTemp, float speedTemp, int tempUnit) {
|
|
xOffset = xOffsetTemp;
|
|
yOffset = yOffsetTemp;
|
|
x = xTemp;
|
|
y = yTemp;
|
|
speed = speedTemp;
|
|
unit = tempUnit;
|
|
}
|
|
|
|
// Custom method for updating the variables
|
|
void update() {
|
|
x = x + (speed * xDirection);
|
|
if (x >= unit || x <= 0) {
|
|
xDirection *= -1;
|
|
x = x + (1 * xDirection);
|
|
y = y + (1 * yDirection);
|
|
}
|
|
if (y >= unit || y <= 0) {
|
|
yDirection *= -1;
|
|
y = y + (1 * yDirection);
|
|
}
|
|
}
|
|
|
|
// Custom method for drawing the object
|
|
void draw() {
|
|
fill(255);
|
|
ellipse(xOffset + x, yOffset + y, 6, 6);
|
|
}
|
|
}
|