2

Link to code for reference: https://editor.p5js.org/tpant963/sketches/Ft9fBLlRU

Hi! So I've been trying to make a review game on Java OOP concepts on p5.js, but I'm beginning to get a bit overwhelmed because this is my very first p5.js project. How the game works is that there is a question printed on the screen with bubbles floating around that are supposed to have word associations on them. If the correct bubble is clicked then it will turn green and if it is incorrect, it will turn red. The round ends when all the correct bubbles are clicked.

My first problem is that I can't make the text appear on the bubbles. I tried doing it like this (using the correct array as an example) but it resulted in my bubbles and text one the screen getting very messed up, not to mention, the text never showed up.

textAlign(CENTER, CENTER);
    for (let i = 0; i < correct.length; i++) {
    ellipse(correct[i].x, correct[i].y, 
            correct[i].r, correct[i].r);
    textSize(correct[i].r);
    text(correct[i].q1C, correct[i].x, correct[i].y);   }

My second issue lies in the fact that I'm unsure of how to shuffle the questions and keep the game going until all the questions are done.

Thanks!

Tanya
  • 43
  • 5
  • It's better to ask one question at a time. Folks will downvote you for having multiple questions. There is a canonical answer [here](https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array) for how to shuffle an array. I don't understand what your code is supposed to be doing. You should choose transparent variable and property names so that other people can understand your code, and so that you can when you come back to it in two weeks. – Charlie Bamford Jun 18 '21 at 08:06
  • 1
    I modified your code example https://editor.p5js.org/cbamford/sketches/YmRTH9h2g. There wasn't one problem that was keeping you from being able to print your text. I made an outline of the changes I made at the top of sketch.js. Hope that helps – Charlie Bamford Jun 18 '21 at 09:17
  • Woah... I actually learned a lot from your modifications. Thank you so much! – Tanya Jun 18 '21 at 16:07
  • @CharlesBamford you should post that link and a brief explanation as an Answer instead of a comment. – Paul Wheeler Jun 18 '21 at 20:34

1 Answers1

0

Well, for the shuffling you could use the built in p5.js function:

shuffle(Arr)

and then just keep count of how many questions you have:

let questionCount

function newQuestion(){
questionCount++
questionArr[questionCount]
}

or something close to that; haven't looked thru your project all that much

Ulti
  • 514
  • 3
  • 5