Background Variables Help?
in
Programming Questions
•
5 months ago
I have been working on a simulation where a man walks through a house. My problem is that I do not know how to set variables to backgrounds. In mine, I have made it so that if I press E in front of a stove, it turns on by changing the background. If I am in a different background and I am in the same coordinates, My room will change. Is there a way to work around this, because I can't set backgrounds as variables. Here is my messy code so far:
PImage img;
PImage front;
PImage back;
PImage left;
PImage right;
PImage stove;
PImage sink;
int x = 150;
int y = 150;
void setup(){
size(492, 414);
frameRate(90);
img = loadImage("kitchen1.PNG");
sink = loadImage("sink.png");
stove = loadImage("stove.PNG");
front = loadImage("frontchef.png");
back = loadImage("backchef.png");
right = loadImage("rightchef.png");
left = loadImage("leftchef.png");
background(img);
}
void draw(){
background(img);
if (keyPressed){
if(key == 'e'){
if(((x > 0) && (x < 50) && (y < 60))){
img = loadImage("stove.PNG");
}else{
img = loadImage("kitchen1.PNG");
if(((x > 200) && (x < 359) && (y < 60))){
img = loadImage("sink.png");
}else{
img = loadImage("kitchen1.PNG");
}
}
}
}
if(keyPressed){
if((((key == 'd')||(key == 'w')||(key == 'a')||(key == 's')))){
tint(255,0);
}
}
image(back, x, y);
if (keyPressed){
if (key == 'd'){
tint(255,255);
image(right, x, y);
back = loadImage("rightchef.png");
x++;
}
if (key == 'w'){
tint(255,255);
image(back, x, y);
back = loadImage("backchef.png");
y--;
}
if (key == 'a'){
tint(255,255);
image(left, x, y);
back = loadImage("leftchef.png");
x--;
}
if (key == 's'){
tint(255,255);
image(front, x, y);
back = loadImage("frontchef.png");
y++;
if((y > 88) && (x > 165)){
y--;
}
}
}
if(y > 225){
y--;
}
if(y < 50){
y++;
}
if(x > 400){
x--;
}
if(x < 0){
x++;
}
if((y > 88) && (x > 165)){
x--;
}
if((y > 88) && (x > 165)){
y--;
}
if(keyPressed){
if (key == 'q'){
if (x > 350){
img = loadImage("TheoreticalBackground.PNG");
}
}
}
}
PImage img;
PImage front;
PImage back;
PImage left;
PImage right;
PImage stove;
PImage sink;
int x = 150;
int y = 150;
void setup(){
size(492, 414);
frameRate(90);
img = loadImage("kitchen1.PNG");
sink = loadImage("sink.png");
stove = loadImage("stove.PNG");
front = loadImage("frontchef.png");
back = loadImage("backchef.png");
right = loadImage("rightchef.png");
left = loadImage("leftchef.png");
background(img);
}
void draw(){
background(img);
if (keyPressed){
if(key == 'e'){
if(((x > 0) && (x < 50) && (y < 60))){
img = loadImage("stove.PNG");
}else{
img = loadImage("kitchen1.PNG");
if(((x > 200) && (x < 359) && (y < 60))){
img = loadImage("sink.png");
}else{
img = loadImage("kitchen1.PNG");
}
}
}
}
if(keyPressed){
if((((key == 'd')||(key == 'w')||(key == 'a')||(key == 's')))){
tint(255,0);
}
}
image(back, x, y);
if (keyPressed){
if (key == 'd'){
tint(255,255);
image(right, x, y);
back = loadImage("rightchef.png");
x++;
}
if (key == 'w'){
tint(255,255);
image(back, x, y);
back = loadImage("backchef.png");
y--;
}
if (key == 'a'){
tint(255,255);
image(left, x, y);
back = loadImage("leftchef.png");
x--;
}
if (key == 's'){
tint(255,255);
image(front, x, y);
back = loadImage("frontchef.png");
y++;
if((y > 88) && (x > 165)){
y--;
}
}
}
if(y > 225){
y--;
}
if(y < 50){
y++;
}
if(x > 400){
x--;
}
if(x < 0){
x++;
}
if((y > 88) && (x > 165)){
x--;
}
if((y > 88) && (x > 165)){
y--;
}
if(keyPressed){
if (key == 'q'){
if (x > 350){
img = loadImage("TheoreticalBackground.PNG");
}
}
}
}
1