I've been trying for hours to get my grid code below to work with a class Grid. It's really doing my head in because it's only the start of what I really need.
This is what I know I need:
class Grid {
variables here
Grid() {
height/width
position
color etc
}
methods to display here
}
I've tried arranging the code below into that but then I go to initialise it in setup and draw and it doesn't work. Any help would be amazing thanks. :)
I'm having trouble setting boundaries for a moving red ball inside the top area of my program. Which is above the black line.
I know that I need a condition which changes the direction of the ball once the radius of the ball goes near the edges of the program, but I'm not exactly sure how to implement it.
After that I need to add a black ball, on the bottom middle which needs to be "shot" straight up after any key is pressed and if it hits the red ball then text "You Win!" is displayed, and if it misses then text "Game Over" is displayed; hence I need to code to know when there's a collision or not. For that part I have a vague idea of using the dist function to compare the sum of the two balls radiuses, and if it's less than the sum then it's a collision(display win text), otherwise not(display game over text).
But I'm trying to solve one problem at a time, so boundaries first. :)
So far I've got the red ball moving freely, and a line.
float dia, centerX, centerY, speedX, speedY;
PFont font;
void setup() {
size(200, 200);
background(255);
smooth();
font = createFont("Arial",16); // to fix text delay later when text is added in