Random numbers - Griffith-ICT/1701ICT-Creative-Coding GitHub Wiki
Moving the object to one location isn't overly exciting. Games often use the concept of randomness to make games more unpredictable and more natural.
p5.js provides the random() function which provides a random number within a specified range.
For example if we call random with the width of the canvas:
var number = random(400);
We will get a random number between 0 and 399, which is perfect as our co-ordinates always start at 0.
We can now randomly move our target each time there is a collision:
targetX = random(width);
targetY = random(height);
We could now start both the robot and targets at random locations.
Perhaps we could also keep track of a score each time there is a collision and display on the screen?