Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating object class for invaders
#1
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
Good Luck,

Juston Metarref
Currently a programming student
Future Gameplay/Ai Programer
Reply
#2
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.
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 



Reply
#3
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!
Brian Beuken
Lecturer in Game Programming at Breda University of Applied Sciences.
Author of The Fundamentals of C/C++ Game Programming: Using Target-based Development on SBC's 



Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)