Yep first thing I looked at was the references on processing but it’s not a very extensive run through. I understqnd setup will run it once but now i’m having another problem where if I make a ball run through it, it leaves a trail. I can’t put a white background on it because that doesn’t work, does anyone know what else I can do?
float yPos;
float xPos;
float xBallPos;
float xHolePos;
float lastBallx;
float b;
float r;
int xDirection;
float ySpeed;
int x;
int y;
int size = 40;
boolean launch;
int n = 1;
color[] c;
void setup() {
size(1280, 960);
stroke(255);
xPos = 50;
xBallPos= 50;
xDirection = 1;
yPos = 940;
ySpeed = 10.0;
r = random(0, 1025); //initial random goal position
c = new color [n];
Grass();
}
void drawBall() {
fill(255);
stroke(255);
circle(xBallPos, yPos, 20);
}
// create a hole with random x position
void drawHole() {
fill(180);
stroke(255);
circle(xHolePos = r, 20, 25);
}
void drawPlayer() {
fill(255,249,32);
stroke(0);
circle(xPos, 910, 50);
fill(0);
circle(xPos-10,907,10);
circle(xPos+10,907,10);
arc(xPos, 915, 25, 25, 0, PI);
}
void drawSurprise() {
fill(255,249, 32);
stroke(0);
circle(xPos, 910, 50);
fill(0);
circle(xPos-10,907,10);
circle(xPos+10,907,10);
circle(xPos, 920, 15);
}
void Grass(){
for (int row = 0; row < height; row++){
for(int col = 0; col < 21.5; col++) {
for(int i=0; i<n; i++){
c[i] = color(random(0), random(180,255), random(0));
noStroke();
fill(c[i]);
rect(row*size, col*size, size, size);
}
}
}
}
void keyPressed()
{
if(key == 32)
launch = true;
}
void draw() {
//make the playing field
fill(250, 237, 139);
stroke(250, 237, 139);
rect(0,860,1280,960);
if(launch == true){
drawSurprise();
drawBall();
drawHole();
yPos = (yPos - 10);
xBallPos = xPos;
}
if(yPos < 6){
launch = false;
//Reset key stroke
key =1;
//reset ball y pos
yPos = 940;
// create next random hole positioun
r = random(0, 1026);
}
if (launch ==false){
drawHole();
drawPlayer();
if (xPos > 1200) {
xDirection = 0;
}
if (xPos < 50) {
xDirection = 1;
yPos = yPos + 1;
}
//player movement
if (xDirection == 1){
xPos = xPos + 10;}
{
if (xDirection != 1) {
xPos = xPos - 10;
}
}
}
}