I'm playing around with some code and I'm trying to get the orbiting circle to change colour when hovered over. I'm not really sure what I'm doing wrong here.
// Angle of rotation around sun and planets
float theta = 0;
float x,y,w;
boolean mouse;
void setup() {
size(200,200);
smooth();
x = 0;
y = 0;
w = 10;
mouse = false;
}
void draw() {
background(255);
stroke(0);
// Translate to center of window to draw the sun.
//position of rotate origin
translate(width/2,height/2);
fill(255,200,50);
ellipse(0,0,20,20);
// The earth rotates around the sun
pushMatrix();
rotate(theta);
//position relative to sun
translate(50,0);
fill(50,200,255);
ellipse(x,y,w,w);
if (mouse) {
fill(0);
} else {
fill(50,200,255);
}
popMatrix();
theta += 0.001;
}
void rollover(int mx, int my) {
if (mx > x && mx < x + w && my > y && my < y + w) {
I want to have the falling laundry objects have a random image each time they fall and still interact with the basket at the bottom, however I'm not sure how to implement that into the code. The code I'm using is the code from learningprocessing.com for the raindrop game. I only want to use 3 images for the laundry objects (sock,scarf, and shirt image tags).
Right now I only have one image. I tried duplicating image(shirt, x, y,40,40); with a second image but it only layered the images. I also tried image(shirt, random(x), random(y),40,40); but then that randomly generated them without falling or interacting with the basket. I'm not sure what else to do.
Tab 1 (Final)
Basket basket;
Timer timer;
Laundry[] laundry;
boolean gameOver = false;
final static int EAST = 2;
final static int WEST = 8;
int result;
int score = 0;
int level = 1;
int lives = 3;
int levelCounter = 0;
int totalLaundry = 0;
int x = 400;
PFont f;
PImage bg,bin,shirt,sock,scarf;
void setup() {
size(800,600);
smooth();
noCursor();
basket = new Basket(132); //control basket height
laundry = new Laundry[15]; //amount of laundry
timer = new Timer(1000); //spread of objects over time
timer.start();
rectMode(CENTER);
imageMode(CENTER);
f = createFont("Arial",12,true);
bg = loadImage("background.gif");
bin = loadImage("basket.gif");
sock = loadImage("sock.gif");
shirt = loadImage("shirt.gif");
scarf = loadImage("scarf.gif");
}
void draw() {
background(bg);
switch(result) {
case EAST: x = x + 5; break;
case WEST: x = x - 5; break;
}
if (gameOver) {
textFont(f,48);
textAlign(CENTER);
fill(95,67,14);
text("GAME OVER",width/2,height/2);
text("score: " + score,width/2,height/2 + 50);
}
else {
basket.setLocation(x,590);
basket.display();
x = constrain(x,66,733);
//timer
if (timer.isFinished()) {
// Initialize laundry
if (totalLaundry < laundry.length) {
laundry[totalLaundry] = new Laundry();
totalLaundry++;
}
timer.start();
}
//display laundry
for (int i = 0; i < totalLaundry; i++ ) {
if (!laundry[i].finished) {
laundry[i].move();
laundry[i].display();
if (laundry[i].reachedBottom()) {
levelCounter++;
laundry[i].finished();
lives--;
if (lives <= 0) {
gameOver = true;
}
}
if (basket.intersect(laundry[i])) {
laundry[i].finished();
levelCounter++;
score++;
}
}
}
if (levelCounter >= laundry.length) {
level++;
levelCounter = 0;
timer.setTime(constrain(300-level*25,0,300));
totalLaundry = 0;
}
//HUD
textFont(f,14);
fill(95,67,14);
text(" " + lives,25,20); //lives
rect(20,40,10,lives*20);
text(" " + level,770,20); //level
text(" " + score,770,40); //score
}
}
void keyPressed(){
switch(key) {
case('d'):case('D'):result |=EAST;break;
case('a'):case('A'):result |=WEST;break;
}
}
void keyReleased(){
switch(key) {
case('d'):case('D'):result ^=EAST;break;
case('a'):case('A'):result ^=WEST;break;
}
}
Tab 2 (Basket)
class Basket {
float x,y,h;
Basket(float tempH) {
h = tempH;
x = 0;
y = 0;
}
void setLocation(float tempX, float tempY) {
x = tempX;
y = tempY;
}
void display() {
noStroke();
noFill();
rect(x,y,h,h);
image(bin,x,y,132,132);
}
//if basket intersects laundry
boolean intersect(Laundry l) {
if ( dist(x,y,l.x,l.y) < h - l.h) {
return true;
} else {
return false;
}
}
}
Tab 3 (Laundry)
class Laundry {
float x, y, h, speed;
//is object still being used
boolean finished = false;
Laundry() {
h = 40;
x = random(width);
y = 0;
speed = random(0.5, 0.7);
}
void move() {
y += speed*(level*.5);
}
boolean reachedBottom() {
if (y > height + h) {
return true;
}
else {
return false;
}
}
void display() {
fill(175);
noStroke();
rect(x, y, h, h);
image(shirt, x, y,40,40);
x = constrain(x, 20, 780);
}
void finished() {
finished = true;
}
}
Tab 4 (Timer)
class Timer {
int savedTime; // When Timer started
int totalTime; // How long Timer should last
Timer(int tempTotalTime) {
totalTime = tempTotalTime;
}
void setTime(int t) {
totalTime = t;
}
void start() {
savedTime = millis();
}
// The function isFinished() returns true if 5,000 ms have passed.