xxxxxxxxxx
//declare variables for background and moving objects
PImage FIELD;
PImage BALL;
PImage KOBE;
PImage TROPHY;
//declaring the arrays
Fave faves[] = new Fave[15];
void setup() {
//SETTING UP FUNCTIONS FOR OBJECTS AND VARIABLES
size(500, 500);
background(0);
//introducing images
FIELD = loadImage("FIELD.png");
BALL = loadImage("BALL.jpg");
KOBE = loadImage("kobe.png");
TROPHY = loadImage("trophy.jpg");
//for loop
for (int i = 0; i < faves.length; i++) {
faves[i] = new Fave(0, random(100), random(100));
}
}
void draw() {
//VISUALS AND UPDATE OF MOVEMENTS OF VARIABLES
if (mousePressed == true){
image(KOBE,0,0,500,500);
}else{
image(FIELD,0,0,500,500);
}
for (int i = 0; i < faves.length; i++) {
faves[i].display();
faves[i].update();
}
}
//delaring class variables
class Fave {
float xPos, yPos; // for position
float MVal, KVal, DVal; //variables for color (red,green,blue)
Fave(float M, float K, float D) { //constructor method passes arguments to class for each object
//*Class Constructor* runs once - Used to initialize settings, variables and objects
xPos = random(width);
yPos = random(height);
MVal = M;
KVal = K;
DVal = D;
}
void update() {
// Update function for class variables
//move gnat around randomly
xPos += random(-5, 5);
yPos += random(-5, 5);
//boundaries(help stay on screen)
if(xPos > width) {
xPos = width;
}
if(xPos < 0){
xPos = 0;
}
if(yPos > height) {
yPos = width;
}
if(yPos < 0){
yPos = 0;
}
}
void mousePressed() {
if (mouseButton == LEFT){
image(KOBE,xPos, yPos, 60, 60);
}
}
void display(){
//update function
fill(MVal, KVal, DVal);
if (mousePressed == true){
image(KOBE,xPos, yPos, 60, 60);
}else
image(BALL,xPos, yPos, 60, 60);
}
}