I am creating a game in Javascript/HTML5 (in a canvas) which involves 2 types of objects (let's call them object type A and object type B) that start falling from above the canvas.
The player is meant to swipe the objects as they fall so that the objects don't fall through the bottom of the screen.
I want to create a horizontal line on which the program would choose a random point to spawn an object from.
The program also has to decide for each object spawn whether it is an object of type A or B.
How exactly would I create code to spawn the objects to consider both of these independent probabilities?
I assume Math.random
is involved, but I am very inexperienced in Javascript and do not know how to code this.
Also, when spawning objects, what would I use to control the rate of spawning and the change of rate of spawning over time?
I have heard that Unity can be helpful in spawning, but is there an effective way to do it without Unity?