Exemplo n.º 1
0
def setupEnemyBullets(image, main_node):
    global bullet0_animation, bullet1_animation, bullet2_animation
    #ENEMY 0 BULLET SETUP
    bullet0_image = anim.createFrames(image, [64, 64], [0, 0], [1], [0, 2]) #se recorta la imagen
    bullet0_explote_frames = anim.createFrames(image, [64, 64], [0, 0], [6], [0, 3])
    # se crean las animaciones
    bullet0_anim = anim.Animation(bullet0_image, 1, True, False)
    bullet0_explote_anim = anim.Animation(bullet0_explote_frames, 12, False, False)
    # se crea la agrupacion de animaciones
    bullet0_animation = {"shooted" : bullet0_anim, "explote" : bullet0_explote_anim}

    # ENEMY 1 BULLET SETUP
    bullet1_image = anim.createFrames(image, [64, 64], [0, 0], [1], [0, 6]) #se recorta la imagen
    bullet1_explote_frames = anim.createFrames(image, [64, 64], [0, 0], [6], [0, 7])
    # se crean las animaciones
    bullet1_anim = anim.Animation(bullet1_image, 1, True, False)
    bullet1_explote_anim = anim.Animation(bullet1_explote_frames, 12, False, False)
    # se crea la agrupacion de animaciones
    bullet1_animation = {"shooted": bullet1_anim, "explote": bullet1_explote_anim}

    # ENEMY 2 BULLET SETUP
    bullet2_image = anim.createFrames(image, [64, 64], [0, 0], [1], [0, 10]) #se recorta la imagen
    bullet2_explote_frames = anim.createFrames(image, [64, 64], [0, 0], [6], [0, 11])
    # se crean las animaciones
    bullet2_anim = anim.Animation(bullet2_image, 1, True, False)
    bullet2_explote_anim = anim.Animation(bullet2_explote_frames, 12, False, False)
    # se crea la agrupacion de animaciones
    bullet2_animation = {"shooted": bullet2_anim, "explote": bullet2_explote_anim}

    # se crea la coleccion de balas y se agrega al nodo principal
    bullets_collection = sg.SceneGraphNode("enemy_bullets")
    main_node.childs += [bullets_collection]

    # retorna una referencia a la coleccion de balas enemigas
    return go.findNode(main_node, "enemy_bullets")
Exemplo n.º 2
0
def setupPlayerBullets(image, main_node, player):
    #recorta la imagen de la bala y crea una gpuShape
    bullet_image = anim.createFrames(image, [128, 128], [0, 0], [1], [0, 2])
    player.bullet = bullet_image[0] #se le entrega al objeto player
    #se crea al nodo que contendra las balas disparadas por Player
    bullets_collection = sg.SceneGraphNode("player_bullets")
    #se agrega la coleccion de balas al nodo principal
    main_node.childs += [bullets_collection]

    #retorna la refencia a la coleciion de balas
    return go.findNode(main_node, "player_bullets")
Exemplo n.º 3
0
def setupPlayer(image, main_node):
    #Se crean los distintos frames para cada animacion, recortando la imagen
    ship_frames1 = anim.createFrames(image, [128, 128], [0, 0], [2], [0, 0]) #animacion para avanzar
    ship_frames2 = anim.createFrames(image, [128, 128], [0, 0], [2], [0, 1]) #animacion para retroceder
    hurt_frames = anim.createFrames(image, [128, 128], [0, 0], [2], [2, 2]) # animacion cuando le llega una bala
    explode_frames = anim.createFrames(image, [128, 128], [0, 0], [2, 5], [2, 0]) # animacion de explosion

    #se crea un diccionario con las animaciones
    ship_animations = {}
    ship_animations["fast"] = anim.Animation(ship_frames1, 12, True, False)
    ship_animations["slow"] = anim.Animation(ship_frames2, 12, True, False)
    ship_animations["hurt"] = anim.Animation(hurt_frames, 12, True, False)
    ship_animations["explode"] = anim.Animation(explode_frames, 9, False, False)

    #se crea el controlador de animaciones y se inicializa
    ship_Anim = anim.Anim_Controller(ship_animations, [PLAYER_SIZE, WIDTH / HEIGHT * PLAYER_SIZE, 1], 0)
    ship_Anim.Play("slow")

    #se crea un nodo que contiene la animacion
    anim_node = sg.SceneGraphNode("anim_player")
    anim_node.childs += [ship_Anim]

    # se crea un nodo con una gpuShape que servira para detectar las colisiones y verlas si se quiere
    collision_node = sg.SceneGraphNode("collision_player")
    collision_node.childs +=  [es.toGPUShape(cl.createCircleHitbox(PLAYER_HITBOX_RADIO, 10, 0, 1, 0))]

    # se crea uno nodo/objeto CollisionShape que tiene informacion y metodos para detectar colisiones con respecto de una gpuShape
    scaled_collision = cl.CollisionShape("scaled_collision", PLAYER_HITBOX_RADIO, True)
    # se escala la hitbox para que tenga el mismo tamaño que la textura
    scaled_collision.transform = tr.scale(1, 1 * WIDTH/HEIGHT, 1)
    scaled_collision.childs += [collision_node]

    # se crea el objeto player que contendra como nodos hijos a la animacion y la hitbox
    player_gameObject = playerObject("player")
    # se traslada la nave en la pantalla a su posicion inicial
    player_gameObject.transform = tr.translate(0, -0.5, 0)
    player_gameObject.position[0] = 0
    player_gameObject.position[1] = -0.5
    player_gameObject.position[2] = 0
    player_gameObject.childs += [anim_node] #se agrega la animacion
    player_gameObject.childs += [scaled_collision] #se agrega la hitbox
    player_gameObject.childs[1].parent = player_gameObject # se agrega la referencia de padre al objeto CollisionShape

    #agrega el objeto player a la escena principal
    main_node.childs += [player_gameObject]

    #retorna la referencia al objeto player
    return go.findNode(main_node, "player")
Exemplo n.º 4
0
def setupHearts(image, main_node):
    #recorta la imagen de los corazones y crea una gpuShape
    heart_Image =anim.createFrames(image, [128, 128], [0, 0], [1], [1, 2])
    heartGPU = heart_Image[0]
    #se crea la coleccion de corazones
    hearts_collection = sg.SceneGraphNode("hearts")
    #se añaden los corazones con los parametros definidos
    for i in range(3):
        heart = sg.SceneGraphNode("heart")
        heart.transform = tr.scale(HEART_SIZE, HEART_SIZE * WIDTH/HEIGHT, 1)
        heart.childs += [heartGPU]

        scaledHeart = go.gameObject("scaledHeart")
        scaledHeart.transform = tr.translate(HEART1_POSX + i*HEARTS_LENGTH/2, HEARTS_POSY, 0)
        scaledHeart.childs += [heart]

        hearts_collection.childs += [scaledHeart]
    #se agregan los corazones al nodo principal
    main_node.childs += [hearts_collection]
    #retorna la referencia a la coleccion de corazones
    return go.findNode(main_node, "hearts")
Exemplo n.º 5
0
def setupEnemies(image, main_node, enemies_amount):
    global enemy0_animations, enemy1_animations, enemy2_animations, ENEMIES_LEFT, CURRENT_ENEMY

    # ENEMY0 SETUP
    enemy0_flying_frames = anim.createFrames(image, [64, 64], [0, 0], [4], [0, 0]) #se recorta la imagen
    enemy0_explote_frames = anim.createFrames(image, [64, 64], [0, 0], [9], [0, 1])
    #se crean las animaciones
    enemy0_flying_anim = anim.Animation(enemy0_flying_frames, 12, True, False)
    enemy0_explote_anim = anim.Animation(enemy0_explote_frames, 12, False, False)
    #se crea la agrupacion de animaciones
    enemy0_animations = {"flying" : enemy0_flying_anim, "explote" : enemy0_explote_anim}

    #ENEMY1 SETUP
    enemy1_flying_frames = anim.createFrames(image, [64, 64], [0, 0], [4], [0, 4]) #se recorta la imagen
    enemy1_explote_frames = anim.createFrames(image, [64, 64], [0, 0], [9], [0, 5])
    # se crean las animaciones
    enemy1_flying_anim = anim.Animation(enemy1_flying_frames, 12, True, False)
    enemy1_explote_anim = anim.Animation(enemy1_explote_frames, 12, False, False)
    # se crea la agrupacion de animaciones
    enemy1_animations = {"flying": enemy1_flying_anim, "explote": enemy1_explote_anim}

    # ENEMY2 SETUP
    enemy2_flying_frames = anim.createFrames(image, [64, 64], [0, 0], [4], [0, 8]) #se recorta la imagen
    enemy2_explote_frames = anim.createFrames(image, [64, 64], [0, 0], [9], [0, 9])
    # se crean las animaciones
    enemy2_flying_anim = anim.Animation(enemy2_flying_frames, 12, True, False)
    enemy2_explote_anim = anim.Animation(enemy2_explote_frames, 12, False, False)
    # se crea la agrupacion de animaciones
    enemy2_animations = {"flying": enemy2_flying_anim, "explote": enemy2_explote_anim}

    #se crea la coleccion de enmigos y se agrega al nodo principal
    enemies_collection = sg.SceneGraphNode("enemies")
    main_node.childs += [enemies_collection]
    Enemies = go.findNode(main_node, "enemies")

    #se define la cantidad de enemigos restantes
    ENEMIES_LEFT = enemies_amount
    #se elige un tipo de enemigos aleatoriamente
    random_enemy = random.randint(0, ENEMIES - 1)
    if enemies_amount <=5:
        #si la cantidad de enemigos es menor a 5 apaarece un grupo de enemy1
        addEnemies1(Enemies, enemies_amount)
        ENEMIES_LEFT -= enemies_amount
        CURRENT_ENEMY = 1
    elif random_enemy == 0:
        #aparece un grupo de enemy0 y se actualizan las variables
        addEnemies0(Enemies, ENEMY0_AMOUNT)
        ENEMIES_LEFT -= ENEMY0_AMOUNT
        CURRENT_ENEMY = 0
    elif random_enemy == 1:
        # aparece un grupo de enemy1 y se actualizan las variables
        addEnemies1(Enemies, ENEMY1_AMOUNT)
        ENEMIES_LEFT -= ENEMY1_AMOUNT
        CURRENT_ENEMY = 1
    elif random_enemy == 2:
        # aparece un grupo de enemy2 y se actualizan las variables
        addEnemies2(Enemies, ENEMY2_AMOUNT)
        ENEMIES_LEFT -= ENEMY2_AMOUNT
        CURRENT_ENEMY = 2

    #retorna una referencia a la coleccion de enemigos
    return Enemies