GLfloat GetLocationO return location private
GLfloat location[2]; II meteor's location. location[0] = x-, location!-!] =y- coordinate
The location array stores the current (x,^-coordinates of the meteor. For this example, we let all meteors fall straight down along they-axis.
The update function merely decrements the location[l] variable in order to make the meteor fall down. You can experiment with giving meteors an x-direction as well.
The Draw routine draws a white colored point (glVertex) at the meteor's current location, whereas the DrawCollision routine draws a bigger red colored point to indicate a collision.
The functions HitEarth and OutOfScreen test the meteor's current location to determine if it has hit Earth or is out of the boundary of the defined world coorindates. It returns a TRUE value if the test is positive.
We use the ID variable to uniquely identify each meteor. The entire code for this object can be found under the directory Example4_l, in files Meteor, h and Meteor.cpp.
The function createMeteor is used to randomly create meteors during the game.The function generates a random number between 0 and 1 and only creates a meteor if this number is less than a constant. This is to ensure we do not have too many meteors being generated.
Post a comment