示例#1
0
    def draw(self):

        glColor3f(1.0, 1.0, 1.0)
        # glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        glBindTexture(GL_TEXTURE_2D, self.planets[self.skin])

        glPushMatrix()

        glRotate(self.angle, 0, 1, 0)
        for i in range(0, self.lats + 1):
            lat0 = pi * (-0.5 + float(float(i - 1) / float(self.lats)))
            z0 = sin(lat0)
            zr0 = cos(lat0)

            lat1 = pi * (-0.5 + float(float(i) / float(self.lats)))
            z1 = sin(lat1)
            zr1 = cos(lat1)

            # Use Quad strips to draw the sphere
            glBegin(GL_QUAD_STRIP)

            for j in range(0, self.longs + 1):
                lng = 2 * pi * float(float(j - 1) / float(self.longs))
                x = cos(lng)
                y = sin(lng)
                glTexCoord2f(0, 1)
                glNormal3f(
                    self.start_position_x + (15 * self.my_scale) + x *
                    (zr0 * 15), self.move_y + self.start_position_y +
                    (20 * self.my_scale) + y * (zr0 * 15), z0 * -15)
                glTexCoord2f(1, 1)
                glVertex3f(
                    self.start_position_x + (15 * self.my_scale) + x *
                    (zr0 * 15), self.move_y + self.start_position_y +
                    (20 * self.my_scale) + y * (zr0 * 15), z0 * -15)
                glTexCoord2f(1, 0)
                glNormal3f(
                    self.start_position_x + (15 * self.my_scale) + x *
                    (zr1 * 15), self.move_y + self.start_position_y +
                    (20 * self.my_scale) + y * (zr1 * 15), z1 * -15)
                glTexCoord2f(0, 0)
                glVertex3f(
                    self.start_position_x + (15 * self.my_scale) + x *
                    (zr1 * 15), self.move_y + self.start_position_y +
                    (20 * self.my_scale) + y * (zr1 * 15), z1 * -15)

            glEnd()
        glPopMatrix()
        glDisable(GL_TEXTURE_2D)
示例#2
0
 def draw_faces(position: Tuple[int, int], size: Tuple[float, float, float],
                face_color: Tuple[float, float, float]):
     pos_x, pos_y = position
     size_x, size_y, size_z = size
     glColor(face_color)
     for face in Draw.faces:
         glBegin(GL_POLYGON)
         for vertex in face:
             glVertex3f(Draw.vertices[vertex, 0] * size_x + pos_x,
                        -(Draw.vertices[vertex, 1] * size_y + pos_y),
                        Draw.vertices[vertex, 2] * size_z)
         glEnd()
示例#3
0
 def draw_border(position: Tuple[int, int], size: Tuple[float, float,
                                                        float],
                 border_color: Tuple[float, float, float]):
     pos_x, pos_y = position
     size_x, size_y, size_z = size
     glBegin(GL_LINES)
     glColor(border_color)
     for edge in Draw.edges:
         for vertex in edge:
             glVertex3f(Draw.vertices[vertex, 0] * size_x + pos_x,
                        -(Draw.vertices[vertex, 1] * size_y + pos_y),
                        Draw.vertices[vertex, 2] * size_z)
     glEnd()
    def draw(self):

        glColor3f(1.0, 1.0, 1.0)
        # glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        if self.type == "inicio":
            glBindTexture(GL_TEXTURE_2D, self.logo_inicio)
        elif self.type == "fim":
            glBindTexture(GL_TEXTURE_2D, self.logo_fim)

        glPushMatrix()
        glRotate(90, 1, 0, 0)
        glBegin(GL_QUADS)
        glTexCoord2f(0, 1)
        glVertex3f(self.start_position_x - 35, self.start_position_y - 25, -70)
        glTexCoord2f(1, 1)
        glVertex3f(self.start_position_x + 35, self.start_position_y - 25, -70)
        glTexCoord2f(1, 0)

        glVertex3f(self.start_position_x + 35, self.start_position_y + 25, -70)
        glTexCoord2f(0, 0)
        glVertex3f(self.start_position_x - 35, self.start_position_y + 25, -70)
        glEnd()

        glPopMatrix()
        glDisable(GL_TEXTURE_2D)
    def draw(self):

        glColor3f(1.0, 1.0, 1.0)
        glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        glBindTexture(GL_TEXTURE_2D, self.imageID)

        glPushMatrix()

        glBegin(GL_QUADS)
        glTexCoord2f(0, 1)
        glVertex3f(self.start_position_x - 40,
                   self.move_y + self.start_position_y, 0)
        glTexCoord2f(1, 1)
        glVertex3f(self.start_position_x + 40,
                   self.move_y + self.start_position_y, 0)
        glTexCoord2f(1, 0)

        glVertex3f(self.start_position_x + 40,
                   self.move_y + self.start_position_y_2, 0)
        glTexCoord2f(0, 0)
        glVertex3f(self.start_position_x - 40,
                   self.move_y + self.start_position_y_2, 0)
        glEnd()

        glPopMatrix()
        glDisable(GL_TEXTURE_2D)
示例#6
0
    def draw(self):
        self.propellant.draw()

        glColor3f(1.0, 1.0, 1.0)
        glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        if self.nave_type == 0:
            glBindTexture(GL_TEXTURE_2D, self.skin_azul)
        elif self.nave_type == 1:
            glBindTexture(GL_TEXTURE_2D, self.skin_amarela)
        elif self.nave_type == 2:
            glBindTexture(GL_TEXTURE_2D, self.skin_preta)

        glPushMatrix()

        glBegin(GL_QUADS)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + self.position_x - 4.0, self.move_y, 0)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + self.position_x + 4.0, self.move_y, 0)
        glTexCoord2f(1, 0)

        glVertex3f(self.move_x + self.position_x + 4.0, self.move_y + 12, 0)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + self.position_x - 4.0, self.move_y + 12, 0)
        glEnd()

        glPopMatrix()
        glDisable(GL_TEXTURE_2D)
示例#7
0
    def draw_x_switch(position: Tuple[int, int], color: Tuple[float, float,
                                                              float]):

        glPushMatrix()
        glTranslate(0.5 + position[0], -0.5 - position[1], 0)

        height = 0.15
        # glColor(Cube.colors['light_blue'])
        if len(Draw.x_switch_pt) == 0:
            width = 0.15
            size = 0.25
            Draw.x_switch_pt = [(-width, 0), (-(width + size), -size),
                                (-(width + size), -(width + size)),
                                (-size, -(width + size)), (0, -width),
                                (size, -(width + size)),
                                (width + size, -(width + size)),
                                (width + size, -size), (width, 0),
                                (width + size, size),
                                (width + size, width + size),
                                (size, width + size), (0, width),
                                (-size, width + size),
                                (-(width + size), width + size),
                                (-(width + size), size)]

        glColor(color)
        glBegin(GL_QUAD_STRIP)
        for x, y in Draw.x_switch_pt:
            glVertex3f(x, y, height)
            glVertex3f(x, y, 0)
        glVertex3f(Draw.x_switch_pt[0][0], Draw.x_switch_pt[0][1], height)
        glVertex3f(Draw.x_switch_pt[0][0], Draw.x_switch_pt[0][1], 0)
        glEnd()

        glLineWidth(3)
        glColor(Draw.colors['gray'])
        # -0.2, 0 -> -0.8, 0.6
        glBegin(GL_POLYGON)
        for x, y in Draw.x_switch_pt:
            glVertex3f(x, y, height)
        glEnd()
        glLineWidth(1)

        glPopMatrix()
    def draw(self):
        img = self.imgs[self.quadro]

        w = 30
        h = 43

        glColor3f(1.0, 1.0, 1.0)
        glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        glBindTexture(GL_TEXTURE_2D, self.imgs[self.quadro])

        glPushMatrix()

        glBegin(GL_QUADS)

        glTexCoord2f(0, 1)
        glVertex3f(self.x - w / 2, self.y - h / 2, 1)
        glTexCoord2f(1, 1)
        glVertex3f(self.x + w / 2, self.y - h / 2, 1)
        glTexCoord2f(1, 0)
        glVertex3f(self.x + w / 2, self.y + h / 2, 1)
        glTexCoord2f(0, 0)
        glVertex3f(self.x - w / 2, self.y + h / 2, 1)

        glEnd()

        glPopMatrix()
        glDisable(GL_TEXTURE_2D)

        if time() - self.start >= EXPLOSION_FRAME:
            if not self.type == "player":
                self.quadro += 1
                self.start = time()

                if self.quadro >= EXPLOSION_FRAMES:
                    self.quadro = 0
                    self.dead = True
            else:
                self.quadro += 1
                self.start = time()

                if self.quadro >= EXPLOSION_FRAMES:
                    self.quadro = 0
                    self.dead = True
示例#9
0
    def draw(self):

        glColor3f(1.0, 1.0, 1.0)
        glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        glBindTexture(GL_TEXTURE_2D, self.planets[self.skin])

        glPushMatrix()

        glBegin(GL_QUADS)
        glTexCoord2f(0, 1)
        glVertex3f(self.start_position_x - (15 * self.my_scale),
                   self.move_y + self.start_position_y - (15 * self.my_scale),
                   -1)
        glTexCoord2f(1, 1)
        glVertex3f(self.start_position_x + (15 * self.my_scale),
                   self.move_y + self.start_position_y - (15 * self.my_scale),
                   -1)
        glTexCoord2f(1, 0)

        glVertex3f(self.start_position_x + (15 * self.my_scale),
                   self.move_y + self.start_position_y + (20 * self.my_scale),
                   -1)
        glTexCoord2f(0, 0)
        glVertex3f(self.start_position_x - (15 * self.my_scale),
                   self.move_y + self.start_position_y + (20 * self.my_scale),
                   -1)
        glEnd()

        glPopMatrix()
        glDisable(GL_TEXTURE_2D)
示例#10
0
    def paintGL(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()

        gluLookAt(0.0, 2.5, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)

        glRotatef(self.angle, 0.0, 1.0, 0.0)

        glBegin(GL_TRIANGLES)
        glColor3f(1.0, 1.0, 0.0)
        glVertex3f(0.0, 1.0, 0.0)
        glVertex3f(-1.0, -1.0, 0.0)
        glVertex3f(1.0, -1.0, 0.0)
        glEnd()

        glPopMatrix()

        glFlush()
示例#11
0
    def draw_teleport_switch(position: Tuple[int, int],
                             color: Tuple[float, float, float]):
        radius = 0.4
        height = 0.15
        angle_stepsize = 0.1

        glPushMatrix()
        glTranslate(0.5 + position[0], -0.5 - position[1], 0)
        glColor(color)

        # side 1
        glBegin(GL_QUAD_STRIP)
        angle = 0.0
        first = True
        temp_x, temp_y = 0, 0
        while angle < 2 * pi:
            x = radius * cos(angle)
            y = radius * sin(angle)
            if y >= 0.1:
                if first:
                    temp_x, temp_y = x, y
                    first = False
                glVertex3f(x, y, height)
                glVertex3f(x, y, 0)
            angle += angle_stepsize

        while angle > 0:
            x = radius * cos(angle)
            y = radius * sin(angle)
            if y >= 0.1:
                glVertex3f(x * 0.6, y * 0.6, height)
                glVertex3f(x * 0.6, y * 0.6, 0)
            angle -= angle_stepsize
        glVertex3f(temp_x, temp_y, height)
        glVertex3f(temp_x, temp_y, 0)
        glEnd()

        # side 2
        glBegin(GL_QUAD_STRIP)
        angle = 0.0
        first = True
        temp_x, temp_y = 0, 0
        while angle < 2 * pi:
            x = radius * cos(angle)
            y = radius * sin(angle)
            if y <= -0.1:
                if first:
                    temp_x, temp_y = x, y
                    first = False
                glVertex3f(x, y, height)
                glVertex3f(x, y, 0)
            angle += angle_stepsize

        while angle > 0:
            x = radius * cos(angle)
            y = radius * sin(angle)
            if y <= -0.1:
                glVertex3f(x * 0.6, y * 0.6, height)
                glVertex3f(x * 0.6, y * 0.6, 0)
            angle -= angle_stepsize
        glVertex3f(temp_x, temp_y, height)
        glVertex3f(temp_x, temp_y, 0)
        glEnd()

        # top 1
        glColor(Draw.colors['gray'])
        glBegin(GL_QUAD_STRIP)
        angle = 0.0
        while angle < 2 * pi:
            x1 = radius * cos(angle)
            y1 = radius * sin(angle)
            x2 = radius * cos(angle) * 0.6
            y2 = radius * sin(angle) * 0.6
            if y1 >= 0.1:
                glVertex3f(x1, y1, height)
                glVertex3f(x2, y2, height)
            angle += angle_stepsize
        glEnd()

        # top 2
        glColor(Draw.colors['gray'])
        glBegin(GL_QUAD_STRIP)
        angle = 0.0
        while angle < 2 * pi:
            x1 = radius * cos(angle)
            y1 = radius * sin(angle)
            x2 = radius * cos(angle) * 0.6
            y2 = radius * sin(angle) * 0.6
            if y1 <= -0.1:
                glVertex3f(x1, y1, height)
                glVertex3f(x2, y2, height)
            angle += angle_stepsize
        glEnd()

        glPopMatrix()
示例#12
0
    def draw_cube():
        glScalef(
            0.5, 0.5, 0.5
        )  # dimensions below are for a 2x2x2 cube, so scale it down by a half first
        glBegin(GL_QUADS)  # Start Drawing The Cube

        glVertex3f(1.0, 1.0, -1.0)  # Top Right Of The Quad (Top)
        glVertex3f(-1.0, 1.0, -1.0)  # Top Left Of The Quad (Top)
        glVertex3f(-1.0, 1.0, 1.0)  # Bottom Left Of The Quad (Top)
        glVertex3f(1.0, 1.0, 1.0)  # Bottom Right Of The Quad (Top)

        glVertex3f(1.0, -1.0, 1.0)  # Top Right Of The Quad (Bottom)
        glVertex3f(-1.0, -1.0, 1.0)  # Top Left Of The Quad (Bottom)
        glVertex3f(-1.0, -1.0, -1.0)  # Bottom Left Of The Quad (Bottom)
        glVertex3f(1.0, -1.0, -1.0)  # Bottom Right Of The Quad (Bottom)

        glVertex3f(1.0, 1.0, 1.0)  # Top Right Of The Quad (Front)
        glVertex3f(-1.0, 1.0, 1.0)  # Top Left Of The Quad (Front)
        glVertex3f(-1.0, -1.0, 1.0)  # Bottom Left Of The Quad (Front)
        glVertex3f(1.0, -1.0, 1.0)  # Bottom Right Of The Quad (Front)

        glVertex3f(1.0, -1.0, -1.0)  # Bottom Left Of The Quad (Back)
        glVertex3f(-1.0, -1.0, -1.0)  # Bottom Right Of The Quad (Back)
        glVertex3f(-1.0, 1.0, -1.0)  # Top Right Of The Quad (Back)
        glVertex3f(1.0, 1.0, -1.0)  # Top Left Of The Quad (Back)

        glVertex3f(-1.0, 1.0, 1.0)  # Top Right Of The Quad (Left)
        glVertex3f(-1.0, 1.0, -1.0)  # Top Left Of The Quad (Left)
        glVertex3f(-1.0, -1.0, -1.0)  # Bottom Left Of The Quad (Left)
        glVertex3f(-1.0, -1.0, 1.0)  # Bottom Right Of The Quad (Left)

        glVertex3f(1.0, 1.0, -1.0)  # Top Right Of The Quad (Right)
        glVertex3f(1.0, 1.0, 1.0)  # Top Left Of The Quad (Right)
        glVertex3f(1.0, -1.0, 1.0)  # Bottom Left Of The Quad (Right)
        glVertex3f(1.0, -1.0, -1.0)  # Bottom Right Of The Quad (Right)
        glEnd()  # Done Drawing The Quad

        # Draw the wireframe edges
        glColor3f(0.0, 0.0, 0.0)  # draw edges in black
        glLineWidth(1.0)

        glBegin(GL_LINE_LOOP)
        glVertex3f(1.0, 1.0, -1.0)  # Top Right Of The Quad (Top)
        glVertex3f(-1.0, 1.0, -1.0)  # Top Left Of The Quad (Top)
        glVertex3f(-1.0, 1.0, 1.0)  # Bottom Left Of The Quad (Top)
        glVertex3f(1.0, 1.0, 1.0)  # Bottom Right Of The Quad (Top)
        glEnd()  # Done Drawing The Quad

        glBegin(GL_LINE_LOOP)
        glVertex3f(1.0, -1.0, 1.0)  # Top Right Of The Quad (Bottom)
        glVertex3f(-1.0, -1.0, 1.0)  # Top Left Of The Quad (Bottom)
        glVertex3f(-1.0, -1.0, -1.0)  # Bottom Left Of The Quad (Bottom)
        glVertex3f(1.0, -1.0, -1.0)  # Bottom Right Of The Quad (Bottom)
        glEnd()  # Done Drawing The Quad

        glBegin(GL_LINE_LOOP)
        glVertex3f(1.0, 1.0, 1.0)  # Top Right Of The Quad (Front)
        glVertex3f(-1.0, 1.0, 1.0)  # Top Left Of The Quad (Front)
        glVertex3f(-1.0, -1.0, 1.0)  # Bottom Left Of The Quad (Front)
        glVertex3f(1.0, -1.0, 1.0)  # Bottom Right Of The Quad (Front)
        glEnd()  # Done Drawing The Quad

        glBegin(GL_LINE_LOOP)
        glVertex3f(1.0, -1.0, -1.0)  # Bottom Left Of The Quad (Back)
        glVertex3f(-1.0, -1.0, -1.0)  # Bottom Right Of The Quad (Back)
        glVertex3f(-1.0, 1.0, -1.0)  # Top Right Of The Quad (Back)
        glVertex3f(1.0, 1.0, -1.0)  # Top Left Of The Quad (Back)
        glEnd()  # Done Drawing The Quad

        glBegin(GL_LINE_LOOP)
        glVertex3f(-1.0, 1.0, 1.0)  # Top Right Of The Quad (Left)
        glVertex3f(-1.0, 1.0, -1.0)  # Top Left Of The Quad (Left)
        glVertex3f(-1.0, -1.0, -1.0)  # Bottom Left Of The Quad (Left)
        glVertex3f(-1.0, -1.0, 1.0)  # Bottom Right Of The Quad (Left)
        glEnd()  # Done Drawing The Quad

        glBegin(GL_LINE_LOOP)
        glVertex3f(1.0, 1.0, -1.0)  # Top Right Of The Quad (Right)
        glVertex3f(1.0, 1.0, 1.0)  # Top Left Of The Quad (Right)
        glVertex3f(1.0, -1.0, 1.0)  # Bottom Left Of The Quad (Right)
        glVertex3f(1.0, -1.0, -1.0)  # Bottom Right Of The Quad (Right)
        glEnd()  # Done Drawing The Quad
示例#13
0
    def draw_round_switch(position: Tuple[int, int], color: Tuple[float, float,
                                                                  float]):

        glPushMatrix()
        glTranslate(0.5 + position[0], -0.5 - position[1], 0)
        glColor(color)

        radius = 0.4
        height = 0.15
        angle = 0.0
        angle_stepsize = 0.1
        # glColor(Cube.colors['light_blue'])
        glBegin(GL_QUAD_STRIP)
        while angle < 2 * pi:
            x = radius * cos(angle)
            y = radius * sin(angle)
            glVertex3f(x, y, height - 0.01)
            glVertex3f(x, y, 0.0)
            angle += angle_stepsize

        glVertex3f(radius, 0.0, height - 0.01)
        glVertex3f(radius, 0.0, 0.0)
        glEnd()

        # glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
        glLineWidth(3)
        glColor(Draw.colors['gray'])
        glBegin(GL_POLYGON)
        angle = 0.0
        while angle < 2 * pi:
            x = radius * cos(angle)
            y = radius * sin(angle)
            glVertex3f(x, y, height)
            angle += angle_stepsize
        glVertex3f(radius, 0.0, height)
        glEnd()
        glLineWidth(1)

        glPopMatrix()
示例#14
0
    def draw(self):
        glColor3f(1.0, 1.0, 1.0)

        glPushMatrix()

        glBegin(GL_TRIANGLE_FAN)
        glVertex3f(self.move_x + 0 * self.scale, self.move_y + 0 * self.scale,
                   0)
        glVertex3f(self.move_x + 0 * self.scale, self.move_y + 2 * self.scale,
                   0)
        glVertex3f(self.move_x + 1.5 * self.scale,
                   self.move_y + 1.5 * self.scale, 0)
        glVertex3f(self.move_x + 2 * self.scale, self.move_y + 0 * self.scale,
                   0)
        glVertex3f(self.move_x + 1.5 * self.scale,
                   self.move_y + -1.5 * self.scale, 0)
        glVertex3f(self.move_x + 0 * self.scale, self.move_y - 2 * self.scale,
                   0)
        glVertex3f(self.move_x - 1.5 * self.scale,
                   self.move_y - 1.5 * self.scale, 0)
        glVertex3f(self.move_x - 2 * self.scale, self.move_y + 0 * self.scale,
                   0)
        glVertex3f(self.move_x - 1.5 * self.scale,
                   self.move_y + 1.5 * self.scale, 0)
        glVertex3f(self.move_x + 0 * self.scale, self.move_y + 2 * self.scale,
                   0)
        glEnd()

        glPopMatrix()
    def draw(self):

        glColor3f(1.0, 1.0, 1.0)
        # glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        glBindTexture(GL_TEXTURE_2D, self.imageID)

        glPushMatrix()
        # if self.is_enemy:
        #     glRotate(self.angle, 0, 0, 1)
        #

        glBegin(GL_QUADS)

        # glColor3f(0.0, 0.0, 1.0)
        glTexCoord2f(0, 1)
        glVertex3f(self.start_position_x + 1.0, self.move + self.start_position_y_2, -1.0)
        glTexCoord2f(1, 1)
        glVertex3f(self.start_position_x - 1.0, self.move + self.start_position_y_2, -1.0)
        glTexCoord2f(1, 0)
        glVertex3f(self.start_position_x - 1.0, self.move + self.start_position_y_2, 1.0)
        glTexCoord2f(0, 0)
        glVertex3f(self.start_position_x + 1.0, self.move + self.start_position_y_2, 1.0)

        # glColor3f(0.0, 1.0, 1.0)
        glTexCoord2f(0, 1)
        glVertex3f(self.start_position_x + 1.0, self.move + self.start_position_y, 1.0)
        glTexCoord2f(1, 1)
        glVertex3f(self.start_position_x + -1.0, self.move + self.start_position_y, 1.0)
        glTexCoord2f(1, 0)
        glVertex3f(self.start_position_x + -1.0, self.move + self.start_position_y, -1.0)
        glTexCoord2f(0, 0)
        glVertex3f(self.start_position_x + 1.0, self.move + self.start_position_y, -1.0)

        # glColor3f(1.0, 0.0, 0.0)
        glTexCoord2f(0, 1)
        glVertex3f(self.start_position_x + 1.0, self.move + self.start_position_y_2, 1.0)
        glTexCoord2f(1, 1)
        glVertex3f(self.start_position_x + -1.0, self.move + self.start_position_y_2, 1.0)
        glTexCoord2f(1, 0)
        glVertex3f(self.start_position_x + -1.0, self.move + self.start_position_y, 1.0)
        glTexCoord2f(0, 0)
        glVertex3f(self.start_position_x + 1.0, self.move + self.start_position_y, 1.0)

        # glColor3f(0.0, 1.0, 0.0)
        glTexCoord2f(0, 1)
        glVertex3f(self.start_position_x + 1.0, self.move + self.start_position_y, -1.0)
        glTexCoord2f(1, 1)
        glVertex3f(self.start_position_x + -1.0, self.move + self.start_position_y, -1.0)
        glTexCoord2f(1, 0)
        glVertex3f(self.start_position_x + -1.0, self.move + self.start_position_y_2, -1.0)
        glTexCoord2f(0, 0)
        glVertex3f(self.start_position_x + 1.0, self.move + self.start_position_y_2, -1.0)

        # glColor3f(1.0, 1.0, 0.0)
        glTexCoord2f(0, 1)
        glVertex3f(self.start_position_x + -1.0, self.move + self.start_position_y_2, 1.0)
        glTexCoord2f(1, 1)
        glVertex3f(self.start_position_x + -1.0, self.move + self.start_position_y_2, -1.0)
        glTexCoord2f(1, 0)
        glVertex3f(self.start_position_x + -1.0, self.move + self.start_position_y, -1.0)
        glTexCoord2f(0, 0)
        glVertex3f(self.start_position_x + -1.0, self.move + self.start_position_y, 1.0)

        # glColor3f(1.0, 0.0, 1.0)
        glTexCoord2f(0, 1)
        glVertex3f(self.start_position_x+ 1.0, self.move + self.start_position_y_2, -1.0)
        glTexCoord2f(1, 1)
        glVertex3f(self.start_position_x + 1.0, self.move + self.start_position_y_2, 1.0)
        glTexCoord2f(1, 0)
        glVertex3f(self.start_position_x + 1.0, self.move + self.start_position_y, 1.0)
        glTexCoord2f(0, 0)
        glVertex3f(self.start_position_x + 1.0, self.move + self.start_position_y, -1.0)

        glEnd()

        glPopMatrix()

        glDisable(GL_TEXTURE_2D)
    def draw(self):
        # self.propellant.draw()
        #
        glColor3f(1.0, 1.0, 1.0)
        # glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        if self.nave_type == 0:
            glBindTexture(GL_TEXTURE_2D, self.skin_azul)
        elif self.nave_type == 1:
            glBindTexture(GL_TEXTURE_2D, self.skin_amarela)
        elif self.nave_type == 2:
            glBindTexture(GL_TEXTURE_2D, self.skin_preta)

        glPushMatrix()

        # glBegin(GL_QUADS)
        # glTexCoord2f(0, 1)
        # glVertex3f(self.move_x + self.position_x -4.0,
        #            self.move_y, 0)
        # glTexCoord2f(1, 1)
        # glVertex3f(self.move_x + self.position_x +4.0,
        #            self.move_y, 0)
        # glTexCoord2f(1, 0)
        #
        # glVertex3f(self.move_x + self.position_x + 4.0,
        #            self.move_y + 12, 0)
        # glTexCoord2f(0, 0)
        # glVertex3f(self.move_x + self.position_x - 4.0,
        #            self.move_y + 12, 0)
        # glEnd()

        if self.moving_right:
            glRotate(10, 0.1, 0.7, 0.2)
        elif self.moving_left:
            glRotate(-10, 0.1, 0.7, 0.2)

        #Vermelho, baixo
        glBegin(GL_TRIANGLES)
        # glColor3f(1.0, 0.0, 0.0)
        glTexCoord2f(0, 1)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + self.position_x + 5.0, self.move_y + 12, -2.0)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x + self.position_x + 0.0, self.move_y, 0.0)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + self.position_x - 5.0, self.move_y + 12, -2.0)
        glEnd()
        # VERDE esq
        glBegin(GL_TRIANGLES)
        # glColor3f(0.0, 1.0, 0.0)
        glTexCoord2f(0, 1)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + self.position_x - 5.0, self.move_y + 12, -2.0)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x + self.position_x + 0.0, self.move_y, 0.0)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + self.position_x + 0.0, self.move_y + 12, 2.0)
        glEnd()
        #############3 Azul escuro dir
        glBegin(GL_TRIANGLES)
        # glColor3f(0.5, 0.5, 1.0)
        glTexCoord2f(0, 1)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + self.position_x + 5.0, self.move_y + 12, -2.0)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x + self.position_x + 0.0, self.move_y, 0.0)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + self.position_x + 0.0, self.move_y + 12, 2.0)
        glEnd()
        #####################Roxo FRENTE
        glBegin(GL_TRIANGLES)
        # glColor3f(0.0, 0.0, 1.0)
        glTexCoord2f(0, 1)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + self.position_x + 0.0, self.move_y + 12, 2.0)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x + self.position_x + 5.0, self.move_y + 12, -2.0)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + self.position_x - 5.0, self.move_y + 12, -2.0)
        glEnd()
        glPopMatrix()
        glDisable(GL_TEXTURE_2D)
示例#17
0
    def draw(self):
        glColor3f(1.0, 1.0, 1.0)
        # glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        glPushMatrix()
        if self.moving_right:
            glRotate(5, 0, 1, 0.2)
        elif self.moving_left:
            glRotate(-5, 0, 1, 0.2)

        glBindTexture(GL_TEXTURE_2D, self.casco)

        #Base da nave
        glBegin(GL_TRIANGLE_FAN)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + 0, self.move_y + 0, 1)
        glVertex3f(self.move_x + 0, self.move_y + 6, 1)
        glVertex3f(self.move_x + 1.5, self.move_y + 3, 1)
        glVertex3f(self.move_x + 2, self.move_y + 0, 1)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + 5, self.move_y - 6, 1)
        glVertex3f(self.move_x + 2, self.move_y - 7, 1)
        glVertex3f(self.move_x + 1, self.move_y - 7, 1)
        glVertex3f(self.move_x + 0, self.move_y - 8, 1)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x - 1, self.move_y - 7, 1)
        glVertex3f(self.move_x - 2, self.move_y - 7, 1)
        glVertex3f(self.move_x - 5, self.move_y - 6, 1)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x - 2, self.move_y + 0, 1)
        glVertex3f(self.move_x - 1.5, self.move_y + 3, 1)
        glVertex3f(self.move_x + 0, self.move_y + 6, 1)
        glEnd()

        #Casco da nave (fora)
        glBegin(GL_QUAD_STRIP)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + 0, self.move_y + 6, 1)
        glVertex3f(self.move_x + 0, self.move_y + 3, 2)
        glVertex3f(self.move_x + 1.5, self.move_y + 3, 1)
        glVertex3f(self.move_x + 0.5, self.move_y + 2, 2)
        glVertex3f(self.move_x + 2, self.move_y + 0, 1)
        glVertex3f(self.move_x + 1, self.move_y + 0, 2)
        glVertex3f(self.move_x + 5, self.move_y - 6, 1)
        glVertex3f(self.move_x + 2, self.move_y - 4, 2)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + 2, self.move_y - 7, 1)
        glVertex3f(self.move_x + 1, self.move_y - 6, 2)
        glVertex3f(self.move_x + 1, self.move_y - 7, 1)
        glVertex3f(self.move_x + 0.5, self.move_y - 6, 2)
        glVertex3f(self.move_x + 0, self.move_y - 8, 1)
        glVertex3f(self.move_x + 0, self.move_y - 7, 2)
        glVertex3f(self.move_x - 1, self.move_y - 7, 1)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x - 0.5, self.move_y - 6, 2)
        glVertex3f(self.move_x - 2, self.move_y - 7, 1)
        glVertex3f(self.move_x - 1, self.move_y - 6, 2)
        glVertex3f(self.move_x - 5, self.move_y - 6, 1)
        glVertex3f(self.move_x - 2, self.move_y - 4, 2)
        glVertex3f(self.move_x - 2, self.move_y + 0, 1)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x - 1, self.move_y + 0, 2)
        glVertex3f(self.move_x - 1.5, self.move_y + 3, 1)
        glVertex3f(self.move_x - 0.5, self.move_y + 2, 2)
        glVertex3f(self.move_x + 0, self.move_y + 6, 1)
        glVertex3f(self.move_x + 0, self.move_y + 3, 2)
        glEnd()

        glDisable(GL_TEXTURE_2D)

        glColor3f(1.0, 1.0, 1.0)
        glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        glBindTexture(GL_TEXTURE_2D, self.metal)

        #Parte verde
        glBegin(GL_QUAD_STRIP)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + 0, self.move_y + 3, 2)
        glVertex3f(self.move_x + 0, self.move_y + 2, 2.5)
        glVertex3f(self.move_x + 0.5, self.move_y + 2, 2)
        glVertex3f(self.move_x + 0.5, self.move_y + 1, 2.5)
        glVertex3f(self.move_x + 1, self.move_y + 0, 2)
        glVertex3f(self.move_x + 0.5, self.move_y + 0, 2.5)
        glVertex3f(self.move_x + 2, self.move_y - 4, 2)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + 1, self.move_y - 4, 2.5)
        glVertex3f(self.move_x + 1, self.move_y - 6, 2)
        glVertex3f(self.move_x + 1, self.move_y - 5, 2.5)
        glVertex3f(self.move_x + 0.5, self.move_y - 6, 2)
        glVertex3f(self.move_x + 0.5, self.move_y - 5, 2.5)
        glVertex3f(self.move_x + 0, self.move_y - 7, 2)
        glVertex3f(self.move_x + 0, self.move_y - 5, 2.5)
        glVertex3f(self.move_x - 0.5, self.move_y - 6, 2)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x - 0.5, self.move_y - 5, 2.5)
        glVertex3f(self.move_x - 1, self.move_y - 6, 2)
        glVertex3f(self.move_x - 1, self.move_y - 5, 2.5)
        glVertex3f(self.move_x - 2, self.move_y - 4, 2)
        glVertex3f(self.move_x - 1, self.move_y - 4, 2.5)
        glVertex3f(self.move_x - 1, self.move_y + 0, 2)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x - 0.5, self.move_y + 0, 2.5)
        glVertex3f(self.move_x - 0.5, self.move_y + 2, 2)
        glVertex3f(self.move_x - 0.5, self.move_y + 1, 2.5)
        glVertex3f(self.move_x + 0, self.move_y + 3, 2)
        glVertex3f(self.move_x + 0, self.move_y + 2, 2.5)
        glEnd()

        glDisable(GL_TEXTURE_2D)

        glColor3f(1.0, 1.0, 1.0)
        glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        glBindTexture(GL_TEXTURE_2D, self.vidro)

        # #Vidro da nave
        glBegin(GL_TRIANGLE_FAN)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + 0, self.move_y - 3, 4)
        glVertex3f(self.move_x + 0, self.move_y + 2, 2.5)
        glVertex3f(self.move_x + 0.5, self.move_y + 1, 2.5)
        glVertex3f(self.move_x + 0.5, self.move_y + 0, 2.5)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + 1, self.move_y - 4, 2.5)
        glVertex3f(self.move_x + 1, self.move_y - 5, 2.5)
        glVertex3f(self.move_x + 0.5, self.move_y - 5, 2.5)
        glVertex3f(self.move_x + 0, self.move_y - 5, 2.5)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x - 0.5, self.move_y - 5, 2.5)
        glVertex3f(self.move_x - 1, self.move_y - 5, 2.5)
        glVertex3f(self.move_x - 1, self.move_y - 4, 2.5)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x - 0.5, self.move_y + 0, 2.5)
        glVertex3f(self.move_x - 0.5, self.move_y + 1, 2.5)
        glVertex3f(self.move_x + 0, self.move_y + 2, 2.5)
        glEnd()

        glPopMatrix()

        glDisable(GL_TEXTURE_2D)
示例#18
0
    def draw(self):
        glColor3f(1.0, 1.0, 1.0)
        # glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        glBindTexture(GL_TEXTURE_2D, self.imageID)

        glPushMatrix()
        glRotate(self.scene_angle , 0, 1, 0)

        glBegin(GL_TRIANGLE_FAN)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 1, -3)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, -2)
        glVertex3f(self.move_x + self.position_x +1, self.move_y + -2, -2)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + -1, -2)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + 0, -2)
        glVertex3f(self.move_x + self.position_x +1.5, self.move_y + 1, -2)
        glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 3, -2)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 3, -2)
        glVertex3f(self.move_x + self.position_x +-0.2, self.move_y + 2, -2)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + 1, -2)
        glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 0, -2)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + self.position_x +-1.5, self.move_y + -1, -2)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 2, -2)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, -2)
        glEnd()

        # glColor3f(1.0, 1.0, 0)

        glBegin(GL_QUAD_STRIP)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -4, 0)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, -2)
        glVertex3f(self.move_x + self.position_x +2.5, self.move_y + -3, 0)
        glVertex3f(self.move_x + self.position_x +1, self.move_y + -2, -2)
        glVertex3f(self.move_x + self.position_x +3, self.move_y + 0, 0)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + -1, -2)
        glVertex3f(self.move_x + self.position_x +3, self.move_y + 2, 0)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + 0, -2)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + 4, 0)
        glVertex3f(self.move_x + self.position_x +1.5, self.move_y + 1, -2)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + 5, 0)
        glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 3, -2)
        glVertex3f(self.move_x + self.position_x +-3, self.move_y + 4, 0)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 3, -2)
        glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 2, 0)
        glVertex3f(self.move_x + self.position_x +-0.2, self.move_y + 2, -2)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x + self.position_x +-4, self.move_y + 0, 0)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + 1, -2)
        glVertex3f(self.move_x + self.position_x +-3.5, self.move_y + -1.5, 0)
        glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 0, -2)
        glVertex3f(self.move_x + self.position_x +-2, self.move_y + -2, 0)
        glVertex3f(self.move_x + self.position_x +-1.5, self.move_y + -1, -2)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + -4, 0)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 2, -2)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -4, 0)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, -2)
        glEnd()

        # glColor3f(1.0, 0, 0)
        glBegin(GL_QUAD_STRIP)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -4, 0)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, 2)
        glVertex3f(self.move_x + self.position_x +2.5, self.move_y + -3, 0)
        glVertex3f(self.move_x + self.position_x +1, self.move_y + -2, 2)
        glVertex3f(self.move_x + self.position_x +3, self.move_y + 0, 0)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + -1, 2)
        glVertex3f(self.move_x + self.position_x +3, self.move_y + 2, 0)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + 0, 2)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + 4, 0)
        glVertex3f(self.move_x + self.position_x +1.5, self.move_y + 1, 2)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + 5, 0)
        glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 3, 2)
        glVertex3f(self.move_x + self.position_x +-3, self.move_y + 4, 0)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 3, 2)
        glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 2, 0)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x + self.position_x +-0.2, self.move_y + 2, 2)
        glVertex3f(self.move_x + self.position_x +-4, self.move_y + 0, 0)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + 1, 2)
        glVertex3f(self.move_x + self.position_x +-3.5, self.move_y + -1.5, 0)
        glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 0, 2)
        glVertex3f(self.move_x + self.position_x +-2, self.move_y + -2, 0)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + self.position_x +-1.5, self.move_y + -1, 2)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + -4, 0)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 2, 2)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -4, 0)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, 2)
        glEnd()

        # glColor3f(0, 1.0, 0)
        glBegin(GL_TRIANGLE_FAN)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 1, 3)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, 2)
        glVertex3f(self.move_x + self.position_x +1, self.move_y + -2, 2)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + -1, 2)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + 0, 2)
        glVertex3f(self.move_x + self.position_x +1.5, self.move_y + 1, 2)
        glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 3, 2)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 3, 2)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x + self.position_x +-0.2, self.move_y + 2, 2)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + 1, 2)
        glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 0, 2)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + self.position_x +-1.5, self.move_y + -1, 2)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 2, 2)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, 2)
        glEnd()

        glPopMatrix()
        glDisable(GL_TEXTURE_2D)
示例#19
0
    def draw(self):

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        gluPerspective(45, 1.65, 0.1, 500)
        gluLookAt(self.xizi, self.yizi - 50, 3.9, self.xizi, self.yizi, 0, 0,
                  1, 0)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        glColor3f(1.0, 1.0, 1.0)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        # glRotate(20, 0, 0, 1)
        glPushMatrix()
        # glBindTexture(GL_TEXTURE_2D, self.casco)
        #
        # #Base da nave
        # glBegin(GL_TRIANGLE_FAN)
        # glTexCoord2f(0, 1)
        # glVertex3f(self.move_x + 0, self.move_y + 0, 1)
        # glTexCoord2f(1, 1)
        # glVertex3f(self.move_x + 0, self.move_y + 6, 1)
        # glTexCoord2f(1, 0)
        # glVertex3f(self.move_x + 1.5, self.move_y + 3, 1)
        # glTexCoord2f(0, 0)
        # glVertex3f(self.move_x + 2, self.move_y + 0, 1)
        # glTexCoord2f(0, 1)
        # glVertex3f(self.move_x + 5, self.move_y - 6, 1)
        # glTexCoord2f(1, 1)
        # glVertex3f(self.move_x + 2, self.move_y - 7, 1)
        # glTexCoord2f(1, 0)
        # glVertex3f(self.move_x + 1, self.move_y - 7, 1)
        # glTexCoord2f(1, 1)
        # glVertex3f(self.move_x + 0, self.move_y - 8, 1)
        # glTexCoord2f(1, 0)
        # glVertex3f(self.move_x - 1, self.move_y - 7, 1)
        # glTexCoord2f(0, 0)
        # glVertex3f(self.move_x - 2, self.move_y - 7, 1)
        # glTexCoord2f(0, 1)
        # glVertex3f(self.move_x - 5, self.move_y - 6, 1)
        # glTexCoord2f(1, 1)
        # glVertex3f(self.move_x - 2, self.move_y + 0, 1)
        # glTexCoord2f(1, 0)
        # glVertex3f(self.move_x - 1.5, self.move_y + 3, 1)
        # glTexCoord2f(0, 0)
        # glVertex3f(self.move_x + 0, self.move_y + 6, 1)
        # glEnd()
        #
        # #Casco da nave (fora)
        # glBegin(GL_QUAD_STRIP)
        # glTexCoord2f(0, 1)
        # glVertex3f(self.move_x + 0, self.move_y + 6, 1)
        # glVertex3f(self.move_x + 0, self.move_y + 3, 2)
        # glVertex3f(self.move_x + 1.5, self.move_y + 3, 1)
        # glVertex3f(self.move_x + 0.5, self.move_y + 2, 2)
        # glVertex3f(self.move_x + 2, self.move_y + 0, 1)
        # glVertex3f(self.move_x + 1, self.move_y + 0, 2)
        # glVertex3f(self.move_x + 5, self.move_y - 6, 1)
        # glVertex3f(self.move_x + 2, self.move_y - 4, 2)
        # glTexCoord2f(1, 1)
        # glVertex3f(self.move_x + 2, self.move_y - 7, 1)
        # glVertex3f(self.move_x + 1, self.move_y - 6, 2)
        # glVertex3f(self.move_x + 1, self.move_y - 7, 1)
        # glVertex3f(self.move_x + 0.5, self.move_y - 6, 2)
        # glVertex3f(self.move_x + 0, self.move_y - 8, 1)
        # glVertex3f(self.move_x + 0, self.move_y - 7, 2)
        # glVertex3f(self.move_x - 1, self.move_y - 7, 1)
        # glTexCoord2f(1, 0)
        # glVertex3f(self.move_x - 0.5, self.move_y - 6, 2)
        # glVertex3f(self.move_x - 2, self.move_y - 7, 1)
        # glVertex3f(self.move_x - 1, self.move_y - 6, 2)
        # glVertex3f(self.move_x - 5, self.move_y - 6, 1)
        # glVertex3f(self.move_x - 2, self.move_y - 4, 2)
        # glVertex3f(self.move_x - 2, self.move_y + 0, 1)
        # glTexCoord2f(0, 0)
        # glVertex3f(self.move_x - 1, self.move_y + 0, 2)
        # glVertex3f(self.move_x - 1.5, self.move_y + 3, 1)
        # glVertex3f(self.move_x - 0.5, self.move_y + 2, 2)
        # glVertex3f(self.move_x + 0, self.move_y + 6, 1)
        # glVertex3f(self.move_x + 0, self.move_y + 3, 2)
        # glEnd()
        #
        # glDisable(GL_TEXTURE_2D)
        #
        # glColor3f(1.0, 1.0, 1.0)
        # glDisable(GL_LIGHTING)
        # glEnable(GL_TEXTURE_2D)
        #
        # glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        # glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        # glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        #
        # glBindTexture(GL_TEXTURE_2D, self.metal)
        #
        # #Parte verde
        # glBegin(GL_QUAD_STRIP)
        # glTexCoord2f(0, 1)
        # glVertex3f(self.move_x + 0, self.move_y + 3, 2)
        # glVertex3f(self.move_x + 0, self.move_y + 2, 2.5)
        # glVertex3f(self.move_x + 0.5, self.move_y + 2, 2)
        # glVertex3f(self.move_x + 0.5, self.move_y + 1, 2.5)
        # glVertex3f(self.move_x + 1, self.move_y + 0, 2)
        # glVertex3f(self.move_x + 0.5, self.move_y + 0, 2.5)
        # glVertex3f(self.move_x + 2, self.move_y - 4, 2)
        # glTexCoord2f(1, 1)
        # glVertex3f(self.move_x + 1, self.move_y - 4, 2.5)
        # glVertex3f(self.move_x + 1, self.move_y - 6, 2)
        # glVertex3f(self.move_x + 1, self.move_y - 5, 2.5)
        # glVertex3f(self.move_x + 0.5, self.move_y - 6, 2)
        # glVertex3f(self.move_x + 0.5, self.move_y - 5, 2.5)
        # glVertex3f(self.move_x + 0, self.move_y - 7, 2)
        # glVertex3f(self.move_x + 0, self.move_y - 5, 2.5)
        # glVertex3f(self.move_x - 0.5, self.move_y - 6, 2)
        # glTexCoord2f(1, 0)
        # glVertex3f(self.move_x - 0.5, self.move_y - 5, 2.5)
        # glVertex3f(self.move_x - 1, self.move_y - 6, 2)
        # glVertex3f(self.move_x - 1, self.move_y - 5, 2.5)
        # glVertex3f(self.move_x - 2, self.move_y - 4, 2)
        # glVertex3f(self.move_x - 1, self.move_y - 4, 2.5)
        # glVertex3f(self.move_x - 1, self.move_y + 0, 2)
        # glTexCoord2f(0, 0)
        # glVertex3f(self.move_x - 0.5, self.move_y + 0, 2.5)
        # glVertex3f(self.move_x - 0.5, self.move_y + 2, 2)
        # glVertex3f(self.move_x - 0.5, self.move_y + 1, 2.5)
        # glVertex3f(self.move_x + 0, self.move_y + 3, 2)
        # glVertex3f(self.move_x + 0, self.move_y + 2, 2.5)
        # glEnd()
        #
        # glDisable(GL_TEXTURE_2D)
        #
        # glColor3f(1.0, 1.0, 1.0)
        # glEnable(GL_TEXTURE_2D)
        #
        # glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        # glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        # glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        # glBindTexture(GL_TEXTURE_2D, self.vidro)
        #
        # #Mira
        #
        # glDisable(GL_TEXTURE_2D)
        glColor3f(1, 0, 0)

        glBegin(GL_LINES)
        glVertex3f(self.move_x + 0, self.move_y + 70, 3)
        glVertex3f(self.move_x + 0, self.move_y + 70, -3)
        glEnd()
        glBegin(GL_LINES)
        glVertex3f(self.move_x + 3, self.move_y + 70, 0)
        glVertex3f(self.move_x + -3, self.move_y + 70, 0)
        glEnd()
        glPopMatrix()

        glColor3f(1.0, 1.0, 1.0)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
        glBindTexture(GL_TEXTURE_2D, self.vidro)

        #Cookpit
        # glPushMatrix()
        glBegin(GL_QUADS)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + -11, self.move_y + 6.9, 9.5)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x + 11, self.move_y + 6.9, 9.5)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + 11, self.move_y + 6.9, -4)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + -11, self.move_y + 6.9, -4)
        # glTexCoord2f(0, 1)
        # glVertex3f(self.move_x+ -50, self.move_y +50, 50)
        # glTexCoord2f(1, 1)
        # glVertex3f(self.move_x+ 50, self.move_y +50, 50)
        # glTexCoord2f(1, 0)
        # glVertex3f(self.move_x+ 50, self.move_y +-50, -50)
        # glTexCoord2f(0, 0)
        # glVertex3f(self.move_x+ -50, self.move_y +-50, -50)
        glEnd()
        glDisable(GL_TEXTURE_2D)
    def paintGL(self):

        # Checa se a musica de fundo acabou e reinicia
        self.check_end_backm()
        self.update()
        # Se o player morreu, entao o jogo acaba
        if self.myNave.dead:
            self.started = False

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()

        self.update_time()
        self.spawn_planets()

        # Desenha os ornamentos ( "Flores" )
        # e retira os objetos "mortos" retornando eles para a fila
        for obj in self.ornaments:
            if not obj == None:
                if obj.dead:
                    if isinstance(obj, Planeta):
                        self.planets_queue.push(obj)
                        self.ornaments.remove(obj)
                    elif isinstance(obj, Explode):
                        self.explosion_queue.push(obj)
                        self.ornaments.remove(obj)
                obj.draw()
                obj.act()
                obj.check_dead()
            if isinstance(obj, Planeta):
                if self.myNave.moving_right:
                    obj.scene_angle = -20
                elif self.myNave.moving_left:
                    obj.scene_angle = 20
                elif not self.myNave.moving_right and not self.myNave.moving_left:
                    obj.scene_angle = 0

        scaleSB = 100
        #Skybox

        # glDisable(GL_DEPTH_TEST)
        glColor3f(1.0, 1.0, 1.0)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        glBindTexture(GL_TEXTURE_2D, self.skybox)
        glPushMatrix()

        glBegin(GL_QUADS)
        glTexCoord2f(0, 1)
        glVertex3f(-1 * scaleSB, 1 * scaleSB, 1 * scaleSB)
        glTexCoord2f(1, 1)
        glVertex3f(1 * scaleSB, 1 * scaleSB, 1 * scaleSB)
        glTexCoord2f(1, 0)
        glVertex3f(1 * scaleSB, -1 * scaleSB, 1 * scaleSB)
        glTexCoord2f(0, 0)
        glVertex3f(-1 * scaleSB, -1 * scaleSB, 1 * scaleSB)
        glEnd()

        glBegin(GL_QUADS)
        glTexCoord2f(0, 1)
        glVertex3f(-1 * scaleSB, 1 * scaleSB, -1 * scaleSB)
        glTexCoord2f(1, 1)
        glVertex3f(1 * scaleSB, 1 * scaleSB, -1 * scaleSB)
        glTexCoord2f(1, 0)
        glVertex3f(1 * scaleSB, -1 * scaleSB, -1 * scaleSB)
        glTexCoord2f(0, 0)
        glVertex3f(-1 * scaleSB, -1 * scaleSB, -1 * scaleSB)
        glEnd()

        glBegin(GL_QUADS)
        glTexCoord2f(0, 1)
        glVertex3f(-1 * scaleSB, -1 * scaleSB, 1 * scaleSB)
        glTexCoord2f(1, 1)
        glVertex3f(1 * scaleSB, -1 * scaleSB, 1 * scaleSB)
        glTexCoord2f(1, 0)
        glVertex3f(1 * scaleSB, -1 * scaleSB, -1 * scaleSB)
        glTexCoord2f(0, 0)
        glVertex3f(-1 * scaleSB, -1 * scaleSB, -1 * scaleSB)
        glEnd()

        glBegin(GL_QUADS)
        glTexCoord2f(0, 1)
        glVertex3f(-1 * scaleSB, 1 * scaleSB, 1 * scaleSB)
        glTexCoord2f(1, 1)
        glVertex3f(1 * scaleSB, 1 * scaleSB, 1 * scaleSB)
        glTexCoord2f(1, 0)
        glVertex3f(1 * scaleSB, 1 * scaleSB, -1 * scaleSB)
        glTexCoord2f(0, 0)
        glVertex3f(-1 * scaleSB, 1 * scaleSB, -1 * scaleSB)
        glEnd()

        glBegin(GL_QUADS)
        glTexCoord2f(0, 1)
        glVertex3f(1 * scaleSB, 1 * scaleSB, 1 * scaleSB)
        glTexCoord2f(1, 1)
        glVertex3f(1 * scaleSB, 1 * scaleSB, -1 * scaleSB)
        glTexCoord2f(1, 0)
        glVertex3f(1 * scaleSB, -1 * scaleSB, -1 * scaleSB)
        glTexCoord2f(0, 0)
        glVertex3f(1 * scaleSB, -1 * scaleSB, 1 * scaleSB)
        glEnd()

        glBegin(GL_QUADS)
        glTexCoord2f(0, 1)
        glVertex3f(-1 * scaleSB, 1 * scaleSB, 1 * scaleSB)
        glTexCoord2f(1, 1)
        glVertex3f(-1 * scaleSB, 1 * scaleSB, -1 * scaleSB)
        glTexCoord2f(1, 0)
        glVertex3f(-1 * scaleSB, -1 * scaleSB, -1 * scaleSB)
        glTexCoord2f(0, 0)
        glVertex3f(-1 * scaleSB, -1 * scaleSB, 1 * scaleSB)
        glEnd()

        glPopMatrix()
        glDisable(GL_TEXTURE_2D)

        # glEnable(GL_DEPTH_TEST)

        # Verifica se o jogo foi iniciado
        if not self.started:
            return
        # Desenha a cena
        # e retira os objetos mortos retornando ele para a fila
        # e instancia uma explosao no lugar
        for obj in self.in_scene:
            if not obj == None:
                if obj.dead:
                    if isinstance(obj, Enemy):
                        new_explosion = self.explosion_queue.pop()
                        new_explosion.load(self.animation_explosion,
                                           obj.move_x + obj.position_x,
                                           obj.move_y + 6, "enemy", 15)
                        self.in_scene.append(new_explosion)
                        self.enemy_queue.push(obj)
                        self.in_scene.remove(obj)
                    elif isinstance(obj, Asteroide):
                        new_explosion = self.explosion_queue.pop()
                        new_explosion.load(self.animation_explosion,
                                           obj.move_x + obj.position_x,
                                           obj.move_y + 5, "enemy", 15)
                        self.in_scene.append(new_explosion)
                        self.asteroid_queue.push(obj)
                        self.in_scene.remove(obj)
                    elif isinstance(obj, Shoot):
                        self.bullets_queue.push(obj)
                        self.in_scene.remove(obj)
                    elif isinstance(obj, Explode):
                        obj.dead = False
                        self.explosion_queue.push(obj)
                        self.in_scene.remove(obj)
                    elif isinstance(obj, Power_up):
                        self.power_queue.push(obj)
                        self.in_scene.remove(obj)
                if isinstance(obj, Nave):
                    if obj.shooting:
                        self.create_shoot(obj.move_x + obj.position_x)
                if isinstance(obj, Enemy) or isinstance(obj, Asteroide):
                    if self.myNave.moving_right:
                        obj.scene_angle = -20
                    elif self.myNave.moving_left:
                        obj.scene_angle = 20
                    elif not self.myNave.moving_right and not self.myNave.moving_left:
                        obj.scene_angle = 0
                obj.draw()
                obj.act()
                obj.check_dead()

        # Testa as colisoes e aplica os efeitos (ganhar pontos, ou perder vida)
        for obj_A in self.in_scene:
            if isinstance(obj_A, Asteroide):
                for obj_B in self.in_scene:
                    if not (obj_A == obj_B):
                        if isinstance(obj_B, Nave) and self.collide(
                                obj_B, obj_A):
                            #ui.down_life()
                            obj_A.dead = True
                        elif isinstance(obj_B, Shoot) and self.collide(
                                obj_B, obj_A):
                            if not obj_B.is_enemy:
                                obj_A.dead = True
                                obj_B.dead = True
                                self.sound_explosion.play()
                                ui.up_point(10)
                                if ui.score % 1000 == 0:
                                    self.sound_1000pts.play()
            elif isinstance(obj_A, Enemy):
                obj_A.elapsed_shoot_time += time()
                if obj_A.elapsed_shoot_time >= SHOOT_TIME_ENEMY:
                    pos = [obj_A.get_x()[0] + 5, obj_A.get_y()[0] + 6, 0]
                    player = [
                        self.myNave.get_x()[0] + 5,
                        self.myNave.get_y()[0] - 8, 0
                    ]
                    dir = [
                        player[0] - pos[0], player[1] - pos[1],
                        player[2] - pos[2]
                    ]
                    angle_R = math.atan2(dir[1], pos[0])
                    angle = math.degrees(angle_R)
                    if obj_A.nave_type == 0:
                        self.create_shoot(obj_A.move_x + obj_A.position_x,
                                          obj_A.move_y, obj_A.move_y + 6, True,
                                          obj_A.nave_type, obj_A.shoot_type,
                                          self.img_tiro_azul, angle)
                    elif obj_A.nave_type == 1:
                        self.create_shoot(obj_A.move_x + obj_A.position_x,
                                          obj_A.move_y, obj_A.move_y + 6, True,
                                          obj_A.nave_type, obj_A.shoot_type,
                                          self.img_tiro_amarelo, angle)
                    elif obj_A.nave_type == 2:
                        self.create_shoot(obj_A.move_x + obj_A.position_x,
                                          obj_A.move_y, obj_A.move_y + 6, True,
                                          obj_A.nave_type, obj_A.shoot_type,
                                          self.img_tiro_preto, angle)

                    obj_A.elapsed_shoot_time = 0
                for obj_B in self.in_scene:
                    if not (obj_A == obj_B):
                        if isinstance(obj_B, Nave) and self.collide(
                                obj_B, obj_A):
                            #ui.down_life()
                            obj_A.dead = True
                        elif isinstance(obj_B, Shoot) and self.collide(
                                obj_B, obj_A):
                            if not obj_B.is_enemy:
                                obj_A.dead = True
                                obj_B.dead = True
                                self.sound_explosion.play()
                                ui.up_point(10)
                                if ui.score % 1000 == 0:
                                    self.sound_1000pts.play()
            elif isinstance(obj_A, Shoot):
                if obj_A.is_enemy:
                    for obj_B in self.in_scene:
                        if not (obj_A == obj_B):
                            if isinstance(obj_B, Nave) and self.collide(
                                    obj_B, obj_A):
                                #ui.down_life()
                                obj_A.dead = True
            elif isinstance(obj_A, Nave):
                for obj_B in self.in_scene:
                    if not (obj_A == obj_B):
                        if isinstance(obj_B, Power_up) and self.collide(
                                obj_B, obj_A):
                            obj_B.dead = True
                            self.sound_power.play()
                            if obj_B.skin == 0:
                                ui.up_life()
                            elif obj_B.skin == 1:
                                self.hack = True
                                self.elapsed_time_power_shoot = 0
                            elif obj_B.skin == 2:
                                self.speed = True
                                self.elapsed_time_power_speed = 0

        self.spawn_asteroide()
        self.spawn_inimigos()
        self.update()
    def paintGL(self):

        # Checa se a musica de fundo acabou e reinicia
        self.check_end_backm()
        self.update()
        # Se o player morreu, entao o jogo acaba
        if self.myNave.dead:
            self.started = False

        glClear(GL_COLOR_BUFFER_BIT)
        glLoadIdentity()

        # Desenha o background
        ''''' Inicio do background ''' ''
        glColor3f(1.0, 1.0, 1.0)
        glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        glBindTexture(GL_TEXTURE_2D, self.imageID_back)

        glPushMatrix()

        glBegin(GL_QUADS)
        glTexCoord2f(0, 1)
        glVertex3f(50, -50, 1)
        glTexCoord2f(1, 1)
        glVertex3f(-50, -50, 1)
        glTexCoord2f(1, 0)
        glVertex3f(-50, 50, 1)
        glTexCoord2f(0, 0)
        glVertex3f(50, 50, 1)
        glEnd()

        glPopMatrix()
        glDisable(GL_TEXTURE_2D)
        ''''' Fim do background ''' ''

        self.update_time()
        self.spawn_flowers()
        self.spawn_planets()
        self.spawn_stars()

        # Desenha os ornamentos ( "Flores" )
        # e retira os objetos "mortos" retornando eles para a fila
        for obj in self.ornaments:
            if not obj == None:
                if obj.dead:
                    if isinstance(obj, Flor):
                        self.flowers_queue.push(obj)
                        self.ornaments.remove(obj)
                    elif isinstance(obj, Planeta):
                        self.planets_queue.push(obj)
                        self.ornaments.remove(obj)
                    elif isinstance(obj, Star):
                        self.ornaments.remove(obj)
                    elif isinstance(obj, Explode):
                        self.explosion_queue.push(obj)
                        self.ornaments.remove(obj)
                    elif isinstance(obj, Propellant):
                        self.propellant_queue.push(obj)
                        self.ornaments.remove(obj)
                obj.draw()
                obj.act()
                obj.check_dead()

        # print (self.enemy_queue.tam())
        # Verifica se o jogo foi iniciado
        if (not self.started):
            return

        # Desenha a cena
        # e retira os objetos mortos retornando ele para a fila
        # e instancia uma explosao no lugar
        for obj in self.in_scene:
            if not obj == None:
                if obj.dead:
                    if isinstance(obj, Enemy):
                        new_explosion = self.explosion_queue.pop()
                        new_explosion.load(self.animation_explosion,
                                           obj.move_x + obj.position_x,
                                           obj.move_y + 6, "enemy")
                        self.in_scene.append(new_explosion)
                        self.enemy_queue.push(obj)
                        self.in_scene.remove(obj)
                    elif isinstance(obj, Asteroide):
                        new_explosion = self.explosion_queue.pop()
                        new_explosion.load(self.animation_explosion,
                                           obj.move_x + obj.position_x,
                                           obj.move_y + 5, "enemy")
                        self.in_scene.append(new_explosion)
                        self.asteroid_queue.push(obj)
                        self.in_scene.remove(obj)
                    elif isinstance(obj, Shoot):
                        self.bullets_queue.push(obj)
                        self.in_scene.remove(obj)
                    elif isinstance(obj, Explode):
                        obj.dead = False
                        self.explosion_queue.push(obj)
                        self.in_scene.remove(obj)
                    elif isinstance(obj, Power_up):
                        self.power_queue.push(obj)
                        self.in_scene.remove(obj)
                if isinstance(obj, Nave):
                    if obj.shooting:
                        self.create_shoot(obj.move_x + obj.position_x)
                obj.draw()
                obj.act()
                obj.check_dead()

        # Testa as colisoes e aplica os efeitos (ganhar pontos, ou perder vida)
        for obj_A in self.in_scene:
            if isinstance(obj_A, Asteroide):
                for obj_B in self.in_scene:
                    if not (obj_A == obj_B):
                        if isinstance(obj_B, Nave) and self.collide(
                                obj_B, obj_A):
                            ui.down_life()
                            obj_A.dead = True
                        elif isinstance(obj_B, Shoot) and self.collide(
                                obj_B, obj_A):
                            if not obj_B.is_enemy:
                                obj_A.dead = True
                                if not self.hack:
                                    obj_B.dead = True
                                self.sound_explosion.play()
                                ui.up_point(10)
                                if ui.score % 1000 == 0:
                                    self.sound_1000pts.play()
            elif isinstance(obj_A, Enemy):
                obj_A.elapsed_shoot_time += time()
                if obj_A.elapsed_shoot_time >= SHOOT_TIME_ENEMY:
                    if obj_A.nave_type == 0:
                        self.create_shoot(obj_A.move_x + obj_A.position_x,
                                          obj_A.move_y, obj_A.move_y + 6, True,
                                          obj_A.nave_type, obj_A.shoot_type,
                                          self.img_tiro_azul)
                    elif obj_A.nave_type == 1:
                        self.create_shoot(obj_A.move_x + obj_A.position_x,
                                          obj_A.move_y, obj_A.move_y + 6, True,
                                          obj_A.nave_type, obj_A.shoot_type,
                                          self.img_tiro_amarelo)
                    elif obj_A.nave_type == 2:
                        self.create_shoot(obj_A.move_x + obj_A.position_x,
                                          obj_A.move_y, obj_A.move_y + 6, True,
                                          obj_A.nave_type, obj_A.shoot_type,
                                          self.img_tiro_preto)

                    obj_A.elapsed_shoot_time = 0
                for obj_B in self.in_scene:
                    if not (obj_A == obj_B):
                        if isinstance(obj_B, Nave) and self.collide(
                                obj_B, obj_A):
                            ui.down_life()
                            obj_A.dead = True
                        elif isinstance(obj_B, Shoot) and self.collide(
                                obj_B, obj_A):
                            if not obj_B.is_enemy:
                                obj_A.dead = True
                                if self.hack:
                                    obj_B.dead = False
                                else:
                                    obj_B.dead = True
                                self.sound_explosion.play()
                                ui.up_point(10)
                                if ui.score % 1000 == 0:
                                    self.sound_1000pts.play()
            elif isinstance(obj_A, Shoot):
                if obj_A.is_enemy:
                    for obj_B in self.in_scene:
                        if not (obj_A == obj_B):
                            if isinstance(obj_B, Nave) and self.collide(
                                    obj_B, obj_A):
                                ui.down_life()
                                obj_A.dead = True
            elif isinstance(obj_A, Nave):
                if self.speed:
                    obj_A.speed = 3
                else:
                    obj_A.speed = 0
                for obj_B in self.in_scene:
                    if not (obj_A == obj_B):
                        if isinstance(obj_B, Power_up) and self.collide(
                                obj_B, obj_A):
                            obj_B.dead = True
                            self.sound_power.play()
                            if obj_B.skin == 0:
                                ui.up_life()
                            elif obj_B.skin == 1:
                                self.hack = True
                                self.elapsed_time_power_shoot = 0
                            elif obj_B.skin == 2:
                                self.speed = True
                                self.elapsed_time_power_speed = 0

        self.spawn_asteroide()
        self.spawn_inimigos()
        self.spawn_powers()
        self.update()
示例#22
0
    def paintGL(self):
        self.check_end_backm()
        self.update()
        if self.myNave.dead:
            self.started = False

        glClear(GL_COLOR_BUFFER_BIT)
        glLoadIdentity()

        ########### DRAW BACKGROUND ##################
        glColor3f(1.0, 1.0, 1.0)
        glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        glBindTexture(GL_TEXTURE_2D, self.imageID_back)

        glPushMatrix()

        glBegin(GL_QUADS)
        glTexCoord2f(0, 1)
        glVertex3f(50, -50, 1)
        glTexCoord2f(1, 1)
        glVertex3f(-50, -50, 1)
        glTexCoord2f(1, 0)
        glVertex3f(-50, 50, 1)
        glTexCoord2f(0, 0)
        glVertex3f(50, 50, 1)
        glEnd()

        glPopMatrix()
        glDisable(GL_TEXTURE_2D)

        self.update_time()
        self.spawn_flowers()
        self.spawn_planets()
        self.spawn_stars()

        ########### DRAW ORNAMENTS ##################
        for obj in self.ornaments:
            if not obj == None:
                if obj.dead:
                    if isinstance(obj, Flor):
                        self.flowers_queue.push(obj)
                        self.ornaments.remove(obj)
                    elif isinstance(obj, Planeta):
                        self.planets_queue.push(obj)
                        self.ornaments.remove(obj)
                    elif isinstance(obj, Star):
                        self.ornaments.remove(obj)
                obj.draw()
                obj.act()
                obj.check_dead()

        # print(self.bullets_queue.tam())
        ########### VERIFY IF THE GAME HAS STARTED ##################
        if (not self.started):
            return

        ########### DRAW SCENE ##################
        for obj in self.in_scene:
            if not obj == None:
                if obj.dead:
                    if isinstance(obj, Enemy):
                        new_explosion = self.explosion_queue.pop()
                        new_explosion.load(self.animation_explosion,
                                           obj.move_x + obj.position_x,
                                           obj.move_y + 6, "enemy")
                        self.in_scene.append(new_explosion)
                        self.enemy_queue.push(obj)
                        self.in_scene.remove(obj)
                    elif isinstance(obj, Asteroide):
                        new_explosion = self.explosion_queue.pop()
                        new_explosion.load(self.animation_explosion,
                                           obj.move_x + obj.position_x,
                                           obj.move_y + 5, "enemy")
                        self.in_scene.append(new_explosion)
                        self.asteroid_queue.push(obj)
                        self.in_scene.remove(obj)
                    elif isinstance(obj, Shoot):
                        self.bullets_queue.push(obj)
                        self.in_scene.remove(obj)
                    elif isinstance(obj, Explode):
                        obj.dead = False
                        self.explosion_queue.push(obj)
                        self.in_scene.remove(obj)
                obj.draw()
                obj.act()
                obj.check_dead()

        ########### COLLISION CHECK ##################
        for obj_A in self.in_scene:
            if isinstance(obj_A, Asteroide):
                for obj_B in self.in_scene:
                    if not (obj_A == obj_B):
                        if isinstance(obj_B, Nave) and self.collide(
                                obj_B, obj_A):
                            # obj_B.dead = True
                            ui.down_life()
                            obj_A.dead = True
                        elif isinstance(obj_B, Shoot) and self.collide(
                                obj_B, obj_A):
                            if not obj_B.is_enemy:
                                obj_A.dead = True
                                if not self.hack:
                                    obj_B.dead = True
                                self.sound_explosion.play()
                                ui.up_point(10)
                                if ui.score % 1000 == 0:
                                    self.sound_1000pts.play()
            elif isinstance(obj_A, Enemy):
                obj_A.elapsed_shoot_time += time()
                if obj_A.elapsed_shoot_time >= SHOOT_TIME_ENEMY:
                    if obj_A.nave_type == 0:
                        self.create_shoot(obj_A.move_x + obj_A.position_x,
                                          obj_A.move_y, obj_A.move_y + 6, True,
                                          obj_A.nave_type, obj_A.shoot_type,
                                          self.img_tiro_azul)
                    elif obj_A.nave_type == 1:
                        self.create_shoot(obj_A.move_x + obj_A.position_x,
                                          obj_A.move_y, obj_A.move_y + 6, True,
                                          obj_A.nave_type, obj_A.shoot_type,
                                          self.img_tiro_amarelo)
                    elif obj_A.nave_type == 2:
                        self.create_shoot(obj_A.move_x + obj_A.position_x,
                                          obj_A.move_y, obj_A.move_y + 6, True,
                                          obj_A.nave_type, obj_A.shoot_type,
                                          self.img_tiro_preto)

                    obj_A.elapsed_shoot_time = 0
                for obj_B in self.in_scene:
                    if not (obj_A == obj_B):
                        if isinstance(obj_B, Nave) and self.collide(
                                obj_B, obj_A):
                            # obj_B.dead = True
                            ui.down_life()
                            obj_A.dead = True
                        elif isinstance(obj_B, Shoot) and self.collide(
                                obj_B, obj_A):
                            if not obj_B.is_enemy:
                                obj_A.dead = True
                                if self.hack:
                                    obj_B.dead = False
                                else:
                                    obj_B.dead = True
                                self.sound_explosion.play()
                                ui.up_point(10)
                                if ui.score % 1000 == 0:
                                    self.sound_1000pts.play()
            elif isinstance(obj_A, Shoot):
                if obj_A.is_enemy:
                    for obj_B in self.in_scene:
                        if not (obj_A == obj_B):
                            if isinstance(obj_B, Nave) and self.collide(
                                    obj_B, obj_A):
                                # obj_B.dead = True
                                ui.down_life()
                                obj_A.dead = True

        self.spawn_asteroide()
        self.spawn_inimigos()

        self.update()
示例#23
0
    def draw(self):
        glColor3f(1.0, 1.0, 1.0)
        # glDisable(GL_LIGHTING)
        glEnable(GL_TEXTURE_2D)

        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
        glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)

        glBindTexture(GL_TEXTURE_2D, self.imageID)

        glPushMatrix()
        # glRotate(self.angle, 0, 0, 0)
        #
        # for i in range(0, self.lats + 1):
        #     lat0 = pi * (-0.5 + float(float(i - 1) / float(self.lats)))
        #     z0 = sin(lat0)
        #     zr0 = cos(lat0)
        #
        #     lat1 = pi * (-0.5 + float(float(i) / float(self.lats)))
        #     z1 = sin(lat1)
        #     zr1 = cos(lat1)
        #
        #     # Use Quad strips to draw the sphere
        #     glBegin(GL_QUAD_STRIP)
        #
        #     for j in range(0, self.longs + 1):
        #         lng = 2 * pi * float(float(j - 1) / float(self.longs))
        #         x = cos(lng)
        #         y = sin(lng)
        #         glTexCoord2f(0, 1)
        #         glNormal3f(self.move_x + self.position_x + x * (zr0 * 3),
        #                    self.move_y + 4 + y * (zr0 * 3), z0 * 3)
        #         glTexCoord2f(1, 1)
        #         glVertex3f(self.move_x + self.position_x + x * (zr0 * 3),
        #                    self.move_y + 4+ y * (zr0 * 3), z0 * 3)
        #         glTexCoord2f(1, 0)
        #         glNormal3f(self.move_x + self.position_x + x * (zr1 * 3),
        #                    self.move_y + 4 + y * (zr1 * 3), z1 * 3)
        #         glTexCoord2f(0, 0)
        #         glVertex3f(self.move_x + self.position_x + x * (zr1 * 3),
        #                    self.move_y + 4 + y * (zr1 * 3), z1 * 3)
        #
        #     glEnd()

        # glColor3f(0, 0, 1)
        glBegin(GL_TRIANGLE_FAN)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 1, -3)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, -2)
        glVertex3f(self.move_x + self.position_x +1, self.move_y + -2, -2)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + -1, -2)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + 0, -2)
        glVertex3f(self.move_x + self.position_x +1.5, self.move_y + 1, -2)
        glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 3, -2)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 3, -2)
        glVertex3f(self.move_x + self.position_x +-0.2, self.move_y + 2, -2)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + 1, -2)
        glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 0, -2)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + self.position_x +-1.5, self.move_y + -1, -2)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 2, -2)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, -2)
        glEnd()

        # glColor3f(1.0, 1.0, 0)

        glBegin(GL_QUAD_STRIP)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -4, 0)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, -2)
        glVertex3f(self.move_x + self.position_x +2.5, self.move_y + -3, 0)
        glVertex3f(self.move_x + self.position_x +1, self.move_y + -2, -2)
        glVertex3f(self.move_x + self.position_x +3, self.move_y + 0, 0)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + -1, -2)
        glVertex3f(self.move_x + self.position_x +3, self.move_y + 2, 0)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + 0, -2)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + 4, 0)
        glVertex3f(self.move_x + self.position_x +1.5, self.move_y + 1, -2)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + 5, 0)
        glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 3, -2)
        glVertex3f(self.move_x + self.position_x +-3, self.move_y + 4, 0)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 3, -2)
        glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 2, 0)
        glVertex3f(self.move_x + self.position_x +-0.2, self.move_y + 2, -2)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x + self.position_x +-4, self.move_y + 0, 0)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + 1, -2)
        glVertex3f(self.move_x + self.position_x +-3.5, self.move_y + -1.5, 0)
        glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 0, -2)
        glVertex3f(self.move_x + self.position_x +-2, self.move_y + -2, 0)
        glVertex3f(self.move_x + self.position_x +-1.5, self.move_y + -1, -2)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + -4, 0)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 2, -2)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -4, 0)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, -2)
        glEnd()

        # glColor3f(1.0, 0, 0)
        glBegin(GL_QUAD_STRIP)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -4, 0)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, 2)
        glVertex3f(self.move_x + self.position_x +2.5, self.move_y + -3, 0)
        glVertex3f(self.move_x + self.position_x +1, self.move_y + -2, 2)
        glVertex3f(self.move_x + self.position_x +3, self.move_y + 0, 0)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + -1, 2)
        glVertex3f(self.move_x + self.position_x +3, self.move_y + 2, 0)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + 0, 2)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + 4, 0)
        glVertex3f(self.move_x + self.position_x +1.5, self.move_y + 1, 2)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + 5, 0)
        glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 3, 2)
        glVertex3f(self.move_x + self.position_x +-3, self.move_y + 4, 0)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 3, 2)
        glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 2, 0)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x + self.position_x +-0.2, self.move_y + 2, 2)
        glVertex3f(self.move_x + self.position_x +-4, self.move_y + 0, 0)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + 1, 2)
        glVertex3f(self.move_x + self.position_x +-3.5, self.move_y + -1.5, 0)
        glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 0, 2)
        glVertex3f(self.move_x + self.position_x +-2, self.move_y + -2, 0)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + self.position_x +-1.5, self.move_y + -1, 2)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + -4, 0)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 2, 2)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -4, 0)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, 2)
        glEnd()

        # glColor3f(0, 1.0, 0)
        glBegin(GL_TRIANGLE_FAN)
        glTexCoord2f(0, 1)
        glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 1, 3)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, 2)
        glVertex3f(self.move_x + self.position_x +1, self.move_y + -2, 2)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + -1, 2)
        glTexCoord2f(1, 1)
        glVertex3f(self.move_x + self.position_x +2, self.move_y + 0, 2)
        glVertex3f(self.move_x + self.position_x +1.5, self.move_y + 1, 2)
        glVertex3f(self.move_x + self.position_x +0.5, self.move_y + 3, 2)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 3, 2)
        glTexCoord2f(1, 0)
        glVertex3f(self.move_x + self.position_x +-0.2, self.move_y + 2, 2)
        glVertex3f(self.move_x + self.position_x +-1, self.move_y + 1, 2)
        glVertex3f(self.move_x + self.position_x +-2.5, self.move_y + 0, 2)
        glTexCoord2f(0, 0)
        glVertex3f(self.move_x + self.position_x +-1.5, self.move_y + -1, 2)
        glVertex3f(self.move_x + self.position_x +-0.5, self.move_y + 2, 2)
        glVertex3f(self.move_x + self.position_x +0, self.move_y + -1.5, 2)
        glEnd()

        glPopMatrix()
        glDisable(GL_TEXTURE_2D)