Creating object class for invaders - Printable Version +- Forums (http://www.scratchpadgames.net/forums) +-- Forum: Main Forums (http://www.scratchpadgames.net/forums/forumdisplay.php?fid=1) +--- Forum: Help my code won't work?? (http://www.scratchpadgames.net/forums/forumdisplay.php?fid=22) +--- Thread: Creating object class for invaders (/showthread.php?tid=81) |
Creating object class for invaders - mayoricecream - 04-26-2018 Hello again, I am getting started on the Invaders game and was a bit confused with the bit about creating the object class. I am not sure when it is the class is supposed to go. I created a header called objects.h and put the code in there but when I do that my Shooter.cpp gives me errors. Severity Code Description Project File Line Suppression State Error [Clang IntelliSense] Error: no matching constructor for initialization of 'Objects' InvaderStart c:\users\justo\desktop\invaders\invaderstart\Shooter.cpp 10 RE: Creating object class for invaders - Brian Beuken - 04-26-2018 Have you done any C++ before this? Since creating a class is one of the skills I assume readers can do? But ok, I'll try to explain, this is basically a minimum description of a class, remember I assume you understand the basic concepts and syntax of C++ so when I ask you to write a class its fair for me to assume you know that it is a 2 part process of a header file and a cpp file. But lets try to get you moving. A header file only contains a description of a class, as the book describes, write a class description like this. enum Types { Bullet,Missile1,Missile2, Alien, AShooter,AShelter }; class Objects { public: Objects(); ~Objects(); Types Type; float Xpos, Ypos; bool Update(Surface* s,Input* InputHandler); Surface* Image; }; So that's the class description, if you look at it, there are 2 user classes being used, Surface and Input, so you will need to make sure you have #include's for both of those classes. Now with that basic class described we need to write an Objects.cpp file, which will contain the actual code that describes the 3 methods here which are the Constructor, the destructor, and an update function. They can all be empty to start with, you just want to create the basics. I just checked the version of Invaderstart I uploaded and its actually the wrong one, its a slightly more advanced general version, so I will fix that in the morning to use these basic objects classes and you can see how it all works. But you can still get some idea of whats going if you look at the GameObjects class which is an enhanced version of an Objects class, but still very simple. RE: Creating object class for invaders - Brian Beuken - 04-27-2018 I've now added the proper Invaderstart files, which use Objects as their base class and the InvadersFin example which shows further development of the invaders from the book descriptions, but leaves enough for you to add more content! |