I'm creating a simple HTML5 JS game, and at the moment my javascript file has reached nearly 1500 lines and it is slowly getting harder and harder to manage with so much more to do, is there a simple way to split some of the script up into "classes" which I mean separate files and then import all the "classes" files into one "main" file?
So for example I have this
File1.js
function pointInRect(pnt_x, pnt_y, rect_x, rect_y, rect_w, rect_h) { if ( (pnt_x >= rect_x) && (pnt_x <= rect_x + rect_w - 1) ) { if ( (pnt_y >= rect_y) && (pnt_y <= rect_y + rect_h - 1) ) {return true;} } return false; }
File2.js
if( pointInRect(1,1,1,1,1,1) == true){ console.log("Yo, there be a collision");}
how do I get file2 import file1 and use that method? If anyone could help me that would be awesome, it would really help me with manage my huge JS file.
Canvas