def display(self, x=0, y=0): '''Called for every refresh; redraws the floor and objects based on the camera angle. Calls collision detection, handles the appropriate objects for keys, doors, etc.''' glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() self.camera.move(self.objects) self.camera.check_collisions(self.objects) self.camera.renderCamera() self.renderLightSource() self.makeFloor() # Transparent objects! glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) self.sort_by_dist() for obj in self.objects: if obj.get_dist(self.camera.pos_X, self.camera.pos_Y, self.camera.pos_Z) < 15: color = obj.get_color() pos = obj.get_pos() obj_type = obj.get_type() glPushMatrix() # Set the objects shininess, ambient, diffuse, and # specular reflections. The objects are slightly # transparent. <- (nick: Why?) glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, 15) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [color[0], color[1], color[2], .5]) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [.4, .4, .4, 1]) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [.9, .9, .9, .5]) glTranslate(pos[0], pos[1], pos[2]) if obj_type == 'block': glutSolidCube(2) elif obj_type == 'key' or obj_type == 'chest': if not obj.get_has(): glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, 75) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [color[0], color[1], color[2], .5]) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [.4, .4, .4, .7]) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [.9, .9, .9, .6]) self.makeobj(obj.get_type()) elif obj_type == 'zombie': glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, 75) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [color[0], color[1], color[2], .5]) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [.4, .4, .4, .7]) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [.9, .9, .9, .6]) zomX, zomY, zomZ = pos # We already grabbed pos. self.makeobj(obj.get_type()) elif obj_type == 'chest': glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, 75) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [color[0], color[1], color[2], .5]) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [.4, .4, .4, .7]) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [.9, .9, .9, .6]) self.makeobj(obj.get_type()) elif obj_type == 'door': if obj.get_key().get_has(): glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [color[0], color[1], color[2], .2]) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [.4, .4, .4, .2]) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [.9, .9, .9, .2]) else: glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, 75) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [color[0], color[1], color[2], .5]) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [.4, .4, .4, .7]) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [.9, .9, .9, .6]) glRotate(obj.get_rotation(), 0, 1, 0) self.makeobj(obj.get_type()) else: glutSolidSphere(2, 40, 40) glPopMatrix() glDisable(GL_BLEND) Overlay.draw_overlay(self.camera, self.soundboard.paused) if self.camera.key_timeout > 0: Overlay.draw_text("Got a key!") self.camera.key_timeout -= 1 if self.camera.dead_timeout > 0: Overlay.draw_text("A zombie killed you!") self.camera.dead_timeout -= 1 if self.camera.treasure_timeout > 0: Overlay.draw_text("Got treasure!") self.camera.treasure_timeout -= 1 glutSwapBuffers()