Hello,I've been working on this simple shoot 'em up for a while,and I've finished most of the main gameplay loop now,I have a looping background,a character that you can move and shoot with,enemies to shoot,a working healthbar,dying/respawning mechanic...
Objects like enemies,player,and background already have their own respective header and source files,where I declared their classes and defined their related methods,but all of the objects and their related variables are declared in the main.cpp file,along with most of the game logic, like, collision, dying/respwaning, shooting, spawning/destroying enemies and projectiles,etc...
And now I want to work on other aspects of the game,such as adding other scenes (Main menu,level selection),so what I want to do is move all of the objects I've declared into a header file (Let's call it "Game.h" ) and move all of the game loop logic into a method that I can call inside the main loop (Declared inside a class in "Game.h" and defined in "Game.cpp" ) ,but I kept getting strange errors when I tried to compile,such as a linker error in main.obj telling me that the "objects are already defined in game.obj ",even though I already commented them out in main.cpp (Note here that I only moved the objects,not what's inside the game loop),among other things,everytime I try something that I think would work I end up with another error.
TL;DR how do i move everything in the main.cpp file to another file without messing up the whole project? Preferably while also keeping the general structure of the main.cpp file intact: Event handling,game loop, and then displaying everything,which now that I think about is part of the game loop so I'm not sure...