April 2017
Beginner to intermediate
394 pages
9h 16m
English
So far, we have only considered what members the game object has. We haven't considered how each object will have its behavior updated. Right now, the game object is just data. Since it has no functions, it can't update itself. We could easily add an Update function for the game object but, in order to update each type of object correctly, we would need a switch statement:
//Create our objects Object gameObjects[MAX_COUNT]; //initialization code here //... //Update loop for(int i = 0; i < objectInUse; ++i) { switch(gameObjects[i].type) { case OT_PLAYER: //Update based on input break; case OT_SUPER_RAIDER: //Add intercept code here break; case OT_SUPER_BOMBER: //Add case code here break; case ...Read now
Unlock full access