Still learning c++ I finally hit classes (yeah yeah slow learner I know ) , but although I get the concept it seems there is something missing in my writing of classes.
This is where I got using soloLearn,
In the Main.cpp I need to include the .h file where the class is
#include "ClassFile.h"
Then inside the ClassFile.h I can setup a simple class
class GameObject
{
public://declare public variables
int x;
int y;
int width;
int height;
int direction;
int speed;
GameObject()//constructor, runs once to create the object
{
x = positionX;//take over the X position of the turret
y = positionY;//take over the y position of the turret
width = 1;
height = 3;
speed = 1;
}
void update()
{
// Draw and change the location of the object.
Pokitto.Display.drawLine(x,y,x+height,y);
x++;
}
bool collidesWidth(GameObject *o)
{
// Hit test
}
};
If I want to use this in the main.cpp I can use
// spawn a bullet
GameObject spawnBullet(positionX,positionY);
And use spawnBullet.update()
to update the position, in a loop somewhere
I am using Embitz to try this but i get a few errors so there is something amissâŚ
- PositionX and PositionY was not declared in this scope, if I understand this correctly the PositionX / Y object was not found,how do i place this correctly ?
- error: expected primary-expression before â.â token| because this
Pokitto.Display.drawLine(x,y,x+height,y); x++;
Is in the Class, seems the same thing that the Pokitto lib is not found in the class ?
I feel like i should place a include in the ClassFile.h but wouldnt this create a loop between the 2 files ?