Exemple #1
0
    def __init__(self, gameModel, backgroundFile, gameoverFile, winFile):
        # gameModel - GameModel instance
        # backgroundFile - File path of background texture
        # gameoverFile - File path of game over texture
        # winFile - File path of the game win texture
        # Reference to the game model instance
        self.gameModel = gameModel
        # Load background and gameover models
        self.background = gs.create_background(backgroundFile)
        self.gameoverScreen = gs.create_gameover_screen(gameoverFile)
        self.winScreen = gs.create_gameover_screen(winFile)

        # Define pipelines for drawing
        self.pipelineTexture = es.SimpleTextureTransformShaderProgram()
        self.pipelineColor = es.SimpleTransformShaderProgram()

        # Trayectory animation for end screen
        self.endTray = None
        self.endScreen = None
Exemple #2
0
def updateGameOverAnim(delta, pipeline):
    global scale, color
    #modifica el pipeline anterior (el de grafo de escena) a una escala de grises progresivamente
    pipeline.grayScale(color)

    #pipeline para dibujar normalmente la animacion
    temp_pipeline = es.SimpleTextureTransformShaderProgram()
    glUseProgram(temp_pipeline.shaderProgram)
    BACKGROUND_ANIM.Update(temp_pipeline, delta, tr.identity(), False)
    LETTERS_ANIM.Update(temp_pipeline, delta, tr.identity(), False)

    #se vuelve al pipeline anterior
    glUseProgram(pipeline.shaderProgram)

    #efecto de letras crecientes
    if scale < 0.3:
        scale += delta *0.1
    LETTERS_ANIM.scale = [2 * (0.4 + scale), WIDTH / HEIGHT *(0.4 + scale), 1]

    #efecto progresivo de la escala de grises
    if color > 0:
        color -= delta
    else:
        color = 0
Exemple #3
0
    height = 600

    window = glfw.create_window(width, height, "Space War", None, None)

    if not window:
        glfw.terminate()
        sys.exit()

    glfw.make_context_current(window)

    # Connecting the callback function 'on_key' to handle keyboard events
    glfw.set_key_callback(window, on_key)

    # Assembling the shader program (pipeline) with both shaders
    pipeline = es.SimpleTransformShaderProgram()
    pipelineGameOver = es.SimpleTextureTransformShaderProgram()

    # Telling OpenGL to use our shader program
    glUseProgram(pipeline.shaderProgram)

    # Setting up the clear screen color
    glClearColor(0.0, 0.0, 0.0, 1.0)

    # Creating shapes on GPU memory
    ship = createShip()
    enemyShip = createEnemyShip()
    shot = createShot()
    enemyShot = createEnemyShot()

    redPlanet1 = createRedPlanet(); greenPlanet1 = createGreenPlanet(); bluePlanet1 = createBluePlanet()
    redPlanet2 = createRedPlanet(); greenPlanet2 = createGreenPlanet(); bluePlanet2 = createBluePlanet()
Exemple #4
0
    height = 600

    window = glfw.create_window(width, height, "SPACE WAR", None, None)

    if not window:
        glfw.terminate()
        sys.exit()

    glfw.make_context_current(window)

    # Connecting the callback function 'on_key' to handle keyboard events
    glfw.set_key_callback(window, on_key)

    # Assembling the shader programs (pipeline) with both shaders
    pipeline = es.SimpleTransformShaderProgram()
    texturePipeline = es.SimpleTextureTransformShaderProgram()

    # Telling OpenGL to use our shader program
    glUseProgram(pipeline.shaderProgram)

    # Setting up the clear screen color
    glClearColor(0.0, 0.0, 0.0, 1.0)

    # Creating shapes on GPU memory
    createEnemies(2)
    player = createPlayer()
    background = ve.createBackground()
    gameOver = ve.createGameOver()
    victory = ve.createGameOver(True)

    while not glfw.window_should_close(window):
Exemple #5
0
def draw(p1, p2, p3, p4):
    # Initialize glfw
    if not glfw.init():
        sys.exit()

    width = 600
    height = 600

    window = glfw.create_window(width, height,
                                "Datos acumulados hasta el dia de Hoy", None,
                                None)

    if not window:
        glfw.terminate()
        sys.exit()

    glfw.make_context_current(window)
    glfw.set_key_callback(window, on_key)

    # shaders a usar
    pipeline = es.SimpleTransformShaderProgram()
    pipeline_tex = es.SimpleTextureTransformShaderProgram()
    # matrices
    transform1 = np.matmul(tr.scale(1, 0.5, 0), tr.translate(0, 1.5, 0))
    transform2 = tr.translate(0, -1, 0)
    # textura de la leyenda
    imagen = es.toGPUShape(bs.createTextureQuad("img/leyenda.png", 1, 1),
                           GL_REPEAT, GL_NEAREST)

    # Telling OpenGL to use our shader program
    glUseProgram(pipeline.shaderProgram)

    # Setting up the clear screen color
    glClearColor(1.0, 1.0, 1.0, 1.0)

    torta = createTortaGraph(p1, p2, p3, p4)

    while not glfw.window_should_close(window):
        glfw.poll_events()
        # Clearing the screen in both, color and depth
        glClear(GL_COLOR_BUFFER_BIT)
        # Texturas con fondos transparentes
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        # Shader de textura y dibujar
        glUseProgram(pipeline_tex.shaderProgram)
        glUniformMatrix4fv(
            glGetUniformLocation(pipeline_tex.shaderProgram, "transform"), 1,
            GL_TRUE, transform1)
        pipeline_tex.drawShape(imagen)

        # Cambiar shaders y dibujar grafico de torta
        glUseProgram(pipeline.shaderProgram)
        glUniformMatrix4fv(
            glGetUniformLocation(pipeline.shaderProgram, "transform"), 1,
            GL_TRUE, transform2)
        drawShape(pipeline.shaderProgram, torta)

        # Once the drawing is rendered, buffers are swap so an uncomplete drawing is never seen.
        glfw.swap_buffers(window)

    glfw.terminate()
Exemple #6
0
def Amy_jump(estructura):
    if __name__ == "__main__":

        # Initialize glfw
        if not glfw.init():
            sys.exit()

        width = 700
        height = 700

        window = glfw.create_window(width, height, "Amy Jump", None, None)

        if not window:
            glfw.terminate()
            sys.exit()

        glfw.make_context_current(window)

        # Connecting the callback function 'on_key' to handle keyboard events
        glfw.set_key_callback(window, on_key)

        # Defining shader programs
        pipeline = ls.SimpleGouraudShaderProgram()
        texture_pipeline = es.SimpleTextureModelViewProjectionShaderProgram()
        color_pipeline = es.SimpleModelViewProjectionShaderProgram()
        tex_pipeline = es.SimpleTextureTransformShaderProgram()

        # Telling OpenGL to use our shader program
        glUseProgram(pipeline.shaderProgram)

        # Setting up the clear screen color
        glClearColor(0.85, 0.85, 0.85, 1.0)

        # As we work in 3D, we need to check which part is in front,
        # and which one is at the back
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        # Creamos los objetos
        # Amy
        gpuAmy = es.toGPUShape(shape=readOBJ('amy.obj', (1, 0, 0.5)))

        # Anillo (trofeo)
        gpuAnillo = es.toGPUShape(shape=readOBJ('ring.obj', (0.9, 0.9, 0)))

        # Fondo
        fondo = Fondo()

        #Piso
        piso = bs.createTextureCube('piso.jpg')
        gpupiso = es.toGPUShape(piso, GL_REPEAT, GL_LINEAR)
        piso_transform = tr.matmul(
            [tr.uniformScale(24),
             tr.translate(0, 0, -0.53)])

        # Pantalla de inicio
        amyi = es.toGPUShape(bs.createTextureQuad("amy2.png", 1, 1), GL_REPEAT,
                             GL_LINEAR)

        # Pantala de perdida
        eggman = es.toGPUShape(bs.createTextureQuad("eggman.png", 1, 1),
                               GL_REPEAT, GL_LINEAR)

        # Pantalla de ganador
        amyf = es.toGPUShape(bs.createTextureQuad("am.png", 1, 1), GL_REPEAT,
                             GL_LINEAR)

        # Barras
        barras = CreateBarras()
        barras.create(estructura)

        #Revisamos el tiempo
        t0 = glfw.get_time()

        # Posiciones de Amy
        posX = 0
        posY = 0
        posZ = 0.5

        #Cuenta los fondo que ya se crearon
        count = 1

        # Indica hasta que altura se debe llegar al saltar
        alt = 0

        # Dice si se puede saltar o no
        salto = True

        #Indica cuando se "pierde" por saltar mal
        perder = False

        #Indica cuando se pierde por una flecha
        perder2 = False

        # Dice si se debe mandar una flecha de ataque
        arrow = True

        #Se crea la flecha con las posiciones hacia Amy
        flechas = Flecha(posX, posY, posZ)

        #Tamaño inicial de la imagen de partida, de perdida y de ganador
        ag = 2
        eg = 0
        af = 0

        # rotaciones de Amy
        rotz = np.pi
        rotx = np.pi / 2
        roty = 0

        #Indica si ya estuvo en una barra
        bt = False

        #Rotaciones y posiciones del aro
        ra = 0
        x = 0
        y = 0
        #Indica si gana o pierde
        ganar = False

        while not glfw.window_should_close(window):
            # Using GLFW to check for input events
            glfw.poll_events()

            # Getting the time difference from the previous iteration
            t1 = glfw.get_time()
            dt = t1 - t0
            t0 = t1

            #Se define la vista "fija" del juego
            view = tr.lookAt(np.array([12, -5, 8 + (posZ - 0.5)]),
                             np.array([posX * 0.4, posY * 0.4, posZ]),
                             np.array([0, 0, 1]))

            #Cambia la vista mientras se mantengan apretadas las teclas

            if (glfw.get_key(window, glfw.KEY_B) == glfw.PRESS):
                view = tr.lookAt(np.array([0, 1, 17.5 + (posZ)]),
                                 np.array([0, 0, 0]), np.array([0, 0, 1]))
            if (glfw.get_key(window, glfw.KEY_N) == glfw.PRESS):
                view = tr.lookAt(np.array([-12, -5, 7.5 + posZ]),
                                 np.array([posX, posY, posZ]),
                                 np.array([0, 0, 1]))
            if (glfw.get_key(window, glfw.KEY_M) == glfw.PRESS):
                view = tr.lookAt(np.array([0, 10, -0.5 + posZ]),
                                 np.array([posX, posY, posZ]),
                                 np.array([0, 0, 1]))

            # Setting up the projection transform
            projection = tr.perspective(60,
                                        float(width) / float(height), 0.1, 100)

            # Clearing the screen in both, color and depth
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

            #Dibujamos el fondo
            fondo.Draw(texture_pipeline, projection, view)

            # Revisamos si se debe crear otro fondo
            if posZ > 13 * count:
                fondoazul = FondoAzul(count, fondo)
                count += 1

            #Dibujamos el piso
            glUseProgram(texture_pipeline.shaderProgram)
            glUniformMatrix4fv(
                glGetUniformLocation(texture_pipeline.shaderProgram, "model"),
                1, GL_TRUE, piso_transform)
            glUniformMatrix4fv(
                glGetUniformLocation(texture_pipeline.shaderProgram,
                                     "projection"), 1, GL_TRUE, projection)
            glUniformMatrix4fv(
                glGetUniformLocation(texture_pipeline.shaderProgram, "view"),
                1, GL_TRUE, view)
            texture_pipeline.drawShape(gpupiso)

            # Luz
            glUseProgram(pipeline.shaderProgram)
            glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "La"),
                        1.0, 1.0, 1.0)
            glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "Ld"),
                        1.0, 1.0, 1.0)
            glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "Ls"),
                        1.0, 1.0, 1.0)

            glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "Ka"),
                        0.3, 0.3, 0.3)
            glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "Kd"),
                        0.9, 0.9, 0.9)
            glUniform3f(glGetUniformLocation(pipeline.shaderProgram, "Ks"),
                        0.2, 0.2, 0.2)

            glUniform3f(
                glGetUniformLocation(pipeline.shaderProgram, "lightPosition"),
                0, 0, posZ + 5)
            glUniform3f(
                glGetUniformLocation(pipeline.shaderProgram, "viewPosition"),
                0, 0, posZ + 5)
            glUniform1ui(
                glGetUniformLocation(pipeline.shaderProgram, "shininess"),
                1000)
            glUniform1f(
                glGetUniformLocation(pipeline.shaderProgram,
                                     "constantAttenuation"), 0.01)
            glUniform1f(
                glGetUniformLocation(pipeline.shaderProgram,
                                     "linearAttenuation"), 0.1)
            glUniform1f(
                glGetUniformLocation(pipeline.shaderProgram,
                                     "quadraticAttenuation"), 0.01)

            #Dibujamos a Amy
            glUniformMatrix4fv(
                glGetUniformLocation(pipeline.shaderProgram, "projection"), 1,
                GL_TRUE, projection)
            glUniformMatrix4fv(
                glGetUniformLocation(pipeline.shaderProgram, "view"), 1,
                GL_TRUE, view)
            glUniformMatrix4fv(
                glGetUniformLocation(pipeline.shaderProgram, "model"), 1,
                GL_TRUE,
                tr.matmul([
                    tr.translate(posX, posY, posZ),
                    tr.rotationZ(rotz),
                    tr.rotationX(rotx),
                    tr.rotationY(roty),
                    tr.uniformScale(0.4)
                ]))
            pipeline.drawShape(gpuAmy)

            #Dibujamos el anillo a la altura de la ultima barra
            glUniformMatrix4fv(
                glGetUniformLocation(pipeline.shaderProgram, "model"), 1,
                GL_TRUE,
                tr.matmul([
                    tr.translate(x, y, barras.altura * 2),
                    tr.rotationZ(ra),
                    tr.uniformScale(0.5)
                ]))
            pipeline.drawShape(gpuAnillo)

            # Dibujamos la pantalla inicial
            glUseProgram(tex_pipeline.shaderProgram)
            glUniformMatrix4fv(
                glGetUniformLocation(tex_pipeline.shaderProgram, "transform"),
                1, GL_TRUE,
                tr.matmul([tr.translate(0, 0, 0),
                           tr.uniformScale(ag)]))
            tex_pipeline.drawShape(amyi)

            # Dibujamos la pantalla de perdida
            glUniformMatrix4fv(
                glGetUniformLocation(tex_pipeline.shaderProgram, "transform"),
                1, GL_TRUE,
                tr.matmul([tr.translate(0, 0, 0),
                           tr.uniformScale(eg)]))
            tex_pipeline.drawShape(eggman)

            # Dibujamos la pantalla de ganador
            glUniformMatrix4fv(
                glGetUniformLocation(tex_pipeline.shaderProgram, "transform"),
                1, GL_TRUE,
                tr.matmul([tr.translate(0, 0, 0),
                           tr.uniformScale(af)]))
            tex_pipeline.drawShape(amyf)

            # Hace una copia de la lista de barras
            b = barras.barras

            #Indica que hay gravedad por lo cual amy va a caer mientras no este en una plataforma
            grav = True

            #Cambia el angulo de de rotación del aro
            ra -= 2 * dt

            #Revisa que la posición de las barras calza con Amy
            for i in range(len(b)):
                if posX <= 2 * b[i].posx + 1 and posX >= 2 * b[
                        i].posx - 1 and posY <= 2 * b[
                            i].posy + 1 and posY >= 2 * b[
                                i].posy - 1 and posZ <= b[
                                    i].posz * 0.3 + 1.4 and posZ >= b[
                                        i].posz * 0.3 + 1.25:
                    if b[i].real == False:  #Revisa si la barra es real, de serlo no la dibuja y no apaga la gravedad
                        b[i].dibujo = False
                    else:
                        grav = False  #si no, apaga la gravedad
                        bt = True  #indica que ya se subio una barra

            # Implementa la gravedad
            if posZ > 0.6 and grav == True:
                posZ -= 3 * dt

            #Mueve a Amy dependiendo de la tecla que se precione
            if (glfw.get_key(window, glfw.KEY_A) == glfw.PRESS):
                if posX > -6:
                    posX -= 5 * dt
            if (glfw.get_key(window, glfw.KEY_D) == glfw.PRESS):
                if posX < 6:
                    posX += 5 * dt
            if (glfw.get_key(window, glfw.KEY_W) == glfw.PRESS):
                if posY < 6:
                    posY += 5 * dt
            if (glfw.get_key(window, glfw.KEY_S) == glfw.PRESS):
                if posY > -6:
                    posY -= 5 * dt
            #Implementa los saltos
            if (glfw.get_key(window, glfw.KEY_SPACE) == glfw.PRESS):
                #si se puede saltar
                if salto == True:
                    salto = False  #se bloquea otro salto
                    alt = 2 + posZ  #calcula hasta donde debe llegar
                #si no pierde y no llega al limite de altura
                if alt >= posZ and perder == False:
                    posZ += 5 * dt  #salta
                #Si esta en una barra y aún no pierde
                if grav == False and perder2 == False:
                    salto = True  #Puede volver a saltar
                    perder = False  #aún no pierde
                #Inidica que perdio
                if alt < posZ + 0.01:
                    perder = True
            # Si es que se puede hacer una flecha
            if arrow == True:
                ti = t1  #Revisamos el tiempo actual
                arrow = False  #decimos que no se pueden hacer mas flechas
                flechas = Flecha(posX, posY,
                                 posZ)  #se indica las posicones de la flecha
            # Si ya pasa un tiempo especifico
            if ti + 3 < t1:
                arrow = True  # se puede hacer otra flecha
            #Revisamos que una flecha toca a Amy
            if flechas.posx <= posX + 0.1 and flechas.posx >= posX - 0.1 and flechas.posy <= -posY * 0.2 + 0.1 and flechas.posy >= -posY * 0.2 - 0.1 and flechas.posz <= posZ * 0.2 + 0.1 and flechas.posz >= posZ * 0.2 - 0.1:
                perder2 = True  #Pierde
            #Mueve las flechas a partir de un tiempo en especifico
            if t1 > 8:
                flechas.update(4 * dt)
                flechas.draw(pipeline, projection, view)
            #Hace el movimiento de la imagen inicial
            if t1 < 8:
                if ag > 0:
                    ag -= dt
            #Si pierde genera la imagen de game over y Amy empieza a rotar
            if ((posZ >= 0.5 and posZ <= 0.6 and grav and bt) or perder2 or
                (salto == False and posZ >= 0.5
                 and posZ <= 0.6)) and ganar == False:
                if eg < 2:
                    eg += 0.8 * dt
                rotx -= 2 * dt
                rotz -= 2 * dt
            #Indica cuando gana
            if barras.altura * 2 - posZ <= 0.5 and barras.altura * 2 - posZ >= 0 and grav == False:
                ganar = True
                #Mueve el aro a Amy
                if x < 1.7 * posX:
                    x += 5 * dt
                elif x >= 1.7 * posX:
                    x -= 5 * dt
                if y < 1 * posY:
                    y += 5 * dt
                elif y >= 1 * posY:
                    y -= 5 * dt
                #Hace el movimiento de la imagen de ganador
                if af < 2:
                    af += 0.8 * dt

            #Dibuja las barras
            barras.draw(color_pipeline, projection, view)

            # Once the drawing is rendered, buffers are swap so an uncomplete drawing is never seen.
            glfw.swap_buffers(window)

        glfw.terminate()
Exemple #7
0
def monkey_jump(structure):
    if __name__ == '__main__':

        # Initialize glfw
        if not glfw.init():
            sys.exit()

        width = 700
        height = 700

        window = glfw.create_window(width, height, 'Saltarin', None, None)

        if not window:
            glfw.terminate()
            sys.exit()

        glfw.make_context_current(window)

        # Creamos el controlador
        controlador = Controller()

        # Connecting the callback function 'on_key' to handle keyboard events
        glfw.set_key_callback(window, controlador.on_key)

        # Creating shader programs for textures and for colors
        texture = es.SimpleTextureTransformShaderProgram()
        color = es.SimpleTransformShaderProgram()
    

        # Setting up the clear screen color
        glClearColor(0.15, 0.15, 0.15, 1.0)

   
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_BLEND )

        # Creamos los objetos
        fondo = Fondobaja()
        mono = Mono("parado.png")
        pasto=Pasto()
        
        # Leemos el csv
        def leer(estructura):
                with open(estructura) as csv_file:
                    csv_reader = csv.reader(csv_file, delimiter=',')
                    r=[]
                    for row in csv_reader:
                        r.append(row[0])
                return r
        r=leer(structure)
        #creamos las barras a partir del csv
        barra = BarraCreator(r, mono)
            
        controlador.set_model(mono)
        controlador.set_barra(barra)
        controlador.set_fondo(fondo)

    
        t0=0
        while not glfw.window_should_close(window):

            # Using GLFW to check for input events
            glfw.poll_events()
            
            # Filling or not the shapes depending on the controller state
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
            
            
            # Clearing the screen in both, color and depth
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

            # Dibujamos
            ti = glfw.get_time()
            dt = ti - t0
            t0 = ti
            
            #dibujamos el fondo y hacemos que se mueva
            fondo.create_fondo()
            fondo.update(0.2 * dt)
            fondo.draw(texture)
            
            #Dibujamos el pasto al al comienzo y se comienza a mover
            pasto.update(0.2*dt)
            pasto.draw(texture)
            
            #Dibujamos las barras
            barra.create_barra()  
            barra.update(0.4 * dt)
            
            #se revisan las barras creadas para que el mono salte en ellas y se dibuja el mono
            mono.jump(barra) 
            mono.draw(texture)
            
            #se dibujan las barras
            barra.draw(color)
            
            #si el mono perdió, se pone la pantalla como game over 
            if mono.loser:
                mono=Mono("gameover.png")
                mono.loser=True
                monoTransform=  tr.uniformScale(1.7)
                mono.tra = monoTransform
            
            #si el mono ganó, se indica la victoria 
            elif mono.winner :
                mono=Mono("victory2.png")
                monoTransform=  tr.uniformScale(1.7)
                mono.tra = monoTransform
            
        

            # Once the drawing is rendered, buffers are swap so an uncomplete drawing is never seen.
            glfw.swap_buffers(window)

        glfw.terminate()