help with simple ellipse game

Hello fellow processing gurus and masterminds!

It's my first time doing coding so I am having quite the struggle to come up with a simple game for my little project that I'm working on :( I do apologize if similar coding has been explained before... waahhhhh

The coding so far shows circles falling down from the top (that's the extend of my skills..), I would like the user to be able to click on it before it falls to the bottom, and the circle would disappear when clicked. If the circles reaches the bottom without it being clicked, the game finishes.. I know I'm suppose to use the forloop but it didn't work for me..

This is my code so far, I'd totally be eternally grateful if I get any help <33

xx

int speed =2; int posX =250; int posY =0;

int posN =450; int posM =0;

int posA =100; int posB =0;

int posC =300; int posD =-120;

int posE =200; int posF =-40;

void setup(){ size (500,500);

}

void draw(){ background(0);

ellipse(posX,posY,10,10);

if(posY <600){ posY = posY + speed+5;

}

ellipse(posN,posM,20,20);

if(posM <600){ posM = posM + speed+5; }

ellipse(posA,posB,30,30);

if(posA <600){ posB = posB + speed+3; }

ellipse(posC,posD,30,30);
if(posA <600){

posD = posD + speed+3; } ellipse(posE,posF,15,15); if(posA <600){ posF = posF + speed+3; } }

Answers

  • When posting code, make sure you use the code button to preserve your formatting and make it easier to read.

    What exactly are you confused about? Maybe try to start smaller- can you create a little example sketch that just shows a circle and prints something out whenever you click inside the circle?

  • hi KevinWorkman:

    Thank you so much for your reply, I've only been introduced to coding a couple of days ago and I'm so interested in understanding more of how it works so I don't have much knowledge of it so far ><

    I guess I'm a little confused on how to use the noloop() function and execute it when I mouse click, when I tried to add it in the setup, the program stops.

    I haven't really found a solution to the mouseclick function as I click on the circles, I'm really sorry if that sounds ambiguous, I am really new in this area..

    xx

  • Why are you trying to use noLoop()?

    Here is an example that uses the dist() function to determine the distance between the center of the circle and the mouse position.

  • Or don't put the mouse clicked function in setup or draw put it under draw and use mouseX and mouseY along with circle position and size to see if when the mouse is clicked it is within the circle.

Sign In or Register to comment.