Jump to content

Guide to Game Development/Theory/Game logic/Creating an entity class

50% developed
From Wikibooks, open books for an open world

Note: the following code uses Vector3 and Particle

This is an outline for what an entity class could look like written in C++:

Entity.h:

#include "Vector3.h"
#include "Particle.h"
using namespace std;
 
class Entity: public Particle { 
public:
    //These functions are going to be overloaded, they are there as a template for the for loops above to call them.
    void Tick();
    void Render();

    Entity();
    ~Entity();

    Vector3 Scale;
};

Entity.cpp:

#include "Entity.h"

void Entity::Tick(){
	Particle::Tick();
}

Entity::Entity(){}
Entity::~Entity(){}

Example child class

[edit | edit source]

car.cpp:

#include "Entity.h"
class Car: public Entity { //I've used a car as an example, but you'll need one for every type of distinct object.
public:
    //Polymorphism used
    void Car::Tick(){
        Entity::Tick(); //Call parent function
 
        //Handle other things if necessary like AI
    }
    void Car::Render(){
        //Draw the geometry
    }
};