Hi, I've written this code as a variation of the wheres wally game. You search round the wheres wally picture with the mouse. When you find him, you click on him and a tick comes up.
2 Questions: Why does this run so slow? Is it something to do with the mouse searchlight being in draw?
also
How can i get it so that when wally is clicked, the whole picture is revealed for a few seconds, and then a new one comes in and the game restarts?
Thank you in advance.
float wallyx = 160;
float wallyy = 140;
float wallyw = 200;
float wallyh = 200;
PImage img;
PImage img2;
void setup() {
size(1024, 768);
frameRate(50);
img = loadImage("hello.jpg");
img2 = loadImage("correct.png");
}
void draw() {
loadPixels();
for (int x = 0; x < img.width; x++) {
loadPixels();
for (int y = 0; y < img.height; y++ ) {
// Calculate the 1D location from a 2D grid
int loc = x + y*img.width;
// Get the R,G,B values from image
float r, g, b;
r = red (img.pixels[loc]);
g = green (img.pixels[loc]);
b = blue (img.pixels[loc]);
// Calculate an amount to change brightness based on proximity to the mouse
float maxdist = 50;//dist(0,0,width,height);
float d = dist(x, y, mouseX, mouseY);
float adjustbrightness = 200*(maxdist-d)/maxdist;
r += adjustbrightness;
g += adjustbrightness;
b += adjustbrightness;
// Constrain RGB to make sure they are within 0-255 color range
r = constrain(r, 0, 255);
g = constrain(g, 0, 255);
b = constrain(b, 0, 255);
// Make a new color and set pixel in the window
color c = color(r, g, b);
//color c = color(r);
pixels[y*width + x] = c;
}
updatePixels();
}
updatePixels();
}
void mousePressed() {
if (mouseX>wallyx && mouseX <wallyx+wallyw && mouseY <wallyy+wallyh)
I want to have a picture of a wheres wally image, and i want it all to be black apart from where the mouse is. The mouse acts as a spotlight and wherever it is on the image, that part of the image can be viewed.
Then, when wally is found, i want to be able to click on him, and when you do, a new image comes up saying 'correct'. I dont know what is going on here. Before i started putting in the mouse pressed stuff the spotlight thing worked, its only when i wanted to introduce a new image that its gone apeshit.
The error that comes up is "unexpected token: void" and it highlights mousePressed at the bottom. Help!:
float x = 160; float y = 140; float w = 200; float h = 200; PImage img; PImage img2;
void setup() { size(1024, 768); frameRate(50); img = loadImage("hello.jpg"); img2 = loadImage("correct.png"); img.loadPixels(); // Only need to load the pixels[] array once, because we're only // manipulating pixels[] inside draw(), not drawing shapes. loadPixels(); }
void draw() { rect(x,y,w,h); for (int x = 0; x < img.width; x++) { for (int y = 0; y < img.height; y++ ) { // Calculate the 1D location from a 2D grid int loc = x + y*img.width; // Get the R,G,B values from image float r,g,b; r = red (img.pixels[loc]); g = green (img.pixels[loc]); b = blue (img.pixels[loc]); // Calculate an amount to change brightness based on proximity to the mouse float maxdist = 50;//dist(0,0,width,height); float d = dist(x, y, mouseX, mouseY); float adjustbrightness = 200*(maxdist-d)/maxdist; r += adjustbrightness; g += adjustbrightness; b += adjustbrightness; // Constrain RGB to make sure they are within 0-255 color range r = constrain(r, 0, 255); g = constrain(g, 0, 255); b = constrain(b, 0, 255); // Make a new color and set pixel in the window color c = color(r, g, b); //color c = color(r); pixels[y*width + x] = c; } void mousePressed() { if(mouseX>x && mouseX <x+w && mouseY <y+h) { loadPixels(); img.loadPixels(); for (int y=0; y<height; y++) { for (int x=0; x<width; x++) { int loc=x+y*width;
float r = red (img.pixels[loc]); float g = green(img.pixels[loc]); float b = blue(img.pixels[loc]);