Good game-project to check what good game code structure looks?[Code of my project Inside]

I think there’s quite a few things you could do but I would first look at implementing InverisfyJS. Rather use a proper IoC for injecting dependencies.

Also try make your classes follow SRP (Single Responsibility) as much as possible as this would prevent some of the issues you’re having. Your engine should definitely not handle the gun shooting. As sharp mentioned using Observables to communicate between components would be much better.

Honestly I don’t like using ES5/ES6 as I feel it’s open to writing chaos. I have a TypeScript “scaffold” repo with Inversify that I’m working on improving so that when I fire up any project I can follow SOLID principles straight away.

Also avoid mixing ES5 and ES6 as I see you’re using prototypes and classes. Stick to one approach.

I personally also avoid inheritance and OOP at all costs especially when it comes to something like a game.

Unfortunately I don’t have anything substantial to show you as I’m still experimenting with all the features to make a game work like imported 3D meshes, texturing, a good scaffold (TypeScript, DI etc.), lighting, socket server, socket client (the game itself), physics, animation. Once I’ve got all these experiments down I’m going to start piecing the game together. Actually… I do still have a big task ahead of generating my stages from a JSON file instead of actually manually building them in Babylon. Once that’s done I’ll probably start making something that resembles a game.

I have another experiment I was busy with that may give you some kind of idea what I’m talking about: Solar-System/src/app at master · Wancieho/Solar-System · GitHub but there are a few things I would change for eg. I think the generating of the skybox should actually maybe be inside a Milky Way/galaxy component which injects the solar system component. The entry point is the app.ts.

3 Likes