Beispiel #1
0
     j.velx = 0
     j.fila = 4
 if event.key == pg.K_UP:
     j.vely = -10
     j.velx = 0
     j.fila = 7
 # if event.key == pg.K_RIGHT:
 #     time.sleep(0.01)
 #     if event.key == pg.K_UP:
 #         j.velx=10
 #         j.vely=-10
 #         j.fila=7
 if event.key == pg.K_SPACE:
     # CREAR BALA
     if j.fila == 7 or j.fila == 4:
         b = Bala(j.rect.midright, matriz_bala_jugador, 5)
         balas_jugador.add(b)
         b.velx = 30
     if j.fila == 2:
         b = Bala(j.rect.midright, matriz_bala_jugador, 5)
         b2 = Bala(j.rect.topright, matriz_bala_jugador, 5)
         balas_jugador.add(b)
         balas_jugador.add(b2)
         b.velx = 30
         b2.velx = 30
     if j.fila == 5:
         b = Bala(j.rect.midleft, matriz_bala_jugador, 4)
         b2 = Bala(j.rect.topleft, matriz_bala_jugador, 4)
         balas_jugador.add(b)
         balas_jugador.add(b2)
         b.velx = -30
Beispiel #2
0
from OpenGL.GL import *
from glew_wish import *
import glfw
from math import *
from Bala import *

bala = Bala()


class Carrito:
    posicionX = 0.0
    posicionY = -0.8
    angulo = 0
    desfase= 90
    velocidad = 1
    velocidad_angular = 180
    disparando = False 
    colisionando = False

    def disparar(self):
        global bala
        self.disparando = True
        bala.posicionX = self.posicionX
        bala.posicionY = self.posicionY
        bala.anguloBala = self.angulo

    def dibujar(self):
        global bala
        glPushMatrix()
        glTranslate(self.posicionX, self.posicionY, 0.0)
        glRotate(self.angulo, 0.0, 0.0, 1.0)
 def shoot(self):
     if self.derecha:
         bala = Bala([self.rect.x, self.rect.y], -20)
     if self.izquierda:
         bala = Bala([self.rect.x, self.rect.y], +20)
     return bala
Beispiel #4
0
     j.velx=0
     j.fila=0
 if event.key == pg.K_UP:
     j.vely=-10
     j.velx=0
     j.fila=1
 # if event.key == pg.K_RIGHT:
 #     time.sleep(0.01)
 #     if event.key == pg.K_UP:
 #         j.velx=10
 #         j.vely=-10
 #         j.fila=7
 if event.key== pg.K_SPACE:
     # CREAR BALA
     if j.fila == 1:
         b=Bala(j.rect.midtop,matriz_bala_jugador,0)
         b2=Bala(j.rect.topleft,matriz_bala_jugador,0)
         balas_jugador.add(b)
         balas_jugador.add(b2)
         b.vely=-30
         b2.vely=-30
     if j.fila == 0:
         b=Bala(j.rect.midbottom,matriz_bala_jugador,2)
         b2=Bala(j.rect.bottomleft,matriz_bala_jugador,2)
         balas_jugador.add(b)
         balas_jugador.add(b2)
         b.vely=30
         b2.vely=30
     if j.fila == 2:
         b=Bala(j.rect.midright,matriz_bala_jugador,5)
         b2=Bala(j.rect.topright,matriz_bala_jugador,5)
Beispiel #5
0
 if event.key == pg.K_UP:
     j.vely = -10
     j.velx = 0
     j.fila = 7
     j.fila3 = 7
 # if event.key == pg.K_RIGHT:
 #     time.sleep(0.01)
 #     if event.key == pg.K_UP:
 #         j.velx=10
 #         j.vely=-10
 #         j.fila=7
 if event.key == pg.K_SPACE:
     # CREAR BALA
     ms_disparo_j.play()
     if j.fila == 7 or j.fila == 4:
         b = Bala(j.rect.midright, matriz_bala_jugador, 5)
         balas_jugador.add(b)
         b.velx = 30
     if j.fila == 2:
         b = Bala(j.rect.midright, matriz_bala_jugador, 5)
         b2 = Bala(j.rect.topright, matriz_bala_jugador, 5)
         balas_jugador.add(b)
         balas_jugador.add(b2)
         b.velx = 30
         b2.velx = 30
     if j.fila == 5:
         b = Bala(j.rect.midleft, matriz_bala_jugador, 4)
         b2 = Bala(j.rect.topleft, matriz_bala_jugador, 4)
         balas_jugador.add(b)
         balas_jugador.add(b2)
         b.velx = -30
Beispiel #6
0
def main(argv):
    # imprime en consola
    print 'Earth Defender'

    Rmax = 200.0  # "radio" maximo meteoritos
    Rmin = 30.0  # "radio" minimo meteoritos
    w = 900  # ancho
    h = 600  # alto
    t = 0  # tiempo de conteo para generar meteoritos

    # si se desea utilizar argumentos del programa...
    # if len(argv) > 1:
    # var1 = argv[1]
    # var2 = int(argv[2])

    v0 = Vector(0, 30)  # velocidad balas
    a = Vector(0.0, -0.5)  # aceleración de gravedad
    T = 600  # periodo de aparicion de meteoritos

    ms = []  # contenedor de meteoritos
    bs = []  # contenedor de balas
    nave = Nave()
    tierra = Tierra(w)
    vista = Vista()
    # inicializando ...
    init_pygame((w, h), "Earth Defender")
    init_opengl((w, h))

    # sonidos
    sound_shoot = pygame.mixer.Sound("laser.wav")
    sound_shoot.set_volume(0.2)

    # música de fondo
    pygame.mixer.music.load("background.mp3")
    pygame.mixer.music.play(-1, 0.0)

    # medida de tiempo inicial
    t0 = pygame.time.get_ticks()

    run = True
    while run:
        # 0: CONTROL DEL TIEMPO
        t1 = pygame.time.get_ticks()  # tiempo actual
        dt = (t1 - t0)  # diferencial de tiempo asociado a la iteración
        t0 = t1  # actualizar tiempo inicial para siguiente iteración

        for event in pygame.event.get():
            mouse_pos = pygame.mouse.get_pos()
            nave.p = Vector(mouse_pos[0], 100)

            # disparar
            if event.type == MOUSEBUTTONDOWN:
                bs.append(Bala(nave.p, v0))
                sound_shoot.play()

            # cerrar
            if event.type == QUIT:
                run = False

            if event.type == KEYDOWN:
                # ataque especial
                if event.key == K_SPACE:
                    if nave.sp - 1 >= 0:
                        bs.append(Bala(nave.p, v0))
                        bs.append(Bala(nave.p, rotar(v0, math.pi / 12)))
                        bs.append(Bala(nave.p, rotar(v0, -math.pi / 12)))
                        bs.append(Bala(nave.p, rotar(v0, math.pi / 6)))
                        bs.append(Bala(nave.p, rotar(v0, -math.pi / 6)))
                        bs.append(Bala(nave.p, rotar(v0, math.pi / 4)))
                        bs.append(Bala(nave.p, rotar(v0, -math.pi / 4)))
                        nave.sp = nave.sp - 1

                # cambia la aceleración del nivel
                if event.key == K_RETURN:
                    a = Vector(uniform(-0.5, 0.5), uniform(-1.0, 0))
                    print "a = ", a.cartesianas()

                # genera meteoritos más rápido
                if event.key == K_BACKSPACE:
                    T -= T * 0.1
                    print "T = ", T

                # cerrar
                if event.key == K_ESCAPE:
                    run = False

        # si se acaban las vidas termina el programa.
        if tierra.vida <= 0:
            print 'GAME OVER'
            run = False

        # efecua las acciones necesarias de manera proporcional a dt
        vista.dibujar(nave, ms, bs, tierra, dt, a, w, h, Rmin, Rmax)

        # si supero el periodo de creacion de meteoritos
        # creo un meteorito, y reinicio el tiempo
        t = t + dt
        if t > T:
            t = t - T
            ms.append(crearMeteorito(w, h, Rmin, Rmax))

        # pone el dibujo en la pantalla
        pygame.display.flip()
        # ajusta para trabajar a 30 fps.
        pygame.time.wait(1000 / 30)

    # termina pygame (cerrar ventana)
    pygame.quit()
 def shoot(self):
     if self.direction == 1:
         bala = Bala([self.rect.x, self.rect.y],-20)
     if self.direction == 0:
         bala = Bala([self.rect.x, self.rect.y],+20)
     return bala