Esempio n. 1
0
def remove_arrow(arrow_list,enm,HP_ENM,arrow_dir,sprite_layers,point):   
    # remove arrows if they collide with enemies or go out of field of view
    # decrease the HP of enemy if arrow collides with enemy
    i = 0
    l = len(arrow_list)
    while (i<l and i>=0):
        j=0
        check = 0
        for j in range(len(enm)):
            if pygame.sprite.collide_rect(enm[j],arrow_list[i]):
                if point==10.0:
                    specialarrow_sound = sound.create_soundfx('./sounds/specialarrow_touch.ogg')
                    sound.volume(specialarrow_sound,0.4)
                else:
                    arrow_sound = sound.create_soundfx('./sounds/arrow_touch.ogg')
                    sound.volume(arrow_sound,0.4)
                HP_ENM[j] -= point
                check = 1
                break
        if check==1 or movements1.check_collision(arrow_list[i].rect.centerx, arrow_list[i].rect.centery, 8*arrow_dir[2*i],8*arrow_dir[(2*i)+1],\
                                                  arrow_list[i].rect.width, 5, sprite_layers[3]) == (0,0):
            sprite_layers[1].remove_sprite(arrow_list[i])
            arrow_list.pop(i)
            arrow_dir.pop(2*i)
            arrow_dir.pop(2*i)
        else :
            arrow_list[i].rect.centerx += 25*arrow_dir[2*i]
            arrow_list[i].rect.centery += 25*arrow_dir[(2*i)+1]
            i += 1
        l = len(arrow_list)
Esempio n. 2
0
def remove_arrow(arrow_list, enm, HP_ENM, arrow_dir, sprite_layers, point):
    # remove arrows if they collide with enemies or go out of field of view
    # decrease the HP of enemy if arrow collides with enemy
    i = 0
    l = len(arrow_list)
    while (i < l and i >= 0):
        j = 0
        check = 0
        for j in range(len(enm)):
            if pygame.sprite.collide_rect(enm[j], arrow_list[i]):
                if point == 10.0:
                    specialarrow_sound = sound.create_soundfx(
                        './sounds/specialarrow_touch.ogg')
                    sound.volume(specialarrow_sound, 0.4)
                else:
                    arrow_sound = sound.create_soundfx(
                        './sounds/arrow_touch.ogg')
                    sound.volume(arrow_sound, 0.4)
                HP_ENM[j] -= point
                check = 1
                break
        if check==1 or movements1.check_collision(arrow_list[i].rect.centerx, arrow_list[i].rect.centery, 8*arrow_dir[2*i],8*arrow_dir[(2*i)+1],\
                                                  arrow_list[i].rect.width, 5, sprite_layers[3]) == (0,0):
            sprite_layers[1].remove_sprite(arrow_list[i])
            arrow_list.pop(i)
            arrow_dir.pop(2 * i)
            arrow_dir.pop(2 * i)
        else:
            arrow_list[i].rect.centerx += 25 * arrow_dir[2 * i]
            arrow_list[i].rect.centery += 25 * arrow_dir[(2 * i) + 1]
            i += 1
        l = len(arrow_list)
Esempio n. 3
0
def remove_weapon(hero,enm,weap_list,weap_dir,point,sprite_layers):  
    savegame=pk.load(open("./save.p","rb"))
    # remove weapons if they collide with hero
    # decrease the HP of player if it collides with any of enemies
    # if player has armor then both armor and hero shares the half of the loss
    j = 0
    for j in range(len(enm)):
        if pygame.sprite.collide_rect(hero,enm[j]):
            weap_sound = sound.create_soundfx('./sounds/weapon_touch.ogg')
            sound.volume(weap_sound,0.4)
            if savegame['sheild_hp']>0:
                savegame['sheild_hp'] -= (point/2)
                savegame['hp'] -= (point/2)
                if savegame['sheild_hp']<0:
                    savegame['sheild_hp'] = 0        
            else :
                savegame['hp'] -= point
            pk.dump(savegame,open("./save.p","wb"))    
            
    i = 0
    l = len(weap_list)
    while (i<l and i>=0):
        if pygame.sprite.collide_rect(hero,weap_list[i]):
            weap_sound = sound.create_soundfx('./sounds/weapon_touch.ogg')
            sound.volume(weap_sound,0.7)
            if savegame['sheild_hp']>0:
                savegame['sheild_hp'] -= (point/2)
                savegame['hp'] -= (point/2)
                if savegame['sheild_hp']<0:
                    savegame['sheild_hp'] = 0 
            else:
                savegame['hp'] -= point
            sprite_layers[2].remove_sprite(weap_list[i])
            weap_list.pop(i)
            weap_dir.pop(2*i)
            weap_dir.pop(2*i)
        elif movements1.check_collision(weap_list[i].rect.centerx, weap_list[i].rect.centery, 5*weap_dir[2*i],5*weap_dir[(2*i)+1],weap_list[i].rect.width,\
                                        5, sprite_layers[3]) == (0,0):
            sprite_layers[2].remove_sprite(weap_list[i])
            weap_list.pop(i)
            weap_dir.pop(2*i)
            weap_dir.pop(2*i)
        else :
            weap_list[i].rect.centerx += 5*weap_dir[2*i]
            weap_list[i].rect.centery += 5*weap_dir[(2*i)+1]
            i += 1
        l = len(weap_list)
        pk.dump(savegame,open("./save.p","wb"))
Esempio n. 4
0
def remove_weapon(hero, enm, weap_list, weap_dir, point, sprite_layers):
    savegame = pk.load(open("./save.p", "rb"))
    # remove weapons if they collide with hero
    # decrease the HP of player if it collides with any of enemies
    # if player has armor then both armor and hero shares the half of the loss
    j = 0
    for j in range(len(enm)):
        if pygame.sprite.collide_rect(hero, enm[j]):
            weap_sound = sound.create_soundfx('./sounds/weapon_touch.ogg')
            sound.volume(weap_sound, 0.4)
            if savegame['sheild_hp'] > 0:
                savegame['sheild_hp'] -= (point / 2)
                savegame['hp'] -= (point / 2)
                if savegame['sheild_hp'] < 0:
                    savegame['sheild_hp'] = 0
            else:
                savegame['hp'] -= point
            pk.dump(savegame, open("./save.p", "wb"))

    i = 0
    l = len(weap_list)
    while (i < l and i >= 0):
        if pygame.sprite.collide_rect(hero, weap_list[i]):
            weap_sound = sound.create_soundfx('./sounds/weapon_touch.ogg')
            sound.volume(weap_sound, 0.7)
            if savegame['sheild_hp'] > 0:
                savegame['sheild_hp'] -= (point / 2)
                savegame['hp'] -= (point / 2)
                if savegame['sheild_hp'] < 0:
                    savegame['sheild_hp'] = 0
            else:
                savegame['hp'] -= point
            sprite_layers[2].remove_sprite(weap_list[i])
            weap_list.pop(i)
            weap_dir.pop(2 * i)
            weap_dir.pop(2 * i)
        elif movements1.check_collision(weap_list[i].rect.centerx, weap_list[i].rect.centery, 5*weap_dir[2*i],5*weap_dir[(2*i)+1],weap_list[i].rect.width,\
                                        5, sprite_layers[3]) == (0,0):
            sprite_layers[2].remove_sprite(weap_list[i])
            weap_list.pop(i)
            weap_dir.pop(2 * i)
            weap_dir.pop(2 * i)
        else:
            weap_list[i].rect.centerx += 5 * weap_dir[2 * i]
            weap_list[i].rect.centery += 5 * weap_dir[(2 * i) + 1]
            i += 1
        l = len(weap_list)
        pk.dump(savegame, open("./save.p", "wb"))
Esempio n. 5
0
def move_mon(mon_dir,mon,mon_image,sprite_layers,speed1):
    i = 0
    for i in range(len(mon)):
        next_dir = random.randint(0,1000)
        # if it collides to the collision layer then change the direction
        step_x, step_y = movements1.check_collision(mon[i].rect.centerx, mon[i].rect.centery, speed1*mon_dir[2*i],speed1*mon_dir[(2*i)+1],\
                                                    mon[i].rect.width, 5, sprite_layers[3])
        dx = step_x*100
        dy = step_y*100
        # randomly change the direction of monster depending of next_dir
        if (((-2<dx<2) & (-2<dy<2)) | (next_dir%25 == 0)):
            mon_dir[2*i] = (-1)*mon_dir[2*i]
            mon_dir[(2*i)+1] = (-1)*mon_dir[(2*i)+1]
        (mon,mon_image) = imageupdate(mon_dir,mon,mon_image,i)
        mon[i].rect.centerx += speed1*mon_dir[2*i]
        mon[i].rect.centery += speed1*mon_dir[(2*i)+1]
    return (mon_dir,mon,mon_image)
Esempio n. 6
0
def move_mon(mon_dir, mon, mon_image, sprite_layers, speed1):
    i = 0
    for i in range(len(mon)):
        next_dir = random.randint(0, 1000)
        # if it collides to the collision layer then change the direction
        step_x, step_y = movements1.check_collision(mon[i].rect.centerx, mon[i].rect.centery, speed1*mon_dir[2*i],speed1*mon_dir[(2*i)+1],\
                                                    mon[i].rect.width, 5, sprite_layers[3])
        dx = step_x * 100
        dy = step_y * 100
        # randomly change the direction of monster depending of next_dir
        if (((-2 < dx < 2) & (-2 < dy < 2)) | (next_dir % 25 == 0)):
            mon_dir[2 * i] = (-1) * mon_dir[2 * i]
            mon_dir[(2 * i) + 1] = (-1) * mon_dir[(2 * i) + 1]
        (mon, mon_image) = imageupdate(mon_dir, mon, mon_image, i)
        mon[i].rect.centerx += speed1 * mon_dir[2 * i]
        mon[i].rect.centery += speed1 * mon_dir[(2 * i) + 1]
    return (mon_dir, mon, mon_image)