void gameLoop() {
// Calculate timing delta since last loop
makeGameControllerUpdateCurrentSceneWithDelta(delta);
render();
}
Then, my function for updating the current scene (level), updates the positions of Entities (characters, either Human or Computer).
This game is really simple right now. The screen is fixed (and will remain that way, so all Entities are generally on screen at once) and also right now there is just one Human player, but I'm trying to design it with the eventual goal of having other players (networked… I'll cross that bridge later, I just want my engine to not make assumptions about how many Entities are Human).
void makeGameControllerUpdateCurrentSceneWithDelta(float delta) {
// Assume the scene is not paused; ie it's running. I do checks in my actual code
// I first call a function to update all the entities in the scene. This loops through each of them and calls their respective "updateWithDelta(float)"
updateAllEntitiesWithDelta(delta);
// other things
// should collision detection go here?
checkCollisionForAllEntitiesWithDelta(delta);
}
My question is kind of in the code. Should my collision detection happen in the scene's update function, OR should it be part of each entity's updateWithDelta() call (ie, should each entity call the checking…. I'm thinking NO, because then it would have to know about all other entities, right? Seems like a bad design, but maybe I'm wrong).
Also, my checkCollisionForAllEntities() should be checking every single entity against EVERY other entity of the scene, right? When I do the check (let's assume just really simple rectangle intersection for now), and they do collide, then should I be calling some function on both entities of the collision? Like
if (rectIntersection(entityARect, entityBRect)) {
entityA.collidedWithEntity(entityB);
entityB.collidedWithEntity(entityA);
// Or would just one of these be sufficient?
}
I think that's all I've got at this point, just trying to better my understanding of how to design this properly. Thanks in advance for any help!