Circle - Rect Collision


Joined
Jan 12, 2021
Messages
1
Reaction score
0
I am trying to make an end screen appear when the red circle reaches the end of the window, but it continues to go past the window.
Here is my code:

float xspeed = 2.5;


boolean upPressed = false;
boolean downPressed = false;
boolean leftPressed = false;
boolean rightPressed = false;

float circleX = 0;
float circleY = 500;


PImage img1, img2, img3;
float[] circleD = new float[180];

int time;
int wait = 5000;
void setup() {
size(1000, 500);
time=millis();
rectMode(CENTER);
img1 = loadImage("stars.gif");
img2 = loadImage("splash_screen_example2.png");
img3 = loadImage("character_1.png");


for (int i = 0; i < circleD.length; i++) {
circleD = random(height);
}
}

void draw() {


background(#18468E);
//stars
image(img1, 0, 0);
img1.resize(1000,500);
tint(255,255); // Tint blue
image(img1, 0, 0);

//text
fill(#FFFFFF);
textSize(100);
text("Red", 400, 187);
textSize(75);
text("Ball", 420, 247);
textSize(50);
text("Dash",440,287);

fill(#FF0303);
textSize(100);
text("Red", 400, 200, +5000);
textSize(75);
text("Ball", 420, 260);
textSize(50);
text("Dash",440,300);

if (millis() - time > wait){ //splash screen


background(50);
fill(#F57C0A);
for (int i = 0; i < circleD.length; i++) {
float circleE = width * i / circleD.length;
ellipse(circleE, circleD, 18, 18);

circleD++;

if (circleD > height) {
circleD = 0;
}
}
}
if (upPressed) {
circleY=circleY-xspeed;

}
if (downPressed) {
circleY=circleY+xspeed;
}
if (leftPressed) {
circleX=circleX-xspeed;
}
if (rightPressed) {
circleX=circleX+xspeed;

}
fill(#FF0303);
ellipse(circleX, circleY, 13, 13);
}

void keyPressed() {
if (keyCode == UP) {
upPressed = true;
}
else if (keyCode == DOWN) {
downPressed = true;
}

if (keyCode == LEFT) {
leftPressed = true;
}
else if (keyCode == RIGHT) {
rightPressed = true;
}
}

void keyReleased() {
if (keyCode == UP) {
upPressed = false;
}
else if (keyCode == DOWN) {
downPressed = false;
}
else if (keyCode == LEFT) {
leftPressed = false;
}
else if (keyCode == RIGHT) {
rightPressed = false;
}
}
void mousePressed() {
loop();
}

void mouseReleased() {
noLoop();
}
void edges() {
if (circleX > width){
image(img2, 0, 0);
img2.resize(1000,500);
fill(#18468E);
ellipse(circleX,circleY,13,13);
}
}
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top