Playing around with a component based design pattern in 3dgs. An entity can have multiple components(scripts are also components). This is an example of a script component attached to an entity:
Php Code:
CPTransform transformation; //cache the transformation
//@TODO caching only works for one instance at the moment. need to add the possibility to store variables for every instance
void PlayerStart()
{
transformation = CPGetComponent("transform"); //CPGetComponent is always refering to components of the current entity(the one with the player script in this case)
printf("player initialized");
}
void PlayerUpdate()
{
transformation->rotation->pan+=1*time_step;
CPTransformTranslate(transformation, vector(1*time_step, 0, 0));
}
At the moment you have to attach those components per script: