I was trying to make my game less messy by using classes.
I am learning classes now for the first time and I am not sure i get it so let me start off asking:
1) Is the possibility of "initialising all the objects at once" and "limiting user access to class members" the only reason why I should use classes rather than structures?
2) Assuming I am making a game where you've got a little man going around killing enemies, and assuming I want to make a class for these enemies, would it make sense to create another .h and .cpp files for this class?
Are ".h +.cpp" files only meant to improve organisation?
Also, this is my class:
Code: Select all
class Player
{
float positionX;
float positionY;
float velocity;
int colour;
int health;
public:
Player();
~Player();
void updatePosition();
void updateSpeed();
void updateColour();
void updateHealth();
bool checkCollision();
};
Code: Select all
gfx.DrawLine( 100,100,200,200,0,0,0 ); //this is fine
Player Mike;
gfx.DrawLine( Mike.x,Mike,y,200,200,0,0,0 ); //this is not
Also, my class has variables and functions and when I want to define a function in Player.h, there is absolutely no problem (see code at the beginning) BUT when I want to define a function in Player.cpp it turns out that I am not allowed to use "kbd.etc..","gfx.etc..".
Code: Select all
void Player::updatePosition()
{
if ( kbd.DownIsPressed )
}
I attached everything:
Code: Select all
#include "D3DGraphics.h"
#include "Keyboard.h"
#include "Mouse.h"
#include "Sound.h"