I’m building a Midway Galaga clone in Javascript and the browser Canvas API, based on the video here: https://www.youtube.com/watch?v=P9h9RkHC-Iw. Currently I’m implementing the scrolling starfield, and have this code for placing the stars:
for(let index = 0; index < this.count; index += 1) {
const x = (Math.random() * width) | 0;
const y = (Math.random() * height) | 0;
this.stars.push(new Star(x, y));
}
Due to the simple nature of the coordinate generation, stars have a habit of clustering too much and even overlapping. Is there a better coordinate generation method? My full current progress can be found here: https://codepen.io/ntchambers/pen/wvLdOer/5dc2ccba73fa9aaf98023c5b8179b516 (ignore the fact that it doesn’t scroll. I have thoughts on that but will be implementing it last).