Objects in the long run will make things less complex. But i too found objects a bit daunting at the start.
Ill show you both examples, apologies im working on my phone so i am limited in my typing.
Arraylist<sceneObj> objects = new ArrayList<sceneObj>();
Player player;
void setup(){
player = new Player(random(400),random(400));
for(int i=0;i<10;i++){
sceneObj object = new sceneObj(random(400),random(400));
objects.add(object);
}
size(400,400);
}
void draw(){
player.draw();
for(int i=0;i<10;i++){
sceneObj o = objects.get(i);
o.draw();
if(collide()) o.col = color(0);
else o.col = color(255);
}
}
Class Player{
float x,y;
boolean collide;
color col = color(255);
Player(float x, float y){
this.x = x;
this.y = y;
}
void draw(){
fill(255,0,0);
rect(x,y,20,40);
}
void update(){
if(keyPressed&&keyCode==left arrow){
x-=5;
}
if(keyPressed&&keyCode==right arrow){
x+=5;
}
};
};
Class sceneObj{
float x,y;
boolean collide;
color col = color(255);
sceneObj (float x, float y){
this.x = x;
this.y = y;
}
void draw(){
fill(col);
rect(x,y,20,20);
}
void collide(){
return player.x>x&&player.x<x+20&&player.y>y&&player.y<y+20
}
I think that should work the only thing you need to do is find the keycode for the arrows and sub them into the key part, and add the y key if statements.
I might have a few other errors as this is untested code.
For more advanced collisions you may want to read up