I'm horrible at this coding thing, but there's a class at uni that I have to pass. I really need your help.
I need to modify a code that consists of a shape(let's call it X) chasing another shape(Y). The original code makes it go "game over/black screen" when one monster catches another. What I want to do is make the screen go black for a second or something, and shape Y starts chasing X instead (like pacman).
So far I just removed a couple of lines to remove the game over screen thing.
Quote:/VARIABLES
String myName = "C.S";
color monsterColor = color(random(255),random(255),random(255)); //assign a random color to the ball
//variables controlling the position of the ball
float xPos = 100+random(200);
float yPos = 100+random(200);
//variables controllin the size of the ball
float size = 40;
//variables controlling the speed of the ball
float speedX = random(5);
float speedY = random(5);
//SETUP CODE-BLOCK
void setup() {
size(400,400);
background(255);
frameRate(40);
print(myName);
smooth();
noCursor(); //hides the mouse cursor inside the canvas
}
//DRAW CODE-BLOCK
void draw() {
if(frameCount % 200 == 0) { //increase the speed every 200 frames
speedX = speedX*1.5;
speedY = speedY*1.5;
frameCount = 0; //reset frameCount
}
background(255); //draw the background
//collision detection for the x-axis
if(xPos+size/2 >= width || xPos-size/2 < 0) {
speedX = (speedX)*(-1);
monsterColor = color(random(255),random(255),random(255));
}
//collision detection for the y-axis
if(yPos+20 >=height || yPos-20 < 0) {
speedY = speedY*-1;
monsterColor = color(random(255),random(255),random(255));
}
//move the monster
xPos = xPos + speedX;
yPos = yPos + speedY;
//draw the monster
fill(monsterColor);
stroke(monsterColor);
ellipse(xPos, yPos, size/2,size/2);
noFill();
ellipse(xPos, yPos, size,size);
line(xPos,yPos,xPos-20,yPos-20);
ellipse(xPos-20,yPos-20,5,5);
line(xPos,yPos,xPos+20,yPos-20);
ellipse(xPos+20,yPos-20,5,5);
arc(xPos,yPos+10, size-5, size-frameCount%15, 0, PI); //draws the mouth of the monster. It's hight will change over time because it depends on frameCount
rectMode(CENTER);
fill(0);
stroke(0);
ellipse(mouseX,mouseY,size,size);
fill(255);
ellipse(mouseX-8,mouseY-5,10,10);
ellipse(mouseX+8,mouseY-5,10,10);
ellipse(mouseX,mouseY+10,10,18-(dist(mouseX,mouseY, xPos, yPos)/400)*18); //changes the size of the prey's eyes based on the distance to the monster
//check if the monster caught it's prey by calculating the distance between them
float distance = dist(mouseX,mouseY, xPos, yPos);
if(distance <= size) {
rectMode(CORNER);
fill(0);
rect(0,0,400,400);
}
}
Yeah.. I'm kinda dumb.