game over if collision detected with mouse. game over screen, click to play screen

edited October 2015 in Questions about Code

int dia = 40;

float xPos;

float yPos;

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

int counter = 0;

////////////////

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);

text(counter, 100,100);

textSize(50);

xPos = xPos + ( velocityX * xdirection );

yPos = yPos + ( velocityY * ydirection );

fill(0, 255, 134); //aqua green

ellipse(mouseX, mouseY, 50, 50);

if (xPos > width-dia || xPos < dia) {

xdirection *= -1;

}

if (yPos > height-dia || yPos < dia) {

ydirection *= -1;

}

rect (xPos, yPos, dia, dia);

rect (xPos-200,yPos+150,dia,dia);

rect (xPos+200,yPos-200,dia,dia); }

/////////////

void mouseMoved (){

counter = counter +1;

if (counter > 99999999) {

counter = 0;

} }

Tagged:

Answers

  • go back edit your post

    empty lines before and after the code block

    then select the code block

    then use ctrl-o

  • use dist() - see reference to detect the distance from mouse to rect

    then if the result is < 30 or so

    say gameover=true;

Sign In or Register to comment.