After trying a couple different HTML5 frameworks, I've always found pure JS the most appealing. However, I am uncertain about the way I'm structuring it.
Currently, I have been declaring different objects as global variables as such:
var titlescreen = new Titlescreen();
var fps = new FPSTracker();
var input = new Input();
var background = new Background();
var shops = new Shops();
var chunkhandler = new ChunkHandler();
var explosionhandler = new ExplosionHandler();
var ui = new UI();
var world = new World();
var player = new Player();
var joystick = new Joystick();
My main problem with this is how I have them communicate with each other. For example, the Player
class accesses some of world
's functions by simply using it's name (world.functionINeedToUse();
). Coming from a Java background, this gives me a very bad vibe as it depends on the declaration of this global variable with the specific name. Though I've found JS to be a more forgiving language, this still does not feel right. I haven't found any problems with it, so far.
Are there more effective ways to structure a game? What about the problem with player/world?