OK, so I'm creating a <canvas>
game using JavaScript (ES6+) features like Classes. It's straight from the vue-cli
and webpack
.
So, I have these Classes with the following (and such) variables
class Player {
this.x = 1;
this.y = 5;
this.name = 'Guy';
this.stats = [];
}
class Map {
this.level = 1;
this.config = {};
this.images = Image();
this.canvas = null;
this.context = null;
this.board = []; // From a tileset
}
// POINT OF ENTRY STARTS HERE
// const game = new Game();
class Game {
this.map = null;
this.player = null;
this.assets = Images();
}
The problem I'm having is that sometimes, I'm having to access a created object that was instantiated elsewhere.
For example, this.player
was instantiated inside the Game
class. But in the Map
class, I have the drawMouseSelection
method where it needs the current Player
's X and Y and Map
's board array of tiles.
For example, I pass the all of board[2500]
to a static helper method in UI
class to get the correct tile hovered on.
** What I am doing**
I just pass the whole object and deal with it as such. Am I passing too big of objects?