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


Messages In This Thread
RE: Creating object class for invaders - by Brian Beuken - 04-26-2018, 02:04 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)