collision ? game over & start screen?

edited October 2015 in Questions about Code

hi i was trying to add a collision for my game so that when the mouse come in contact with the objets then a game over page will appear, i know that some how i must implement a boolean function for when it is in play mode and when it is game over , but im trying to mainly get the collision to work here is the code i have so far :

int dia = 40; // Width of the shape float xPos; // Starting position of shape float yPos; // position of shape

float velocityX = 10; // Speed of the shape float velocityY = 10; // Speed of the shape

int xdirection = 1; // Left or Right int ydirection = 1; // Top to Bottom float r = random(50);

void setup() { bg = loadImage("pug.jpg"); size(1366, 768); frameRate(30); rectMode(RADIUS); // Set the starting position of the shape xPos = width/2; yPos = height/2; }

void draw() { background(bg);

// Update the position of the shape xPos = xPos + ( velocityX * xdirection ); yPos = yPos + ( velocityY * ydirection ); fill(0, 255, 134); //aqua green ellipse(mouseX, mouseY, 50, 50); // Test to see if the shape exceeds the boundaries of the screen // If it does, reverse its direction by multiplying by -1 if (xPos > width-dia || xPos < dia) { // if the position of the shape is greater than width - 60 (shape size) or if the diameter is greater than the x then the below statement will execute both statements must be false in order for it to execute xdirection *= -1; } if (yPos > height-dia || yPos < dia) { ydirection *= -1; }

// Draw the shape rect (xPos, yPos, dia, dia); rect (xPos-200,yPos+150,dia,dia); rect (xPos+200,yPos-200,dia,dia); }

Tagged:
This discussion has been closed.