Beispiel #1
0
    def update(self, t):
        self.update_parent_x()
        self.update_parent_y()
        parent_x = self.get_parent_x()
        parent_y = self.get_parent_y()
        d = self.get_distance()
        w = self.get_velocity()
        new_x = d * sin(w * t)
        new_y = d * cos(w * t)
        self.set_x(new_x + parent_x)
        self.set_y(new_y + parent_y)
        satellites = self.get_satellites_objects()

        model = self.get_model()
        body = sg.findNode(model, 'body')
        body.transform = tr.translate(self.get_x(), self.get_y(), 0)
        orbit = sg.findNode(model, 'orbit')
        orbit.transform = tr.matmul([
            tr.uniformScale(self.get_zoom()),
            tr.translate(self.get_parent_x(), self.get_parent_y(), 0)
        ])

        for planeta in satellites:
            planeta.update(t)

        selection = sg.findNode(model, 'selection_circle')
        if self.selected:
            selection.transform = tr.uniformScale(self.radius + 0.009)
        else:
            selection.transform = tr.uniformScale(0)
Beispiel #2
0
 def draw(self, pipeline):
     if self.last_direction == "D":
         self.face_orientation = "D"
         new_gpu_snake = es.toGPUShape(bs.createTextureQuad("boo_r.png"),
                                       GL_CLAMP, GL_NEAREST)
         sg.findNode(self.model, "snake_head").childs = [new_gpu_snake]
     elif self.last_direction == "A":
         self.face_orientation = "A"
         new_gpu_snake = es.toGPUShape(bs.createTextureQuad("boo_l.png"),
                                       GL_CLAMP, GL_NEAREST)
         sg.findNode(self.model, "snake_head").childs = [new_gpu_snake]
     sg.drawSceneGraphNode(self.model, pipeline, "transform")
Beispiel #3
0
 def move_all(self):
     self.check_life()
     if not self.life_status:
         return
     self.move(self.movement_queue)
     movement = tr.identity()
     if self.next_direction == "W":
         movement = tr.translate(0, 1, 0)
         self.locationY += 1
     elif self.next_direction == "A":
         movement = tr.translate(-1, 0, 0)
         self.locationX += -1
     elif self.next_direction == "S":
         movement = tr.translate(0, -1, 0)
         self.locationY += -1
     elif self.next_direction == "D":
         movement = tr.translate(1, 0, 0)
         self.locationX += 1
     self.queue_movement(self.next_direction)
     self.last_direction = self.next_direction
     if self.check_apple():
         self.eat_apple()
     self.last_position = [self.locationX, self.locationY]
     self.occupied_positions = [self.last_position
                                ] + self.occupied_positions[1:]
     sg.findNode(self.model, "snake_head").transform = tr.matmul(
         [sg.findTransform(self.model, "snake_head"), movement])
Beispiel #4
0
    def draw(self, pipeline, stage):
        # Drawing Structure model with a given pipeline
        # The textures depends on the stage given
        background = sg.findNode(self.model, "background")

        if stage == 0:
            background.childs = [self.texture_0]
        elif stage == 1:
            background.childs = [self.texture_2]
        elif stage == 2:
            background.childs = [self.texture_2]
        elif stage == 3:
            background.childs = [self.texture_3]
        elif stage == 4:
            background.childs = [self.texture_4]
        elif stage == 5:
            background.childs = [self.texture_5]
        elif stage == 6:
            background.childs = [self.texture_6]
        elif stage == 7:
            background.childs = [self.texture_7]
        elif stage == 8:
            background.childs = [self.texture_8]
        elif stage == 9:
            background.childs = [self.texture_9]
        elif stage == 10:
            background.childs = [self.texture_10]

        glUseProgram(pipeline.shaderProgram)
        sg.drawSceneGraphNode(self.model, pipeline, "transform")
Beispiel #5
0
def drawScreen(pipeline, time, background, player):

    global controller
    global logic

    # Local position of the animated flames
    flameLoop = 0.2 * np.sin(12 * time)

    # Drawing the animated background.
    backTime = time % 5
    background.transform = tr.translate(0, -backTime * 0.4, 0)
    sg.drawSceneGraphNode(background, pipeline, "transform")

    # Drawing the explosions of defeated ships
    drawExplosions(time)

    # Drawing the enemies
    for enemy in logic.enemies:
        ship = enemy.ship
        ship.transform = tr.translate(enemy.xPos, enemy.yPos, 0)

        animatedFlame = sg.findNode(ship, "animatedFlame")
        animatedFlame.transform = tr.translate(0, flameLoop, 0)

        sg.drawSceneGraphNode(ship, pipeline, "transform")

    # Drawing the bullets
    for bullet in logic.bullets:
        shape = bullet.shape
        shape.transform = tr.translate(bullet.xPos, bullet.yPos, 0)
        sg.drawSceneGraphNode(shape, pipeline, "transform")

    # Drawing the player
    player.transform = tr.translate(controller.xPos, controller.yPos, 0)

    animatedFlame = sg.findNode(player, "animatedFlame")
    animatedFlame.transform = tr.translate(0, flameLoop, 0)

    sg.drawSceneGraphNode(player, pipeline, "transform")

    # Drawing the lifebar of the player, with the corresponding colors
    drawLifeBar(pipeline, logic.hp)
Beispiel #6
0
    def add_body(self):
        posX = self.body_queue[
            len(self.body_queue) - 1]["last_position"][0] if len(
                self.body_queue) > 0 else self.last_position[0]
        posY = self.body_queue[
            len(self.body_queue) - 1]["last_position"][1] if len(
                self.body_queue) > 0 else self.last_position[1]
        snake_body = sg.SceneGraphNode(f'snake_body_{len(self.body_queue)}')
        snake_body.transform = tr.matmul([
            tr.scale(self.dimensions[0] / self.tiles,
                     self.dimensions[1] / self.tiles, 0),
            tr.translate(-self.tiles / 2 + posX + 0.5,
                         -self.tiles / 2 + posY - 0.5, 0)
        ])
        snake_body.childs += [self.gpu_body]

        self.body_queue.append({
            "name": f'snake_body_{len(self.body_queue)}',
            "position": [posX, posY],
            "last_position": [posX, posY]
        })

        sg.findNode(self.model, "snake").childs += [snake_body]
Beispiel #7
0
    def draw(self, pipeline_texture):
        # Draws the monkey model with a given pipeline texture
        # The state depends on the state of the monkey

        monkey_body = sg.findNode(self.model, "body")

        if self.is_jumping or self.is_falling:
            monkey_body.childs = [self.gpu_texture_jumping]
        elif self.position_x > self.aiming_x:
            monkey_body.childs = [self.gpu_texture_left]
        elif self.position_x < self.aiming_x:
            monkey_body.childs = [self.gpu_texture_right]
        else:
            monkey_body.childs = [self.gpu_texture_monkey]

        glUseProgram(pipeline_texture.shaderProgram)
        sg.drawSceneGraphNode(self.model, pipeline_texture, 'transform')
Beispiel #8
0
    def draw(self, pipeline_texture, t):
        # Drawing Structure model with a given pipeline
        # The texture depends on the given time variable

        scene = sg.findNode(self.model, "scene")

        if t < 0.2:
            scene.childs = [self.texture_1]
        elif 0.4 >= t >= 0.2:
            scene.childs = [self.texture_2]
        elif 0.6 >= t >= 0.4:
            scene.childs = [self.texture_3]
        elif 0.8 >= t >= 0.6:
            scene.childs = [self.texture_4]
        else:
            scene.childs = [self.texture_5]

        glUseProgram(pipeline_texture.shaderProgram)
        sg.drawSceneGraphNode(self.model, pipeline_texture, 'transform')
Beispiel #9
0
    def move(self, move_Q):
        moveX = 0
        moveY = 0
        movement = tr.identity()
        body_positions = []
        for i in range(len(self.body_queue)):
            direction = move_Q[len(move_Q) - 1 - i]
            if direction == "W":
                movement = tr.translate(0, 1, 0)
                moveY = 1
            elif direction == "A":
                movement = tr.translate(-1, 0, 0)
                moveX = -1
            elif direction == "S":
                movement = tr.translate(0, -1, 0)
                moveY = -1
            elif direction == "D":
                movement = tr.translate(1, 0, 0)
                moveX = 1
            sg.findNode(self.model,
                        self.body_queue[i]["name"]).transform = tr.matmul([
                            sg.findTransform(self.model,
                                             self.body_queue[i]["name"]),
                            movement
                        ])
            self.body_queue[i]["last_position"][0] = self.body_queue[i][
                "position"][0]
            self.body_queue[i]["last_position"][1] = self.body_queue[i][
                "position"][1]
            self.body_queue[i]["position"][
                0] = self.body_queue[i]["position"][0] + moveX
            self.body_queue[i]["position"][
                1] = self.body_queue[i]["position"][1] + moveY
            moveX = 0
            moveY = 0
            body_positions.append(self.body_queue[i]["position"])

        self.occupied_positions = self.occupied_positions[0] + body_positions
Beispiel #10
0
                                 "quadraticAttenuation"), 0.01)

        glUniformMatrix4fv(
            glGetUniformLocation(phongPipeline.shaderProgram, "projection"), 1,
            GL_TRUE, projection)
        glUniformMatrix4fv(
            glGetUniformLocation(phongPipeline.shaderProgram, "view"), 1,
            GL_TRUE, view)
        glUniformMatrix4fv(
            glGetUniformLocation(phongPipeline.shaderProgram, "model"), 1,
            GL_TRUE, model)

        # Movement of the wings
        for birdNode in birdNodes:
            # Right wing
            upperRightRotationNode = sg.findNode(birdNode,
                                                 "upperRightRotation")
            upperRightRotationNode.transform = tr.rotationX(-rotation)
            foreRightRotationNode = sg.findNode(birdNode, "foreRightRotation")
            foreRightRotationNode.transform = tr.matmul([
                tr.translate(0, -0.58, 0),
                tr.rotationX(-4 * rotation),
                tr.translate(0, 0.58, 0)
            ])
            # Left wing
            upperLeftRotationNode = sg.findNode(birdNode, "upperLeftRotation")
            upperLeftRotationNode.transform = tr.rotationX(rotation)
            foreLeftRotationNode = sg.findNode(birdNode, "foreLeftRotation")
            foreLeftRotationNode.transform = tr.matmul([
                tr.translate(0, 0.58, 0),
                tr.rotationX(4 * rotation),
                tr.translate(0, -0.58, 0)
Beispiel #11
0
        # Lose condition upon reaching base of scene
        if controller.monkey.y < scene_movement + 0.3 and controller.lost is False:
            controller.lost = True
            controller.end_game_time = theta

        # Lose animation start and end
        if controller.lost:
            monkey_left = False
            monkey_right = False
            controller.monkey.collision = False
            controller.monkey.start_jump()
            controller.monkey.is_falling = False
            controller.leftKeyOn = False
            controller.rightKeyOn = False
            sg.findNode(main_scene_translate, "Monkey Texture").childs = \
                [monkey_texture_lost]
            if theta - controller.end_game_time > 0.35:
                sys.exit("You fell out.")

        # Win condition
        if controller.won is False and controller.monkey.has_banana:
            controller.won = True
            controller.end_game_time = theta
        elif controller.won:
            sg.findNode(main_scene_translate, "Monkey Texture").childs = \
                [monkey_texture_won]
            monkey_left = False
            monkey_right = False
            controller.leftKeyOn = False
            controller.rightKeyOn = False
        # Clearing the screen in both, color and depth
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Filling or not the shapes depending on the controller state
        if (controller.fillPolygon):
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
        else:
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)

        if controller.showAxis:
            glUniformMatrix4fv(glGetUniformLocation(mvcPipeline.shaderProgram, "model"), 1, GL_TRUE, tr.identity())
            mvcPipeline.drawShape(gpuAxis, GL_LINES)

        # Moving the red car and rotating its wheels
        redCarNode.transform = tr.translate(3 * np.sin( glfw.get_time() ),0,0.5)
        redWheelRotationNode = sg.findNode(redCarNode, "wheelRotation")
        redWheelRotationNode.transform = tr.rotationY(-10 * glfw.get_time())

        # Uncomment to print the red car position on every iteration
        #print(sg.findPosition(redCarNode, "car"))

        # Drawing the Car
        sg.drawSceneGraphNode(redCarNode, mvcPipeline, "model")
        sg.drawSceneGraphNode(blueCarNode, mvcPipeline, "model")

        # Once the render is done, buffers are swapped, showing only the complete scene.
        glfw.swap_buffers(window)

    
    glfw.terminate()
Beispiel #13
0
    # Telling OpenGL to use our shader program
    glUseProgram(shaderProgram)

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

    # Creating shapes on GPU memory
    car = createCar()

    # Our shapes here are always fully painted
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

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

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

        # Modifying only a specific node in the scene graph
        wheelRotationNode = sg.findNode(car, "wheelRotation")
        theta = -10 * glfw.get_time()
        wheelRotationNode.transform = tr.rotationZ(theta)

        # Drawing the Car
        sg.drawSceneGraphNode(car, shaderProgram, tr.identity())

        # Once the render is done, buffers are swapped, showing only the complete scene.
        glfw.swap_buffers(window)

    glfw.terminate()
Beispiel #14
0
 def draw_game_over(self, pipeline, dt):
     sg.findNode(self.g_over, "game_over_banner_TR").transform = tr.matmul([
         sg.findTransform(self.g_over, "game_over_banner_TR"),
         tr.rotationZ(dt)
     ])
     sg.drawSceneGraphNode(self.g_over, pipeline, "transform")
		x = controller.x 
		y = controller.y
		z = -controller.z

		view = tr.lookAt(
			np.array([0 + x,-0.0015 + y,7 + z]),
			np.array([x, y,0]),
			np.array([0,0,1])
		)

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

		nodoAnterior = sg.findNode(malla, "T" + cursoAnterior.codigo)
		tapaAnt = nodoAnterior.childs[1]
		nodoAnterior.childs = [cuboR, tapaAnt]

		nodoAnterior = sg.findNode(malla, cursoAnterior.codigo)
		nodoAnterior.transform = tr.scale(1,1,1)

		for requisitoAnt in cursoAnterior.requisitos:
			nodoReqAnt = sg.findNode(malla, "T" + requisitoAnt)
			tapaReqAnt = nodoReqAnt.childs[1]
			nodoReqAnt.childs = [cuboR, tapaReqAnt]

			nodoReqAnt = sg.findNode(malla, requisitoAnt)
			nodoReqAnt.transform = tr.scale(1,1,1)

		for requisitoDeAnt in cursoAnterior.requisitosDe:
Beispiel #16
0
        elif glfw.get_key(window, glfw.KEY_DOWN) == glfw.PRESS:
            if zoom > 0.4:
                zoom -= 0.05

        # Zoom transformations
        scaledSurfaceA.transform = tr.uniformScale(zoom)
        scaledSurfaceB.transform = tr.uniformScale(zoom)
        scaledSurfaceC.transform = tr.uniformScale(zoom)
        scaledBorder.transform = tr.uniformScale(zoom)

        # Fish transformations
        for i in range(len(fishesA)):
            fishesA[i].transform = tr.matmul([tr.uniformScale(zoom),
                                              tr.translate(pointsA[nas[i]][1] - 20, pointsA[nas[i]][0] - 10, pointsA[nas[i]][2] - 10),
                                              tr.rotationZ(randomRotationA[i])])
            tailRotationA = sg.findNode(fishesA[i], 'tailRotation')
            tailRotationA.transform = tr.rotationZ(rotation)

        for i in range(len(fishesB)):
            fishesB[i].transform = tr.matmul([tr.uniformScale(zoom),
                                              tr.translate(pointsB[nbs[i]][1] - 20, pointsB[nbs[i]][0] - 10, pointsB[nbs[i]][2] - 10),
                                              tr.rotationZ(randomRotationB[i])])
            tailRotationB = sg.findNode(fishesB[i], 'tailRotation')
            tailRotationB.transform = tr.rotationZ(rotation)

        for i in range(len(fishesC)):
            fishesC[i].transform = tr.matmul([tr.uniformScale(zoom),
                                              tr.translate(pointsC[ncs[i]][1] - 20, pointsC[ncs[i]][0] - 10, pointsC[ncs[i]][2] - 10),
                                              tr.rotationZ(randomRotationC[i])])
            tailRotationC = sg.findNode(fishesC[i], 'tailRotation')
            tailRotationC.transform = tr.rotationZ(rotation)
Beispiel #17
0
    def enfermar(self):
        gpu_triangulo_rojo = es.toGPUShape(bs.createColorTriangle(1, 0, 0))

        self.estado = 'Enferma'
        triangulo = sg.findNode(self.model, 'triangulo')
        triangulo.childs = [gpu_triangulo_rojo]
Beispiel #18
0
        pipeline2 = es.SimpleTextureTransformShaderProgram()

        glUseProgram(pipeline2.shaderProgram)



        sg.drawSceneGraphNode(sky, pipeline2, "transform")


        pipeline = es.SimpleTransformShaderProgram()


        glUseProgram(pipeline.shaderProgram)

        riel=sg.findNode(rollercoaster,'riel')
        #creando el movimiento del rollercoaster
        riel.transform=np.matmul(tr.uniformScale(1.7), tr.translate(-0.29-0.0001*int(t), -0.025, 0))
        carro=sg.findNode(rollercoaster,"rollercoaster")
        #evitando que se indetermine el angulo
        while curva[n][0] - curva[n - 1][0] == 0:
            n+=1
            t+=1
        #calculando el angulo de rotacion del carrito
        angulo=np.arctan((curva[n][1]-curva[n-1][1])/(curva[n][0]-curva[n-1][0]))

        #viendo si el carrito esta en el vacio
        for punto in cortes:
         if (0<punto[0] - curva[n][0] <= 0.002)  and vacio==0:
            vacio=1
            contador=0