Ejemplo n.º 1
0
def resize(width, height):
    glViewport(0, 0, width, height)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(60.0, float(width)/height, 0.1, 1000.0)
    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()
Ejemplo n.º 2
0
    def resizeGL(self, w, h):
        if h <= 0:
            h = 1

        glViewport(0, 0, w, h)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(60.0, float(w) / float(h), 0.1, 100)
Ejemplo n.º 3
0
    def initializeGL(self):
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glShadeModel(GL_SMOOTH)

        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        glEnable(GL_ALPHA_TEST)
        glAlphaFunc(GL_NOTEQUAL, 0.0)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glOrtho(-50.0, 50.0, -50.0, 50.0, -1, 1)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        self.myNave = Nave(self.animation_propellant_enemy, self.player_x)
        self.in_scene.append(self.myNave)

        self.myNave2 = Nave(self.animation_propellant_enemy, self.player2_x)
        self.in_scene.append(self.myNave2)

        self.imageID_back = self.loadImage("img/Background.png")

        for i in range(EXPLOSION_FRAMES):
            self.animation_explosion[i] = self.loadImage("img/explosion/Comp" +
                                                         str(i) + ".png")

        for i in range(PROPELLANT_FRAMES):
            self.animation_propellant_enemy[i] = self.loadImage(
                "img/fire/Comp" + str(i) + ".png")

        self.img_nave_amarela = self.loadImage("img/nave4.png")
        self.img_nave_azul = self.loadImage("img/nave1.png")
        self.img_nave_preta = self.loadImage("img/nave3.png")
        self.img_tiro_amarelo = self.loadImage("img/nave4_pow.png")
        self.img_tiro_preto = self.loadImage("img/nave3_pow.png")
        self.img_tiro_azul = self.loadImage("img/nave1_pow.png")
        self.img_tiro = self.loadImage("img/nave2_pow.png")
        self.logo_init = self.loadImage("img/SpaceCute.png")
        self.logo_end = self.loadImage("img/YouDied.png")

        self.myLogo_i.load("inicio", self.logo_init, self.logo_end)
        self.ornaments.append(self.myLogo_i)
        self.myLogo_i.inited = True

        self.myLogo_e.load("fim", self.logo_init, self.logo_end)

        self.init_queue()
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
    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()

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

        glDisable(GL_DEPTH_TEST)

        # 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, 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()

        # Verifica se o jogo foi iniciado
        if not self.started:
            return

        glEnable(GL_DEPTH_TEST)

        # 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:
                    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
                                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()
Ejemplo n.º 6
0
    def initializeGL(self):
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glShadeModel(GL_SMOOTH)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        glEnable(GL_ALPHA_TEST)
        glAlphaFunc(GL_NOTEQUAL, 0.0)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        gluPerspective(45, 1.65, 0.1, 500)
        gluLookAt(0, -100, 50, 0, 0, 0, 0, 1, 0)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        self.myNave = Nave(self.animation_propellant_enemy, 0)
        self.in_scene.append(self.myNave)

        for i in range(EXPLOSION_FRAMES):
            self.animation_explosion[i] = self.loadImage("img/explosion/Comp" +
                                                         str(i) + ".png")

        for i in range(PROPELLANT_FRAMES):
            self.animation_propellant_enemy[i] = self.loadImage(
                "img/fire/Comp" + str(i) + ".png")

        for i in range(10):
            self.img_planets[i] = self.loadImage("img/planets/planeta" +
                                                 str(i) + ".png")

        self.img_nave_amarela = self.loadImage("img/nave4.png")
        self.img_nave_azul = self.loadImage("img/nave1.png")
        self.img_nave_preta = self.loadImage("img/nave3.png")
        self.img_tiro_amarelo = self.loadImage("img/nave4_pow.png")
        self.img_tiro_preto = self.loadImage("img/nave3_pow.png")
        self.img_tiro_azul = self.loadImage("img/nave1_pow.png")
        self.img_tiro = self.loadImage("img/nave2_pow.png")
        self.logo_init = self.loadImage("img/SpaceCute.png")
        self.logo_end = self.loadImage("img/YouDied.png")
        self.power_up_vida = self.loadImage("img/power_up_life.png")
        self.power_up_shoot = self.loadImage("img/power_up_shot.png")
        self.power_up_speed = self.loadImage("img/power_up_speed.png")

        self.myLogo_i.load("inicio", self.logo_init, self.logo_end)
        self.ornaments.append(self.myLogo_i)
        self.myLogo_i.inited = True

        self.myLogo_e.load("fim", self.logo_init, self.logo_end)

        self.init_queue()

        # Arrumando erros de frict
        fix_p = self.propellant_queue.pop()
        fix_p.load(self.animation_propellant_enemy, 1000, 1000, "fix")
        self.ornaments.append(fix_p)

        new_explosion = self.explosion_queue.pop()
        new_explosion.load(self.animation_explosion, 1000, 1000, "fix")
        self.ornaments.append(new_explosion)

        tx = 0
        ambiente = [0.2, 0.2, 0.2, 1.0]
        difusa = [0.7, 0.7, 0.7, 1.0]
        especular = [1.0, 1.0, 1.0, 1.0]
        posicao = [0.0, 3.0, 2.0, 0.0]
        lmodelo_ambiente = [0.2, 0.2, 0.2, 1.0]

        glLightfv(GL_LIGHT0, GL_AMBIENT, ambiente)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, difusa)
        glLightfv(GL_LIGHT0, GL_POSITION, posicao)
        glLightfv(GL_LIGHT0, GL_SPECULAR, especular)
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodelo_ambiente)
        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        glEnable(GL_COLOR_MATERIAL)
    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()
Ejemplo n.º 8
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()
    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()