So i have created the tron light bike and now I want it that when it crashes it I want it maybe to reset and then go again. for this I’m using of a crash detection function using get to check the pixel colour, a crash has occurred if the pixel is not the background colour;
the tron light cycle code:
//arrow keys to draw
float x, y;
int speedY = 0;
int speedX = 1;
void setup() {
size(500, 500);
background(255, 255, 255); //background white
x=150;
y=150;
stroke(0, 0, 0); //pen black
}
void draw() {
stroke(0, 0, 0);
point(x, y); //draw a point at current (x,y)
updatepoint();
}
boolean crash(float x, float y)
{
color col=get((int)x,(int)y);
if (col==color(0,0,0))
point(x,y);
return true;
}
void updatepoint() {
x = x + speedX;
y = y + speedY;
}
void keyPressed() {
if (key == CODED)
{
if (keyCode == UP && y>=0) { //restrict to screen edge
speedX=0;
speedY=-1;
} else if (keyCode == DOWN && y<=500) {
speedX=0;
speedY=1;
} else if (keyCode == LEFT && x>=0) {
speedX=-1;
speedY=0;
} else if (keyCode == RIGHT && x<=500) {
speedX=1;
speedY=0;
}
}
}
if and boolean statement I’m working with:
boolean crash(float x, float y)
{
color col=get((int)x,(int)y);
if (col==color(0,0,0))
point(x,y);
return true;
}
what I don’t understand is boolean uses true and also, so here I’ve said if it has collided then reset to the point of x and y but that seems not too work…